aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/foi_attachment_spec.rb
blob: 05c4fc5fd799517c323feded94b01ff92d17add4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe FoiAttachment, " when calculating due date" do
    fixtures :incoming_messages, :raw_emails, :public_bodies, :public_body_translations, :info_requests, :users, :foi_attachments

    before(:each) do
        load_raw_emails_data(raw_emails)
    end

    it "sets the body" do
        attachment = FoiAttachment.new
        attachment.body = "baz"
        attachment.body.should == "baz"
    end
    it "sets the size" do
        attachment = FoiAttachment.new
        attachment.body = "baz"
        attachment.body.should == "baz"
        attachment.update_display_size!
        attachment.display_size.should == "0K"
    end
    it "reparses the body if it disappears" do
        im = incoming_messages(:useless_incoming_message)
        im.extract_attachments!
        main = im.get_main_body_text_part
        orig_body = main.body
        main.delete_cached_file!
        lambda {
            im.get_main_body_text_part.body
        }.should_not raise_error(Errno::ENOENT)
        main.delete_cached_file!
        main = im.get_main_body_text_part
        main.body.should == orig_body
        
    end
end