diff options
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/public_body_controller_spec.rb | 35 | ||||
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 31 |
2 files changed, 66 insertions, 0 deletions
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index d15482e51..f157d4ac4 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -139,6 +139,41 @@ describe PublicBodyController, "when showing JSON version for API" do end +describe PublicBodyController, "when doing type ahead searches" do + fixtures :info_requests, :info_request_events, :public_bodies, :public_body_translations, :users, :incoming_messages, :raw_emails, :outgoing_messages, :comments + it "should return nothing for the empty query string" do + get :search_typeahead, :q => "" + response.should render_template('public_body/_search_ahead') + assigns[:xapian_requests].results.size.should == 0 + end + + it "should return a body matching the given keyword, but not users with a matching description" do + get :search_typeahead, :q => "Geraldine" + response.should render_template('public_body/_search_ahead') + assigns[:xapian_requests].results.size.should == 1 + assigns[:xapian_requests].results[0][:model].name.should == public_bodies(:geraldine_public_body).name + end + it "should return all requests matching any of the given keywords" do + get :search_typeahead, :q => "Geraldine Humpadinking" + response.should render_template('public_body/_search_ahead') + assigns[:xapian_requests].results.size.should == 2 + assigns[:xapian_requests].results[0][:model].name.should == public_bodies(:humpadink_public_body).name + assigns[:xapian_requests].results[1][:model].name.should == public_bodies(:geraldine_public_body).name + end + it "should return requests matching the given keywords in any of their locales" do + get :search_typeahead, :q => "baguette" # part of the spanish notes + response.should render_template('public_body/_search_ahead') + assigns[:xapian_requests].results.size.should == 1 + assigns[:xapian_requests].results[0][:model].name.should == public_bodies(:humpadink_public_body).name + end + + it "should return partial matches" do + get :search_typeahead, :q => "geral" # 'geral' for 'Geraldine' + response.should render_template('public_body/_search_ahead') + assigns[:xapian_requests].results.size.should == 1 + assigns[:xapian_requests].results[0][:model].name.should == public_bodies(:geraldine_public_body).name + end +end diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 69c1433f2..ffb9861f7 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1286,5 +1286,36 @@ describe RequestController, "when showing JSON version for API" do end +describe RequestController, "when doing type ahead searches" do + fixtures :info_requests, :info_request_events, :public_bodies, :public_body_translations, :users, :incoming_messages, :raw_emails, :outgoing_messages, :comments + + it "should return nothing for the empty query string" do + get :search_typeahead, :q => "" + response.should render_template('request/_search_ahead.rhtml') + assigns[:xapian_requests].results.size.should == 0 + end + + it "should return a request matching the given keyword, but not users with a matching description" do + get :search_typeahead, :q => "chicken" + response.should render_template('request/_search_ahead.rhtml') + assigns[:xapian_requests].results.size.should == 1 + assigns[:xapian_requests].results[0][:model].title.should == info_requests(:naughty_chicken_request).title + end + + it "should return all requests matching any of the given keywords" do + get :search_typeahead, :q => "money dog" + response.should render_template('request/_search_ahead.rhtml') + assigns[:xapian_requests].results.size.should == 2 + assigns[:xapian_requests].results[0][:model].title.should == info_requests(:fancy_dog_request).title + assigns[:xapian_requests].results[1][:model].title.should == info_requests(:naughty_chicken_request).title + end + + it "should return partial matches" do + get :search_typeahead, :q => "chick" # 'chick' for 'chicken' + response.should render_template('request/_search_ahead.rhtml') + assigns[:xapian_requests].results.size.should == 1 + assigns[:xapian_requests].results[0][:model].title.should == info_requests(:naughty_chicken_request).title + end +end |