aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/foi_attachment_spec.rb18
-rw-r--r--spec/models/info_request_event_spec.rb5
-rw-r--r--spec/models/xapian_spec.rb19
3 files changed, 24 insertions, 18 deletions
diff --git a/spec/models/foi_attachment_spec.rb b/spec/models/foi_attachment_spec.rb
index d8166dddc..05c4fc5fd 100644
--- a/spec/models/foi_attachment_spec.rb
+++ b/spec/models/foi_attachment_spec.rb
@@ -20,17 +20,17 @@ describe FoiAttachment, " when calculating due date" do
attachment.display_size.should == "0K"
end
it "reparses the body if it disappears" do
- mail_body = load_file_fixture('incoming-request-attach-attachments.email')
- mail = TMail::Mail.parse(mail_body)
- mail.base64_decode
im = incoming_messages(:useless_incoming_message)
- im.stub!(:mail).and_return(mail)
- #im.extract_attachments!
- attachments = im.get_attachments_for_display
- FileUtils.rm attachments[0].filepath
+ im.extract_attachments!
+ main = im.get_main_body_text_part
+ orig_body = main.body
+ main.delete_cached_file!
lambda {
- attachments = im.get_attachments_for_display
- body = attachments[0].body
+ 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
diff --git a/spec/models/info_request_event_spec.rb b/spec/models/info_request_event_spec.rb
index 3229284cc..5423b8da8 100644
--- a/spec/models/info_request_event_spec.rb
+++ b/spec/models/info_request_event_spec.rb
@@ -29,7 +29,8 @@ describe InfoRequestEvent do
describe "should know" do
it "that it's an incoming message" do
- event = InfoRequestEvent.new(:incoming_message => mock_model(IncomingMessage))
+ event = InfoRequestEvent.new()
+ event.stub!(:incoming_message_selective_columns).and_return(1)
event.is_incoming_message?.should be_true
event.is_outgoing_message?.should be_false
event.is_comment?.should be_false
@@ -37,6 +38,7 @@ describe InfoRequestEvent do
it "that it's an outgoing message" do
event = InfoRequestEvent.new(:outgoing_message => mock_model(OutgoingMessage))
+ event.id = 1
event.is_incoming_message?.should be_false
event.is_outgoing_message?.should be_true
event.is_comment?.should be_false
@@ -44,6 +46,7 @@ describe InfoRequestEvent do
it "that it's a comment" do
event = InfoRequestEvent.new(:comment => mock_model(Comment))
+ event.id = 1
event.is_incoming_message?.should be_false
event.is_outgoing_message?.should be_false
event.is_comment?.should be_true
diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb
index ec11c944b..ebd6b1890 100644
--- a/spec/models/xapian_spec.rb
+++ b/spec/models/xapian_spec.rb
@@ -63,6 +63,9 @@ describe PublicBody, " when indexing public bodies with Xapian" do
xapian_object.results.size.should == 1
xapian_object.results[0][:model].should == public_bodies(:humpadink_public_body)
+ info_request_events(:badger_outgoing_message_event).destroy
+ outgoing_messages(:badger_outgoing_message).destroy
+ info_requests(:badger_request).destroy
public_bodies(:humpadink_public_body).destroy
update_xapian_index
@@ -141,16 +144,16 @@ describe User, " when indexing requests by user they are from" do
it "should find requests from the user" do
rebuild_xapian_index
xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith", 'created_at', true, nil, 100, 1)
- xapian_object.results.size.should == 4
+ xapian_object.results.size.should == 5
end
it "should find just the sent message events from a particular user" do
rebuild_xapian_index
# def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page)
xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith variety:sent", 'created_at', true, nil, 100, 1)
- xapian_object.results.size.should == 2
- xapian_object.results[1][:model].should == info_request_events(:useless_outgoing_message_event)
- xapian_object.results[0][:model].should == info_request_events(:silly_outgoing_message_event)
+ xapian_object.results.size.should == 3
+ xapian_object.results[2][:model].should == info_request_events(:useless_outgoing_message_event)
+ xapian_object.results[1][:model].should == info_request_events(:silly_outgoing_message_event)
end
it "should not find it when one of the request's users is changed" do
@@ -164,8 +167,8 @@ describe User, " when indexing requests by user they are from" do
# def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page)
xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith", 'created_at', true, 'request_collapse', 100, 1)
- xapian_object.results.size.should == 1
- xapian_object.results[0][:model].should == info_request_events(:silly_comment_event)
+ xapian_object.results.size.should == 2
+ xapian_object.results[1][:model].should == info_request_events(:silly_comment_event)
end
it "should not get confused searching for requests when one user has a name which has same stem as another" do
@@ -198,7 +201,7 @@ describe User, " when indexing requests by user they are from" do
# initial search
rebuild_xapian_index
xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith", 'created_at', true, nil, 100, 1)
- xapian_object.results.size.should == 4
+ xapian_object.results.size.should == 5
models_found_before = xapian_object.results.map { |x| x[:model] }
# change the URL name of the body
@@ -212,7 +215,7 @@ describe User, " when indexing requests by user they are from" do
xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith", 'created_at', true, nil, 100, 1)
xapian_object.results.size.should == 0
xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:robert_smith", 'created_at', true, nil, 100, 1)
- xapian_object.results.size.should == 4
+ xapian_object.results.size.should == 5
models_found_after = xapian_object.results.map { |x| x[:model] }
models_found_before.should == models_found_after