From b99b1ec3bc5242084c780082a6c737fb736991a8 Mon Sep 17 00:00:00 2001 From: David Cabo Date: Wed, 17 Aug 2011 00:35:50 +0200 Subject: Extend "new public body" form to support multiple locales (closes #142) --- .../admin_public_body_controller_spec.rb | 64 +++++++++++++++++++--- 1 file changed, 56 insertions(+), 8 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index 357564211..64eb45288 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -109,14 +109,6 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" get :show, {:id => 2, :locale => "es" } end - it "creates a new public body" do - I18n.default_locale = :es - PublicBody.count.should == 2 - post :create, { :public_body => { :name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' } } - PublicBody.count.should == 3 - I18n.default_locale = :en - end - it "edits a public body" do I18n.default_locale = :es get :edit, {:id => 3, :locale => :es} @@ -148,3 +140,59 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" end end + +describe AdminPublicBodyController, "when creating public bodies with i18n" do + integrate_views + fixtures :public_bodies, :public_body_translations + + before do + username = MySociety::Config.get('ADMIN_USERNAME', '') + password = MySociety::Config.get('ADMIN_PASSWORD', '') + basic_auth_login @request + end + + it "creates a new public body in one locale" do + PublicBody.count.should == 2 + post :create, { :public_body => { :name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' } } + PublicBody.count.should == 3 + + body = PublicBody.find_by_name("New Quango") + response.should redirect_to("http://test.host/en/admin/body/show/#{body.id}") + end + + it "creates a new public body with multiple locales" do + PublicBody.count.should == 2 + post :create, { + :public_body => { :name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' }, + :public_body_es => { :name => "Nuevo Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' } + } + PublicBody.count.should == 3 + + body = PublicBody.find_by_name("New Quango") + body.translations.map {|t| t.locale.to_s}.sort.should == ["en", "es"] + PublicBody.with_locale(:en) do + body.name.should == "New Quango" + body.url_name.should == "new_quango" + end + PublicBody.with_locale(:es) do + body.name.should == "Nuevo Quango" + body.url_name.should == "nuevo_quango" + end + + response.should redirect_to("http://test.host/en/admin/body/show/#{body.id}") + end + + # when submitting the 'new' form, we should ignore a locale if the user hasn't set any value in it + it "doesn't create the public body if anything fails" do + PublicBody.count.should == 2 + post :create, { + :public_body => { :name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' }, + :public_body_fr => { :name => "Neuf Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' }, + :public_body_es => { :name => "" }, # invalid + } + response.should render_template('new') + PublicBody.count.should == 2 + I18n.locale.should == :en # don't mess up the previous locale + end + +end -- cgit v1.2.3 From 4b1d6f2baea450949047288e4dc76f4197b85b80 Mon Sep 17 00:00:00 2001 From: David Cabo Date: Wed, 17 Aug 2011 00:51:36 +0200 Subject: Make public body creation tests more robust --- spec/controllers/admin_public_body_controller_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index 64eb45288..67832cb0e 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -149,6 +149,8 @@ describe AdminPublicBodyController, "when creating public bodies with i18n" do username = MySociety::Config.get('ADMIN_USERNAME', '') password = MySociety::Config.get('ADMIN_PASSWORD', '') basic_auth_login @request + + ActionController::Routing::Routes.filters.clear # don't auto-insert locale, complicates assertions end it "creates a new public body in one locale" do @@ -157,7 +159,7 @@ describe AdminPublicBodyController, "when creating public bodies with i18n" do PublicBody.count.should == 3 body = PublicBody.find_by_name("New Quango") - response.should redirect_to("http://test.host/en/admin/body/show/#{body.id}") + response.should redirect_to(:controller=>'admin_public_body', :action=>'show', :id=>body.id) end it "creates a new public body with multiple locales" do @@ -179,7 +181,7 @@ describe AdminPublicBodyController, "when creating public bodies with i18n" do body.url_name.should == "nuevo_quango" end - response.should redirect_to("http://test.host/en/admin/body/show/#{body.id}") + response.should redirect_to(:controller=>'admin_public_body', :action=>'show', :id=>body.id) end # when submitting the 'new' form, we should ignore a locale if the user hasn't set any value in it -- cgit v1.2.3 From 6af5f5cba5cf3c8478d676170faa66bca0ff90ab Mon Sep 17 00:00:00 2001 From: David Cabo Date: Wed, 17 Aug 2011 02:25:36 +0200 Subject: Support editing of public bodies simultaneously in all locales (closes #143) --- .../admin_public_body_controller_spec.rb | 27 +++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index 67832cb0e..8c0980db4 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -110,19 +110,25 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" end it "edits a public body" do - I18n.default_locale = :es - get :edit, {:id => 3, :locale => :es} - response.body.should include('Baguette') - I18n.default_locale = :en + get :edit, {:id => 3, :locale => :en} + + # When editing a body, the controller returns all available translations + assigns[:public_body_es].name.should == 'El Department for Humpadinking' + assigns[:public_body].name.should == 'Department for Humpadinking' + response.should render_template('edit') end it "saves edits to a public body" do - I18n.default_locale = :es - pb = PublicBody.find(id=3) - pb.name.should == "El Department for Humpadinking" - post :update, { :id => 3, :public_body => { :name => "Renamed", :short_name => "", :tag_string => "some tags", :request_email => 'edited@localhost', :last_edit_comment => 'From test code' }} - response.flash[:notice].should include('successful') - I18n.default_locale = :en + PublicBody.with_locale(:es) do + pb = PublicBody.find(id=3) + pb.name.should == "El Department for Humpadinking" + post :update, { + :id => 3, + :public_body => { :name => "Department for Humpadinking", :short_name => "", :tag_string => "some tags", :request_email => 'edited@localhost', :last_edit_comment => 'From test code' }, + :public_body_es => { :name => "Renamed", :short_name => "", :tag_string => "some tags", :request_email => 'edited@localhost', :last_edit_comment => 'From test code' } + } + response.flash[:notice].should include('successful') + end pb = PublicBody.find(public_bodies(:humpadink_public_body).id) PublicBody.with_locale(:es) do @@ -196,5 +202,4 @@ describe AdminPublicBodyController, "when creating public bodies with i18n" do PublicBody.count.should == 2 I18n.locale.should == :en # don't mess up the previous locale end - end -- cgit v1.2.3 From 7f3d321e8da99d0204b66161d9f00381ac24ad2d Mon Sep 17 00:00:00 2001 From: David Cabo Date: Wed, 17 Aug 2011 11:02:40 +0200 Subject: Refactor fixes to #142 and #143, new implementation much simpler to understand --- .../admin_public_body_controller_spec.rb | 39 +++++++++++----------- 1 file changed, 19 insertions(+), 20 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index 8c0980db4..53db4f412 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -113,7 +113,7 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" get :edit, {:id => 3, :locale => :en} # When editing a body, the controller returns all available translations - assigns[:public_body_es].name.should == 'El Department for Humpadinking' + assigns[:public_body].translation("es").name.should == 'El Department for Humpadinking' assigns[:public_body].name.should == 'Department for Humpadinking' response.should render_template('edit') end @@ -124,8 +124,16 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" pb.name.should == "El Department for Humpadinking" post :update, { :id => 3, - :public_body => { :name => "Department for Humpadinking", :short_name => "", :tag_string => "some tags", :request_email => 'edited@localhost', :last_edit_comment => 'From test code' }, - :public_body_es => { :name => "Renamed", :short_name => "", :tag_string => "some tags", :request_email => 'edited@localhost', :last_edit_comment => 'From test code' } + :public_body => { + :name => "Department for Humpadinking", + :short_name => "", + :tag_string => "some tags", + :request_email => 'edited@localhost', + :last_edit_comment => 'From test code', + :translated_versions => { + 3 => {:locale => "es", :name => "Renamed",:short_name => "", :request_email => 'edited@localhost'} + } + } } response.flash[:notice].should include('successful') end @@ -171,8 +179,10 @@ describe AdminPublicBodyController, "when creating public bodies with i18n" do it "creates a new public body with multiple locales" do PublicBody.count.should == 2 post :create, { - :public_body => { :name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' }, - :public_body_es => { :name => "Nuevo Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' } + :public_body => { + :name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code', + :translated_versions => [{ :locale => "es", :name => "Mi Nuevo Quango", :short_name => "", :request_email => 'newquango@localhost' }] + } } PublicBody.count.should == 3 @@ -181,25 +191,14 @@ describe AdminPublicBodyController, "when creating public bodies with i18n" do PublicBody.with_locale(:en) do body.name.should == "New Quango" body.url_name.should == "new_quango" + body.first_letter.should == "N" end PublicBody.with_locale(:es) do - body.name.should == "Nuevo Quango" - body.url_name.should == "nuevo_quango" + body.name.should == "Mi Nuevo Quango" + body.url_name.should == "mi_nuevo_quango" + body.first_letter.should == "M" end response.should redirect_to(:controller=>'admin_public_body', :action=>'show', :id=>body.id) end - - # when submitting the 'new' form, we should ignore a locale if the user hasn't set any value in it - it "doesn't create the public body if anything fails" do - PublicBody.count.should == 2 - post :create, { - :public_body => { :name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' }, - :public_body_fr => { :name => "Neuf Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' }, - :public_body_es => { :name => "" }, # invalid - } - response.should render_template('new') - PublicBody.count.should == 2 - I18n.locale.should == :en # don't mess up the previous locale - end end -- cgit v1.2.3 From 7796e1fb8d6238ed13b1a4b5ef3ccf91499a9b4b Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Wed, 24 Aug 2011 16:02:28 +0100 Subject: Anneal brittle test --- spec/controllers/user_controller_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index c974c8a0d..438fb8c0c 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -179,7 +179,9 @@ describe UserController, "when signing up" do deliveries = ActionMailer::Base.deliveries deliveries.size.should == 1 - deliveries[0].body.should include("when you already have an") + + # This text may span a line break, depending on the length of the SITE_NAME + deliveries[0].body.should match(/when\s+you\s+already\s+have\s+an/) end # XXX need to do bob@localhost signup and check that sends different email -- 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/general_controller_spec.rb | 2 +- spec/controllers/public_body_controller_spec.rb | 25 ++++++++++++++++--------- spec/controllers/request_controller_spec.rb | 6 +----- 3 files changed, 18 insertions(+), 15 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index 3640a8148..a76cdd3b6 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -64,7 +64,7 @@ describe GeneralController, "when searching" do it "should redirect from search query URL to pretty URL" do post :search_redirect, :query => "mouse" # query hidden in POST parameters - response.should redirect_to(:action => 'search', :combined => "mouse") # URL /search/:query + response.should redirect_to(:action => 'search', :combined => "mouse", :view => "all") # URL /search/:query/all end describe "when using different locale settings" do diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index 0050678d2..0ac2726ea 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -7,47 +7,54 @@ describe PublicBodyController, "when showing a body" do fixtures :public_bodies, :public_body_translations, :public_body_versions it "should be successful" do - get :show, :url_name => "dfh" + get :show, :url_name => "dfh", :view => 'all' response.should be_success end it "should render with 'show' template" do - get :show, :url_name => "dfh" + get :show, :url_name => "dfh", :view => 'all' response.should render_template('show') end it "should assign the body" do - get :show, :url_name => "dfh" + get :show, :url_name => "dfh", :view => 'all' assigns[:public_body].should == public_bodies(:humpadink_public_body) end + it "should assign the requests" do + get :show, :url_name => "tgq", :view => 'all' + assigns[:xapian_requests].results.count.should == 2 + get :show, :url_name => "tgq", :view => 'successful' + assigns[:xapian_requests].results.count.should == 0 + end + it "should assign the body using different locale from that used for url_name" do PublicBody.with_locale(:es) do - get :show, {:url_name => "dfh"} + get :show, {:url_name => "dfh", :view => 'all'} assigns[:public_body].notes.should == "Baguette" end end it "should assign the body using same locale as that used in url_name" do PublicBody.with_locale(:es) do - get :show, {:url_name => "edfh"} + get :show, {:url_name => "edfh", :view => 'all'} assigns[:public_body].notes.should == "Baguette" end end it "should redirect use to the relevant locale even when url_name is for a different locale" do ActionController::Routing::Routes.filters.clear - get :show, {:url_name => "edfh"} + get :show, {:url_name => "edfh", :view => 'all'} response.should redirect_to "http://test.host/body/dfh" end it "should redirect to newest name if you use historic name of public body in URL" do - get :show, :url_name => "hdink" + get :show, :url_name => "hdink", :view => 'all' response.should redirect_to(:controller => 'public_body', :action => 'show', :url_name => "dfh") end it "should redirect to lower case name if you use mixed case name in URL" do - get :show, :url_name => "dFh" + get :show, :url_name => "dFh", :view => 'all' response.should redirect_to(:controller => 'public_body', :action => 'show', :url_name => "dfh") end end @@ -128,7 +135,7 @@ describe PublicBodyController, "when showing JSON version for API" do fixtures :public_bodies, :public_body_translations it "should be successful" do - get :show, :url_name => "dfh", :format => "json" + get :show, :url_name => "dfh", :format => "json", :view => 'all' pb = JSON.parse(response.body) pb.class.to_s.should == 'Hash' 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/general_controller_spec.rb | 28 +++++++++++++++++++++++++ spec/controllers/public_body_controller_spec.rb | 10 +++++++++ spec/controllers/request_controller_spec.rb | 16 ++++++++++++++ 3 files changed, 54 insertions(+) (limited to 'spec/controllers') diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index a76cdd3b6..4d7f1831d 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -122,6 +122,34 @@ describe GeneralController, "when searching" do end + it "should filter results based on end of URL being 'all'" do + get :search, :combined => ['"bob"', "all"] + assigns[:xapian_requests].results.size.should == 2 + assigns[:xapian_users].results.size.should == 1 + assigns[:xapian_bodies].results.size.should == 0 + end + + it "should filter results based on end of URL being 'users'" do + get :search, :combined => ['"bob"', "users"] + assigns[:xapian_requests].should == nil + assigns[:xapian_users].results.size.should == 1 + assigns[:xapian_bodies].should == nil + end + + it "should filter results based on end of URL being 'requests'" do + get :search, :combined => ['"bob"', "requests"] + assigns[:xapian_requests].results.size.should == 2 + assigns[:xapian_users].should == nil + assigns[:xapian_bodies].should == nil + end + + it "should filter results based on end of URL being 'bodies'" do + get :search, :combined => ['"quango"', "bodies"] + assigns[:xapian_requests].should == nil + assigns[:xapian_users].should == nil + assigns[:xapian_bodies].results.size.should == 1 + end + it "should show help when searching for nothing" do get :search_redirect, :query => nil response.should render_template('search') diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index 0ac2726ea..df3fc10dc 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -78,6 +78,16 @@ describe PublicBodyController, "when listing bodies" do assigns[:description].should == "all" end + it "should support simple searching of bodies by title" do + get :list, :public_body_query => 'quango' + assigns[:public_bodies].should == [ public_bodies(:geraldine_public_body) ] + end + + it "should support simple searching of bodies by notes" do + get :list, :public_body_query => 'Albatross' + assigns[:public_bodies].should == [ public_bodies(:humpadink_public_body) ] + end + it "should list bodies in alphabetical order with different locale" do I18n.default_locale = :es get :list 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