diff options
author | Louise Crow <louise.crow@gmail.com> | 2015-06-11 10:05:28 +0100 |
---|---|---|
committer | gorm <gormer@gmail.com> | 2015-06-29 21:32:54 +0200 |
commit | a9471ddd30c97db554a8e0dde10417a86fe02c25 (patch) | |
tree | 4ed955cd1ae0954bd221e26c7e80c9fd4af80789 /spec/models/public_body_spec.rb | |
parent | ab00e035c8c5978d2a8aea2a914747c22494aa9a (diff) |
Move updating of derived attributes to a concern.mimes
Add spec to demonstrate that admin-added bodies aren't getting derived attributes.
Add a spec to demonstrate the problem setting the first letter for translations.
Demonstrate failure to update derived attributes in translations.
Diffstat (limited to 'spec/models/public_body_spec.rb')
-rw-r--r-- | spec/models/public_body_spec.rb | 25 |
1 files changed, 25 insertions, 0 deletions
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) |