From 9925d8f83864dc740d9b284a9e472d422dba12fb Mon Sep 17 00:00:00 2001 From: David Cabo Date: Tue, 26 Jul 2011 22:07:30 +0200 Subject: Adapting New Request flow to new wireframes: added type ahead search when creating new requests --- spec/controllers/request_controller_spec.rb | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 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 9d91bf8c2..e2febacd7 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1250,5 +1250,36 @@ describe RequestController, "when showing JSON version for API" do end +describe RequestController, "when doing type ahead searches" do + fixtures :info_requests, :info_request_events, :public_bodies, :public_body_translations, :users, :incoming_messages, :raw_emails, :outgoing_messages, :comments + + it "should return nothing for the empty query string" do + get :search_typeahead, :q => "" + response.should render_template('request/_search_ahead.rhtml') + assigns[:xapian_requests].results.size.should == 0 + 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') + 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') + assigns[:xapian_requests].results.size.should == 2 + assigns[:xapian_requests].results[0][:model].title.should == info_requests(:fancy_dog_request).title + assigns[:xapian_requests].results[1][:model].title.should == info_requests(:naughty_chicken_request).title + end + + it "should return partial matches" do + get :search_typeahead, :q => "chick" # 'chick' for 'chicken' + response.should render_template('request/_search_ahead.rhtml') + assigns[:xapian_requests].results.size.should == 1 + assigns[:xapian_requests].results[0][:model].title.should == info_requests(:naughty_chicken_request).title + end +end -- cgit v1.2.3 From 03bb6db9b7ca77d2e438d8fa1c8a4ad41327a04d Mon Sep 17 00:00:00 2001 From: David Cabo Date: Sat, 13 Aug 2011 20:49:37 +0200 Subject: Update tests to reflect sign-in is now before Preview when making new request --- spec/controllers/request_controller_spec.rb | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 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 516aa602f..500a30bd0 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -322,7 +322,20 @@ describe RequestController, "when creating a new request" do response.should render_template('new') end + it "should redirect to sign in page when input is good and nobody is logged in" do + params = { :info_request => { :public_body_id => @body.id, + :title => "Why is your quango called Geraldine?", :tag_string => "" }, + :outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." }, + :submitted_new_request => 1, :preview => 1 + } + post :new, params + post_redirect = PostRedirect.get_last_post_redirect + response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token) + # post_redirect.post_params.should == params # XXX get this working. there's a : vs '' problem amongst others + end + it "should show preview when input is good" do + session[:user_id] = @user.id post :new, { :info_request => { :public_body_id => @body.id, :title => "Why is your quango called Geraldine?", :tag_string => "" }, :outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." }, @@ -340,18 +353,6 @@ describe RequestController, "when creating a new request" do response.should render_template('new') end - it "should redirect to sign in page when input is good and nobody is logged in" do - params = { :info_request => { :public_body_id => @body.id, - :title => "Why is your quango called Geraldine?", :tag_string => "" }, - :outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." }, - :submitted_new_request => 1, :preview => 0 - } - post :new, params - post_redirect = PostRedirect.get_last_post_redirect - response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token) - # post_redirect.post_params.should == params # XXX get this working. there's a : vs '' problem amongst others - end - it "should create the request and outgoing message, and send the outgoing message by email, and redirect to request page when input is good and somebody is logged in" do session[:user_id] = @user.id post :new, :info_request => { :public_body_id => @body.id, -- cgit v1.2.3 From 33bd0e919528e1d7eda4be4200db91b042984c97 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Fri, 26 Aug 2011 13:54:05 +0100 Subject: Fixes to get tests to pass following addition of new search / filter functionality --- spec/controllers/request_controller_spec.rb | 6 +----- 1 file changed, 1 insertion(+), 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 f69cf414c..7d0cd2c1a 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1,7 +1,3 @@ -# £2k p/a -# talk about margins -# - require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require 'json' @@ -30,7 +26,7 @@ describe RequestController, "when listing recent requests" do :matches_estimated => 103) InfoRequest.should_receive(:full_search). - with([InfoRequestEvent],"variety:sent", "created_at", anything, anything, anything, anything). + with([InfoRequestEvent]," variety:sent", "created_at", anything, anything, anything, anything). and_return(xap_results) get :list, :view => 'recent' assigns[:list_results].size.should == 25 -- cgit v1.2.3 From b41edc7ae069e6071f7ff7223c1e60cca5e75e8c Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Mon, 29 Aug 2011 13:13:59 +0100 Subject: Add tests & fixes for new search/filtering functionality --- spec/controllers/request_controller_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 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 7d0cd2c1a..2b153ac7a 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -20,6 +20,22 @@ describe RequestController, "when listing recent requests" do response.should render_template('list') end + it "should filter requests" do + get :list, :view => 'all' + assigns[:list_results].size.should == 2 + get :list, :view => 'successful' + assigns[:list_results].size.should == 0 + end + + it "should filter requests by date" do + get :list, :view => 'all', :request_date_before => '13/10/2007' + assigns[:list_results].size.should == 1 + get :list, :view => 'all', :request_date_after => '13/10/2007' + assigns[:list_results].size.should == 1 + get :list, :view => 'all', :request_date_after => '10/10/2007', :request_date_before => '01/01/2010' + assigns[:list_results].size.should == 2 + end + it "should assign the first page of results" do xap_results = mock_model(ActsAsXapian::Search, :results => (1..25).to_a.map { |m| { :model => m } }, -- cgit v1.2.3 From 0420098e50996a033552335e94e35ade781357af Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Tue, 30 Aug 2011 13:32:13 +0100 Subject: Additional changes omitted from commit 9d8388c03d0faeaca29d233a340c58bd65f28a97 (distinguish 404s and 500s), fixes #161. --- spec/controllers/request_controller_spec.rb | 12 +++++------- 1 file changed, 5 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 2b153ac7a..f3084af12 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -161,7 +161,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'] - }.should raise_error(RuntimeError) + }.should raise_error(ActiveRecord::RecordNotFound) end it "should censor attachments downloaded as binary" do @@ -747,18 +747,16 @@ describe RequestController, "when classifying an information request" do response.should redirect_to(:controller => 'help', :action => 'unhappy', :url_title => @dog_request.url_title) end - describe "when using custom statuses from the theme" do + it "knows about extended states" do InfoRequest.send(:require, File.expand_path(File.join(File.dirname(__FILE__), '..', 'models', 'customstates'))) InfoRequest.send(:include, InfoRequestCustomStates) InfoRequest.class_eval('@@custom_states_loaded = true') RequestController.send(:require, File.expand_path(File.join(File.dirname(__FILE__), '..', 'models', 'customstates'))) RequestController.send(:include, RequestControllerCustomStates) RequestController.class_eval('@@custom_states_loaded = true') - it "knows about extended states" do - Time.stub!(:now).and_return(Time.utc(2007, 11, 10, 00, 01)) - post_status('deadline_extended') - flash[:notice].should == 'Authority has requested extension of the deadline.' - end + Time.stub!(:now).and_return(Time.utc(2007, 11, 10, 00, 01)) + post_status('deadline_extended') + flash[:notice].should == 'Authority has requested extension of the deadline.' end end -- cgit v1.2.3 From e91482b918698013fd5fdfaf7e0a4e59d00081fb Mon Sep 17 00:00:00 2001 From: David Cabo Date: Thu, 1 Sep 2011 03:53:55 +0200 Subject: Fix test: sign-in step is after Preview request, not before --- 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 c92de9755..d8fe6cc1d 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -353,7 +353,7 @@ describe RequestController, "when creating a new request" do params = { :info_request => { :public_body_id => @body.id, :title => "Why is your quango called Geraldine?", :tag_string => "" }, :outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." }, - :submitted_new_request => 1, :preview => 1 + :submitted_new_request => 1, :preview => 0 } post :new, params post_redirect = PostRedirect.get_last_post_redirect -- cgit v1.2.3 From 204e5c3a739a2bedf927b2f6aa82c373731bbda8 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Sat, 3 Sep 2011 11:44:34 +0100 Subject: Store user's locale against profile, so we can send them localised track emails. Also internationalize more strings at the same time. Fixes #163. --- 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 f3084af12..55b5fc5e3 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -450,6 +450,7 @@ describe RequestController, "when making a new request" do @user.stub!(:get_undescribed_requests).and_return([]) @user.stub!(:can_leave_requests_undescribed?).and_return(false) @user.stub!(:can_file_requests?).and_return(true) + @user.stub!(:locale).and_return("en") User.stub!(:find).and_return(@user) @body = mock_model(PublicBody, :id => 314, :eir_only? => false, :is_requestable? => true, :name => "Test Quango") -- cgit v1.2.3 From 50a1f019535f61f7ed7e09931d0d114e5e4fd538 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Tue, 13 Sep 2011 11:45:45 +0100 Subject: Provide ability to download zip file containing complete request. Closes #11 --- spec/controllers/request_controller_spec.rb | 23 ++++++++++++++++++++++- 1 file changed, 22 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 63e86b525..b4aef8470 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -216,7 +216,28 @@ describe RequestController, "when showing one request" do response.body.should have_tag("p.attachment strong", /goodbye.txt/m) end - + it "should make a zipfile available, which has a different URL when it changes" do + ir = info_requests(:fancy_dog_request) + session[:user_id] = ir.user.id # bob_smith_user + receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) + title = 'why_do_you_have_such_a_fancy_dog' + get :download_entire_request, :url_title => title + assigns[:url_path].should have_text(/#{title}.zip$/) + old_path = assigns[:url_path] + response.location.should have_text(/#{assigns[:url_path]}$/) + zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", old_path)) { |zipfile| + zipfile.count.should == 2 + } + 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$/) + response.location.should have_text(/#{assigns[:url_path]}/) + assigns[:url_path].should_not == old_path + zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", assigns[:url_path])) { |zipfile| + zipfile.count.should == 4 +zipfile.entries.each {|x| puts x.name} + } + end end end -- cgit v1.2.3 From 0f0854cd60aebde1b4a69e455ee40686c4ab0353 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Thu, 15 Sep 2011 11:50:21 +0100 Subject: Simplify the "Send follow up" / "Reply" UI: only offer singe "Write a reply" option, and on the next page, give the user the opportunity to change the recipient from the default (the last valid sender of a message) to any other valid recipient. Closes #35. --- spec/controllers/request_controller_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 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 b4aef8470..aa3027c00 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -533,6 +533,22 @@ describe RequestController, "when viewing an individual response for reply/follo response.should render_template('show_response') end + 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/) + end + + it "should offer an opportunity to reply to another address" do + session[:user_id] = users(:bob_smith_user).id + ir = info_requests(:fancy_dog_request) + ir.allow_new_responses_from = "anybody" + 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/) + end + it "should not show individual responses if request hidden, even if request owner" do ir = info_requests(:fancy_dog_request) ir.prominence = 'hidden' -- cgit v1.2.3 From b48df57d9243336d4b96e29c5587137eff3a3c67 Mon Sep 17 00:00:00 2001 From: David Cabo Date: Fri, 23 Sep 2011 02:50:41 +0200 Subject: Remove invalid collate argument for public body searches The existing bug wasn't catched by the tests, because it only fails when running in dev: otherwise all the classes are loaded before the search is done, and acts_as_xapian can find the provided 'request_collapse' argument, even if the PublicBody class doesn't define it, since all the init options end up together in acts_as_xapian. --- spec/controllers/request_controller_spec.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 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 aa3027c00..494713a4a 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -329,6 +329,33 @@ end # response.headers["Status"].should == "404 Not Found" # end +describe RequestController, "when searching for an authority" do + fixtures :public_bodies, :users + + # 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 + @user = users(:bob_smith_user) + end + + it "should return nothing for the empty query string" do + session[:user_id] = @user.id + get :select_authority, :query => "" + + response.should render_template('select_authority') + assigns[:xapian_requests].results.size == 0 + end + + it "should return matching bodies" do + session[:user_id] = @user.id + get :select_authority, :query => "Quango" + + response.should render_template('select_authority') + assigns[:xapian_requests].results.size == 1 + assigns[:xapian_requests].results[0][:model].name.should == public_bodies(:geraldine_public_body).name + end +end + describe RequestController, "when creating a new request" do integrate_views fixtures :info_requests, :outgoing_messages, :public_bodies, :public_body_translations, :users -- cgit v1.2.3