From be0c61f6c75bcad598450b1047e52d3f2db44777 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Wed, 11 Jan 2012 12:01:49 +0000 Subject: Fix typeahead search specs to match recent API change --- spec/controllers/public_body_controller_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'spec/controllers/public_body_controller_spec.rb') diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index 8182e1331..3996bd520 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -175,20 +175,20 @@ describe PublicBodyController, "when doing type ahead searches" do fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things it "should return nothing for the empty query string" do - get :search_typeahead, :q => "" + get :search_typeahead, :query => "" response.should render_template('public_body/_search_ahead') assigns[:xapian_requests].should be_nil end it "should return a body matching the given keyword, but not users with a matching description" do - get :search_typeahead, :q => "Geraldine" + get :search_typeahead, :query => "Geraldine" response.should render_template('public_body/_search_ahead') assigns[:xapian_requests].results.size.should == 1 assigns[:xapian_requests].results[0][:model].name.should == public_bodies(:geraldine_public_body).name end it "should return all requests matching any of the given keywords" do - get :search_typeahead, :q => "Geraldine Humpadinking" + get :search_typeahead, :query => "Geraldine Humpadinking" response.should render_template('public_body/_search_ahead') assigns[:xapian_requests].results.size.should == 2 assigns[:xapian_requests].results[0][:model].name.should == public_bodies(:humpadink_public_body).name @@ -196,14 +196,14 @@ describe PublicBodyController, "when doing type ahead searches" do end it "should return requests matching the given keywords in any of their locales" do - get :search_typeahead, :q => "baguette" # part of the spanish notes + get :search_typeahead, :query => "baguette" # part of the spanish notes response.should render_template('public_body/_search_ahead') assigns[:xapian_requests].results.size.should == 1 assigns[:xapian_requests].results[0][:model].name.should == public_bodies(:humpadink_public_body).name end it "should not return matches for short words" do - get :search_typeahead, :q => "b" + get :search_typeahead, :query => "b" response.should render_template('public_body/_search_ahead') assigns[:xapian_requests].should be_nil end -- cgit v1.2.3 From 07068037e9b0ac8de80a9eae36a323689c83139d Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Fri, 13 Jan 2012 13:28:23 +0000 Subject: Fix bug introduced in cec2c545e0a10e0641c4ee67839c88d872b394b8, related to issue #343. --- spec/controllers/public_body_controller_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'spec/controllers/public_body_controller_spec.rb') diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index 3996bd520..a563b92ad 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -6,6 +6,11 @@ describe PublicBodyController, "when showing a body" do integrate_views fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things + before(:each) do + load_raw_emails_data(raw_emails) + rebuild_xapian_index + end + it "should be successful" do get :show, :url_name => "dfh", :view => 'all' response.should be_success @@ -26,6 +31,8 @@ describe PublicBodyController, "when showing a body" do assigns[:xapian_requests].results.count.should == 2 get :show, :url_name => "tgq", :view => 'successful' assigns[:xapian_requests].results.count.should == 0 + get :show, :url_name => "dfh", :view => 'all' + assigns[:xapian_requests].results.count.should == 1 end it "should assign the body using different locale from that used for url_name" do -- cgit v1.2.3 From b50adc72e533a9c20aca03063a676f6af4d32b85 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Wed, 18 Jan 2012 08:46:06 +0000 Subject: Fix paging bug for type ahead search. This wasn't caught because the spec didn't call "integrate_views", so the rendering part was mocked by RSpec instead of executed. --- spec/controllers/public_body_controller_spec.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'spec/controllers/public_body_controller_spec.rb') diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index a563b92ad..72fbe965c 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -181,6 +181,8 @@ end describe PublicBodyController, "when doing type ahead searches" do fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things + integrate_views + it "should return nothing for the empty query string" do get :search_typeahead, :query => "" response.should render_template('public_body/_search_ahead') @@ -190,6 +192,7 @@ describe PublicBodyController, "when doing type ahead searches" do it "should return a body matching the given keyword, but not users with a matching description" do get :search_typeahead, :query => "Geraldine" response.should render_template('public_body/_search_ahead') + response.body.should include('search_ahead') assigns[:xapian_requests].results.size.should == 1 assigns[:xapian_requests].results[0][:model].name.should == public_bodies(:geraldine_public_body).name end -- cgit v1.2.3 From 34dad8557132bc730db8e502684f12e4c247c24d Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Fri, 20 Jan 2012 12:10:15 +0000 Subject: Be sure to restore RoutingFilters There were some order-dependent test failures that turned out to be caused by the fact that the RoutingFilters were cleared and not subsequently restored, by some tests. --- spec/controllers/public_body_controller_spec.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'spec/controllers/public_body_controller_spec.rb') diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index 72fbe965c..131412a90 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -50,9 +50,13 @@ describe PublicBodyController, "when showing a body" do end it "should redirect use to the relevant locale even when url_name is for a different locale" do - ActionController::Routing::Routes.filters.clear + old_filters = ActionController::Routing::Routes.filters + ActionController::Routing::Routes.filters = RoutingFilter::Chain.new + get :show, {:url_name => "edfh", :view => 'all'} response.should redirect_to "http://test.host/body/dfh" + + ActionController::Routing::Routes.filters = old_filters end it "should redirect to newest name if you use historic name of public body in URL" do -- cgit v1.2.3 From 24bbaa5afac5ce27c351e3b460be1b0182446ba1 Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Thu, 26 Jan 2012 23:21:12 +0000 Subject: Refactor test code so new test data can be added Previously many of the tests made assumptions about the global structure of the test data set: the total number of requests, for example, or the names of all public bodies. This makes it difficult to add to the test data. This change is intended to make the test data easier to extend by eliminating such global assumptions. --- spec/controllers/public_body_controller_spec.rb | 30 ++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'spec/controllers/public_body_controller_spec.rb') diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index 131412a90..4b657849a 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -26,13 +26,23 @@ describe PublicBodyController, "when showing a body" do assigns[:public_body].should == public_bodies(:humpadink_public_body) end - it "should assign the requests" do + it "should assign the requests (1)" do get :show, :url_name => "tgq", :view => 'all' - assigns[:xapian_requests].results.count.should == 2 + assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ InfoRequest.all( + :conditions => ["public_body_id = ?", public_bodies(:geraldine_public_body).id]) + end + + it "should assign the requests (2)" do get :show, :url_name => "tgq", :view => 'successful' - assigns[:xapian_requests].results.count.should == 0 + assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ InfoRequest.all( + :conditions => ["described_state = ? and public_body_id = ?", + "successful", public_bodies(:geraldine_public_body).id]) + end + + it "should assign the requests (3)" do get :show, :url_name => "dfh", :view => 'all' - assigns[:xapian_requests].results.count.should == 1 + assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ InfoRequest.all( + :conditions => ["public_body_id = ?", public_bodies(:humpadink_public_body).id]) end it "should assign the body using different locale from that used for url_name" do @@ -81,16 +91,16 @@ describe PublicBodyController, "when listing bodies" do it "should list all bodies from default locale, even when there are no translations for selected locale" do PublicBody.with_locale(:en) do - english_only = PublicBody.new(:name => 'English only', + @english_only = PublicBody.new(:name => 'English only', :short_name => 'EO', :request_email => 'english@flourish.org', :last_edit_editor => 'test', :last_edit_comment => '') - english_only.save + @english_only.save end PublicBody.with_locale(:es) do get :list - assigns[:public_bodies].length.should == 3 + assigns[:public_bodies].include?(@english_only).should == true end end @@ -99,7 +109,7 @@ describe PublicBodyController, "when listing bodies" do response.should render_template('list') - assigns[:public_bodies].should == [ public_bodies(:humpadink_public_body), public_bodies(:geraldine_public_body) ] + assigns[:public_bodies].should == PublicBody.all(:order => "name", :conditions => "id <> #{PublicBody.internal_admin_body.id}") assigns[:tag].should == "all" assigns[:description].should == "" end @@ -135,11 +145,11 @@ describe PublicBodyController, "when listing bodies" do get :list, :tag => "other" response.should render_template('list') - assigns[:public_bodies].should == [ public_bodies(:geraldine_public_body) ] + assigns[:public_bodies].should =~ PublicBody.all(:conditions => "id not in (#{public_bodies(:humpadink_public_body).id}, #{PublicBody.internal_admin_body.id})") get :list response.should render_template('list') - assigns[:public_bodies].count.should == 2 + assigns[:public_bodies].should =~ PublicBody.all(:conditions => "id <> #{PublicBody.internal_admin_body.id}") end -- cgit v1.2.3 From 347a24ccfe0881b494044778cae64809d3e001c0 Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Fri, 27 Jan 2012 09:36:02 +0000 Subject: More test data and a new test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a test for what I thought issue #370 might be. However this test is passing, so it isn’t that. --- spec/controllers/public_body_controller_spec.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'spec/controllers/public_body_controller_spec.rb') diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index 4b657849a..bd4e625ca 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -105,11 +105,14 @@ describe PublicBodyController, "when listing bodies" do end it "should list bodies in alphabetical order" do + # Note that they are alphabetised by localised name get :list response.should render_template('list') - assigns[:public_bodies].should == PublicBody.all(:order => "name", :conditions => "id <> #{PublicBody.internal_admin_body.id}") + assigns[:public_bodies].should == PublicBody.all( + :conditions => "id <> #{PublicBody.internal_admin_body.id}", + :order => "(select name from public_body_translations where public_body_id=public_bodies.id and locale='en')") assigns[:tag].should == "all" assigns[:description].should == "" end -- cgit v1.2.3 From 5aa2bd13042110e73212f83564c35b3a1d672bbb Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Sun, 29 Jan 2012 16:26:50 +0000 Subject: Load all raw emails for testing Previously there was just one raw email, and the test code relied on that fact. Generalise it to handle multiple raw emails. This change causes a number of tests to fail, because it exposes failures that should have happened when the second raw email was added but were masked by the fact that the text of this second raw email was never loaded. These failures will be fixed in the next commit. --- spec/controllers/public_body_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers/public_body_controller_spec.rb') diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index bd4e625ca..bf9888685 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -7,7 +7,7 @@ describe PublicBodyController, "when showing a body" do fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things before(:each) do - load_raw_emails_data(raw_emails) + load_raw_emails_data rebuild_xapian_index end -- cgit v1.2.3 From 9613b118b148dff0d54100d7f931189b59f3535c Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Sun, 29 Jan 2012 16:35:06 +0000 Subject: More test data, and fix tests Add some more test data, and fix the tests to accommodate both this new test data and the fact that raw emails are now correctly loaded into the test environment. --- spec/controllers/public_body_controller_spec.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'spec/controllers/public_body_controller_spec.rb') diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index bf9888685..a285a8900 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -199,6 +199,11 @@ describe PublicBodyController, "when doing type ahead searches" do fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things integrate_views + + before(:each) do + load_raw_emails_data + rebuild_xapian_index + end it "should return nothing for the empty query string" do get :search_typeahead, :query => "" @@ -217,16 +222,16 @@ describe PublicBodyController, "when doing type ahead searches" do it "should return all requests matching any of the given keywords" do get :search_typeahead, :query => "Geraldine Humpadinking" response.should render_template('public_body/_search_ahead') - assigns[:xapian_requests].results.size.should == 2 - assigns[:xapian_requests].results[0][:model].name.should == public_bodies(:humpadink_public_body).name - assigns[:xapian_requests].results[1][:model].name.should == public_bodies(:geraldine_public_body).name + assigns[:xapian_requests].results.map{|x|x[:model]}.should =~ [ + public_bodies(:humpadink_public_body), + public_bodies(:geraldine_public_body), + ] end it "should return requests matching the given keywords in any of their locales" do get :search_typeahead, :query => "baguette" # part of the spanish notes response.should render_template('public_body/_search_ahead') - assigns[:xapian_requests].results.size.should == 1 - assigns[:xapian_requests].results[0][:model].name.should == public_bodies(:humpadink_public_body).name + assigns[:xapian_requests].results.map{|x|x[:model]}.should =~ [public_bodies(:humpadink_public_body)] end it "should not return matches for short words" do -- cgit v1.2.3 From f6cd280bbfafa2151ededb8280407686fb73e8a7 Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Sun, 29 Jan 2012 19:12:01 +0000 Subject: Test duplicate requests are coalesced Test that duplicate requests are coalesced on the front page. --- spec/controllers/public_body_controller_spec.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'spec/controllers/public_body_controller_spec.rb') diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index a285a8900..4d27ea3f5 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -153,7 +153,6 @@ describe PublicBodyController, "when listing bodies" do get :list response.should render_template('list') assigns[:public_bodies].should =~ PublicBody.all(:conditions => "id <> #{PublicBody.internal_admin_body.id}") - end it "should list a machine tagged thing, should get it in both ways" do -- cgit v1.2.3 From fd042ca3c96dcb454eddfdc423f68e233b2b3bab Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Mon, 30 Jan 2012 10:47:13 +0000 Subject: Make better wording at the top of the page listing subsets of public bodies. At the same time, cause the tests not to rely on WDTK data. Fixes #396 --- spec/controllers/public_body_controller_spec.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'spec/controllers/public_body_controller_spec.rb') diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index 4d27ea3f5..06077ac60 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- coding: undecided -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require 'json' @@ -138,13 +139,15 @@ describe PublicBodyController, "when listing bodies" do end it "should list a tagged thing on the appropriate list page, and others on the other page, and all still on the all page" do + load_test_categories + public_bodies(:humpadink_public_body).tag_string = "foo local_council" get :list, :tag => "local_council" response.should render_template('list') assigns[:public_bodies].should == [ public_bodies(:humpadink_public_body) ] assigns[:tag].should == "local_council" - assigns[:description].should == "Local councils" + assigns[:description].should == "in the category ‘Local councils’" get :list, :tag => "other" response.should render_template('list') -- cgit v1.2.3 From ac4587afff81177a0bf86fc0064b81538811cb29 Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Tue, 31 Jan 2012 16:29:04 +0000 Subject: Load all fixtures for all tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ad hoc specification of fixtures has been an ongoing source of bugs in the tests. The straw that broke the camel’s back is that 7c6eb09 requires the fixtures to be loaded in order (i.e. children before their parents), and it would have been a painful process to reorder all the dozens of different fixture lists, but the test system ought to be more reliable this way. --- spec/controllers/public_body_controller_spec.rb | 6 ------ 1 file changed, 6 deletions(-) (limited to 'spec/controllers/public_body_controller_spec.rb') diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index 06077ac60..e6eca0781 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -1,11 +1,9 @@ -# -*- coding: undecided -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require 'json' describe PublicBodyController, "when showing a body" do integrate_views - fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things before(:each) do load_raw_emails_data @@ -83,7 +81,6 @@ end describe PublicBodyController, "when listing bodies" do integrate_views - fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things it "should be successful" do get :list @@ -183,8 +180,6 @@ end describe PublicBodyController, "when showing JSON version for API" do - fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things - it "should be successful" do get :show, :url_name => "dfh", :format => "json", :view => 'all' @@ -198,7 +193,6 @@ describe PublicBodyController, "when showing JSON version for API" do end describe PublicBodyController, "when doing type ahead searches" do - fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things integrate_views -- cgit v1.2.3