diff options
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/admin_public_body_controller_spec.rb | 52 | ||||
-rw-r--r-- | spec/controllers/public_body_controller_spec.rb | 26 | ||||
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 18 | ||||
-rw-r--r-- | spec/controllers/track_controller_spec.rb | 2 | ||||
-rw-r--r-- | spec/controllers/user_controller_spec.rb | 7 |
5 files changed, 80 insertions, 25 deletions
diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index a32c27dd9..cb622dabd 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -3,7 +3,14 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminPublicBodyController, "when administering public bodies" 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 "shows the index page" do get :index end @@ -41,6 +48,24 @@ describe AdminPublicBodyController, "when administering public bodies" do 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 @@ -48,6 +73,12 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" 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 "shows the index page" do get :index end @@ -62,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" @@ -95,5 +130,4 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" 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 ac44cb905..64f3f8061 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -526,6 +526,8 @@ describe RequestController, "when classifying an information request" do response.should render_template('user/wrong_user') end + + describe 'when the request is old and unclassified' do before do @@ -714,6 +716,16 @@ describe RequestController, "when classifying an information request" do post_status('rejected') response.should redirect_to(:controller => 'help', :action => 'unhappy', :url_title => @dog_request.url_title) end + + describe "when using custom statuses from the theme" do + InfoRequest.send(:require, File.expand_path(File.join(File.dirname(__FILE__), '..', 'models', 'customstates'))) + + 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 + end end describe 'when redirecting after a successful status update by the request owner' do @@ -735,7 +747,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 @@ -903,7 +915,7 @@ describe RequestController, "sending overdue request alerts" do deliveries = ActionMailer::Base.deliveries deliveries.size.should == 1 mail = deliveries[0] - mail.body.should =~ /promptly, as normally\s+required by law/ + mail.body.should =~ /promptly, as normally/ mail.to_addrs.to_s.should == info_requests(:naughty_chicken_request).user.name_and_email mail.body =~ /(http:\/\/.*\/c\/(.*))/ @@ -931,7 +943,7 @@ describe RequestController, "sending overdue request alerts" do deliveries = ActionMailer::Base.deliveries deliveries.size.should == 1 mail = deliveries[0] - mail.body.should =~ /promptly, as normally\s+required by law during term time/ + mail.body.should =~ /promptly, as normally/ mail.to_addrs.to_s.should == info_requests(:naughty_chicken_request).user.name_and_email end 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') |