From 64a93911ebae4eaa2a1bc2b9e09d1468d77aadb9 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Sun, 9 Dec 2012 19:08:59 +1100 Subject: Remove interlock as it's not compatible with Rails 3 and is unmaintained --- spec/controllers/request_controller_spec.rb | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index f40eecfff..e930e570b 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -59,19 +59,6 @@ describe RequestController, "when listing recent requests" do :conditions => "id in (select info_request_id from info_request_events where created_at between '2007-10-13'::date and '2007-11-01'::date)") end - it "should make a sane-sized cache tag" do - get :list, :view => 'all', :request_date_after => '13/10/2007', :request_date_before => '01/11/2007' - assigns[:cache_tag].size.should <= 32 - end - - it "should vary the cache tag with locale" do - get :list, :view => 'all', :request_date_after => '13/10/2007', :request_date_before => '01/11/2007' - en_tag = assigns[:cache_tag] - session[:locale] = :es - get :list, :view => 'all', :request_date_after => '13/10/2007', :request_date_before => '01/11/2007' - assigns[:cache_tag].should_not == en_tag - end - it "should list internal_review requests as unresolved ones" do get :list, :view => 'awaiting' -- cgit v1.2.3 From c9feb6a4002fc4b63021aeb5ffd6b2846ada7748 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Tue, 11 Dec 2012 15:00:40 +1100 Subject: integrate_views is render_views RSpec 2 --- spec/controllers/request_controller_spec.rb | 30 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index e930e570b..9e14153a7 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -121,7 +121,7 @@ end describe RequestController, "when changing things that appear on the request page" do - integrate_views + render_views it "should purge the downstream cache when mail is received" do ir = info_requests(:fancy_dog_request) @@ -187,7 +187,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 @@ -445,7 +445,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) @@ -895,7 +895,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) @@ -1131,7 +1131,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 @@ -1564,7 +1564,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 @@ -1646,7 +1646,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 @@ -1791,7 +1791,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 @@ -1821,7 +1821,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 @@ -1874,7 +1874,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 @@ -1953,7 +1953,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 @@ -1976,7 +1976,7 @@ 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 @@ -2086,7 +2086,7 @@ end describe RequestController, "when doing type ahead searches" do - integrate_views + render_views it "should return nothing for the empty query string" do get :search_typeahead, :q => "" @@ -2144,7 +2144,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 @@ -2178,7 +2178,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) -- cgit v1.2.3 From fc326e9b3d1750c28cacd680d944c8bed302bc61 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Fri, 4 Jan 2013 12:24:42 +1100 Subject: No need to specify extension when testing particular template is rendered --- spec/controllers/request_controller_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 9e14153a7..6b5e3e216 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -2090,20 +2090,20 @@ describe RequestController, "when doing type ahead searches" do 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), @@ -2113,13 +2113,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 -- cgit v1.2.3 From 8ab884f0da68b17f33577a197ebd0e7d412a28ed Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Fri, 25 Jan 2013 11:23:43 +1100 Subject: Disable routing filter in tests by using RoutingFilter.active rather than writing to ActionController::Routing::Routes.filters --- spec/controllers/request_controller_spec.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index da05785c5..2a812a1fb 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1513,11 +1513,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 -- cgit v1.2.3 From bc0ce470ade27fed5376e983d72e9f495d4c0405 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Mon, 28 Jan 2013 16:33:17 +1100 Subject: Use preceding slash on paths to fixtures files --- spec/controllers/request_controller_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 2a812a1fb..a85919f2c 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -2060,7 +2060,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, @@ -2088,7 +2088,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, -- cgit v1.2.3 From b37586c7165afb7b3447dfe2780169a88cb0a942 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Mon, 28 Jan 2013 19:44:22 +1100 Subject: Replace use of have_tag with have_selector from webrat --- spec/controllers/request_controller_spec.rb | 42 ++++++++++++++--------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index a85919f2c..f952eecc6 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -222,14 +222,14 @@ describe RequestController, "when showing one request" do 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 @@ -237,7 +237,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 @@ -254,13 +254,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', :text => /answer the question above/) end end @@ -278,7 +278,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', :text =>/requesting an internal review/) end end @@ -296,7 +296,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', :text =>/send a follow up message/) end end @@ -313,7 +313,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 @@ -339,12 +339,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 @@ -361,7 +361,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 @@ -377,12 +377,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 @@ -696,7 +696,7 @@ describe RequestController, "when showing one request" do # 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", :content => "hello.txt") censor_rule = CensorRule.new() censor_rule.text = "hello.txt" @@ -706,7 +706,7 @@ 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", :content => "goodbye.txt") ensure ir.censor_rules.clear end @@ -1199,7 +1199,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 @@ -1209,7 +1209,7 @@ describe RequestController, "when viewing an individual response for reply/follo ir.save! receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "Frob ") 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 @@ -2007,15 +2007,15 @@ 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", :content => "Silly.*left an annotation") + response.body.should_not have_selector("div#comment-1 h2", :content => "You.*left an annotation") 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", :content => "Silly.*left an annotation") + response.body.should_not have_selector("div#comment-1 h2", :content => "You.*left an annotation") end end -- cgit v1.2.3 From e3f045826c0c48cbcffb94816028948784bfd4a3 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 29 Jan 2013 09:49:21 +1100 Subject: Correct use of have_selector in b37586c7165afb7b3447dfe2780169a88cb0a942. --- spec/controllers/request_controller_spec.rb | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index f952eecc6..36af1cd96 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -260,7 +260,7 @@ describe RequestController, "when showing one request" do 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_selector('p#request_status', :text => /answer the question above/) + response.should have_selector('p#request_status', :content => "answer the question above") end end @@ -278,7 +278,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_selector('p#request_status', :text =>/requesting an internal review/) + response.should have_selector('p#request_status', :content => "requesting an internal review") end end @@ -296,7 +296,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_selector('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 @@ -696,7 +696,9 @@ describe RequestController, "when showing one request" do # 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_selector("p.attachment strong", :content => "hello.txt") + 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" @@ -706,7 +708,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_selector("p.attachment strong", :content => "goodbye.txt") + response.body.should have_selector("p.attachment strong") do |s| + s.should contain /goodbye.txt/m + end ensure ir.censor_rules.clear end @@ -2007,15 +2011,19 @@ 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_selector("div#comment-1 h2", :content => "Silly.*left an annotation") - response.body.should_not have_selector("div#comment-1 h2", :content => "You.*left an annotation") + 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_selector("div#comment-1 h2", :content => "Silly.*left an annotation") - response.body.should_not have_selector("div#comment-1 h2", :content => "You.*left an annotation") + 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 -- cgit v1.2.3 From c0360fa374b096964b67ff5195e86ef83936c62f Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 29 Jan 2013 10:40:07 +1100 Subject: Replace use of have_text with contain from webrat or match --- spec/controllers/request_controller_spec.rb | 44 ++++++++++++++--------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 36af1cd96..5f9ead973 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -481,11 +481,11 @@ 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'], :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 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 @@ -504,7 +504,7 @@ describe RequestController, "when showing one request" 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 @@ -513,7 +513,7 @@ describe RequestController, "when showing one request" do 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 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 @@ -578,7 +578,7 @@ describe RequestController, "when showing one request" do 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 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 @@ -586,7 +586,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") @@ -598,19 +598,19 @@ describe RequestController, "when showing one request" do }.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/) + 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) 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" 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/) + response.should contain "Third hello" end it "should treat attachments with unknown extensions as binary" do @@ -620,7 +620,7 @@ 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.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 @@ -648,7 +648,7 @@ 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'], :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,7 +670,7 @@ 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'], :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 @@ -733,17 +733,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 } @@ -754,9 +754,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 } @@ -766,7 +766,7 @@ 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 @@ -855,14 +855,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 -- cgit v1.2.3 From 10e7fe18316f03b525a467c3d8a6e2115391c83e Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 29 Jan 2013 13:04:00 +1100 Subject: Reset Actionmailer deliveries on controller tests. Apparently rspec isn't now doing this automatically --- spec/controllers/request_controller_spec.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 5f9ead973..847031674 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -2,6 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe RequestController, "when listing recent requests" do + before { ActionMailer::Base.deliveries = [] } before(:each) do load_raw_emails_data @@ -120,6 +121,7 @@ describe RequestController, "when listing recent requests" do end describe RequestController, "when changing things that appear on the request page" do + before { ActionMailer::Base.deliveries = [] } render_views @@ -187,6 +189,7 @@ describe RequestController, "when changing things that appear on the request pag end describe RequestController, "when showing one request" do + before { ActionMailer::Base.deliveries = [] } render_views before(:each) do @@ -445,6 +448,8 @@ describe RequestController, "when showing one request" do describe 'when handling incoming mail' do + before { ActionMailer::Base.deliveries = [] } + render_views it "should receive incoming messages, send email to creator, and show them" do @@ -773,6 +778,7 @@ describe RequestController, "when showing one request" do end describe RequestController, "when changing prominence of a request" do + before { ActionMailer::Base.deliveries = [] } before(:each) do load_raw_emails_data @@ -906,6 +912,7 @@ end # end describe RequestController, "when searching for an authority" do + before { ActionMailer::Base.deliveries = [] } # Whether or not sign-in is required for this step is configurable, # so we make sure we're logged in, just in case @@ -946,6 +953,8 @@ describe RequestController, "when searching for an authority" do end describe RequestController, "when creating a new request" do + + before { ActionMailer::Base.deliveries = [] } render_views before do @@ -1133,6 +1142,7 @@ end # These go with the previous set, but use mocks instead of fixtures. # TODO harmonise these describe RequestController, "when making a new request" do + before { ActionMailer::Base.deliveries = [] } before do @user = mock_model(User, :id => 3481, :name => 'Testy') @@ -1182,6 +1192,7 @@ describe RequestController, "when making a new request" do end describe RequestController, "when viewing an individual response for reply/followup" do + before { ActionMailer::Base.deliveries = [] } render_views before(:each) do @@ -1244,6 +1255,8 @@ describe RequestController, "when viewing an individual response for reply/follo end describe RequestController, "when classifying an information request" do + + before { ActionMailer::Base.deliveries = [] } describe 'if the request is external' do @@ -1614,6 +1627,7 @@ describe RequestController, "when classifying an information request" do end describe RequestController, "when sending a followup message" do + before { ActionMailer::Base.deliveries = [] } render_views before(:each) do @@ -1700,6 +1714,7 @@ describe RequestController, "sending overdue request alerts" do before(:each) do load_raw_emails_data + ActionMailer::Base.deliveries = [] end it "should send an overdue alert mail to creators of overdue requests" do @@ -1841,6 +1856,7 @@ describe RequestController, "sending overdue request alerts" do end describe RequestController, "sending unclassified new response reminder alerts" do + before { ActionMailer::Base.deliveries = [] } render_views before(:each) do @@ -1871,6 +1887,7 @@ describe RequestController, "sending unclassified new response reminder alerts" end describe RequestController, "clarification required alerts" do + before { ActionMailer::Base.deliveries = [] } render_views before(:each) do load_raw_emails_data @@ -1924,6 +1941,7 @@ describe RequestController, "clarification required alerts" do end describe RequestController, "comment alerts" do + before { ActionMailer::Base.deliveries = [] } render_views before(:each) do load_raw_emails_data @@ -2003,6 +2021,7 @@ describe RequestController, "comment alerts" do end describe RequestController, "when viewing comments" do + before { ActionMailer::Base.deliveries = [] } render_views before(:each) do load_raw_emails_data @@ -2030,6 +2049,7 @@ end describe RequestController, "authority uploads a response from the web interface" do + before { ActionMailer::Base.deliveries = [] } render_views before(:each) do @@ -2120,6 +2140,7 @@ describe RequestController, "authority uploads a response from the web interface end describe RequestController, "when showing JSON version for API" do + before { ActionMailer::Base.deliveries = [] } before(:each) do load_raw_emails_data @@ -2139,6 +2160,7 @@ describe RequestController, "when showing JSON version for API" do end describe RequestController, "when doing type ahead searches" do + before { ActionMailer::Base.deliveries = [] } render_views @@ -2198,6 +2220,7 @@ describe RequestController, "when doing type ahead searches" do end describe RequestController, "when showing similar requests" do + before { ActionMailer::Base.deliveries = [] } render_views it "should work" do @@ -2232,6 +2255,7 @@ end describe RequestController, "when reporting a request when not logged in" do + before { ActionMailer::Base.deliveries = [] } it "should only allow logged-in users to report requests" do get :report_request, :url_title => info_requests(:badger_request).url_title post_redirect = PostRedirect.get_last_post_redirect @@ -2240,6 +2264,7 @@ describe RequestController, "when reporting a request when not logged in" do end describe RequestController, "when reporting a request (logged in)" do + before { ActionMailer::Base.deliveries = [] } render_views before do @@ -2316,6 +2341,7 @@ describe RequestController, "when reporting a request (logged in)" do end describe RequestController, "when caching fragments" do + before { ActionMailer::Base.deliveries = [] } it "should not fail with long filenames" do long_name = "blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah.txt" -- cgit v1.2.3 From 30ef245a8ccb31c120a35eef1df35478877b43bf Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 29 Jan 2013 13:05:21 +1100 Subject: When mocking ActsAsXapian can't use mock_model because it's not a model --- spec/controllers/request_controller_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 847031674..53bae9f9c 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -91,7 +91,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) @@ -104,7 +104,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 { -- cgit v1.2.3 From e975b6b9448c72781665a69e671f2356d35b900f Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 29 Jan 2013 13:05:55 +1100 Subject: Pass string to paremeter in test --- spec/controllers/request_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 53bae9f9c..2f5251276 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -219,7 +219,7 @@ 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 -- cgit v1.2.3 From 166b6d90bc2dc79536d8d2d145281fa340075735 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 29 Jan 2013 13:32:55 +1100 Subject: Email address returned from mail doesn't have the name part anymore --- spec/controllers/request_controller_spec.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 2f5251276..11175542e 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1496,7 +1496,7 @@ describe RequestController, "when classifying an information request" do deliveries.size.should == 1 mail = deliveries[0] mail.body.should =~ /as needing admin/ - mail.from_addrs.first.to_s.should == @request_owner.name_and_email + mail.from_addrs.first.to_s.should == @request_owner.email end it 'should say it is showing advice as to what to do next' do @@ -1681,7 +1681,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 " + mail.to_addrs.first.to_s.should == "foiperson@localhost" response.should redirect_to(:action => 'show', :url_title => info_requests(:fancy_dog_request).url_title) @@ -1729,7 +1729,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 mail.body =~ /(http:\/\/.*\/c\/(.*))/ mail_url = $1 @@ -1758,7 +1758,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 @@ -1786,7 +1786,7 @@ 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_url = $1 @@ -1870,7 +1870,7 @@ 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.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.email mail.body =~ /(http:\/\/.*\/c\/(.*))/ mail_url = $1 mail_token = $2 @@ -1907,7 +1907,7 @@ 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.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.email mail.body =~ /(http:\/\/.*\/c\/(.*))/ mail_url = $1 mail_token = $2 @@ -1961,7 +1961,7 @@ 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.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.email mail.body =~ /(http:\/\/.*)/ mail_url = $1 mail_url.should match("/request/why_do_you_have_such_a_fancy_dog#comment-#{new_comment.id}") @@ -2011,7 +2011,7 @@ 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.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.email mail.body =~ /(http:\/\/.*)/ mail_url = $1 mail_url.should match("/request/why_do_you_have_such_a_fancy_dog#comment-#{comments(:silly_comment).id}") -- cgit v1.2.3 From 531698075c2d20232f110f64a95f705b5bf686f0 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 29 Jan 2013 13:33:29 +1100 Subject: When matching the body of an email to a regex cast it to a string --- spec/controllers/request_controller_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 11175542e..6a012d2b9 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1731,7 +1731,7 @@ describe RequestController, "sending overdue request alerts" do mail.body.should =~ /promptly, as normally/ 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 @@ -1788,7 +1788,7 @@ describe RequestController, "sending overdue request alerts" do mail.body.should =~ /required by law/ 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 @@ -1871,7 +1871,7 @@ describe RequestController, "sending unclassified new response reminder alerts" mail = deliveries[0] mail.body.should =~ /To let everyone know/ mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.email - mail.body =~ /(http:\/\/.*\/c\/(.*))/ + mail.body.to_s =~ /(http:\/\/.*\/c\/(.*))/ mail_url = $1 mail_token = $2 @@ -1908,7 +1908,7 @@ describe RequestController, "clarification required alerts" do mail = deliveries[0] mail.body.should =~ /asked you to explain/ mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.email - mail.body =~ /(http:\/\/.*\/c\/(.*))/ + mail.body.to_s =~ /(http:\/\/.*\/c\/(.*))/ mail_url = $1 mail_token = $2 @@ -1962,7 +1962,7 @@ describe RequestController, "comment alerts" do mail = deliveries[0] mail.body.should =~ /has annotated your/ mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.email - mail.body =~ /(http:\/\/.*)/ + 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}") @@ -2012,7 +2012,7 @@ describe RequestController, "comment alerts" do mail = deliveries[0] mail.body.should =~ /There are 2 new annotations/ mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.email - mail.body =~ /(http:\/\/.*)/ + 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}") -- cgit v1.2.3 From 1e5344db0a4365da174e95ae419dae4b06fd7e47 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 29 Jan 2013 16:26:07 +1100 Subject: modernise redirect tests by converting to using url helpers --- spec/controllers/request_controller_spec.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 6a012d2b9..b7e3f1f57 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1044,7 +1044,7 @@ describe RequestController, "when creating a new request" do mail = deliveries[0] mail.body.should =~ /This is a silly letter. It is too short to be interesting./ - response.should redirect_to(:action => 'show', :url_title => ir.url_title) + 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$/ @@ -1082,7 +1082,7 @@ describe RequestController, "when creating a new request" do ir.url_title.should_not == ir2.url_title - response.should redirect_to(:action => 'show', :url_title => ir2.url_title) + response.should redirect_to show_new_request_url(:url_title => ir2.url_title) end it 'should respect the rate limit' do @@ -1094,14 +1094,14 @@ describe RequestController, "when creating a new request" do :title => "What is the answer to the ultimate question?", :tag_string => "" }, :outgoing_message => { :body => "Please supply the answer from your files." }, :submitted_new_request => 1, :preview => 0 - response.should redirect_to(:action => 'show', :url_title => 'what_is_the_answer_to_the_ultima') + response.should redirect_to show_new_request_url(:url_title => 'what_is_the_answer_to_the_ultima') post :new, :info_request => { :public_body_id => @body.id, :title => "Why did the chicken cross the road?", :tag_string => "" }, :outgoing_message => { :body => "Please send me all the relevant documents you hold." }, :submitted_new_request => 1, :preview => 0 - response.should redirect_to(:action => 'show', :url_title => 'why_did_the_chicken_cross_the_ro') + response.should redirect_to show_new_request_url(:url_title => 'why_did_the_chicken_cross_the_ro') post :new, :info_request => { :public_body_id => @body.id, :title => "What's black and white and red all over?", :tag_string => "" }, @@ -1121,20 +1121,20 @@ describe RequestController, "when creating a new request" do :title => "What is the answer to the ultimate question?", :tag_string => "" }, :outgoing_message => { :body => "Please supply the answer from your files." }, :submitted_new_request => 1, :preview => 0 - response.should redirect_to(:action => 'show', :url_title => 'what_is_the_answer_to_the_ultima') + response.should redirect_to show_new_request_url(:url_title => 'what_is_the_answer_to_the_ultima') post :new, :info_request => { :public_body_id => @body.id, :title => "Why did the chicken cross the road?", :tag_string => "" }, :outgoing_message => { :body => "Please send me all the relevant documents you hold." }, :submitted_new_request => 1, :preview => 0 - response.should redirect_to(:action => 'show', :url_title => 'why_did_the_chicken_cross_the_ro') + response.should redirect_to show_new_request_url(:url_title => 'why_did_the_chicken_cross_the_ro') post :new, :info_request => { :public_body_id => @body.id, :title => "What's black and white and red all over?", :tag_string => "" }, :outgoing_message => { :body => "Please send all minutes of meetings and email records that address this question." }, :submitted_new_request => 1, :preview => 0 - response.should redirect_to(:action => 'show', :url_title => 'whats_black_and_white_and_red_al') + response.should redirect_to show_new_request_url(:url_title => 'whats_black_and_white_and_red_al') end end -- cgit v1.2.3 From 0925f8b6ddd30f6edc19741e1ebee348d08f4a61 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 29 Jan 2013 17:53:45 +1100 Subject: Clear out ActionMailer::Base.deliveries before each test. Rspec should be doing this but isn't for controller tests --- spec/controllers/request_controller_spec.rb | 33 ----------------------------- 1 file changed, 33 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index b7e3f1f57..e9a08e39e 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -2,8 +2,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe RequestController, "when listing recent requests" do - before { ActionMailer::Base.deliveries = [] } - before(:each) do load_raw_emails_data get_fixtures_xapian_index @@ -121,8 +119,6 @@ describe RequestController, "when listing recent requests" do end describe RequestController, "when changing things that appear on the request page" do - before { ActionMailer::Base.deliveries = [] } - render_views it "should purge the downstream cache when mail is received" do @@ -189,7 +185,6 @@ describe RequestController, "when changing things that appear on the request pag end describe RequestController, "when showing one request" do - before { ActionMailer::Base.deliveries = [] } render_views before(:each) do @@ -448,8 +443,6 @@ describe RequestController, "when showing one request" do describe 'when handling incoming mail' do - before { ActionMailer::Base.deliveries = [] } - render_views it "should receive incoming messages, send email to creator, and show them" do @@ -778,8 +771,6 @@ describe RequestController, "when showing one request" do end describe RequestController, "when changing prominence of a request" do - before { ActionMailer::Base.deliveries = [] } - before(:each) do load_raw_emails_data end @@ -912,8 +903,6 @@ end # end describe RequestController, "when searching for an authority" do - before { ActionMailer::Base.deliveries = [] } - # 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 @@ -953,8 +942,6 @@ describe RequestController, "when searching for an authority" do end describe RequestController, "when creating a new request" do - - before { ActionMailer::Base.deliveries = [] } render_views before do @@ -1142,7 +1129,6 @@ end # These go with the previous set, but use mocks instead of fixtures. # TODO harmonise these describe RequestController, "when making a new request" do - before { ActionMailer::Base.deliveries = [] } before do @user = mock_model(User, :id => 3481, :name => 'Testy') @@ -1192,7 +1178,6 @@ describe RequestController, "when making a new request" do end describe RequestController, "when viewing an individual response for reply/followup" do - before { ActionMailer::Base.deliveries = [] } render_views before(:each) do @@ -1255,8 +1240,6 @@ describe RequestController, "when viewing an individual response for reply/follo end describe RequestController, "when classifying an information request" do - - before { ActionMailer::Base.deliveries = [] } describe 'if the request is external' do @@ -1627,7 +1610,6 @@ describe RequestController, "when classifying an information request" do end describe RequestController, "when sending a followup message" do - before { ActionMailer::Base.deliveries = [] } render_views before(:each) do @@ -1714,7 +1696,6 @@ describe RequestController, "sending overdue request alerts" do before(:each) do load_raw_emails_data - ActionMailer::Base.deliveries = [] end it "should send an overdue alert mail to creators of overdue requests" do @@ -1856,7 +1837,6 @@ describe RequestController, "sending overdue request alerts" do end describe RequestController, "sending unclassified new response reminder alerts" do - before { ActionMailer::Base.deliveries = [] } render_views before(:each) do @@ -1887,7 +1867,6 @@ describe RequestController, "sending unclassified new response reminder alerts" end describe RequestController, "clarification required alerts" do - before { ActionMailer::Base.deliveries = [] } render_views before(:each) do load_raw_emails_data @@ -1941,7 +1920,6 @@ describe RequestController, "clarification required alerts" do end describe RequestController, "comment alerts" do - before { ActionMailer::Base.deliveries = [] } render_views before(:each) do load_raw_emails_data @@ -2021,7 +1999,6 @@ describe RequestController, "comment alerts" do end describe RequestController, "when viewing comments" do - before { ActionMailer::Base.deliveries = [] } render_views before(:each) do load_raw_emails_data @@ -2049,7 +2026,6 @@ end describe RequestController, "authority uploads a response from the web interface" do - before { ActionMailer::Base.deliveries = [] } render_views before(:each) do @@ -2140,8 +2116,6 @@ describe RequestController, "authority uploads a response from the web interface end describe RequestController, "when showing JSON version for API" do - before { ActionMailer::Base.deliveries = [] } - before(:each) do load_raw_emails_data end @@ -2160,8 +2134,6 @@ describe RequestController, "when showing JSON version for API" do end describe RequestController, "when doing type ahead searches" do - before { ActionMailer::Base.deliveries = [] } - render_views it "should return nothing for the empty query string" do @@ -2220,7 +2192,6 @@ describe RequestController, "when doing type ahead searches" do end describe RequestController, "when showing similar requests" do - before { ActionMailer::Base.deliveries = [] } render_views it "should work" do @@ -2255,7 +2226,6 @@ end describe RequestController, "when reporting a request when not logged in" do - before { ActionMailer::Base.deliveries = [] } it "should only allow logged-in users to report requests" do get :report_request, :url_title => info_requests(:badger_request).url_title post_redirect = PostRedirect.get_last_post_redirect @@ -2264,7 +2234,6 @@ describe RequestController, "when reporting a request when not logged in" do end describe RequestController, "when reporting a request (logged in)" do - before { ActionMailer::Base.deliveries = [] } render_views before do @@ -2341,8 +2310,6 @@ describe RequestController, "when reporting a request (logged in)" do end describe RequestController, "when caching fragments" do - before { ActionMailer::Base.deliveries = [] } - it "should not fail with long filenames" do long_name = "blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah.txt" info_request = mock(InfoRequest, :user_can_view? => true, -- cgit v1.2.3 From 2a98c2587c3e933e705154768c0f46a34777a56f Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Wed, 20 Feb 2013 16:01:01 +1100 Subject: Mark this test as pending until it's fixed. See #819 --- spec/controllers/request_controller_spec.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index e9a08e39e..195d1e214 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -571,12 +571,15 @@ describe RequestController, "when showing one request" do end it "should generate valid HTML verson of PDF attachments" 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 - response.content_type.should == "text/html" - response.should contain "Walberswick Parish Council" + pending "Disabled during Rails 3 upgrade: https://github.com/mysociety/alaveteli/issues/819" + + # TODO: Fix HTML validation and enable test + # 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 + # response.content_type.should == "text/html" + # 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 -- cgit v1.2.3 From 3e4ef4da5374c1dd6d32ac9351decc9bb6851355 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Mon, 25 Feb 2013 18:16:12 +1100 Subject: Update to new mail sending API --- spec/controllers/request_controller_spec.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 195d1e214..b5612e1f9 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1297,7 +1297,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 @@ -1334,7 +1336,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 @@ -1385,7 +1387,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 @@ -1424,7 +1428,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 @@ -1465,7 +1469,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 -- cgit v1.2.3 From 90edee32bf6ad91522b3e1e772bca1e778a5ba7a Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Tue, 26 Feb 2013 13:39:43 +1100 Subject: file_name is passed as a string not an array --- spec/controllers/request_controller_spec.rb | 43 ++++++++++++++--------------- 1 file changed, 21 insertions(+), 22 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index b5612e1f9..663588303 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -477,11 +477,11 @@ 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 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 contain "First hello" end @@ -494,8 +494,7 @@ 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 @@ -509,7 +508,7 @@ describe RequestController, "when showing one request" 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 contain "Second hello" end @@ -530,11 +529,11 @@ describe RequestController, "when showing one request" do ir.reload ugly_id = "55195" 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 @@ -543,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 @@ -553,11 +552,11 @@ describe RequestController, "when showing one request" do ugly_id = "%d95" % [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 @@ -566,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 @@ -577,7 +576,7 @@ 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 contain "Walberswick Parish Council" end @@ -595,14 +594,14 @@ 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 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 + 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 @@ -610,7 +609,7 @@ describe RequestController, "when showing one request" do ir.incoming_messages[1].parse_raw_email!(force) attachment = IncomingMessage.get_attachment_by_url_part_number(ir.incoming_messages[1].get_attachments_for_display, 2) attachment.body.should contain "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 + 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 @@ -619,7 +618,7 @@ 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 contain "an unusual sort of file" end @@ -630,7 +629,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 @@ -647,7 +646,7 @@ 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 contain "xxxxxx hello" ensure @@ -669,7 +668,7 @@ 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 contain "xxxxxx hello" ensure @@ -878,7 +877,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 @@ -893,7 +892,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 @@ -2332,7 +2331,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", -- cgit v1.2.3 From 835b51c1de0d49e652fe9c9a60f0974275de070c Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Wed, 27 Feb 2013 10:34:47 +1100 Subject: Rename ALL THE TEMPLATES!!1!!!one!!1!! .rhtml is deprecated in favour of .erb in Rails 3 --- spec/controllers/request_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 663588303..ffc15ebe8 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -692,7 +692,7 @@ 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 -- cgit v1.2.3 From 1e463f086ae0e5250392ac553368fccc7b12bd98 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Sun, 3 Mar 2013 13:45:44 +1100 Subject: response.redirected_to is deprecated --- spec/controllers/request_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index ffc15ebe8..1f6b0a516 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -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 -- cgit v1.2.3 From ac412859a4ba0ac625feb7d2f212213444b7ae41 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Mon, 4 Mar 2013 16:51:18 +1100 Subject: Reload the object after reparsing (Rails 3.1 caching) --- spec/controllers/request_controller_spec.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 1f6b0a516..1daa239cc 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -607,6 +607,7 @@ describe RequestController, "when showing one request" do # ...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 contain "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 -- cgit v1.2.3 From 889a9b28f188a144553cb91b698e5a2d7c96c1a2 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Mon, 4 Mar 2013 16:51:52 +1100 Subject: Surely we expect the modified body here --- spec/controllers/request_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 1daa239cc..842b4e47c 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -609,7 +609,7 @@ describe RequestController, "when showing one request" do 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 contain "Second 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 -- cgit v1.2.3 From a4f111b763863d7a2acc4a6dcd08bebc887eb875 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Fri, 15 Mar 2013 15:35:16 +1100 Subject: Update to current matcher API --- spec/controllers/request_controller_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 396182f00..f020ef9d7 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -337,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 -- cgit v1.2.3 From c5e5cb765399b0839704a7636757f0a89ef6a484 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Fri, 15 Mar 2013 16:01:23 +1100 Subject: Changed in 166b6d90bc2dc79536d8d2d145281fa340075735 --- spec/controllers/request_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index f020ef9d7..fa9a2326c 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1367,7 +1367,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 -- cgit v1.2.3 From 2800c08f7579d37d3730d1589db14e6225061911 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Sat, 16 Mar 2013 13:30:51 +1100 Subject: Reenable test now that we don't do HTML validation in the test suite --- spec/controllers/request_controller_spec.rb | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index fa9a2326c..9fda29bf8 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -570,15 +570,12 @@ describe RequestController, "when showing one request" do end it "should generate valid HTML verson of PDF attachments" do - pending "Disabled during Rails 3 upgrade: https://github.com/mysociety/alaveteli/issues/819" - - # TODO: Fix HTML validation and enable test - # 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 - # response.content_type.should == "text/html" - # response.should contain "Walberswick Parish Council" + 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 + response.content_type.should == "text/html" + 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 -- cgit v1.2.3 From 8132738c60f23d5608837d48aa0f8b3b38bc1bd1 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 19 Mar 2013 14:01:51 +1100 Subject: Another order dependent test issue fixed --- spec/controllers/request_controller_spec.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 9fda29bf8..582fb6be0 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -918,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" -- cgit v1.2.3 From f7878a229b597b5fc7ba8172c8e8c94a8fd9d7b6 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 19 Mar 2013 16:11:44 +1100 Subject: Fix another order dependent test issue --- spec/controllers/request_controller_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 582fb6be0..ccbf6b8ab 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -2199,6 +2199,10 @@ end describe RequestController, "when doing type ahead searches" do render_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') -- cgit v1.2.3 From 35dc277233b3e87dca9a86c1b579c0e4d968b571 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 26 Mar 2013 12:57:02 +1100 Subject: Fixup test issue found with config.order = 'random:5549' --- spec/controllers/request_controller_spec.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index ccbf6b8ab..4161f1118 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -2268,6 +2268,8 @@ describe RequestController, "when showing similar requests" do end it "should show similar requests" do + get_fixtures_xapian_index + badger_request = info_requests(:badger_request) get :similar, :url_title => badger_request.url_title -- cgit v1.2.3 From ef7be8c296a39d403193cd1ff6a9e0826a8790ac Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Wed, 1 May 2013 11:39:55 +0100 Subject: The test "should work" relies on the xapian index existing - make sure this is true for all tests in this group. --- spec/controllers/request_controller_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 4161f1118..20420b96d 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -2261,6 +2261,10 @@ end describe RequestController, "when showing similar requests" do render_views + before do + get_fixtures_xapian_index + end + it "should work" do get :similar, :url_title => info_requests(:badger_request).url_title response.should render_template("request/similar") @@ -2268,8 +2272,6 @@ describe RequestController, "when showing similar requests" do end it "should show similar requests" do - get_fixtures_xapian_index - badger_request = info_requests(:badger_request) get :similar, :url_title => badger_request.url_title -- cgit v1.2.3 From 5009bfcf52f99c26896ccdcb33d9f52377c04d6d Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 2 May 2013 15:56:46 +0100 Subject: All the tests in this group rely on having the xapian db - make it part of the setup. --- spec/controllers/request_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 20420b96d..657837c72 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -907,6 +907,7 @@ describe RequestController, "when searching for an authority" do # so we make sure we're logged in, just in case before do @user = users(:bob_smith_user) + get_fixtures_xapian_index end it "should return nothing for the empty query string" do @@ -918,7 +919,6 @@ 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" -- cgit v1.2.3 From 501b2b8672d294268b2eb112092e70ffc2728539 Mon Sep 17 00:00:00 2001 From: Mark Longair Date: Fri, 24 May 2013 18:50:16 +0100 Subject: Check that display_filename matches URL part number or fallback If the display_filename of the attachment found from the URL part number doesn't match the passed in display_filename then the email may have been reparsed, causing a reordering. In that case, look to see if there is another attachment that uniquely matches that filename, and, if so, return that other attachment. If no matching uniquely matching filename is found, redirect to the incoming message, rather than returning a 404. --- spec/controllers/request_controller_spec.rb | 50 ++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 15 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 657837c72..67fed572a 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -578,23 +578,21 @@ describe RequestController, "when showing one request" do 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 + it "should not cause a reparsing of the raw email, even when the attachment can't be found" do ir = info_requests(:fancy_dog_request) 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 = IncomingMessage.get_attachment_by_url_part_number_and_filename(ir.incoming_messages[1].get_attachments_for_display, 2, 'hello.txt') 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") - # asking for an attachment by the wrong filename results - # 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 - }.should raise_error(ActiveRecord::RecordNotFound) + # asking for an attachment by the wrong filename should result in redirecting + # back to the incoming message, but shouldn't cause a reparse: + 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 + response.status.should == 303 - attachment = IncomingMessage.get_attachment_by_url_part_number(ir.incoming_messages[1].get_attachments_for_display, 2) + attachment = IncomingMessage.get_attachment_by_url_part_number_and_filename(ir.incoming_messages[1].get_attachments_for_display, 2, 'hello.txt') attachment.body.should contain "Second hello" # ...nor should asking for it by its correct filename... @@ -605,12 +603,36 @@ describe RequestController, "when showing one request" do 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 = IncomingMessage.get_attachment_by_url_part_number_and_filename(ir.incoming_messages[1].get_attachments_for_display, 2, 'hello.txt') 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 redirect to the incoming message if there's a wrong part number and an ambiguous filename" do + ir = info_requests(:fancy_dog_request) + receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) + ir.reload + + im = ir.incoming_messages[1] + + attachment = IncomingMessage.get_attachment_by_url_part_number_and_filename(im.get_attachments_for_display, 5, 'hello world.txt') + attachment.should be_nil + + get :get_attachment_as_html, :incoming_message_id => im.id, :id => ir.id, :part => 5, :file_name => 'hello world.txt', :skip_cache => 1 + response.status.should == 303 + new_location = response.header['Location'] + new_location.should match(/request\/#{ir.url_title}#incoming-#{im.id}/) + end + + it "should find a uniquely named filename even if the URL part number was wrong" do + ir = info_requests(:fancy_dog_request) + receive_incoming_mail('incoming-request-pdf-attachment.email', ir.incoming_email) + ir.reload + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 5, :file_name => 'fs 50379341.pdf', :skip_cache => 1 + response.content_type.should == "application/pdf" + end + it "should treat attachments with unknown extensions as binary" do ir = info_requests(:fancy_dog_request) receive_incoming_mail('incoming-request-attachment-unknown-extension.email', ir.incoming_email) @@ -625,10 +647,8 @@ describe RequestController, "when showing one request" do ir = info_requests(:fancy_dog_request) receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) - lambda { - get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, - :file_name => 'http://trying.to.hack' - }.should raise_error(ActiveRecord::RecordNotFound) + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'http://trying.to.hack' + response.status.should == 303 end it "should censor attachments downloaded as binary" do @@ -2394,7 +2414,7 @@ describe RequestController, "when caching fragments" do attachment = mock(FoiAttachment, :display_filename => long_name, :body_as_html => ['some text', 'wrapper']) IncomingMessage.stub!(:find).with("44").and_return(incoming_message) - IncomingMessage.stub!(:get_attachment_by_url_part_number).and_return(attachment) + IncomingMessage.stub!(:get_attachment_by_url_part_number_and_filename).and_return(attachment) InfoRequest.stub!(:find).with("132").and_return(info_request) params = { :file_name => long_name, :controller => "request", -- cgit v1.2.3 From 84371abc33bd637d51600017bd91807cc2f70384 Mon Sep 17 00:00:00 2001 From: Mark Longair Date: Fri, 24 May 2013 11:52:24 +0100 Subject: Make an attachment filename in test fixtures more difficult This commit changes 'hello.txt' to 'hello-world.txt' in the incoming-request-two-same-name.email fixture. The reasoning for this change is that if there are no special characters in the filename then filename and display_filename will be the same and the tests won't pick up any confusion between the two. The test requests to :get_attachment and :get_attachment_as_html should get the display_filename rather than filename. --- spec/controllers/request_controller_spec.rb | 48 ++++++++++++++--------------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 67fed572a..231efca36 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -477,11 +477,11 @@ 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 world.txt', :skip_cache => 1 response.content_type.should == "text/plain" 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 world.txt', :skip_cache => 1 response.content_type.should == "text/plain" response.should contain "First hello" end @@ -494,7 +494,7 @@ 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 world.txt' end it "should convert message body to UTF8" do @@ -508,7 +508,7 @@ describe RequestController, "when showing one request" 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 world.txt.html', :skip_cache => 1 response.content_type.should == "text/html" response.should contain "Second hello" end @@ -529,11 +529,11 @@ describe RequestController, "when showing one request" do ir.reload ugly_id = "55195" 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 world.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 world.txt', :skip_cache => 1 }.should raise_error(ActiveRecord::RecordNotFound) end it "should return 404 when incoming message and request ids don't match" do @@ -542,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 world.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 @@ -552,11 +552,11 @@ describe RequestController, "when showing one request" do ugly_id = "%d95" % [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 world.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 world.txt', :skip_cache => 1 }.should raise_error(ActiveRecord::RecordNotFound) end it "should return 404 when incoming message and request ids don't match" do @@ -565,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 world.txt.html', :skip_cache => 1 }.should raise_error(ActiveRecord::RecordNotFound) end @@ -582,30 +582,30 @@ describe RequestController, "when showing one request" do ir = info_requests(:fancy_dog_request) receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) ir.reload - attachment = IncomingMessage.get_attachment_by_url_part_number_and_filename(ir.incoming_messages[1].get_attachments_for_display, 2, 'hello.txt') + attachment = IncomingMessage.get_attachment_by_url_part_number_and_filename(ir.incoming_messages[1].get_attachments_for_display, 2, 'hello world.txt') 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") # asking for an attachment by the wrong filename should result in redirecting # back to the incoming message, but shouldn't cause a reparse: - 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 world.txt.baz.html', :skip_cache => 1 response.status.should == 303 - attachment = IncomingMessage.get_attachment_by_url_part_number_and_filename(ir.incoming_messages[1].get_attachments_for_display, 2, 'hello.txt') + attachment = IncomingMessage.get_attachment_by_url_part_number_and_filename(ir.incoming_messages[1].get_attachments_for_display, 2, 'hello world.txt') 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 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello world.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_and_filename(ir.incoming_messages[1].get_attachments_for_display, 2, 'hello.txt') + attachment = IncomingMessage.get_attachment_by_url_part_number_and_filename(ir.incoming_messages[1].get_attachments_for_display, 2, 'hello world.txt') 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 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello world.txt.html', :skip_cache => 1 response.should contain "Third hello" end @@ -664,7 +664,7 @@ 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 world.txt', :skip_cache => 1 response.content_type.should == "text/plain" response.should contain "xxxxxx hello" ensure @@ -686,7 +686,7 @@ 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 world.txt', :skip_cache => 1 response.content_type.should == "text/plain" response.should contain "xxxxxx hello" ensure @@ -715,11 +715,11 @@ describe RequestController, "when showing one request" do # 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_selector("p.attachment strong") do |s| - s.should contain /hello.txt/m + s.should contain /hello world.txt/m end censor_rule = CensorRule.new() - censor_rule.text = "hello.txt" + censor_rule.text = "hello-world.txt" censor_rule.replacement = "goodbye.txt" censor_rule.last_edit_editor = "unknown" censor_rule.last_edit_comment = "none" @@ -763,7 +763,7 @@ describe RequestController, "when showing one request" do old_path = 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 + zipfile.count.should == 3 # the message plus two "hello-world.txt" files } # The path of the zip file is based on the hash of the timestamp of the last request @@ -776,7 +776,7 @@ describe RequestController, "when showing one request" do assigns[:url_path].should_not == old_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 + zipfile.count.should == 4 # the message, two hello-world.txt plus the unknown attachment } end @@ -895,7 +895,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 world.txt' end.should raise_error(ActiveRecord::RecordNotFound) end @@ -910,7 +910,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 world.txt' end.should raise_error(ActiveRecord::RecordNotFound) end -- cgit v1.2.3 From 395e2273dd02286242f69231b7d61a474ddd0e01 Mon Sep 17 00:00:00 2001 From: Mark Longair Date: Fri, 24 May 2013 11:58:08 +0100 Subject: The file_name on getting an attachment should be the display filename Previously the behaviour would have been the same, since we weren't checking the filename so strictly. --- spec/controllers/request_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 231efca36..b87a4ade8 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -573,7 +573,7 @@ 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 contain "Walberswick Parish Council" end -- cgit v1.2.3 From f8cc81a7791c6055dc6cf829e25138b7f6261a3e Mon Sep 17 00:00:00 2001 From: Mark Longair Date: Fri, 24 May 2013 11:50:26 +0100 Subject: Add a comment about the behaviour of the censor rules --- spec/controllers/request_controller_spec.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index b87a4ade8..9cc60a103 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -719,6 +719,8 @@ describe RequestController, "when showing one request" do end censor_rule = CensorRule.new() + # Note that the censor rule applies to the original filename, + # not the display_filename: censor_rule.text = "hello-world.txt" censor_rule.replacement = "goodbye.txt" censor_rule.last_edit_editor = "unknown" -- cgit v1.2.3 From d9d9997a1d0f6d361097a8a4bdf1aa0fee24edaa Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Mon, 3 Jun 2013 16:41:14 +0100 Subject: Handle json requests for hidden info requests. --- spec/controllers/request_controller_spec.rb | 39 +++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'spec/controllers/request_controller_spec.rb') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 9cc60a103..83e2b1767 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -816,6 +816,16 @@ describe RequestController, "when changing prominence of a request" do response.should render_template('hidden') end + it 'should not show hidden requests if requested using json' do + ir = info_requests(:fancy_dog_request) + ir.prominence = 'hidden' + ir.save! + + session[:user_id] = ir.user.id # bob_smith_user + get :show, :url_title => 'why_do_you_have_such_a_fancy_dog', :format => 'json' + response.code.should == '410' + end + it "should show hidden requests if logged in as super user" do ir = info_requests(:fancy_dog_request) ir.prominence = 'hidden' @@ -1236,14 +1246,29 @@ describe RequestController, "when viewing an individual response for reply/follo 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 - ir = info_requests(:fancy_dog_request) - ir.prominence = 'hidden' - ir.save! + context 'when a request is hidden' do + + before do + ir = info_requests(:fancy_dog_request) + ir.prominence = 'hidden' + ir.save! + + session[:user_id] = users(:bob_smith_user).id + end + + it "should not show individual responses, even if request owner" do + get :show_response, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message) + response.should render_template('request/hidden') + end + + it 'should respond to a json request for a hidden request with a 410 code and no body' do + get :show_response, :id => info_requests(:fancy_dog_request).id, + :incoming_message_id => incoming_messages(:useless_incoming_message), + :format => 'json' + + response.code.should == '410' + end - 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.should render_template('request/hidden') end describe 'when viewing a response for an external request' do -- cgit v1.2.3