From 9b9bee6746dcaca6c8636433f0e7349a77153d1a Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Fri, 10 Feb 2012 15:10:55 +0000 Subject: Make /similar/request/NONESUCH a 404 not 500 error Fixes #421. --- spec/controllers/request_controller_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 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 9018f76fe..ddcb621e9 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1738,6 +1738,30 @@ describe RequestController, "when doing type ahead searches" do assigns[:xapian_requests].results.size.should == 1 end +describe "when showing similar requests" do + integrate_views + + it "should work" do + get :similar, :url_title => info_requests(:badger_request).url_title + response.should render_template("request/similar") + assigns[:info_request].should == info_requests(:badger_request) + end + + it "should show similar requests" do + get :similar, :url_title => info_requests(:badger_request).url_title + assigns[:xapian_object].results.map{|x|x[:model].info_request}.should =~ [ + info_requests(:fancy_dog_request), + info_requests(:naughty_chicken_request), + ] + end + + it "should 404 for non-existent paths" do + lambda { + get :similar, :url_title => "there_is_really_no_such_path_owNAFkHR" + }.should raise_error(ActiveRecord::RecordNotFound) + end +end + end -- cgit v1.2.3 From 506af7a640f63b17000ccfc5e1344bbc3039c913 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Wed, 15 Feb 2012 09:45:20 +0000 Subject: Set a "Content-Disposition: attachment" header when downloading files. Closes #428 --- spec/controllers/request_controller_spec.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 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 ddcb621e9..db5592be1 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -222,7 +222,6 @@ 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/) - 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/) @@ -351,6 +350,15 @@ describe RequestController, "when showing one request" do response.should have_text(/an unusual sort of file/) end + it "should apply a content-disposition header" do + ir = info_requests(:fancy_dog_request) + 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 + response.headers.should include("Content-Disposition") + response.headers["Content-Disposition"].should include('hello.qwglhm') + end + it "should not download attachments with wrong file name" do ir = info_requests(:fancy_dog_request) receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) -- cgit v1.2.3 From dcc312ac215b57afc648725bb8d64ff287bf7798 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Wed, 15 Feb 2012 10:02:30 +0000 Subject: Merge jpmckinney/bundler --- spec/controllers/request_controller_spec.rb | 2 -- 1 file changed, 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 db5592be1..93d3a2bbe 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1,8 +1,6 @@ # -*- coding: utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') -require 'json' - describe RequestController, "when listing recent requests" do before(:each) do -- cgit v1.2.3 From 7bfd0796c2c3a21715bebae8abdc4f5c77f5094b Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Tue, 13 Mar 2012 00:23:12 +0000 Subject: Admin users clicking confirmation links Fixes #446. See issue for details. --- 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 93d3a2bbe..19938ac61 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -637,7 +637,7 @@ describe RequestController, "when creating a new request" do it "should accept a public body parameter" do get :new, :public_body_id => @body.id - assigns[:info_request].public_body.should == @body + assigns[:info_request].public_body.should == @body response.should render_template('new') end -- cgit v1.2.3 From 1fd67376e4ff52f4727b5108f20a25940276ba9f Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Tue, 13 Mar 2012 01:40:15 +0000 Subject: Correct bad nesting --- 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 19938ac61..180577f0d 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1743,8 +1743,9 @@ describe RequestController, "when doing type ahead searches" do get :search_typeahead, :q => "dog -chicken" assigns[:xapian_requests].results.size.should == 1 end +end -describe "when showing similar requests" do +describe RequestController, "when showing similar requests" do integrate_views it "should work" do @@ -1768,6 +1769,4 @@ describe "when showing similar requests" do end end -end - -- cgit v1.2.3 From 887c8c19d19ef108f21686d052221c868457bcdd Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Tue, 13 Mar 2012 01:46:07 +0000 Subject: Fix broken test --- 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 180577f0d..f50158ff9 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1755,11 +1755,11 @@ describe RequestController, "when showing similar requests" do end it "should show similar requests" do - get :similar, :url_title => info_requests(:badger_request).url_title - assigns[:xapian_object].results.map{|x|x[:model].info_request}.should =~ [ - info_requests(:fancy_dog_request), - info_requests(:naughty_chicken_request), - ] + badger_request = info_requests(:badger_request) + get :similar, :url_title => badger_request.url_title + + # Xapian seems to think *all* the requests are similar + assigns[:xapian_object].results.map{|x|x[:model].info_request}.should =~ InfoRequest.all.reject {|x| x == badger_request} end it "should 404 for non-existent paths" do -- cgit v1.2.3 From e58220bfdbdfc0f5e704fc4852fbfb40db0b19cb Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Fri, 10 Feb 2012 15:10:55 +0000 Subject: Make /similar/request/NONESUCH a 404 not 500 error Fixes #421. --- spec/controllers/request_controller_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 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 9018f76fe..ddcb621e9 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1738,6 +1738,30 @@ describe RequestController, "when doing type ahead searches" do assigns[:xapian_requests].results.size.should == 1 end +describe "when showing similar requests" do + integrate_views + + it "should work" do + get :similar, :url_title => info_requests(:badger_request).url_title + response.should render_template("request/similar") + assigns[:info_request].should == info_requests(:badger_request) + end + + it "should show similar requests" do + get :similar, :url_title => info_requests(:badger_request).url_title + assigns[:xapian_object].results.map{|x|x[:model].info_request}.should =~ [ + info_requests(:fancy_dog_request), + info_requests(:naughty_chicken_request), + ] + end + + it "should 404 for non-existent paths" do + lambda { + get :similar, :url_title => "there_is_really_no_such_path_owNAFkHR" + }.should raise_error(ActiveRecord::RecordNotFound) + end +end + end -- cgit v1.2.3 From bf0750e3fa6b231f145ba24591c9acf6f7758e48 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Wed, 15 Feb 2012 09:45:20 +0000 Subject: Set a "Content-Disposition: attachment" header when downloading files. Closes #428 --- spec/controllers/request_controller_spec.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 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 ddcb621e9..db5592be1 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -222,7 +222,6 @@ 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/) - 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/) @@ -351,6 +350,15 @@ describe RequestController, "when showing one request" do response.should have_text(/an unusual sort of file/) end + it "should apply a content-disposition header" do + ir = info_requests(:fancy_dog_request) + 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 + response.headers.should include("Content-Disposition") + response.headers["Content-Disposition"].should include('hello.qwglhm') + end + it "should not download attachments with wrong file name" do ir = info_requests(:fancy_dog_request) receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) -- cgit v1.2.3 From 76de470b1424be57934e58275a6116afb8eb9b3c Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Fri, 9 Mar 2012 11:48:38 +0000 Subject: first stab at sending PURGE requests to upstream varnish for request pages. Next step: making it asynchronous, e.g. with a queue of things to purge via a cron job. --- spec/controllers/request_controller_spec.rb | 58 ++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 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 db5592be1..12ea0cd0a 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -119,6 +119,62 @@ describe RequestController, "when listing recent requests" do end +describe RequestController, "when changing things that appear on the request page" do + + integrate_views + + before(:each) do + FakeWeb.last_request = nil + end + + it "should purge the downstream cache when mail is received" do + ir = info_requests(:fancy_dog_request) + receive_incoming_mail('incoming-request-plain.email', ir.incoming_email) + FakeWeb.last_request.path.should include(ir.url_title) + end + it "should purge the downstream cache when a comment is added" do + ir = info_requests(:fancy_dog_request) + ir.should_receive(:purge_in_cache) + new_comment = info_requests(:fancy_dog_request).add_comment('I also love making annotations.', users(:bob_smith_user)) + end + it "should purge the downstream cache when a followup is made" do + session[:user_id] = users(:bob_smith_user).id + ir = info_requests(:fancy_dog_request) + post :show_response, :outgoing_message => { :body => "What a useless response! You suck.", :what_doing => 'normal_sort' }, :id => ir.id, :incoming_message_id => incoming_messages(:useless_incoming_message), :submitted_followup => 1 + FakeWeb.last_request.path.should include(ir.url_title) + end + it "should purge the downstream cache when the request is categorised" do + ir = info_requests(:fancy_dog_request) + ir.should_receive(:purge_in_cache) + ir.set_described_state('waiting_clarification') + end + it "should purge the downstream cache when the authority data is changed" do + ir = info_requests(:fancy_dog_request) + ir.public_body.name = "Something new" + ir.public_body.save! + FakeWeb.last_request.path.should include(ir.url_title) + end + it "should purge the downstream cache when the user details are changed" do + ir = info_requests(:fancy_dog_request) + ir.user.name = "Something new" + FakeWeb.last_request.should == nil + ir.user.save! + FakeWeb.last_request.path.should include(ir.url_title) + end + it "should purge the downstream cache when censor rules have changed" do + # XXX really, CensorRules should execute expiry logic as part + # of the after_save of the model. Currently this is part of + # the AdminController logic, so must be tested from + # there. Leaving this stub test in place as a reminder + end + it "should purge the downstream cache when something is hidden by an admin" do + ir = info_requests(:fancy_dog_request) + ir.should_receive(:purge_in_cache) + ir.prominence = 'hidden' + ir.save! + end +end + describe RequestController, "when showing one request" do before(:each) do @@ -186,7 +242,7 @@ describe RequestController, "when showing one request" do describe 'when handling incoming mail' do integrate_views - + it "should receive incoming messages, send email to creator, and show them" do ir = info_requests(:fancy_dog_request) ir.incoming_messages.each { |x| x.parse_raw_email! } -- cgit v1.2.3 From 023e8157bb96e37212d9704672ebced79495cd89 Mon Sep 17 00:00:00 2001 From: Mark Longair Date: Mon, 2 Apr 2012 17:45:02 +0100 Subject: Remove cache/zips/ before running tests that write to there --- 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 f50158ff9..894dbda69 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -121,6 +121,7 @@ describe RequestController, "when showing one request" do before(:each) do load_raw_emails_data + FileUtils.rm_rf File.join(File.dirname(__FILE__), "../../cache/zips") end it "should be successful" do -- cgit v1.2.3 From 74d74416d145a49c04f62ec9659f1a564251c1b6 Mon Sep 17 00:00:00 2001 From: James McKinney Date: Mon, 2 Apr 2012 18:00:22 +0100 Subject: use Rails.root, not RAILS_ROOT --- 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 f50158ff9..850ee6334 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -565,7 +565,7 @@ end # XXX do this for invalid ids # it "should render 404 file" do -# response.should render_template("#{RAILS_ROOT}/public/404.html") +# response.should render_template("#{Rails.root}/public/404.html") # response.headers["Status"].should == "404 Not Found" # end -- cgit v1.2.3 From 4533b28661d6ce6973becf5877e82ca5656c37d2 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Fri, 20 Apr 2012 19:10:10 +0100 Subject: More changes and refactoring to make purges work. --- spec/controllers/request_controller_spec.rb | 21 ++++++++------------- 1 file changed, 8 insertions(+), 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 89d165587..9090bc26f 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -121,55 +121,50 @@ describe RequestController, "when changing things that appear on the request pag integrate_views - before(:each) do - FakeWeb.last_request = nil - end - it "should purge the downstream cache when mail is received" do ir = info_requests(:fancy_dog_request) receive_incoming_mail('incoming-request-plain.email', ir.incoming_email) - FakeWeb.last_request.path.should include(ir.url_title) + PurgeRequest.all().first.model_id.should == ir.id end it "should purge the downstream cache when a comment is added" do ir = info_requests(:fancy_dog_request) - ir.should_receive(:purge_in_cache) new_comment = info_requests(:fancy_dog_request).add_comment('I also love making annotations.', users(:bob_smith_user)) + PurgeRequest.all().first.model_id.should == ir.id end it "should purge the downstream cache when a followup is made" do session[:user_id] = users(:bob_smith_user).id ir = info_requests(:fancy_dog_request) post :show_response, :outgoing_message => { :body => "What a useless response! You suck.", :what_doing => 'normal_sort' }, :id => ir.id, :incoming_message_id => incoming_messages(:useless_incoming_message), :submitted_followup => 1 - FakeWeb.last_request.path.should include(ir.url_title) + PurgeRequest.all().first.model_id.should == ir.id end it "should purge the downstream cache when the request is categorised" do ir = info_requests(:fancy_dog_request) - ir.should_receive(:purge_in_cache) ir.set_described_state('waiting_clarification') + PurgeRequest.all().first.model_id.should == ir.id end it "should purge the downstream cache when the authority data is changed" do ir = info_requests(:fancy_dog_request) ir.public_body.name = "Something new" ir.public_body.save! - FakeWeb.last_request.path.should include(ir.url_title) + PurgeRequest.all().map{|x| x.model_id}.should =~ ir.public_body.info_requests.map{|x| x.id} end it "should purge the downstream cache when the user details are changed" do ir = info_requests(:fancy_dog_request) ir.user.name = "Something new" - FakeWeb.last_request.should == nil ir.user.save! - FakeWeb.last_request.path.should include(ir.url_title) + PurgeRequest.all().map{|x| x.model_id}.should =~ ir.user.info_requests.map{|x| x.id} end it "should purge the downstream cache when censor rules have changed" do # XXX really, CensorRules should execute expiry logic as part # of the after_save of the model. Currently this is part of - # the AdminController logic, so must be tested from + # the AdminCensorRuleController logic, so must be tested from # there. Leaving this stub test in place as a reminder end it "should purge the downstream cache when something is hidden by an admin" do ir = info_requests(:fancy_dog_request) - ir.should_receive(:purge_in_cache) ir.prominence = 'hidden' ir.save! + PurgeRequest.all().first.model_id.should == ir.id end end -- cgit v1.2.3 From 743ec524927553b37fd18a5472c14c4f5e19b7fe Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Wed, 2 May 2012 14:18:54 +0100 Subject: Modify InfoRequest stubs so they work with tests that iterate over the collection (e.g. `@user.info_requests.each`) --- 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 9090bc26f..c79ddab36 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1042,6 +1042,7 @@ describe RequestController, "when classifying an information request" do session[:user_id] = @admin_user.id @dog_request = info_requests(:fancy_dog_request) InfoRequest.stub!(:find).and_return(@dog_request) + @dog_request.stub!(:each).and_return([@dog_request]) end it 'should update the status of the request' do @@ -1083,6 +1084,7 @@ describe RequestController, "when classifying an information request" do @dog_request.user = @admin_user @dog_request.save! InfoRequest.stub!(:find).and_return(@dog_request) + @dog_request.stub!(:each).and_return([@dog_request]) end it 'should update the status of the request' do @@ -1119,6 +1121,7 @@ describe RequestController, "when classifying an information request" do @request_owner = users(:bob_smith_user) session[:user_id] = @request_owner.id @dog_request.awaiting_description.should == true + @dog_request.stub!(:each).and_return([@dog_request]) end it "should successfully classify response if logged in as user controlling request" do @@ -1186,6 +1189,7 @@ describe RequestController, "when classifying an information request" do @request_owner = users(:bob_smith_user) session[:user_id] = @request_owner.id @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 -- cgit v1.2.3 From b0b1aebb371211e0deb5e9eac600817e90f83301 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Fri, 4 May 2012 11:53:36 +0100 Subject: Don't ever create more than one entry for each URL that we want Varnish to purge. --- spec/controllers/request_controller_spec.rb | 10 ++++++++++ 1 file changed, 10 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 c79ddab36..cfd11a2ca 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -166,6 +166,16 @@ describe RequestController, "when changing things that appear on the request pag ir.save! PurgeRequest.all().first.model_id.should == ir.id end + it "should not create more than one entry for any given resourcce" do + ir = info_requests(:fancy_dog_request) + ir.prominence = 'hidden' + ir.save! + PurgeRequest.all().count.should == 1 + ir = info_requests(:fancy_dog_request) + ir.prominence = 'hidden' + ir.save! + PurgeRequest.all().count.should == 1 + end end describe RequestController, "when showing one request" do -- cgit v1.2.3 From cc023c6748ceaf3bc8cc3260e0a0fdba054016d7 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Fri, 4 May 2012 12:48:09 +0100 Subject: Don't cache results from pages with different locales using the same key. Fixes #454 --- spec/controllers/request_controller_spec.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 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 cfd11a2ca..c737e5736 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -64,6 +64,14 @@ describe RequestController, "when listing recent requests" do 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' @@ -91,7 +99,7 @@ describe RequestController, "when listing recent requests" do rebuild_xapian_index get :list, :view => 'awaiting' - assigns[:list_results].map(&:info_request).include?(info_requests(:fancy_dog_request)).should == true + assigns[:list_results].map(&:info_request).include?(info_requests(:fancy_dog_request)).should == truei end it "should assign the first page of results" do -- cgit v1.2.3 From fab239d4134d9e0b7560637df6897deff7e77336 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Fri, 11 May 2012 10:55:36 +0100 Subject: Fix typo (introduced in commit cc023c67) that broke a 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 c737e5736..d52c8eaf4 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -99,7 +99,7 @@ describe RequestController, "when listing recent requests" do rebuild_xapian_index get :list, :view => 'awaiting' - assigns[:list_results].map(&:info_request).include?(info_requests(:fancy_dog_request)).should == truei + assigns[:list_results].map(&:info_request).include?(info_requests(:fancy_dog_request)).should == true end it "should assign the first page of results" do -- cgit v1.2.3 From 774c199fa52b98b6780928a602dfdee1b2fce711 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Thu, 24 May 2012 11:49:34 +0100 Subject: Test for reporting functionality --- spec/controllers/request_controller_spec.rb | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 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 d52c8eaf4..c70284748 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1845,3 +1845,44 @@ describe RequestController, "when showing similar requests" do end +describe RequestController, "when reporting a request" do + integrate_views + + it "should mark a request as having been reported" do + ir = info_requests(:badger_request) + title = ir.url_title + get :show, :url_title => title + assigns[:info_request].attention_requested.should == false + get :report_request, :url_title => title + get :show, :url_title => title + assigns[:info_request].attention_requested.should == true + assigns[:info_request].described_state.should == "attention_requested" + end + + it "should not allow a request to be reported twice" do + title = info_requests(:badger_request).url_title + get :report_request, :url_title => title + get :show, :url_title => title + response.body.should include("has been reported") + get :report_request, :url_title => title + get :show, :url_title => title + response.body.should include("has already been reported") + end + + it "should let users know a request has been reported" do + title = info_requests(:badger_request).url_title + get :show, :url_title => title + response.body.should include("Offensive?") + get :report_request, :url_title => title + get :show, :url_title => title + response.body.should_not include("Offensive?") + response.body.should include("This request has been reported") + info_requests(:badger_request).set_described_state("successful") + get :show, :url_title => title + response.body.should_not include("This request has been reported") + response.body.should include("The site administrators have reviewed this request") + end + +end + + -- cgit v1.2.3 From f560987ab0d3ea3471837a2b30d30c7101dc5616 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Tue, 12 Jun 2012 09:55:16 +0100 Subject: Make emails requesting admin attention appear to come from the user who requested the attention, not the user who made the original request. --- spec/controllers/request_controller_spec.rb | 10 ++++++++++ 1 file changed, 10 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 c70284748..daa26c71e 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1883,6 +1883,16 @@ describe RequestController, "when reporting a request" do response.body.should include("The site administrators have reviewed this request") end + it "should send an email from the reporter to admins" do + ir = info_requests(:badger_request) + title = ir.url_title + post :report_request, :url_title => title + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + mail = deliveries[0] + mail.subject.should =~ /attention_requested/ + mail.from.should include(@user.email) + end end -- cgit v1.2.3 From b132a2e3ccd5ac652f9dac17b36655386e993d9b Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Tue, 12 Jun 2012 09:56:08 +0100 Subject: Ensure attention-requesting tests pass by faking a logged in user --- spec/controllers/request_controller_spec.rb | 5 +++++ 1 file changed, 5 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 daa26c71e..fdddac556 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1848,6 +1848,11 @@ end describe RequestController, "when reporting a request" do integrate_views + before do + @user = users(:robin_user) + session[:user_id] = @user.id + end + it "should mark a request as having been reported" do ir = info_requests(:badger_request) title = ir.url_title -- cgit v1.2.3 From 7ac45e7192d5f997acd21564cf163134f1c34c77 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Tue, 12 Jun 2012 09:57:06 +0100 Subject: Use POST rather than GET for tests (this matches better what the UI does) --- spec/controllers/request_controller_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 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 fdddac556..705d96316 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1858,7 +1858,7 @@ describe RequestController, "when reporting a request" do title = ir.url_title get :show, :url_title => title assigns[:info_request].attention_requested.should == false - get :report_request, :url_title => title + post :report_request, :url_title => title get :show, :url_title => title assigns[:info_request].attention_requested.should == true assigns[:info_request].described_state.should == "attention_requested" @@ -1866,10 +1866,10 @@ describe RequestController, "when reporting a request" do it "should not allow a request to be reported twice" do title = info_requests(:badger_request).url_title - get :report_request, :url_title => title + post :report_request, :url_title => title get :show, :url_title => title response.body.should include("has been reported") - get :report_request, :url_title => title + post :report_request, :url_title => title get :show, :url_title => title response.body.should include("has already been reported") end @@ -1878,7 +1878,7 @@ describe RequestController, "when reporting a request" do title = info_requests(:badger_request).url_title get :show, :url_title => title response.body.should include("Offensive?") - get :report_request, :url_title => title + post :report_request, :url_title => title get :show, :url_title => title response.body.should_not include("Offensive?") response.body.should include("This request has been reported") -- cgit v1.2.3 From 4bb3e9d5ff49ec5fb108a5a618993248abcb3692 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Fri, 15 Jun 2012 13:28:07 +0100 Subject: Revert "Set a "Content-Disposition: attachment" header when downloading files. Closes #428" This reverts commit 506af7a640f63b17000ccfc5e1344bbc3039c913. See issue #428 for a discussion --- spec/controllers/request_controller_spec.rb | 10 +--------- 1 file changed, 1 insertion(+), 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 705d96316..28f56dcf6 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -290,6 +290,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(/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/) @@ -418,15 +419,6 @@ describe RequestController, "when showing one request" do response.should have_text(/an unusual sort of file/) end - it "should apply a content-disposition header" do - ir = info_requests(:fancy_dog_request) - 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 - response.headers.should include("Content-Disposition") - response.headers["Content-Disposition"].should include('hello.qwglhm') - end - it "should not download attachments with wrong file name" do ir = info_requests(:fancy_dog_request) receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) -- cgit v1.2.3 From 363e3aaeea5d185e47e22825bad865c31e3e6ed8 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Tue, 19 Jun 2012 09:13:16 +0100 Subject: Correctly name the person who has requested something for admin attention --- 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 28f56dcf6..13887749d 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1889,6 +1889,7 @@ describe RequestController, "when reporting a request" do mail = deliveries[0] mail.subject.should =~ /attention_requested/ mail.from.should include(@user.email) + mail.body.should include(@user.name) end end -- cgit v1.2.3 From f35432197c85911d400a21ba4bfe099210a8811b Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Tue, 19 Jun 2012 12:32:06 +0100 Subject: Fix test to match current wording --- 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 13887749d..99ab4cc71 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1877,7 +1877,7 @@ describe RequestController, "when reporting a request" do info_requests(:badger_request).set_described_state("successful") get :show, :url_title => title response.body.should_not include("This request has been reported") - response.body.should include("The site administrators have reviewed this request") + response.body.should =~ (/the site administrators.*have not hidden it/) end it "should send an email from the reporter to admins" do -- cgit v1.2.3 From 08dac0261325cd757b7146f9626f3c7b48cc672c Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Wed, 20 Jun 2012 10:11:03 +0100 Subject: Only invalidate a user's cached requests when their *name* changes. Otherwise we issue PURGEs every time, for example, we send out email alerts. --- spec/controllers/request_controller_spec.rb | 8 +++++++- 1 file changed, 7 insertions(+), 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 99ab4cc71..01a663bf8 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -156,12 +156,18 @@ describe RequestController, "when changing things that appear on the request pag ir.public_body.save! PurgeRequest.all().map{|x| x.model_id}.should =~ ir.public_body.info_requests.map{|x| x.id} end - it "should purge the downstream cache when the user details are changed" do + it "should purge the downstream cache when the user name is changed" do ir = info_requests(:fancy_dog_request) ir.user.name = "Something new" ir.user.save! PurgeRequest.all().map{|x| x.model_id}.should =~ ir.user.info_requests.map{|x| x.id} end + it "should not purge the downstream cache when non-visible user details are changed" do + ir = info_requests(:fancy_dog_request) + ir.user.hashed_password = "some old hash" + ir.user.save! + PurgeRequest.all().count.should == 0 + end it "should purge the downstream cache when censor rules have changed" do # XXX really, CensorRules should execute expiry logic as part # of the after_save of the model. Currently this is part of -- cgit v1.2.3