diff options
author | Seb Bacon <seb.bacon@gmail.com> | 2011-07-12 11:49:58 +0100 |
---|---|---|
committer | Seb Bacon <seb.bacon@gmail.com> | 2011-07-12 11:49:58 +0100 |
commit | b514aecf08384f3839db5cdb2274d3748a4402a2 (patch) | |
tree | 5354df8cce23f043bc4cbfac0cdcfc24989550a4 /spec/controllers/admin_public_body_controller_spec.rb | |
parent | 0d630ab2c87d925d27879c1cc0db55b0286e46d6 (diff) | |
parent | d5ae493074fa3b71ba517ce34525402f5e59eff0 (diff) |
merge IZ/Kosovo fork and refactor
Diffstat (limited to 'spec/controllers/admin_public_body_controller_spec.rb')
-rw-r--r-- | spec/controllers/admin_public_body_controller_spec.rb | 52 |
1 files changed, 43 insertions, 9 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 |