aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2013-12-05 16:57:02 +0000
committerLouise Crow <louise.crow@gmail.com>2013-12-05 18:54:20 +0000
commit3ad5277ed2c9f98508a7208848e125d274c86a3b (patch)
tree87f8fdb3cc62b26c4766b8ed46c46bd23b3950e8
parentd35b7fec9ad723496c95791ae314964f4d3360dd (diff)
Search for bodies using the underscore version of the locale.
-rw-r--r--app/models/public_body.rb3
-rw-r--r--spec/models/public_body_spec.rb9
2 files changed, 11 insertions, 1 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index 8e474c797..c007afb6e 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -727,7 +727,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 23842ccff..0c29503a3 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -604,3 +604,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