diff options
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/api_controller_spec.rb | 3 | ||||
-rw-r--r-- | spec/controllers/general_controller_spec.rb | 88 | ||||
-rw-r--r-- | spec/controllers/help_controller_spec.rb | 6 | ||||
-rw-r--r-- | spec/controllers/public_body_controller_spec.rb | 40 | ||||
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 15 | ||||
-rw-r--r-- | spec/controllers/track_controller_spec.rb | 5 | ||||
-rw-r--r-- | spec/controllers/user_controller_spec.rb | 49 |
7 files changed, 58 insertions, 148 deletions
diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb index 66b8e33f0..8e9d17fbe 100644 --- a/spec/controllers/api_controller_spec.rb +++ b/spec/controllers/api_controller_spec.rb @@ -83,6 +83,9 @@ describe ApiController, "when using the API" do new_request.last_event_forming_initial_request.outgoing_message.body.should == request_data["body"].strip new_request.public_body_id.should == public_bodies(:geraldine_public_body).id + new_request.info_request_events.size.should == 1 + new_request.info_request_events[0].event_type.should == 'sent' + new_request.info_request_events[0].calculated_state.should == 'waiting_response' end def _create_request diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index 0eda73c51..8c86ad0be 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -108,97 +108,15 @@ describe GeneralController, "when showing the frontpage" do response.should be_success end - describe 'when there is more than one locale' do - - describe 'when using the default locale' do - - before do - @default_lang_home_link = /href=".*\/en\// - @other_lang_home_link = /href=".*\/es\// - @old_include_default_locale_in_urls = AlaveteliConfiguration::include_default_locale_in_urls - end - - def set_default_locale_in_urls(value) - AlaveteliConfiguration.stub!(:include_default_locale_in_urls).and_return(value) - load Rails.root.join("config/initializers/fast_gettext.rb") - end - - describe 'when the config value INCLUDE_DEFAULT_LOCALE_IN_URLS is false' do - - before do - set_default_locale_in_urls(false) - end - - it 'should generate URLs without a locale prepended' do - get :frontpage - response.should_not contain @default_lang_home_link - end - - it 'should render the front page in the default language when no locale param - is present and the session locale is not the default' do - get(:frontpage, {}, {:locale => 'es'}) - response.should_not contain @other_lang_home_link - end - end - - it 'should generate URLs with a locale prepended when the config value - INCLUDE_DEFAULT_LOCALE_IN_URLS is true' do - set_default_locale_in_urls(true) - get :frontpage - response.body.should match /#{@default_lang_home_link}/ - end - - after do - set_default_locale_in_urls(@old_include_default_locale_in_urls) - end - - end - end - - - describe "when using different locale settings" do - home_link_regex = /href=".*\/en\// - - it "should generate URLs with a locale prepended when there's more than one locale set" do - get :frontpage - response.body.should match home_link_regex - end + describe 'when using locales' do it "should use our test PO files rather than the application one" do - I18n.default_locale = :es - get :frontpage + get :frontpage, :locale => 'es' response.body.should match /XOXO/ - I18n.default_locale = :en - end - - it "should generate URLs that include the locale when using one that includes an underscore" do - I18n.default_locale = :"en_GB" - get :frontpage - response.body.should match /href="\/en_GB\// - I18n.default_locale = :en - end - - it "should fall back to the language if the territory is unknown" do - I18n.default_locale = :"en_US" - get :frontpage - response.body.should match /href="\/en\// - response.body.should_not match /href="\/en_US\// - I18n.default_locale = :en - end - - it "should generate URLs without a locale prepended when there's only one locale set" do - old_fgt_available_locales = FastGettext.default_available_locales - old_i18n_available_locales = I18n.available_locales - FastGettext.default_available_locales = I18n.available_locales = ['en'] - - get :frontpage - response.should_not contain home_link_regex - - FastGettext.default_available_locales = old_fgt_available_locales - I18n.available_locales = old_i18n_available_locales end end + end describe GeneralController, "when showing the front page with fixture data" do diff --git a/spec/controllers/help_controller_spec.rb b/spec/controllers/help_controller_spec.rb index c47e1abd3..cc024f840 100644 --- a/spec/controllers/help_controller_spec.rb +++ b/spec/controllers/help_controller_spec.rb @@ -31,17 +31,11 @@ describe HelpController, "when using help" do describe 'when requesting a page in a supported locale ' do before do - # Allow us to supply the locale manually - RoutingFilter.active = false # Prepend our fixture templates fixture_theme_path = File.join(Rails.root, 'spec', 'fixtures', 'theme_views', 'theme_one') controller.prepend_view_path fixture_theme_path end - after do - RoutingFilter.active = true - end - it 'should render the locale-specific template if available' do get :contact, {:locale => 'es'} response.body.should match('contáctenos theme one') diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index e01bcb0a6..4e1841164 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -43,28 +43,20 @@ describe PublicBodyController, "when showing a body" do :conditions => ["public_body_id = ?", public_bodies(:humpadink_public_body).id]) end - it "should redirect to the canonical name in the chosen locale" do - get :show, {:url_name => "dfh", :view => 'all', :show_locale => "es"} - response.should redirect_to "http://test.host/es/body/edfh" + it "should display the body using same locale as that used in url_name" do + get :show, {:url_name => "edfh", :view => 'all', :locale => "es"} + response.should contain("Baguette") end - it "should assign the body using same locale as that used in url_name" do - get :show, {:url_name => "edfh", :view => 'all', :show_locale => "es"} - response.should contain("Baguette") + it 'should show public body names in the selected locale language if present for a locale with underscores' do + AlaveteliLocalization.set_locales('he_IL en', 'en') + get :show, {:url_name => 'dfh', :view => 'all', :locale => 'he_IL'} + response.should contain('Hebrew Humpadinking') end it "should redirect use to the relevant locale even when url_name is for a different locale" do - RoutingFilter.active = false - get :show, {:url_name => "edfh", :view => 'all'} response.should redirect_to "http://test.host/body/dfh" - - RoutingFilter.active = true - end - - it "should remember the filter (view) setting on redirecting" do - get :show, :show_locale => "es", :url_name => "tgq", :view => 'successful' - response.should redirect_to 'http://test.host/es/body/etgq/successful' end it "should redirect to newest name if you use historic name of public body in URL" do @@ -95,12 +87,22 @@ describe PublicBodyController, "when listing bodies" do :last_edit_comment => '') @english_only.save end - I18n.with_locale(:es) do - get :list - assigns[:public_bodies].include?(@english_only).should == true - end + get :list, {:locale => 'es'} + assigns[:public_bodies].include?(@english_only).should == true + end + + it 'should show public body names in the selected locale language if present' do + get :list, {:locale => 'es'} + response.should contain('El Department for Humpadinking') end + it 'should show public body names in the selected locale language if present for a locale with underscores' do + AlaveteliLocalization.set_locales('he_IL en', 'en') + get :list, {:locale => 'he_IL'} + response.should contain('Hebrew Humpadinking') + end + + it "should list bodies in alphabetical order" do # Note that they are alphabetised by localised name get :list diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index c73576c50..2c605a139 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1519,8 +1519,8 @@ describe RequestController, "when classifying an information request" do post_status('rejected') end - it 'should not log a status update event' do - @dog_request.should_not_receive(:log_event) + it 'should log a status update event' do + @dog_request.should_receive(:log_event) post_status('rejected') end @@ -1573,11 +1573,12 @@ describe RequestController, "when classifying an information request" do @dog_request.awaiting_description.should == false @dog_request.described_state.should == 'rejected' @dog_request.get_last_response_event.should == info_request_events(:useless_incoming_message_event) - @dog_request.get_last_response_event.calculated_state.should == 'rejected' + @dog_request.info_request_events.last.event_type.should == "status_update" + @dog_request.info_request_events.last.calculated_state.should == 'rejected' end - it 'should not log a status update event' do - @dog_request.should_not_receive(:log_event) + it 'should log a status update event' do + @dog_request.should_receive(:log_event) post_status('rejected') end @@ -1645,10 +1646,6 @@ describe RequestController, "when classifying an information request" do @dog_request = info_requests(:fancy_dog_request) @dog_request.stub!(:each).and_return([@dog_request]) InfoRequest.stub!(:find).and_return(@dog_request) - RoutingFilter.active = false - end - after do - RoutingFilter.active = true end def request_url diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb index 1575bc84e..a16024828 100644 --- a/spec/controllers/track_controller_spec.rb +++ b/spec/controllers/track_controller_spec.rb @@ -64,8 +64,6 @@ describe TrackController, "when sending alerts for a track" do end it "should send alerts" do - # Don't do clever locale-insertion-unto-URL stuff - RoutingFilter.active = false # set the time the comment event happened at to within the last week ire = info_request_events(:silly_comment_event) @@ -111,9 +109,6 @@ describe TrackController, "when sending alerts for a track" do TrackMailer.alert_tracks deliveries = ActionMailer::Base.deliveries deliveries.size.should == 0 - - # Restore the routing filters - RoutingFilter.active = true end it "should send localised alerts" do diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index b09594b9c..0033309a5 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -3,6 +3,31 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') # XXX Use route_for or params_from to check /c/ links better # http://rspec.rubyforge.org/rspec-rails/1.1.12/classes/Spec/Rails/Example/ControllerExampleGroup.html +describe UserController, "when redirecting a show request to a canonical url" do + + it "should redirect to lower case name if given one with capital letters" do + get :show, :url_name => "Bob_Smith" + response.should redirect_to(:controller => 'user', :action => 'show', :url_name => "bob_smith") + end + + it 'should redirect a long non-canonical name that has a numerical suffix, + retaining the suffix' do + get :show, :url_name => 'Bob_SmithBob_SmithBob_SmithBob_S_2' + response.should redirect_to(:controller => 'user', + :action => 'show', + :url_name => 'bob_smithbob_smithbob_smithbob_s_2') + end + + it 'should not redirect a long canonical name that has a numerical suffix' do + User.stub!(:find).with(:first, anything()).and_return(mock_model(User, + :url_name => 'bob_smithbob_smithbob_smithbob_s_2', + :name => 'Bob Smith Bob Smith Bob Smith Bob Smith')) + User.stub!(:find).with(:all, anything()).and_return([]) + get :show, :url_name => 'bob_smithbob_smithbob_smithbob_s_2' + response.should be_success + end + +end describe UserController, "when showing a user" do render_views @@ -16,11 +41,6 @@ describe UserController, "when showing a user" do response.should be_success end - it "should redirect to lower case name if given one with capital letters" do - get :show, :url_name => "Bob_Smith" - response.should redirect_to(:controller => 'user', :action => 'show', :url_name => "bob_smith") - end - it "should render with 'show' template" do get :show, :url_name => "bob_smith" response.should render_template('show') @@ -105,8 +125,6 @@ describe UserController, "when signing in" do end it "should log in when you give right email/password, and redirect to where you were" do - RoutingFilter.active = false - get :signin, :r => "/list" response.should render_template('sign') post_redirect = get_last_postredirect @@ -117,13 +135,9 @@ describe UserController, "when signing in" do # response doesn't contain /en/ but redirect_to does... response.should redirect_to(:controller => 'request', :action => 'list', :post_redirect => 1) ActionMailer::Base.deliveries.should be_empty - - RoutingFilter.active = true end it "should not log you in if you use an invalid PostRedirect token, and shouldn't give 500 error either" do - RoutingFilter.active = false - post_redirect = "something invalid" lambda { post :signin, { :user_signin => { :email => 'bob@localhost', :password => 'jonespassword' }, @@ -134,8 +148,6 @@ describe UserController, "when signing in" do :token => post_redirect } response.should render_template('sign') assigns[:post_redirect].should == nil - - RoutingFilter.active = true end # No idea how to test this in the test framework :( @@ -159,8 +171,6 @@ describe UserController, "when signing in" do end it "should confirm your email, log you in and redirect you to where you were after you click an email link" do - RoutingFilter.active = false - get :signin, :r => "/list" post_redirect = get_last_postredirect @@ -186,13 +196,9 @@ describe UserController, "when signing in" do get :confirm, :email_token => post_redirect.email_token session[:user_id].should == users(:unconfirmed_user).id response.should redirect_to(:controller => 'request', :action => 'list', :post_redirect => 1) - - RoutingFilter.active = true end it "should keep you logged in if you click a confirmation link and are already logged in as an admin" do - RoutingFilter.active = false - get :signin, :r => "/list" post_redirect = get_last_postredirect @@ -223,7 +229,6 @@ describe UserController, "when signing in" do # And the redirect should still work, of course response.should redirect_to(:controller => 'request', :action => 'list', :post_redirect => 1) - RoutingFilter.active = true end end @@ -301,14 +306,10 @@ describe UserController, "when signing out" do end it "should log you out and redirect you to where you were" do - RoutingFilter.active = false - session[:user_id] = users(:bob_smith_user).id get :signout, :r => '/list' session[:user_id].should be_nil response.should redirect_to(:controller => 'request', :action => 'list') - - RoutingFilter.active = true end end |