diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/admin_public_body_controller_spec.rb | 57 | ||||
-rw-r--r-- | spec/controllers/public_body_controller_spec.rb | 26 | ||||
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 2 | ||||
-rw-r--r-- | spec/controllers/track_controller_spec.rb | 2 | ||||
-rw-r--r-- | spec/controllers/user_controller_spec.rb | 7 | ||||
-rw-r--r-- | spec/helpers/link_to_helper_spec.rb | 3 | ||||
-rw-r--r-- | spec/spec_helper.rb | 6 | ||||
-rw-r--r-- | spec/views/request/show.rhtml_spec.rb | 4 |
8 files changed, 59 insertions, 48 deletions
diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index 9eabb2f8e..cb622dabd 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -47,6 +47,26 @@ describe AdminPublicBodyController, "when administering public bodies" do post :destroy, { :id => 3 } PublicBody.count.should == 1 end + + it "don't allow non-authenticated users to do anything" do + @request.env["HTTP_AUTHORIZATION"] = "" + PublicBody.count.should == 2 + post :destroy, { :id => 3 } + response.code.should == "401" + PublicBody.count.should == 2 + end + + it "when no username/password set, skip admin authorisation" do + config = MySociety::Config.load_default() + config['ADMIN_USERNAME'] = '' + config['ADMIN_PASSWORD'] = '' + @request.env["HTTP_AUTHORIZATION"] = "" + PublicBody.count.should == 2 + post :destroy, { :id => 3 } + PublicBody.count.should == 1 + end + + end describe AdminPublicBodyController, "when administering public bodies with i18n" do @@ -73,24 +93,28 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" end it "creates a new public body" do + I18n.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.locale = :en end it "edits a public body" do - get :edit, {:id => 3, :locale => 'es'} + I18n.locale = :es + get :edit, {:id => 3, :locale => :es} response.body.should include('Baguette') + I18n.locale = :en end it "saves edits to a public body" do - PublicBody.with_locale(:es) do - pb = PublicBody.find(id=3) - pb.name.should == "El Department for Humpadinking" - end + I18n.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.locale = :en - post :update, { :id => 3, :public_body => { :name => "Renamed", :short_name => "", :tag_string => "some tags", :request_email => 'edited@localhost', :last_edit_comment => 'From test code' }, :locale => "es" } - response.flash[:notice].should include('successful') pb = PublicBody.find(public_bodies(:humpadink_public_body).id) PublicBody.with_locale(:es) do pb.name.should == "Renamed" @@ -106,23 +130,4 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" PublicBody.count.should == 1 end - it "don't allow non-authenticated users to do anything" do - @request.env["HTTP_AUTHORIZATION"] = "" - PublicBody.count.should == 2 - post :destroy, { :id => 3 } - response.code.should == "401" - PublicBody.count.should == 2 - end - - it "when no username/password set, skip admin authorisation" do - config = MySociety::Config.load_default() - config['ADMIN_USERNAME'] = '' - config['ADMIN_PASSWORD'] = '' - @request.env["HTTP_AUTHORIZATION"] = "" - PublicBody.count.should == 2 - post :destroy, { :id => 3 } - PublicBody.count.should == 1 - end - - end diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index 8b84b89ec..d15482e51 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -22,20 +22,23 @@ describe PublicBodyController, "when showing a body" do end it "should assign the body using different locale from that used for url_name" do - get :show, {:url_name => "dfh", :locale => 'es'} - assigns[:public_body].notes.should == "Baguette" + PublicBody.with_locale(:es) do + get :show, {:url_name => "dfh"} + assigns[:public_body].notes.should == "Baguette" + end end it "should assign the body using same locale as that used in url_name" do - get :show, {:url_name => "edfh", :locale => 'es'} - assigns[:public_body].notes.should == "Baguette" + PublicBody.with_locale(:es) do + get :show, {:url_name => "edfh"} + assigns[:public_body].notes.should == "Baguette" + end end - it "should assign the body using same locale as that used in url_name even with wrongly set locale" do - PublicBody.with_locale(:en) do - get :show, {:url_name => "edfh", :locale => 'es'} - response.body.should include('Baguette') - 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"} + 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 @@ -69,12 +72,13 @@ describe PublicBodyController, "when listing bodies" do end it "should list bodies in alphabetical order with different locale" do - get :list, :locale => "es" + I18n.locale = :es + get :list response.should render_template('list') - assigns[:public_bodies].should == [ public_bodies(:geraldine_public_body), public_bodies(:humpadink_public_body) ] assigns[:tag].should == "all" assigns[:description].should == "all" + I18n.locale = :en 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 diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 200746e0d..0d9916b71 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -735,7 +735,7 @@ describe RequestController, "when classifying an information request" do def expect_redirect(status, redirect_path) post_status(status) - response.should redirect_to("http://test.host/#{redirect_path}") + response.should redirect_to("http://test.host/en/#{redirect_path}") end it 'should redirect to the "request url" with a message in the right tense when status is updated to "waiting response" and the response is not overdue' do diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb index 8076d40c2..0a8919268 100644 --- a/spec/controllers/track_controller_spec.rb +++ b/spec/controllers/track_controller_spec.rb @@ -43,6 +43,8 @@ describe TrackController, "when sending alerts for a track" do end it "should send alerts" do + # Don't do clever locale-insertion-unto-URL stuff + ActionController::Routing::Routes.filters.clear # set the time the comment event happened at to within the last week ire = info_request_events(:silly_comment_event) ire.created_at = Time.now - 3.days diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index 4e21bc467..c6817fbc6 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -75,6 +75,7 @@ describe UserController, "when signing in" do end it "should log in when you give right email/password, and redirect to where you were" do + ActionController::Routing::Routes.filters.clear get :signin, :r => "/list" response.should render_template('sign') post_redirect = get_last_postredirect @@ -82,6 +83,7 @@ describe UserController, "when signing in" do :token => post_redirect.token } session[:user_id].should == users(:bob_smith_user).id + # response doesn't contain /en/ but redirect_to does... response.should redirect_to(:controller => 'request', :action => 'list', :post_redirect => 1) response.should_not send_email end @@ -107,6 +109,7 @@ 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 + ActionController::Routing::Routes.filters.clear get :signin, :r => "/list" post_redirect = get_last_postredirect @@ -191,6 +194,7 @@ describe UserController, "when signing out" do end it "should log you out and redirect you to where you were" do + ActionController::Routing::Routes.filters.clear session[:user_id] = users(:bob_smith_user).id get :signout, :r => '/list' session[:user_id].should be_nil @@ -420,8 +424,7 @@ describe UserController, "when changing email address" do "signchangeemail"=>{ "old_email"=>"bob@localhost", "new_email"=>"newbob@localhost"}, - "controller"=>"user", - "locale"=>"en"} + "controller"=>"user"} post :signchangeemail, post_redirect.post_params response.should redirect_to(:controller => 'user', :action => 'show', :url_name => 'bob_smith') diff --git a/spec/helpers/link_to_helper_spec.rb b/spec/helpers/link_to_helper_spec.rb index 401c324fe..aae00c298 100644 --- a/spec/helpers/link_to_helper_spec.rb +++ b/spec/helpers/link_to_helper_spec.rb @@ -7,6 +7,7 @@ describe LinkToHelper do describe 'when creating a url for a request' do before do + ActionController::Routing::Routes.filters.clear @mock_request = mock_model(InfoRequest, :url_title => 'test_title') end @@ -20,4 +21,4 @@ describe LinkToHelper do end -end
\ No newline at end of file +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 56b1fd92a..33793dea3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -125,12 +125,6 @@ if $tempfilecount.nil? alias :original_process :process def process(action, parameters = nil, session = nil, flash = nil, http_method = 'GET') - # Call original process function - if parameters.nil? - parameters = {:locale => "en"} - elsif not parameters.has_key?(:locale) - parameters[:locale] = "en" - end self.original_process(action, parameters, session, flash, http_method) # XXX Is there a better way to check this than calling a private method? diff --git a/spec/views/request/show.rhtml_spec.rb b/spec/views/request/show.rhtml_spec.rb index 54ce9c63a..ca4663afc 100644 --- a/spec/views/request/show.rhtml_spec.rb +++ b/spec/views/request/show.rhtml_spec.rb @@ -83,7 +83,8 @@ describe 'when viewing an information request' do describe 'when there is a last response' do - before do + before do + ActionController::Routing::Routes.filters.clear @mock_response = mock_model(IncomingMessage) @mock_request.stub!(:get_last_response).and_return(@mock_response) end @@ -99,6 +100,7 @@ describe 'when viewing an information request' do describe 'when there is no last response' do before do + ActionController::Routing::Routes.filters.clear @mock_request.stub!(:get_last_response).and_return(nil) end |