diff options
Diffstat (limited to 'spec/controllers/request_controller_spec.rb')
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 254 |
1 files changed, 131 insertions, 123 deletions
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 672c2c361..ccbf6b8ab 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -2,7 +2,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe RequestController, "when listing recent requests" do - before(:each) do load_raw_emails_data get_fixtures_xapian_index @@ -90,7 +89,7 @@ describe RequestController, "when listing recent requests" do end it "should assign the first page of results" do - xap_results = mock_model(ActsAsXapian::Search, + xap_results = mock(ActsAsXapian::Search, :results => (1..25).to_a.map { |m| { :model => m } }, :matches_estimated => 1000000) @@ -103,7 +102,7 @@ describe RequestController, "when listing recent requests" do end it "should return 404 for pages we don't want to serve up" do - xap_results = mock_model(ActsAsXapian::Search, + xap_results = mock(ActsAsXapian::Search, :results => (1..25).to_a.map { |m| { :model => m } }, :matches_estimated => 1000000) lambda { @@ -120,10 +119,7 @@ describe RequestController, "when listing recent requests" do end describe RequestController, "when changing things that appear on the request page" do - - before do - PurgeRequest.destroy_all - end + render_views it "should purge the downstream cache when mail is received" do ir = info_requests(:fancy_dog_request) @@ -189,7 +185,7 @@ describe RequestController, "when changing things that appear on the request pag end describe RequestController, "when showing one request" do - integrate_views + render_views before(:each) do load_raw_emails_data @@ -218,20 +214,20 @@ describe RequestController, "when showing one request" do end it "should redirect from a numeric URL to pretty one" do - get :show, :url_title => info_requests(:naughty_chicken_request).id + get :show, :url_title => info_requests(:naughty_chicken_request).id.to_s response.should redirect_to(:action => 'show', :url_title => info_requests(:naughty_chicken_request).url_title) end it 'should show actions the request owner can take' do get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' - response.should have_tag('div#owner_actions') + response.should have_selector('div#owner_actions') end describe 'when the request does allow comments' do it 'should have a comment link' do get :show, { :url_title => 'why_do_you_have_such_a_fancy_dog' }, { :user_id => users(:admin_user).id } - response.should have_tag('#anyone_actions', /Add an annotation/) + response.should have_selector('#anyone_actions', :content => "Add an annotation") end end @@ -239,7 +235,7 @@ describe RequestController, "when showing one request" do it 'should not have a comment link' do get :show, { :url_title => 'spam_1' }, { :user_id => users(:admin_user).id } - response.should_not have_tag('#anyone_actions', /Add an annotation/) + response.should_not have_selector('#anyone_actions', :content => "Add an annotation") end end @@ -256,13 +252,13 @@ describe RequestController, "when showing one request" do it 'should show the describe state form' do get :show, { :url_title => 'why_do_you_have_such_a_fancy_dog' }, { :user_id => users(:admin_user).id } - response.should have_tag('div.describe_state_form') + response.should have_selector('div.describe_state_form') end it 'should ask the user to use the describe state from' do get :show, { :url_title => 'why_do_you_have_such_a_fancy_dog' }, { :user_id => users(:admin_user).id } - response.should have_tag('p#request_status', :text => /answer the question above/) + response.should have_selector('p#request_status', :content => "answer the question above") end end @@ -280,7 +276,7 @@ describe RequestController, "when showing one request" do it 'should give a link to requesting an internal review' do get :show, { :url_title => 'why_do_you_have_such_a_fancy_dog' }, { :user_id => users(:admin_user).id } - response.should have_tag('p#request_status', :text =>/requesting an internal review/) + response.should have_selector('p#request_status', :content => "requesting an internal review") end end @@ -298,7 +294,7 @@ describe RequestController, "when showing one request" do it 'should give a link to make a followup' do get :show, { :url_title => 'why_do_you_have_such_a_fancy_dog' }, { :user_id => users(:admin_user).id } - response.should have_tag('p#request_status a', :text =>/send a follow up message/) + response.should have_selector('p#request_status a', :content => "send a follow up message") end end @@ -315,7 +311,7 @@ describe RequestController, "when showing one request" do it 'should not display actions the request owner can take' do get :show, :url_title => 'balalas' - response.should_not have_tag('div#owner_actions') + response.should_not have_selector('div#owner_actions') end end @@ -341,12 +337,12 @@ describe RequestController, "when showing one request" do it 'should not show the describe state form' do make_request - response.should_not have_tag('div.describe_state_form') + response.should_not have_selector('div.describe_state_form') end it 'should not ask the user to use the describe state form' do make_request - response.should_not have_tag('p#request_status', :text => /answer the question above/) + response.should_not have_selector('p#request_status', :content => "answer the question above") end end @@ -363,7 +359,7 @@ describe RequestController, "when showing one request" do it 'should not give a link to requesting an internal review' do make_request - response.should_not have_tag('p#request_status', :text =>/requesting an internal review/) + response.should_not have_selector('p#request_status', :content => "requesting an internal review") end end @@ -379,12 +375,12 @@ describe RequestController, "when showing one request" do it 'should not give a link to make a followup' do make_request - response.should_not have_tag('p#request_status a', :text =>/send a follow up message/) + response.should_not have_selector('p#request_status a', :content => "send a follow up message") end it 'should not give a link to sign in (in the request status paragraph)' do make_request - response.should_not have_tag('p#request_status a', :text => /sign in/) + response.should_not have_selector('p#request_status a', :content => "sign in") end end @@ -447,7 +443,7 @@ describe RequestController, "when showing one request" do describe 'when handling incoming mail' do - integrate_views + render_views it "should receive incoming messages, send email to creator, and show them" do ir = info_requests(:fancy_dog_request) @@ -481,13 +477,13 @@ describe RequestController, "when showing one request" do (assigns[:info_request_events].size - size_before).should == 1 ir.reload - get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt'], :skip_cache => 1 + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt', :skip_cache => 1 response.content_type.should == "text/plain" - response.should have_text(/Second hello/) + response.should contain "Second hello" - get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 3, :file_name => ['hello.txt'], :skip_cache => 1 + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 3, :file_name => 'hello.txt', :skip_cache => 1 response.content_type.should == "text/plain" - response.should have_text(/First hello/) + response.should contain "First hello" end it 'should cache an attachment on a request with normal prominence' do @@ -498,24 +494,23 @@ describe RequestController, "when showing one request" do get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, - :file_name => ['hello.txt'] - + :file_name => 'hello.txt' end it "should convert message body to UTF8" do ir = info_requests(:fancy_dog_request) receive_incoming_mail('iso8859_2_raw_email.email', ir.incoming_email) get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' - response.should have_text(/tënde/u) + response.should contain "tënde" end it "should generate valid HTML verson of plain text attachments" do ir = info_requests(:fancy_dog_request) receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) ir.reload - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt.html'], :skip_cache => 1 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt.html', :skip_cache => 1 response.content_type.should == "text/html" - response.should have_text(/Second hello/) + response.should contain "Second hello" end # This is a regression test for a bug where URLs of this form were causing 500 errors @@ -534,11 +529,11 @@ describe RequestController, "when showing one request" do ir.reload ugly_id = "55195" lambda { - get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => ['hello.txt.html'], :skip_cache => 1 + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => 'hello.txt.html', :skip_cache => 1 }.should raise_error(ActiveRecord::RecordNotFound) lambda { - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => ['hello.txt'], :skip_cache => 1 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => 'hello.txt', :skip_cache => 1 }.should raise_error(ActiveRecord::RecordNotFound) end it "should return 404 when incoming message and request ids don't match" do @@ -547,7 +542,7 @@ describe RequestController, "when showing one request" do receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) ir.reload lambda { - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => wrong_id, :part => 2, :file_name => ['hello.txt.html'], :skip_cache => 1 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => wrong_id, :part => 2, :file_name => 'hello.txt.html', :skip_cache => 1 }.should raise_error(ActiveRecord::RecordNotFound) end it "should return 404 for ugly URLs contain a request id that isn't an integer, even if the integer prefix refers to an actual request" do @@ -557,11 +552,11 @@ describe RequestController, "when showing one request" do ugly_id = "%d95" % [info_requests(:naughty_chicken_request).id] lambda { - get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => ['hello.txt.html'], :skip_cache => 1 + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => 'hello.txt.html', :skip_cache => 1 }.should raise_error(ActiveRecord::RecordNotFound) lambda { - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => ['hello.txt'], :skip_cache => 1 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => 'hello.txt', :skip_cache => 1 }.should raise_error(ActiveRecord::RecordNotFound) end it "should return 404 when incoming message and request ids don't match" do @@ -570,7 +565,7 @@ describe RequestController, "when showing one request" do receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) ir.reload lambda { - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => wrong_id, :part => 2, :file_name => ['hello.txt.html'], :skip_cache => 1 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => wrong_id, :part => 2, :file_name => 'hello.txt.html', :skip_cache => 1 }.should raise_error(ActiveRecord::RecordNotFound) end @@ -578,9 +573,9 @@ describe RequestController, "when showing one request" do ir = info_requests(:fancy_dog_request) receive_incoming_mail('incoming-request-pdf-attachment.email', ir.incoming_email) ir.reload - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['fs_50379341.pdf.html'], :skip_cache => 1 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'fs_50379341.pdf.html', :skip_cache => 1 response.content_type.should == "text/html" - response.should have_text(/Walberswick Parish Council/) + response.should contain "Walberswick Parish Council" end it "should not cause a reparsing of the raw email, even when the result would be a 404" do @@ -588,7 +583,7 @@ describe RequestController, "when showing one request" do receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) ir.reload attachment = IncomingMessage.get_attachment_by_url_part_number(ir.incoming_messages[1].get_attachments_for_display, 2) - attachment.body.should have_text(/Second hello/) + attachment.body.should contain "Second hello" # change the raw_email associated with the message; this only be reparsed when explicitly asked for ir.incoming_messages[1].raw_email.data = ir.incoming_messages[1].raw_email.data.sub("Second", "Third") @@ -596,23 +591,24 @@ describe RequestController, "when showing one request" do # in a 404 for browsing users. This shouldn't cause a # re-parse... lambda { - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt.baz.html'], :skip_cache => 1 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt.baz.html', :skip_cache => 1 }.should raise_error(ActiveRecord::RecordNotFound) attachment = IncomingMessage.get_attachment_by_url_part_number(ir.incoming_messages[1].get_attachments_for_display, 2) - attachment.body.should have_text(/Second hello/) + attachment.body.should contain "Second hello" # ...nor should asking for it by its correct filename... - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt.html'], :skip_cache => 1 - response.should_not have_text(/Third hello/) + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt.html', :skip_cache => 1 + response.should_not contain "Third hello" # ...but if we explicitly ask for attachments to be extracted, then they should be force = true ir.incoming_messages[1].parse_raw_email!(force) + ir.reload attachment = IncomingMessage.get_attachment_by_url_part_number(ir.incoming_messages[1].get_attachments_for_display, 2) - attachment.body.should have_text(/Second hello/) - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt.html'], :skip_cache => 1 - response.should have_text(/Third hello/) + attachment.body.should contain "Third hello" + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt.html', :skip_cache => 1 + response.should contain "Third hello" end it "should treat attachments with unknown extensions as binary" do @@ -620,9 +616,9 @@ describe RequestController, "when showing one request" do receive_incoming_mail('incoming-request-attachment-unknown-extension.email', ir.incoming_email) ir.reload - get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.qwglhm'], :skip_cache => 1 + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.qwglhm', :skip_cache => 1 response.content_type.should == "application/octet-stream" - response.should have_text(/an unusual sort of file/) + response.should contain "an unusual sort of file" end it "should not download attachments with wrong file name" do @@ -631,7 +627,7 @@ describe RequestController, "when showing one request" do lambda { get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, - :file_name => ['http://trying.to.hack'] + :file_name => 'http://trying.to.hack' }.should raise_error(ActiveRecord::RecordNotFound) end @@ -648,9 +644,9 @@ describe RequestController, "when showing one request" do begin receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) - get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt'], :skip_cache => 1 + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt', :skip_cache => 1 response.content_type.should == "text/plain" - response.should have_text(/xxxxxx hello/) + response.should contain "xxxxxx hello" ensure ir.censor_rules.clear end @@ -670,9 +666,9 @@ describe RequestController, "when showing one request" do receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) ir.reload - get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt'], :skip_cache => 1 + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt', :skip_cache => 1 response.content_type.should == "text/plain" - response.should have_text(/xxxxxx hello/) + response.should contain "xxxxxx hello" ensure ir.user.censor_rules.clear end @@ -694,11 +690,13 @@ describe RequestController, "when showing one request" do get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' assert assigns[:info_request].info_request_events[3].incoming_message.get_attachments_for_display.count == 2 # the issue is that the info_request_events have got cached on them the old info_requests. - # where i'm at: trying to replace those fields that got re-read from the raw email. however tests are failing in very strange ways. currently I don't appear to be getting any attachments parsed in at all when in the template (see "*****" in _correspondence.rhtml) but do when I'm in the code. + # where i'm at: trying to replace those fields that got re-read from the raw email. however tests are failing in very strange ways. currently I don't appear to be getting any attachments parsed in at all when in the template (see "*****" in _correspondence.html.erb) but do when I'm in the code. # so at this point, assigns[:info_request].incoming_messages[1].get_attachments_for_display is returning stuff, but the equivalent thing in the template isn't. # but something odd is that the above is return a whole load of attachments which aren't there in the controller - response.body.should have_tag("p.attachment strong", /hello.txt/m) + response.body.should have_selector("p.attachment strong") do |s| + s.should contain /hello.txt/m + end censor_rule = CensorRule.new() censor_rule.text = "hello.txt" @@ -708,7 +706,9 @@ describe RequestController, "when showing one request" do ir.censor_rules << censor_rule begin get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' - response.body.should have_tag("p.attachment strong", /goodbye.txt/m) + response.body.should have_selector("p.attachment strong") do |s| + s.should contain /goodbye.txt/m + end ensure ir.censor_rules.clear end @@ -731,17 +731,17 @@ describe RequestController, "when showing one request" do ir = info_requests(:fancy_dog_request) session[:user_id] = ir.user.id # bob_smith_user get :download_entire_request, :url_title => title - assigns[:url_path].should have_text(/#{title}.zip$/) + assigns[:url_path].should contain /#{title}.zip$/ old_path = assigns[:url_path] - response.location.should have_text(/#{assigns[:url_path]}$/) + response.location.should contain /#{assigns[:url_path]}$/ zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", old_path)) { |zipfile| zipfile.count.should == 1 # just the message } receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) get :download_entire_request, :url_title => title - assigns[:url_path].should have_text(/#{title}.zip$/) + assigns[:url_path].should contain /#{title}.zip$/ old_path = assigns[:url_path] - response.location.should have_text(/#{assigns[:url_path]}$/) + response.location.should contain /#{assigns[:url_path]}$/ zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", old_path)) { |zipfile| zipfile.count.should == 3 # the message plus two "hello.txt" files } @@ -752,9 +752,9 @@ describe RequestController, "when showing one request" do sleep 1 receive_incoming_mail('incoming-request-attachment-unknown-extension.email', ir.incoming_email) get :download_entire_request, :url_title => title - assigns[:url_path].should have_text(/#{title}.zip$/) + assigns[:url_path].should contain /#{title}.zip$/ assigns[:url_path].should_not == old_path - response.location.should have_text(/#{assigns[:url_path]}/) + response.location.should contain assigns[:url_path] zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", assigns[:url_path])) { |zipfile| zipfile.count.should == 4 # the message, two hello.txt plus the unknown attachment } @@ -764,14 +764,13 @@ describe RequestController, "when showing one request" do info_request = info_requests(:external_request) get :download_entire_request, { :url_title => info_request.url_title }, { :user_id => users(:bob_smith_user) } - response.location.should have_text(/#{assigns[:url_path]}$/) + response.location.should contain /#{assigns[:url_path]}$/ end end end end describe RequestController, "when changing prominence of a request" do - before(:each) do load_raw_emails_data end @@ -853,14 +852,14 @@ describe RequestController, "when changing prominence of a request" do :part => 2, :skip_cache => 1 response.content_type.should == "text/html" - response.should_not have_text(/Second hello/) + response.should_not contain "Second hello" response.should render_template('request/hidden') get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 3, :skip_cache => 1 response.content_type.should == "text/html" - response.should_not have_text(/First hello/) + response.should_not contain "First hello" response.should render_template('request/hidden') response.code.should == '410' end @@ -876,7 +875,7 @@ describe RequestController, "when changing prominence of a request" do get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, - :file_name => ['hello.txt'] + :file_name => 'hello.txt' end.should raise_error(ActiveRecord::RecordNotFound) end @@ -891,7 +890,7 @@ describe RequestController, "when changing prominence of a request" do get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, - :file_name => ['hello.txt'] + :file_name => 'hello.txt' end.should raise_error(ActiveRecord::RecordNotFound) end @@ -904,7 +903,6 @@ end # end describe RequestController, "when searching for an authority" do - # Whether or not sign-in is required for this step is configurable, # so we make sure we're logged in, just in case before do @@ -920,6 +918,8 @@ describe RequestController, "when searching for an authority" do end it "should return matching bodies" do + get_fixtures_xapian_index + session[:user_id] = @user.id get :select_authority, :query => "Quango" @@ -944,7 +944,7 @@ describe RequestController, "when searching for an authority" do end describe RequestController, "when creating a new request" do - integrate_views + render_views before do @user = users(:bob_smith_user) @@ -1036,7 +1036,7 @@ describe RequestController, "when creating a new request" do response.should redirect_to show_new_request_url(:url_title => ir.url_title) # This test uses an explicit path because it's relied in # Google Analytics goals: - response.redirected_to.should =~ /request\/why_is_your_quango_called_gerald\/new$/ + response.redirect_url.should =~ /request\/why_is_your_quango_called_gerald\/new$/ end it "should give an error if the same request is submitted twice" do @@ -1180,7 +1180,7 @@ describe RequestController, "when making a new request" do end describe RequestController, "when viewing an individual response for reply/followup" do - integrate_views + render_views before(:each) do load_raw_emails_data @@ -1201,7 +1201,7 @@ describe RequestController, "when viewing an individual response for reply/follo it "should offer the opportunity to reply to the main address" do session[:user_id] = users(:bob_smith_user).id get :show_response, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message) - response.body.should have_tag("div#other_recipients ul li", /the main FOI contact address for/) + response.body.should have_selector("div#other_recipients ul li", :content => "the main FOI contact address for") end it "should offer an opportunity to reply to another address" do @@ -1211,7 +1211,7 @@ describe RequestController, "when viewing an individual response for reply/follo ir.save! receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "Frob <frob@bonce.com>") get :show_response, :id => ir.id, :incoming_message_id => incoming_messages(:useless_incoming_message) - response.body.should have_tag("div#other_recipients ul li", /Frob/) + response.body.should have_selector("div#other_recipients ul li", :content => "Frob") end it "should not show individual responses if request hidden, even if request owner" do @@ -1295,7 +1295,9 @@ describe RequestController, "when classifying an information request" do before do @dog_request.stub!(:is_old_unclassified?).and_return(true) - RequestMailer.stub!(:deliver_old_unclassified_updated) + mail_mock = mock("mail") + mail_mock.stub(:deliver) + RequestMailer.stub!(:old_unclassified_updated).and_return(mail_mock) end describe 'when the user is not logged in' do @@ -1332,7 +1334,7 @@ describe RequestController, "when classifying an information request" do end it 'should send an email to the requester letting them know someone has updated the status of their request' do - RequestMailer.should_receive(:deliver_old_unclassified_updated) + RequestMailer.should_receive(:old_unclassified_updated) post_status('rejected') end @@ -1364,7 +1366,7 @@ describe RequestController, "when classifying an information request" do deliveries = ActionMailer::Base.deliveries deliveries.size.should == 1 mail = deliveries[0] - mail.from_addrs.first.to_s.should == users(:silly_name_user).name_and_email + mail.from_addrs.first.to_s.should == users(:silly_name_user).email end end end @@ -1403,7 +1405,9 @@ describe RequestController, "when classifying an information request" do end it 'should send an email to the requester letting them know someone has updated the status of their request' do - RequestMailer.should_receive(:deliver_old_unclassified_updated) + mail_mock = mock("mail") + mail_mock.stub :deliver + RequestMailer.should_receive(:old_unclassified_updated).and_return(mail_mock) post_status('rejected') end @@ -1442,7 +1446,7 @@ describe RequestController, "when classifying an information request" do end it 'should not send an email to the requester letting them know someone has updated the status of their request' do - RequestMailer.should_not_receive(:deliver_old_unclassified_updated) + RequestMailer.should_not_receive(:old_unclassified_updated) post_status('rejected') end @@ -1499,7 +1503,7 @@ describe RequestController, "when classifying an information request" do end it 'should not send an email to the requester letting them know someone has updated the status of their request' do - RequestMailer.should_not_receive(:deliver_old_unclassified_updated) + RequestMailer.should_not_receive(:old_unclassified_updated) post_status('rejected') end @@ -1562,11 +1566,10 @@ describe RequestController, "when classifying an information request" do @dog_request = info_requests(:fancy_dog_request) @dog_request.stub!(:each).and_return([@dog_request]) InfoRequest.stub!(:find).and_return(@dog_request) - @old_filters = ActionController::Routing::Routes.filters - ActionController::Routing::Routes.filters = RoutingFilter::Chain.new + RoutingFilter.active = false end after do - ActionController::Routing::Routes.filters = @old_filters + RoutingFilter.active = true end def request_url @@ -1670,7 +1673,7 @@ describe RequestController, "when classifying an information request" do end describe RequestController, "when sending a followup message" do - integrate_views + render_views before(:each) do load_raw_emails_data @@ -1723,7 +1726,7 @@ describe RequestController, "when sending a followup message" do deliveries.size.should == 1 mail = deliveries[0] mail.body.should =~ /What a useless response! You suck./ - mail.to_addrs.first.to_s.should == "FOI Person <foiperson@localhost>" + mail.to_addrs.first.to_s.should == "foiperson@localhost" response.should redirect_to(:action => 'show', :url_title => info_requests(:fancy_dog_request).url_title) @@ -1752,7 +1755,7 @@ end # it can't check the URLs in the emails I don't think, ugh. describe RequestController, "sending overdue request alerts" do - integrate_views + render_views before(:each) do load_raw_emails_data @@ -1770,9 +1773,9 @@ describe RequestController, "sending overdue request alerts" do mail = chicken_mails[0] mail.body.should =~ /promptly, as normally/ - mail.to_addrs.first.to_s.should == info_requests(:naughty_chicken_request).user.name_and_email + mail.to_addrs.first.to_s.should == info_requests(:naughty_chicken_request).user.email - mail.body =~ /(http:\/\/.*\/c\/(.*))/ + mail.body.to_s =~ /(http:\/\/.*\/c\/(.*))/ mail_url = $1 mail_token = $2 @@ -1799,7 +1802,7 @@ describe RequestController, "sending overdue request alerts" do mail = chicken_mails[0] mail.body.should =~ /promptly, as normally/ - mail.to_addrs.first.to_s.should == info_requests(:naughty_chicken_request).user.name_and_email + mail.to_addrs.first.to_s.should == info_requests(:naughty_chicken_request).user.email end it "should send not actually send the overdue alert if the user is banned but should @@ -1827,9 +1830,9 @@ describe RequestController, "sending overdue request alerts" do mail = chicken_mails[0] mail.body.should =~ /required by law/ - mail.to_addrs.first.to_s.should == info_requests(:naughty_chicken_request).user.name_and_email + mail.to_addrs.first.to_s.should == info_requests(:naughty_chicken_request).user.email - mail.body =~ /(http:\/\/.*\/c\/(.*))/ + mail.body.to_s =~ /(http:\/\/.*\/c\/(.*))/ mail_url = $1 mail_token = $2 @@ -1897,7 +1900,7 @@ describe RequestController, "sending overdue request alerts" do end describe RequestController, "sending unclassified new response reminder alerts" do - integrate_views + render_views before(:each) do load_raw_emails_data @@ -1910,8 +1913,8 @@ describe RequestController, "sending unclassified new response reminder alerts" deliveries.size.should == 3 # sufficiently late it sends reminders too mail = deliveries[0] mail.body.should =~ /To let everyone know/ - mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.name_and_email - mail.body =~ /(http:\/\/.*\/c\/(.*))/ + mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.email + mail.body.to_s =~ /(http:\/\/.*\/c\/(.*))/ mail_url = $1 mail_token = $2 @@ -1927,7 +1930,7 @@ describe RequestController, "sending unclassified new response reminder alerts" end describe RequestController, "clarification required alerts" do - integrate_views + render_views before(:each) do load_raw_emails_data end @@ -1946,8 +1949,8 @@ describe RequestController, "clarification required alerts" do deliveries.size.should == 1 mail = deliveries[0] mail.body.should =~ /asked you to explain/ - mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.name_and_email - mail.body =~ /(http:\/\/.*\/c\/(.*))/ + mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.email + mail.body.to_s =~ /(http:\/\/.*\/c\/(.*))/ mail_url = $1 mail_token = $2 @@ -1980,7 +1983,7 @@ describe RequestController, "clarification required alerts" do end describe RequestController, "comment alerts" do - integrate_views + render_views before(:each) do load_raw_emails_data end @@ -1999,8 +2002,8 @@ describe RequestController, "comment alerts" do deliveries = ActionMailer::Base.deliveries mail = deliveries[0] mail.body.should =~ /has annotated your/ - mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.name_and_email - mail.body =~ /(http:\/\/.*)/ + mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.email + mail.body.to_s =~ /(http:\/\/.*)/ mail_url = $1 mail_url.should match("/request/why_do_you_have_such_a_fancy_dog#comment-#{new_comment.id}") @@ -2049,8 +2052,8 @@ describe RequestController, "comment alerts" do deliveries.size.should == 1 mail = deliveries[0] mail.body.should =~ /There are 2 new annotations/ - mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.name_and_email - mail.body =~ /(http:\/\/.*)/ + mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.email + mail.body.to_s =~ /(http:\/\/.*)/ mail_url = $1 mail_url.should match("/request/why_do_you_have_such_a_fancy_dog#comment-#{comments(:silly_comment).id}") @@ -2059,7 +2062,7 @@ describe RequestController, "comment alerts" do end describe RequestController, "when viewing comments" do - integrate_views + render_views before(:each) do load_raw_emails_data end @@ -2067,22 +2070,26 @@ describe RequestController, "when viewing comments" do it "should link to the user who submitted it" do session[:user_id] = users(:bob_smith_user).id get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' - response.body.should have_tag("div#comment-1 h2", /Silly.*left an annotation/m) - response.body.should_not have_tag("div#comment-1 h2", /You.*left an annotation/m) + response.body.should have_selector("div#comment-1 h2") do |s| + s.should contain /Silly.*left an annotation/m + s.should_not contain /You.*left an annotation/m + end end it "should link to the user who submitted to it, even if it is you" do session[:user_id] = users(:silly_name_user).id get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' - response.body.should have_tag("div#comment-1 h2", /Silly.*left an annotation/m) - response.body.should_not have_tag("div#comment-1 h2", /You.*left an annotation/m) + response.body.should have_selector("div#comment-1 h2") do |s| + s.should contain /Silly.*left an annotation/m + s.should_not contain /You.*left an annotation/m + end end end describe RequestController, "authority uploads a response from the web interface" do - integrate_views + render_views before(:each) do # domain after the @ is used for authentication of FOI officers, so to test it @@ -2120,7 +2127,7 @@ describe RequestController, "authority uploads a response from the web interface session[:user_id] = @normal_user.id # post up a photo of the parrot - parrot_upload = fixture_file_upload('files/parrot.png','image/png') + parrot_upload = fixture_file_upload('/files/parrot.png','image/png') post :upload_response, :url_title => 'why_do_you_have_such_a_fancy_dog', :body => "Find attached a picture of a parrot", :file_1 => parrot_upload, @@ -2148,7 +2155,7 @@ describe RequestController, "authority uploads a response from the web interface session[:user_id] = @foi_officer_user.id # post up a photo of the parrot - parrot_upload = fixture_file_upload('files/parrot.png','image/png') + parrot_upload = fixture_file_upload('/files/parrot.png','image/png') post :upload_response, :url_title => 'why_do_you_have_such_a_fancy_dog', :body => "Find attached a picture of a parrot", :file_1 => parrot_upload, @@ -2172,7 +2179,6 @@ describe RequestController, "authority uploads a response from the web interface end describe RequestController, "when showing JSON version for API" do - before(:each) do load_raw_emails_data end @@ -2191,25 +2197,28 @@ describe RequestController, "when showing JSON version for API" do end describe RequestController, "when doing type ahead searches" do + render_views - integrate_views + before :each do + get_fixtures_xapian_index + end it "should return nothing for the empty query string" do get :search_typeahead, :q => "" - response.should render_template('request/_search_ahead.rhtml') + response.should render_template('request/_search_ahead') assigns[:xapian_requests].should be_nil end it "should return a request matching the given keyword, but not users with a matching description" do get :search_typeahead, :q => "chicken" - response.should render_template('request/_search_ahead.rhtml') + response.should render_template('request/_search_ahead') assigns[:xapian_requests].results.size.should == 1 assigns[:xapian_requests].results[0][:model].title.should == info_requests(:naughty_chicken_request).title end it "should return all requests matching any of the given keywords" do get :search_typeahead, :q => "money dog" - response.should render_template('request/_search_ahead.rhtml') + response.should render_template('request/_search_ahead') assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ [ info_requests(:fancy_dog_request), info_requests(:naughty_chicken_request), @@ -2219,13 +2228,13 @@ describe RequestController, "when doing type ahead searches" do it "should not return matches for short words" do get :search_typeahead, :q => "a" - response.should render_template('request/_search_ahead.rhtml') + response.should render_template('request/_search_ahead') assigns[:xapian_requests].should be_nil end it "should do partial matches for longer words" do get :search_typeahead, :q => "chick" - response.should render_template('request/_search_ahead.rhtml') + response.should render_template('request/_search_ahead') assigns[:xapian_requests].results.size.should ==1 end @@ -2250,7 +2259,7 @@ describe RequestController, "when doing type ahead searches" do end describe RequestController, "when showing similar requests" do - integrate_views + render_views it "should work" do get :similar, :url_title => info_requests(:badger_request).url_title @@ -2292,7 +2301,7 @@ describe RequestController, "when reporting a request when not logged in" do end describe RequestController, "when reporting a request (logged in)" do - integrate_views + render_views before do @user = users(:robin_user) @@ -2368,7 +2377,6 @@ describe RequestController, "when reporting a request (logged in)" do end describe RequestController, "when caching fragments" do - it "should not fail with long filenames" do long_name = "blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah.txt" info_request = mock(InfoRequest, :user_can_view? => true, @@ -2384,7 +2392,7 @@ describe RequestController, "when caching fragments" do IncomingMessage.stub!(:find).with("44").and_return(incoming_message) IncomingMessage.stub!(:get_attachment_by_url_part_number).and_return(attachment) InfoRequest.stub!(:find).with("132").and_return(info_request) - params = { :file_name => [long_name], + params = { :file_name => long_name, :controller => "request", :action => "get_attachment_as_html", :id => "132", |