From b99b1ec3bc5242084c780082a6c737fb736991a8 Mon Sep 17 00:00:00 2001 From: David Cabo Date: Wed, 17 Aug 2011 00:35:50 +0200 Subject: Extend "new public body" form to support multiple locales (closes #142) --- .../admin_public_body_controller_spec.rb | 64 +++++++++++++++++++--- 1 file changed, 56 insertions(+), 8 deletions(-) (limited to 'spec/controllers/admin_public_body_controller_spec.rb') diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index 357564211..64eb45288 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -109,14 +109,6 @@ 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} @@ -148,3 +140,59 @@ 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 + 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("http://test.host/en/admin/body/show/#{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' }, + :public_body_es => { :name => "Nuevo 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") + 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" + end + PublicBody.with_locale(:es) do + body.name.should == "Nuevo Quango" + body.url_name.should == "nuevo_quango" + end + + response.should redirect_to("http://test.host/en/admin/body/show/#{body.id}") + end + + # when submitting the 'new' form, we should ignore a locale if the user hasn't set any value in it + it "doesn't create the public body if anything fails" 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' }, + :public_body_fr => { :name => "Neuf Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' }, + :public_body_es => { :name => "" }, # invalid + } + response.should render_template('new') + PublicBody.count.should == 2 + I18n.locale.should == :en # don't mess up the previous locale + end + +end -- cgit v1.2.3 From 4b1d6f2baea450949047288e4dc76f4197b85b80 Mon Sep 17 00:00:00 2001 From: David Cabo Date: Wed, 17 Aug 2011 00:51:36 +0200 Subject: Make public body creation tests more robust --- spec/controllers/admin_public_body_controller_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'spec/controllers/admin_public_body_controller_spec.rb') diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index 64eb45288..67832cb0e 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -149,6 +149,8 @@ describe AdminPublicBodyController, "when creating public bodies with i18n" 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 @@ -157,7 +159,7 @@ describe AdminPublicBodyController, "when creating public bodies with i18n" do PublicBody.count.should == 3 body = PublicBody.find_by_name("New Quango") - response.should redirect_to("http://test.host/en/admin/body/show/#{body.id}") + response.should redirect_to(:controller=>'admin_public_body', :action=>'show', :id=>body.id) end it "creates a new public body with multiple locales" do @@ -179,7 +181,7 @@ describe AdminPublicBodyController, "when creating public bodies with i18n" do body.url_name.should == "nuevo_quango" end - response.should redirect_to("http://test.host/en/admin/body/show/#{body.id}") + response.should redirect_to(:controller=>'admin_public_body', :action=>'show', :id=>body.id) end # when submitting the 'new' form, we should ignore a locale if the user hasn't set any value in it -- cgit v1.2.3 From 6af5f5cba5cf3c8478d676170faa66bca0ff90ab Mon Sep 17 00:00:00 2001 From: David Cabo Date: Wed, 17 Aug 2011 02:25:36 +0200 Subject: Support editing of public bodies simultaneously in all locales (closes #143) --- .../admin_public_body_controller_spec.rb | 27 +++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'spec/controllers/admin_public_body_controller_spec.rb') diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index 67832cb0e..8c0980db4 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -110,19 +110,25 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" 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_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' }, + :public_body_es => { :name => "Renamed", :short_name => "", :tag_string => "some tags", :request_email => 'edited@localhost', :last_edit_comment => 'From test code' } + } + response.flash[:notice].should include('successful') + end pb = PublicBody.find(public_bodies(:humpadink_public_body).id) PublicBody.with_locale(:es) do @@ -196,5 +202,4 @@ describe AdminPublicBodyController, "when creating public bodies with i18n" do PublicBody.count.should == 2 I18n.locale.should == :en # don't mess up the previous locale end - end -- cgit v1.2.3 From 7f3d321e8da99d0204b66161d9f00381ac24ad2d Mon Sep 17 00:00:00 2001 From: David Cabo Date: Wed, 17 Aug 2011 11:02:40 +0200 Subject: Refactor fixes to #142 and #143, new implementation much simpler to understand --- .../admin_public_body_controller_spec.rb | 39 +++++++++++----------- 1 file changed, 19 insertions(+), 20 deletions(-) (limited to 'spec/controllers/admin_public_body_controller_spec.rb') diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index 8c0980db4..53db4f412 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -113,7 +113,7 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" get :edit, {:id => 3, :locale => :en} # When editing a body, the controller returns all available translations - assigns[:public_body_es].name.should == 'El Department for Humpadinking' + 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 @@ -124,8 +124,16 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" 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' }, - :public_body_es => { :name => "Renamed", :short_name => "", :tag_string => "some tags", :request_email => 'edited@localhost', :last_edit_comment => 'From test code' } + :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 @@ -171,8 +179,10 @@ describe AdminPublicBodyController, "when creating public bodies with i18n" do 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' }, - :public_body_es => { :name => "Nuevo Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' } + :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 @@ -181,25 +191,14 @@ describe AdminPublicBodyController, "when creating public bodies with i18n" do 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 == "Nuevo Quango" - body.url_name.should == "nuevo_quango" + 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 - - # when submitting the 'new' form, we should ignore a locale if the user hasn't set any value in it - it "doesn't create the public body if anything fails" 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' }, - :public_body_fr => { :name => "Neuf Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' }, - :public_body_es => { :name => "" }, # invalid - } - response.should render_template('new') - PublicBody.count.should == 2 - I18n.locale.should == :en # don't mess up the previous locale - end end -- cgit v1.2.3