diff options
author | Louise Crow <louise.crow@gmail.com> | 2013-12-09 11:46:37 +0000 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2013-12-09 11:46:37 +0000 |
commit | d326bb5d3d19c60d440b19edaa989578c160542e (patch) | |
tree | 10de9d9976b16b958797a1b186914f9d838164b4 | |
parent | 8a597b7ff7093f8a828a6d5a8af1ccedd8eac05e (diff) | |
parent | 0cbf14f4780a9c38eb73f24f0052e50c60c40769 (diff) |
Merge branch 'feature/locale-underscore-fixes' into rails-3-develop
-rw-r--r-- | app/models/public_body.rb | 7 | ||||
-rw-r--r-- | spec/models/public_body_spec.rb | 18 |
2 files changed, 22 insertions, 3 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb index eb0905f9e..933825d2a 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -260,13 +260,13 @@ class PublicBody < ActiveRecord::Base # When name or short name is changed, also change the url name def short_name=(short_name) - globalize.write(I18n.locale, :short_name, short_name) + globalize.write(Globalize.locale, :short_name, short_name) self[:short_name] = short_name self.update_url_name end def name=(name) - globalize.write(I18n.locale, :name, name) + globalize.write(Globalize.locale, :name, name) self[:name] = name self.update_url_name end @@ -742,7 +742,8 @@ class PublicBody < ActiveRecord::Base # either from config, or based on a (slow!) query if not set body_short_names = AlaveteliConfiguration::frontpage_publicbody_examples.split(/\s*;\s*/) locale_condition = 'public_body_translations.locale = ?' - conditions = [locale_condition, locale] + underscore_locale = locale.gsub '-', '_' + conditions = [locale_condition, underscore_locale] bodies = [] I18n.with_locale(locale) do if body_short_names.empty? diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index d1e2e233d..ed24ced52 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -213,6 +213,15 @@ describe PublicBody, " when saving" do public_body.name.should == "Mark's Public Body" end + it 'should update the right translation when in a locale with an underscore' do + AlaveteliLocalization.set_locales('he_IL', 'he_IL') + public_body = public_bodies(:humpadink_public_body) + translation_count = public_body.translations.size + public_body.name = 'Renamed' + public_body.save! + public_body.translations.size.should == translation_count + end + it 'should not create a new version when nothing has changed' do @public_body.versions.size.should == 0 set_default_attributes(@public_body) @@ -618,3 +627,12 @@ describe PublicBody, "when calculating statistics" do end end + +describe PublicBody, 'when asked for popular bodies' do + + it 'should return bodies correctly when passed the hyphenated version of the locale' do + AlaveteliConfiguration.stub!(:frontpage_publicbody_examples).and_return('') + PublicBody.popular_bodies('he-IL').should == [public_bodies(:humpadink_public_body)] + end + +end |