diff options
author | Gareth Rees <gareth@mysociety.org> | 2014-05-28 10:39:27 +0100 |
---|---|---|
committer | Gareth Rees <gareth@mysociety.org> | 2014-05-28 10:39:27 +0100 |
commit | 96aed851f2d94f95591b9a8180da9d3aa1c57f0a (patch) | |
tree | b78c1b63e75a9baa9047fc1ab478737b4bb2d9f1 | |
parent | 64f13c05a5422d3a079a4b35efa56da8ddf5c2ee (diff) |
Support simple searching of bodies by short_name
-rw-r--r-- | app/controllers/public_body_controller.rb | 10 | ||||
-rw-r--r-- | spec/controllers/public_body_controller_spec.rb | 5 |
2 files changed, 11 insertions, 4 deletions
diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb index 51e2d5d22..96e69d333 100644 --- a/app/controllers/public_body_controller.rb +++ b/app/controllers/public_body_controller.rb @@ -157,9 +157,9 @@ class PublicBodyController < ApplicationController AND default_locale.locale = ? AND #{ get_public_body_list_translated_condition('default_locale', first_letter) }) WHERE #{ where_condition } AND COALESCE(current_locale.name, default_locale.name) IS NOT NULL ORDER BY display_name} - sql = [query, underscore_locale, like_query, like_query] + sql = [query, underscore_locale, like_query, like_query, like_query] sql.push @tag if first_letter - sql += [underscore_default_locale, like_query, like_query] + sql += [underscore_default_locale, like_query, like_query, like_query] sql.push @tag if first_letter sql += where_parameters @public_bodies = PublicBody.paginate_by_sql( @@ -170,7 +170,7 @@ class PublicBodyController < ApplicationController # The simpler case where we're just searching in the current locale: where_condition = get_public_body_list_translated_condition('public_body_translations', first_letter, true) + ' AND ' + where_condition - where_sql = [where_condition, like_query, like_query] + where_sql = [where_condition, like_query, like_query, like_query] where_sql.push @tag if first_letter where_sql += [underscore_locale] + where_parameters @public_bodies = PublicBody.where(where_sql). @@ -344,9 +344,11 @@ class PublicBodyController < ApplicationController end private + def get_public_body_list_translated_condition(table, first_letter=false, locale=nil) result = "(upper(#{table}.name) LIKE upper(?)" \ - " OR upper(#{table}.notes) LIKE upper (?))" + " OR upper(#{table}.notes) LIKE upper(?)" \ + " OR upper(#{table}.short_name) LIKE upper(?))" if first_letter result += " AND #{table}.first_letter = ?" end diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index 63989baaa..6afbf24d1 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -184,6 +184,11 @@ describe PublicBodyController, "when listing bodies" do assigns[:public_bodies].should == [ public_bodies(:geraldine_public_body) ] end + it "should support simple searching of bodies by short_name" do + get :list, :public_body_query => 'DfH' + assigns[:public_bodies].should == [ public_bodies(:humpadink_public_body) ] + end + it "should support simple searching of bodies by notes" do get :list, :public_body_query => 'Albatross' assigns[:public_bodies].should == [ public_bodies(:humpadink_public_body) ] |