aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/public_body_controller.rb12
-rw-r--r--spec/controllers/public_body_controller_spec.rb15
2 files changed, 20 insertions, 7 deletions
diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb
index 251ab5efe..ff9fbadb3 100644
--- a/app/controllers/public_body_controller.rb
+++ b/app/controllers/public_body_controller.rb
@@ -91,31 +91,31 @@ class PublicBodyController < ApplicationController
@query = "%#{params[:public_body_query].nil? ? "" : params[:public_body_query]}%"
@tag = params[:tag]
@locale = self.locale_from_params()
-
+ default_locale = I18n.default_locale.to_s
locale_condition = "(upper(public_body_translations.name) LIKE upper(?)
OR upper(public_body_translations.notes) LIKE upper (?))
AND public_body_translations.locale = ?
AND public_bodies.id <> #{PublicBody.internal_admin_body.id}"
if @tag.nil? or @tag == "all"
@tag = "all"
- conditions = [locale_condition, @query, @query, @locale]
+ conditions = [locale_condition, @query, @query, default_locale]
elsif @tag == 'other'
category_list = PublicBodyCategories::get().tags().map{|c| "'"+c+"'"}.join(",")
conditions = [locale_condition + ' AND (select count(*) from has_tag_string_tags where has_tag_string_tags.model_id = public_bodies.id
and has_tag_string_tags.model = \'PublicBody\'
- and has_tag_string_tags.name in (' + category_list + ')) = 0', @query, @query, @locale]
+ and has_tag_string_tags.name in (' + category_list + ')) = 0', @query, @query, default_locale]
elsif @tag.size == 1
@tag.upcase!
- conditions = [locale_condition + ' AND public_body_translations.first_letter = ?', @query, @query, @locale, @tag]
+ conditions = [locale_condition + ' AND public_body_translations.first_letter = ?', @query, @query, default_locale, @tag]
elsif @tag.include?(":")
name, value = HasTagString::HasTagStringTag.split_tag_into_name_value(@tag)
conditions = [locale_condition + ' AND (select count(*) from has_tag_string_tags where has_tag_string_tags.model_id = public_bodies.id
and has_tag_string_tags.model = \'PublicBody\'
- and has_tag_string_tags.name = ? and has_tag_string_tags.value = ?) > 0', @query, @query, @locale, name, value]
+ and has_tag_string_tags.name = ? and has_tag_string_tags.value = ?) > 0', @query, @query, default_locale, name, value]
else
conditions = [locale_condition + ' AND (select count(*) from has_tag_string_tags where has_tag_string_tags.model_id = public_bodies.id
and has_tag_string_tags.model = \'PublicBody\'
- and has_tag_string_tags.name = ?) > 0', @query, @query, @locale, @tag]
+ and has_tag_string_tags.name = ?) > 0', @query, @query, default_locale, @tag]
end
if @tag == "all"
@description = ""
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb
index ec56707be..53e6c169a 100644
--- a/spec/controllers/public_body_controller_spec.rb
+++ b/spec/controllers/public_body_controller_spec.rb
@@ -68,6 +68,19 @@ describe PublicBodyController, "when listing bodies" do
response.should be_success
end
+ it "should list all bodies even when there are no translations for selected locale" do
+ PublicBody.with_locale(:es) do
+
+ spanish_only = PublicBody.new(:name => 'Spanish only',
+ :short_name => 'SO',
+ :request_email => 'spanish@flourish.org',
+ :last_edit_editor => 'test',
+ :last_edit_comment => '')
+ end
+ get :list
+ assigns[:public_bodies].length.should == 3
+ end
+
it "should list bodies in alphabetical order" do
get :list
@@ -110,7 +123,7 @@ describe PublicBodyController, "when listing bodies" do
get :list, :tag => "other"
response.should render_template('list')
assigns[:public_bodies].should == [ public_bodies(:geraldine_public_body) ]
-
+
get :list
response.should render_template('list')
assigns[:public_bodies].count.should == 2