aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers/admin_public_body_controller_spec.rb
diff options
context:
space:
mode:
authorGareth Rees <gareth@mysociety.org>2015-01-20 12:03:34 +0000
committerGareth Rees <gareth@mysociety.org>2015-02-03 16:24:00 +0000
commit9f2db30774d159eb143497584de65f0d7a68ee40 (patch)
treef5984108e59141a5e793ddba3744cb4f87bee1e5 /spec/controllers/admin_public_body_controller_spec.rb
parenta3dc8ee09b4b0a3661e623ff2665c005fbe8405e (diff)
Add AdminPublicBodyController#update specs
Covers core functionality. Could do with extracting multiple assertions in to individual specs. Strange that you need to call `reload` on the PublicBody instance when testing “updates an existing translation and adds a third translation”
Diffstat (limited to 'spec/controllers/admin_public_body_controller_spec.rb')
-rw-r--r--spec/controllers/admin_public_body_controller_spec.rb106
1 files changed, 106 insertions, 0 deletions
diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb
index 095d23245..8aebbc9ed 100644
--- a/spec/controllers/admin_public_body_controller_spec.rb
+++ b/spec/controllers/admin_public_body_controller_spec.rb
@@ -196,6 +196,111 @@ describe AdminPublicBodyController, "when updating a public body" do
pb.name.should == "Renamed"
end
+ it 'adds a new translation' do
+ pb = public_bodies(:humpadink_public_body)
+ pb.translation_for(:es).destroy
+ pb.reload
+
+ post :update, {
+ :id => pb.id,
+ :public_body => {
+ :name => "Department for Humpadinking",
+ :short_name => "",
+ :tag_string => "some tags",
+ :request_email => 'edited@localhost',
+ :last_edit_comment => 'From test code',
+ :translations_attributes => [
+ { :locale => "es",
+ :name => "El Department for Humpadinking",
+ :short_name => "",
+ :request_email => 'edited@localhost' }
+ ]
+ }
+ }
+
+ request.flash[:notice].should include('successful')
+
+ I18n.with_locale(:es) do
+ expect(pb.name).to eq('El Department for Humpadinking')
+ end
+ end
+
+ it 'adds new translations' do
+ pb = public_bodies(:humpadink_public_body)
+ pb.translation_for(:es).destroy
+ pb.reload
+
+ post :update, {
+ :id => pb.id,
+ :public_body => {
+ :name => "Department for Humpadinking",
+ :short_name => "",
+ :tag_string => "some tags",
+ :request_email => 'edited@localhost',
+ :last_edit_comment => 'From test code',
+ :translations_attributes => [
+ { :locale => "es",
+ :name => "El Department for Humpadinking",
+ :short_name => "",
+ :request_email => 'edited@localhost' },
+ { :locale => "fr",
+ :name => "Le Department for Humpadinking",
+ :short_name => "",
+ :request_email => 'edited@localhost' }
+ ]
+ }
+ }
+
+ request.flash[:notice].should include('successful')
+
+ I18n.with_locale(:es) do
+ expect(pb.name).to eq('El Department for Humpadinking')
+ end
+
+ I18n.with_locale(:fr) do
+ expect(pb.name).to eq('Le Department for Humpadinking')
+ end
+ end
+
+ it 'updates an existing translation and adds a third translation' do
+ pb = public_bodies(:humpadink_public_body)
+
+ post :update, {
+ :id => pb.id,
+ :public_body => {
+ :name => "Department for Humpadinking",
+ :short_name => "",
+ :tag_string => "some tags",
+ :request_email => 'edited@localhost',
+ :last_edit_comment => 'From test code',
+ :translations_attributes => [
+ # Update existing translation
+ { :locale => "es",
+ :name => "Renamed Department for Humpadinking",
+ :short_name => "",
+ :request_email => 'edited@localhost' },
+ # Add new translation
+ { :locale => "fr",
+ :name => "Le Department for Humpadinking",
+ :short_name => "",
+ :request_email => 'edited@localhost' }
+ ]
+ }
+ }
+
+ pb.reload
+
+ request.flash[:notice].should include('successful')
+
+ I18n.with_locale(:es) do
+ expect(pb.name).to eq('Renamed Department for Humpadinking')
+ end
+
+ I18n.with_locale(:fr) do
+ expect(pb.name).to eq('Le Department for Humpadinking')
+ end
+ end
+
it "saves edits to a public body in another locale" do
I18n.with_locale(:es) do
pb = PublicBody.find(id=3)
@@ -226,6 +331,7 @@ describe AdminPublicBodyController, "when updating a public body" do
I18n.with_locale(:en) do
pb.name.should == "Department for Humpadinking"
end
+
end
context 'when the body is being updated as a result of a change request' do