diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/admin_public_body_controller_spec.rb | 5 | ||||
-rw-r--r-- | spec/models/public_body_spec.rb | 25 |
2 files changed, 29 insertions, 1 deletions
diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index 50a373d9d..789a3d3e3 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -128,7 +128,8 @@ describe AdminPublicBodyController, "when creating a public body" do :last_edit_comment => 'From test code', :translations_attributes => { 'es' => { :locale => 'es', - :name => 'Los Quango' } + :name => 'Los Quango', + :short_name => 'lq' } } } } end @@ -159,6 +160,8 @@ describe AdminPublicBodyController, "when creating a public body" do I18n.with_locale(:es) do expect(body.name).to eq('Los Quango') + expect(body.url_name).to eq('lq') + expect(body.first_letter).to eq('L') end end diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index 7b55efda1..8d584e5e1 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -282,6 +282,31 @@ describe PublicBody, " when saving" do pb.first_letter.should == 'Å' end + it 'should save the first letter of a translation' do + existing = FactoryGirl.create(:public_body, :first_letter => 'T', :name => 'Test body') + I18n.with_locale(:es) { existing.update_attributes :name => 'Prueba body' } + PublicBody::Translation. + where(:public_body_id => existing.id, :locale => :es). + pluck('first_letter').first.should == 'P' + end + + it 'should save the first letter of a translation, even when it is the same as the + first letter in the default locale' do + existing = FactoryGirl.create(:public_body, :first_letter => 'T', :name => 'Test body') + I18n.with_locale(:es) { existing.update_attributes :name => existing.name } + PublicBody::Translation. + where(:public_body_id => existing.id, :locale => :es). + pluck('first_letter').first.should == 'T' + end + + it 'should create a url_name for a translation' do + existing = FactoryGirl.create(:public_body, :first_letter => 'T', :short_name => 'Test body') + I18n.with_locale(:es) do + existing.update_attributes :short_name => 'Prueba', :name => 'Prueba body' + existing.url_name.should == 'prueba' + end + end + it "should not save if the url_name is already taken" do existing = FactoryGirl.create(:public_body) pb = PublicBody.new(existing.attributes) |