aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers/admin_public_body_controller_spec.rb
diff options
context:
space:
mode:
authorRobin Houston <robin@lenny.robin>2011-08-25 17:27:59 +0100
committerRobin Houston <robin@lenny.robin>2011-08-25 17:27:59 +0100
commit50cd41b88b4421824e436d9189f8780b84c46a1a (patch)
tree8a2a33222e1f00f88ce102597db7de09fda5b6a0 /spec/controllers/admin_public_body_controller_spec.rb
parentbf949a62d7882c9d337e095bebd1e4ba6c4c6767 (diff)
parent87f7fbd076fc301262fc0a628d81b3a1bd3688e7 (diff)
Merge branch 'develop' of git@github.com:sebbacon/alaveteli into develop
Diffstat (limited to 'spec/controllers/admin_public_body_controller_spec.rb')
-rw-r--r--spec/controllers/admin_public_body_controller_spec.rb90
1 files changed, 72 insertions, 18 deletions
diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb
index 357564211..53db4f412 100644
--- a/spec/controllers/admin_public_body_controller_spec.rb
+++ b/spec/controllers/admin_public_body_controller_spec.rb
@@ -109,28 +109,34 @@ 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}
- 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].translation("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',
+ :translated_versions => {
+ 3 => {:locale => "es", :name => "Renamed",:short_name => "", :request_email => 'edited@localhost'}
+ }
+ }
+ }
+ response.flash[:notice].should include('successful')
+ end
pb = PublicBody.find(public_bodies(:humpadink_public_body).id)
PublicBody.with_locale(:es) do
@@ -148,3 +154,51 @@ 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
+
+ ActionController::Routing::Routes.filters.clear # don't auto-insert locale, complicates assertions
+ 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(:controller=>'admin_public_body', :action=>'show', :id=>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',
+ :translated_versions => [{ :locale => "es", :name => "Mi Nuevo Quango", :short_name => "", :request_email => 'newquango@localhost' }]
+ }
+ }
+ 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"
+ body.first_letter.should == "N"
+ end
+ PublicBody.with_locale(:es) do
+ 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
+end