aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/incoming_message_spec.rb68
-rw-r--r--spec/models/info_request_spec.rb83
-rw-r--r--spec/models/outgoing_mailer_spec.rb58
-rw-r--r--spec/models/outgoing_message_spec.rb2
-rw-r--r--spec/models/public_body_spec.rb32
-rw-r--r--spec/models/raw_email_spec.rb23
-rw-r--r--spec/models/request_mailer_spec.rb6
-rw-r--r--spec/models/track_mailer_spec.rb10
-rw-r--r--spec/models/user_spec.rb4
-rw-r--r--spec/models/xapian_spec.rb124
10 files changed, 359 insertions, 51 deletions
diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb
index f08f1338c..f41dff06d 100644
--- a/spec/models/incoming_message_spec.rb
+++ b/spec/models/incoming_message_spec.rb
@@ -109,7 +109,7 @@ describe IncomingMessage, " checking validity to reply to" do
end
describe IncomingMessage, " when censoring data" do
- fixtures :incoming_messages, :raw_emails
+ fixtures :incoming_messages, :raw_emails, :public_bodies, :info_requests
before do
@test_data = "There was a mouse called Stilton, he wished that he was blue."
@@ -157,6 +157,9 @@ describe IncomingMessage, " when censoring data" do
data.should == "His email was x\000x\000x\000@\000x\000x\000x\000.\000x\000x\000x\000, indeed"
end
+ # As at March 9th 2010: This test fails with pdftk 1.41+dfsg-1 installed
+ # which is in Ubuntu Karmic. It works again for the lasest version
+ # 1.41+dfsg-7 in Debian unstable. And it works for Debian stable.
it "should replace everything in PDF files" do
orig_pdf = load_file_fixture('tfl.pdf')
pdf = orig_pdf.dup
@@ -171,6 +174,13 @@ describe IncomingMessage, " when censoring data" do
masked_text.should match(/xxx@xxx.xxx.xx/)
end
+ it "should not produce zero length output if pdftk silently fails" do
+ orig_pdf = load_file_fixture('psni.pdf')
+ pdf = orig_pdf.dup
+ @im.binary_mask_stuff!(pdf, "application/pdf")
+ pdf.should_not == ""
+ end
+
it "should apply censor rules to HTML files" do
data = @test_data.dup
@im.html_mask_stuff!(data)
@@ -228,4 +238,60 @@ describe IncomingMessage, " when uudecoding bad messages" do
end
+describe IncomingMessage, "when messages are attached to messages" do
+ it "should flatten all the attachments out" do
+ mail_body = load_file_fixture('incoming-request-attach-attachments.email')
+ mail = TMail::Mail.parse(mail_body)
+ mail.base64_decode
+
+ im = IncomingMessage.new
+ im.stub!(:mail).and_return(mail)
+ ir = InfoRequest.new
+ im.info_request = ir
+
+ attachments = im.get_attachments_for_display
+ attachments.size.should == 3
+ attachments[0].display_filename.should == 'Same attachment twice.txt'
+ attachments[1].display_filename.should == 'hello.txt'
+ attachments[2].display_filename.should == 'hello.txt'
+ end
+end
+
+describe IncomingMessage, "when Outlook messages are attached to messages" do
+ it "should flatten all the attachments out" do
+ mail_body = load_file_fixture('incoming-request-oft-attachments.email')
+ mail = TMail::Mail.parse(mail_body)
+ mail.base64_decode
+
+ im = IncomingMessage.new
+ im.stub!(:mail).and_return(mail)
+ ir = InfoRequest.new
+ im.info_request = ir
+
+ attachments = im.get_attachments_for_display
+ attachments.size.should == 2
+ attachments[0].display_filename.should == 'test.html' # picks HTML rather than text by default, as likely to render better
+ attachments[1].display_filename.should == 'attach.txt'
+ end
+end
+
+describe IncomingMessage, "when TNEF attachments are attached to messages" do
+ it "should flatten all the attachments out" do
+ mail_body = load_file_fixture('incoming-request-tnef-attachments.email')
+ mail = TMail::Mail.parse(mail_body)
+ mail.base64_decode
+
+ im = IncomingMessage.new
+ im.stub!(:mail).and_return(mail)
+ ir = InfoRequest.new
+ im.info_request = ir
+
+ attachments = im.get_attachments_for_display
+ attachments.size.should == 2
+ attachments[0].display_filename.should == 'FOI 09 02976i.doc'
+ attachments[1].display_filename.should == 'FOI 09 02976iii.doc'
+ end
+end
+
+
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index b16ced344..63ab31c53 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -110,38 +110,107 @@ describe InfoRequest do
it "should cope with indexing after item is deleted" do
rebuild_xapian_index
- verbose = false
# delete event from underneath indexing; shouldn't cause error
info_request_events(:useless_incoming_message_event).save!
info_request_events(:useless_incoming_message_event).destroy
- ActsAsXapian.update_index(true, verbose)
+ update_xapian_index
end
end
describe "when calculating the status" do
- fixtures :info_requests, :info_request_events, :holidays
+ fixtures :info_requests, :info_request_events, :holidays, :public_bodies
before do
@ir = info_requests(:naughty_chicken_request)
end
+ it "has expected sent date" do
+ @ir.last_event_forming_initial_request.outgoing_message.last_sent_at.strftime("%F").should == '2007-10-14'
+ end
+
it "has correct due date" do
@ir.date_response_required_by.strftime("%F").should == '2007-11-09'
end
- it "isn't overdue on due date" do
+ it "has correct very overdue after date" do
+ @ir.date_very_overdue_after.strftime("%F").should == '2007-12-10'
+ end
+
+ it "isn't overdue on due date (20 working days after request sent)" do
Time.stub!(:now).and_return(Time.utc(2007, 11, 9, 23, 59))
@ir.calculate_status.should == 'waiting_response'
end
- it "is overdue a day after due date " do
- Time.stub!(:now).and_return(Time.utc(2007, 11, 10))
+ it "is overdue a day after due date (20 working days after request sent)" do
+ Time.stub!(:now).and_return(Time.utc(2007, 11, 10, 00, 01))
@ir.calculate_status.should == 'waiting_response_overdue'
end
+
+ it "is still overdue 40 working days after request sent" do
+ Time.stub!(:now).and_return(Time.utc(2007, 12, 10, 23, 59))
+ @ir.calculate_status.should == 'waiting_response_overdue'
+ end
+
+ it "is very overdue the day after 40 working days after request sent" do
+ Time.stub!(:now).and_return(Time.utc(2007, 12, 11, 00, 01))
+ @ir.calculate_status.should == 'waiting_response_very_overdue'
+ end
end
-
+
+ describe "when calculating the status for a school" do
+ fixtures :info_requests, :info_request_events, :holidays, :public_bodies
+
+ before do
+ @ir = info_requests(:naughty_chicken_request)
+ @ir.public_body.tag_string = "school"
+ @ir.public_body.is_school?.should == true
+ end
+
+ it "has expected sent date" do
+ @ir.last_event_forming_initial_request.outgoing_message.last_sent_at.strftime("%F").should == '2007-10-14'
+ end
+
+ it "has correct due date" do
+ @ir.date_response_required_by.strftime("%F").should == '2007-11-09'
+ end
+
+ it "has correct very overdue after date" do
+ @ir.date_very_overdue_after.strftime("%F").should == '2008-01-11' # 60 working days for schools
+ end
+
+ it "isn't overdue on due date (20 working days after request sent)" do
+ Time.stub!(:now).and_return(Time.utc(2007, 11, 9, 23, 59))
+ @ir.calculate_status.should == 'waiting_response'
+ end
+
+ it "is overdue a day after due date (20 working days after request sent)" do
+ Time.stub!(:now).and_return(Time.utc(2007, 11, 10, 00, 01))
+ @ir.calculate_status.should == 'waiting_response_overdue'
+ end
+
+ it "is still overdue 40 working days after request sent" do
+ Time.stub!(:now).and_return(Time.utc(2007, 12, 10, 23, 59))
+ @ir.calculate_status.should == 'waiting_response_overdue'
+ end
+
+ it "is still overdue the day after 40 working days after request sent" do
+ Time.stub!(:now).and_return(Time.utc(2007, 12, 11, 00, 01))
+ @ir.calculate_status.should == 'waiting_response_overdue'
+ end
+
+ it "is still overdue 60 working days after request sent" do
+ Time.stub!(:now).and_return(Time.utc(2008, 01, 11, 23, 59))
+ @ir.calculate_status.should == 'waiting_response_overdue'
+ end
+
+ it "is very overdue the day after 60 working days after request sent" do
+ Time.stub!(:now).and_return(Time.utc(2008, 01, 12, 00, 01))
+ @ir.calculate_status.should == 'waiting_response_very_overdue'
+ end
+ end
+
describe 'when asked if a user is the owning user for this request' do
before do
diff --git a/spec/models/outgoing_mailer_spec.rb b/spec/models/outgoing_mailer_spec.rb
index de59b09b2..eeed53251 100644
--- a/spec/models/outgoing_mailer_spec.rb
+++ b/spec/models/outgoing_mailer_spec.rb
@@ -66,4 +66,62 @@ describe OutgoingMailer, " when working out follow up addresses" do
end
+describe OutgoingMailer, "when working out follow up subjects" do
+ fixtures :info_requests, :incoming_messages, :outgoing_messages
+
+ it "should prefix the title with 'Freedom of Information request -' for initial requests" do
+ ir = info_requests(:fancy_dog_request)
+ im = ir.incoming_messages[0]
+
+ ir.email_subject_request.should == "Freedom of Information request - Why do you have & such a fancy dog?"
+ end
+
+ it "should use 'Re:' and inital request subject for followups which aren't replies to particular messages" do
+ ir = info_requests(:fancy_dog_request)
+ om = outgoing_messages(:useless_outgoing_message)
+
+ OutgoingMailer.subject_for_followup(ir, om).should == "Re: Freedom of Information request - Why do you have & such a fancy dog?"
+ end
+
+ it "should prefix with Re: the subject of the message being replied to" do
+ ir = info_requests(:fancy_dog_request)
+ im = ir.incoming_messages[0]
+ om = outgoing_messages(:useless_outgoing_message)
+ om.incoming_message_followup = im
+
+ OutgoingMailer.subject_for_followup(ir, om).should == "Re: Geraldine FOI Code AZXB421"
+ end
+
+ it "should not add Re: prefix if there already is such a prefix" do
+ ir = info_requests(:fancy_dog_request)
+ im = ir.incoming_messages[0]
+ om = outgoing_messages(:useless_outgoing_message)
+ om.incoming_message_followup = im
+
+ im.raw_email.data = im.raw_email.data.sub("Subject: Geraldine FOI Code AZXB421", "Subject: Re: Geraldine FOI Code AZXB421")
+ OutgoingMailer.subject_for_followup(ir, om).should == "Re: Geraldine FOI Code AZXB421"
+ end
+
+ it "should not add Re: prefix if there already is a lower case re: prefix" do
+ ir = info_requests(:fancy_dog_request)
+ im = ir.incoming_messages[0]
+ om = outgoing_messages(:useless_outgoing_message)
+ om.incoming_message_followup = im
+
+ im.raw_email.data = im.raw_email.data.sub("Subject: Geraldine FOI Code AZXB421", "Subject: re: Geraldine FOI Code AZXB421")
+ OutgoingMailer.subject_for_followup(ir, om).should == "re: Geraldine FOI Code AZXB421"
+ end
+
+ it "should use 'Re:' and initial request subject when replying to failed delivery notifications" do
+ ir = info_requests(:fancy_dog_request)
+ im = ir.incoming_messages[0]
+ om = outgoing_messages(:useless_outgoing_message)
+ om.incoming_message_followup = im
+
+ im.raw_email.data = im.raw_email.data.sub("foiperson@localhost", "postmaster@localhost")
+ im.raw_email.data = im.raw_email.data.sub("Subject: Geraldine FOI Code AZXB421", "Subject: Delivery Failed")
+ OutgoingMailer.subject_for_followup(ir, om).should == "Re: Freedom of Information request - Why do you have & such a fancy dog?"
+ end
+end
+
diff --git a/spec/models/outgoing_message_spec.rb b/spec/models/outgoing_message_spec.rb
index fedde6649..7e8dd4a1e 100644
--- a/spec/models/outgoing_message_spec.rb
+++ b/spec/models/outgoing_message_spec.rb
@@ -31,7 +31,7 @@ end
describe IncomingMessage, " when censoring data" do
- fixtures :outgoing_messages
+ fixtures :outgoing_messages, :info_requests
before do
@om = outgoing_messages(:useless_outgoing_message)
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index 827527213..5c58cdc54 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -85,3 +85,35 @@ describe PublicBody, "when searching" do
end
end
+describe PublicBody, " when loading CSV files" do
+ it "should do a dry run successfully" do
+ original_count = PublicBody.count
+
+ csv_contents = load_file_fixture("fake-authority-type.csv")
+ errors, notes = PublicBody.import_csv(csv_contents, 'fake', true, 'someadmin') # true means dry run
+ errors.should == []
+ notes.size.should == 3
+ notes.should == ["line 1: new authority 'North West Fake Authority' with email north_west_foi@localhost",
+ "line 2: new authority 'Scottish Fake Authority' with email scottish_foi@localhost",
+ "line 3: new authority 'Fake Authority of Northern Ireland' with email ni_foi@localhost"]
+
+ PublicBody.count.should == original_count
+ end
+
+ it "should do full run successfully" do
+ original_count = PublicBody.count
+
+ csv_contents = load_file_fixture("fake-authority-type.csv")
+ errors, notes = PublicBody.import_csv(csv_contents, 'fake', false, 'someadmin') # false means real run
+ errors.should == []
+ notes.size.should == 3
+ notes.should == ["line 1: new authority 'North West Fake Authority' with email north_west_foi@localhost",
+ "line 2: new authority 'Scottish Fake Authority' with email scottish_foi@localhost",
+ "line 3: new authority 'Fake Authority of Northern Ireland' with email ni_foi@localhost"]
+
+ PublicBody.count.should == original_count + 3
+ end
+end
+
+
+
diff --git a/spec/models/raw_email_spec.rb b/spec/models/raw_email_spec.rb
index 65780baed..889bb0783 100644
--- a/spec/models/raw_email_spec.rb
+++ b/spec/models/raw_email_spec.rb
@@ -12,14 +12,21 @@ describe User, "manipulating a raw email" do
@raw_email.data.should == "Hello, world!"
end
- it 'putting data in comes back out even if it has a backslash in it' do
- @raw_email.data = "This \\ that"
- @raw_email.save!
- @raw_email.reload
- STDERR.puts @raw_email.data
- STDERR.puts "This \\ that"
- @raw_email.data.should == "This \\ that"
- end
+ # XXX this test fails, hopefully will be fixed in later Rails.
+ # Doesn't matter too much for us for storing raw_emails, it would seem,
+ # but keep an eye out.
+
+ # This is testing a bug in Rails PostgreSQL code
+ # http://blog.aradine.com/2009/09/rubys-marshal-and-activerecord-and.html
+ # https://rails.lighthouseapp.com/projects/8994/tickets/1063-binary-data-broken-with-postgresql-adapter
+# it 'putting data in comes back out even if it has a backslash in it' do
+# @raw_email.data = "This \\ that"
+# @raw_email.save!
+# @raw_email.reload
+# STDERR.puts @raw_email.data
+# STDERR.puts "This \\ that"
+# @raw_email.data.should == "This \\ that"
+# end
end
diff --git a/spec/models/request_mailer_spec.rb b/spec/models/request_mailer_spec.rb
index 541f1da87..c77920905 100644
--- a/spec/models/request_mailer_spec.rb
+++ b/spec/models/request_mailer_spec.rb
@@ -115,7 +115,7 @@ describe RequestMailer, " when receiving incoming mail" do
deliveries.clear
end
- it "should dump messages to a request if marked to do so" do
+ it "should destroy the messages sent to a request if marked to do so" do
ActionMailer::Base.deliveries.clear
# mark request as anti-spam
ir = info_requests(:fancy_dog_request)
@@ -239,7 +239,7 @@ describe RequestMailer, 'when sending mail when someone has updated an old uncla
:law_used_full => 'Freedom of Information',
:title => 'Test request',
:public_body => @public_body,
- :display_status => 'Rejected.',
+ :display_status => 'Refused.',
:url_title => 'test_request')
@mail = RequestMailer.create_old_unclassified_updated(@info_request)
end
@@ -249,7 +249,7 @@ describe RequestMailer, 'when sending mail when someone has updated an old uncla
end
it 'should tell them what status was picked' do
- @mail.body.should match(/"rejected."/)
+ @mail.body.should match(/"refused."/)
end
it 'should contain the request path' do
diff --git a/spec/models/track_mailer_spec.rb b/spec/models/track_mailer_spec.rb
index 02f3bc991..44619e2bb 100644
--- a/spec/models/track_mailer_spec.rb
+++ b/spec/models/track_mailer_spec.rb
@@ -48,9 +48,11 @@ describe TrackMailer do
describe 'for each tracked thing' do
before do
+ @track_things_sent_emails_array = []
+ @track_things_sent_emails_array.stub!(:find).and_return([]) # this is for the date range find (created in last 14 days)
@track_thing = mock_model(TrackThing, :track_query => 'test query',
- :track_things_sent_emails => [],
- :created_at => Time.utc(2007, 4, 12, 23, 59))
+ :track_things_sent_emails => @track_things_sent_emails_array,
+ :created_at => Time.utc(2007, 11, 9, 23, 59))
TrackThing.stub!(:find).and_return([@track_thing])
@xapian_search = mock('xapian search', :results => [])
@found_event = mock_model(InfoRequestEvent, :described_at => @track_thing.created_at + 1.day)
@@ -59,13 +61,13 @@ describe TrackMailer do
end
it 'should ask for the events returned by the tracking query' do
- InfoRequest.should_receive(:full_search).with([InfoRequestEvent], 'test query', 'described_at', true, nil, 200, 1).and_return(@xapian_search)
+ InfoRequest.should_receive(:full_search).with([InfoRequestEvent], 'test query', 'described_at', true, nil, 100, 1).and_return(@xapian_search)
TrackMailer.alert_tracks
end
it 'should not include in the email any events that the user has already been sent a tracking email about' do
sent_email = mock_model(TrackThingsSentEmail, :info_request_event_id => @found_event.id)
- @track_thing.stub!(:track_things_sent_emails).and_return([sent_email])
+ @track_things_sent_emails_array.stub!(:find).and_return([sent_email]) # this is for the date range find (created in last 14 days)
@xapian_search.stub!(:results).and_return([@search_result])
TrackMailer.should_not_receive(:deliver_event_digest)
TrackMailer.alert_tracks
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index f4df22e9d..5d2bd39c7 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -231,8 +231,8 @@ describe User, " when making name and email address" do
end
end
-
-describe User, " when setting a profile photo" do
+# XXX not finished
+describe User, "when setting a profile photo" do
before do
@user = User.new
@user.name = "Sensible User"
diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb
index b0c122f50..c2a87b969 100644
--- a/spec/models/xapian_spec.rb
+++ b/spec/models/xapian_spec.rb
@@ -3,42 +3,52 @@ require File.dirname(__FILE__) + '/../spec_helper'
describe User, " when indexing users with Xapian" do
fixtures :users
- before(:all) do
- rebuild_xapian_index
- end
-
it "should search by name" do
+ rebuild_xapian_index
# def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page)
xapian_object = InfoRequest.full_search([User], "Silly", 'created_at', true, nil, 100, 1)
xapian_object.results.size.should == 1
xapian_object.results[0][:model].should == users(:silly_name_user)
end
-
end
describe PublicBody, " when indexing public bodies with Xapian" do
- fixtures :public_bodies
+ fixtures :public_bodies, :incoming_messages, :outgoing_messages, :raw_emails, :comments
- before(:all) do
+ it "should search index the main name field" do
rebuild_xapian_index
- end
- it "should search index the main name field" do
xapian_object = InfoRequest.full_search([PublicBody], "humpadinking", 'created_at', true, nil, 100, 1)
xapian_object.results.size.should == 1
xapian_object.results[0][:model].should == public_bodies(:humpadink_public_body)
end
it "should search index the notes field" do
+ rebuild_xapian_index
+
xapian_object = InfoRequest.full_search([PublicBody], "albatross", 'created_at', true, nil, 100, 1)
xapian_object.results.size.should == 1
xapian_object.results[0][:model].should == public_bodies(:humpadink_public_body)
end
+ it "should delete public bodies from the index when they are deleted" do
+ rebuild_xapian_index
+
+ xapian_object = InfoRequest.full_search([PublicBody], "albatross", 'created_at', true, nil, 100, 1)
+ xapian_object.results.size.should == 1
+ xapian_object.results[0][:model].should == public_bodies(:humpadink_public_body)
+
+ public_bodies(:humpadink_public_body).delete
+
+ update_xapian_index
+ xapian_object = InfoRequest.full_search([PublicBody], "albatross", 'created_at', true, nil, 100, 1)
+ xapian_object.results.size.should == 0
+ end
+
end
describe PublicBody, " when indexing requests by body they are to" do
- fixtures :public_bodies, :info_request_events, :info_requests
+ fixtures :public_bodies, :info_request_events, :info_requests, :raw_emails, :comments
it "should find requests to the body" do
rebuild_xapian_index
@@ -47,8 +57,6 @@ describe PublicBody, " when indexing requests by body they are to" do
end
it "should update index correctly when URL name of body changes" do
- verbose = false
-
# initial search
rebuild_xapian_index
xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_from:tgq", 'created_at', true, nil, 100, 1)
@@ -60,7 +68,7 @@ describe PublicBody, " when indexing requests by body they are to" do
body.short_name = 'GQ'
body.save!
body.url_name.should == 'gq'
- ActsAsXapian.update_index(true, verbose) # true = flush to disk
+ update_xapian_index
# check we get results expected
xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_from:tgq", 'created_at', true, nil, 100, 1)
@@ -71,10 +79,32 @@ describe PublicBody, " when indexing requests by body they are to" do
models_found_before.should == models_found_after
end
+
+ # if you index via the Xapian TermGenerator, it ignores terms of this length,
+ # this checks we're using Document:::add_term() instead
+ it "should work with URL names that are longer than 64 characters" do
+ rebuild_xapian_index
+
+ # change the URL name of the body
+ body = public_bodies(:geraldine_public_body)
+ body.short_name = 'The Uncensored, Complete Name of the Quasi-Autonomous Public Body Also Known As Geraldine'
+ body.save!
+ body.url_name.size.should > 70
+ update_xapian_index
+
+ # check we get results expected
+ xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_from:tgq", 'created_at', true, nil, 100, 1)
+ xapian_object.results.size.should == 0
+ xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_from:gq", 'created_at', true, nil, 100, 1)
+ xapian_object.results.size.should == 0
+ xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_from:" + body.url_name, 'created_at', true, nil, 100, 1)
+ xapian_object.results.size.should == 4
+ models_found_after = xapian_object.results.map { |x| x[:model] }
+ end
end
describe User, " when indexing requests by user they are from" do
- fixtures :users, :info_request_events, :info_requests
+ fixtures :users, :info_request_events, :info_requests, :incoming_messages, :outgoing_messages, :raw_emails, :comments
it "should find requests from the user" do
rebuild_xapian_index
@@ -82,9 +112,57 @@ describe User, " when indexing requests by user they are from" do
xapian_object.results.size.should == 4
end
- it "should update index correctly when URL name of user changes" do
- verbose = false
+ 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)
+ end
+
+ it "should not find it when one of the request's users is changed" do
+ rebuild_xapian_index
+ silly_user = users(:silly_name_user)
+ naughty_chicken_request = info_requests(:naughty_chicken_request)
+ naughty_chicken_request.user = silly_user
+ naughty_chicken_request.save!
+ update_xapian_index
+
+ # 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)
+ end
+
+ it "should not get confused searching for requests when one user has a name which has same stem as another" do
+ rebuild_xapian_index
+
+ bob_smith_user = users(:bob_smith_user)
+ bob_smith_user.name = "John King"
+ bob_smith_user.url_name.should == 'john_king'
+ bob_smith_user.save!
+
+ silly_user = users(:silly_name_user)
+ silly_user.name = "John K"
+ silly_user.url_name.should == 'john_k'
+ silly_user.save!
+
+ naughty_chicken_request = info_requests(:naughty_chicken_request)
+ naughty_chicken_request.user = silly_user
+ naughty_chicken_request.save!
+
+ update_xapian_index
+
+ # def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page)
+ xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:john_k", 'created_at', true, 'request_collapse', 100, 1)
+ xapian_object.results.size.should == 1
+ xapian_object.results[0][:model].should == info_request_events(:silly_outgoing_message_event)
+ end
+
+
+ it "should update index correctly when URL name of user changes" do
# initial search
rebuild_xapian_index
xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith", 'created_at', true, nil, 100, 1)
@@ -96,7 +174,7 @@ describe User, " when indexing requests by user they are from" do
u.name = 'Robert Smith'
u.save!
u.url_name.should == 'robert_smith'
- ActsAsXapian.update_index(flush_to_disk=true, verbose)
+ update_xapian_index
# check we get results expected
xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith", 'created_at', true, nil, 100, 1)
@@ -110,7 +188,7 @@ describe User, " when indexing requests by user they are from" do
end
describe User, " when indexing comments by user they are by" do
- fixtures :users, :info_request_events, :info_requests, :comments
+ fixtures :users, :info_request_events, :info_requests, :comments, :incoming_messages, :outgoing_messages, :raw_emails, :comments
it "should find requests from the user" do
rebuild_xapian_index
@@ -119,8 +197,6 @@ describe User, " when indexing comments by user they are by" do
end
it "should update index correctly when URL name of user changes" do
- verbose = false
-
# initial search
rebuild_xapian_index
xapian_object = InfoRequest.full_search([InfoRequestEvent], "commented_by:silly_emnameem", 'created_at', true, nil, 100, 1)
@@ -132,7 +208,7 @@ describe User, " when indexing comments by user they are by" do
u.name = 'Silly Name'
u.save!
u.url_name.should == 'silly_name'
- ActsAsXapian.update_index(true, verbose) # true = flush to disk
+ update_xapian_index
# check we get results expected
xapian_object = InfoRequest.full_search([InfoRequestEvent], "commented_by:silly_emnameem", 'created_at', true, nil, 100, 1)
@@ -146,7 +222,7 @@ describe User, " when indexing comments by user they are by" do
end
describe InfoRequest, " when indexing requests by their title" do
- fixtures :info_request_events, :info_requests, :incoming_messages
+ fixtures :info_request_events, :info_requests, :incoming_messages, :raw_emails, :comments
it "should find events for the request" do
rebuild_xapian_index
@@ -156,15 +232,13 @@ describe InfoRequest, " when indexing requests by their title" do
end
it "should update index correctly when URL title of request changes" do
- verbose = false
-
# change the URL name of the body
rebuild_xapian_index
ir = info_requests(:naughty_chicken_request)
ir.title = 'Really naughty'
ir.save!
ir.url_title.should == 'really_naughty'
- ActsAsXapian.update_index(true, verbose) # true = flush to disk
+ update_xapian_index
# check we get results expected
xapian_object = InfoRequest.full_search([InfoRequestEvent], "request:how_much_public_money_is_wasted_o", 'created_at', true, nil, 100, 1)