From c6623db61b06cd496b9358171111a0ab86a03d5a 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 9018f76fe..9add32f1e 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -631,7 +631,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 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