aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers/public_body_controller_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers/public_body_controller_spec.rb')
-rw-r--r--spec/controllers/public_body_controller_spec.rb76
1 files changed, 64 insertions, 12 deletions
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb
index 0050678d2..c5c9d60e1 100644
--- a/spec/controllers/public_body_controller_spec.rb
+++ b/spec/controllers/public_body_controller_spec.rb
@@ -7,47 +7,54 @@ describe PublicBodyController, "when showing a body" do
fixtures :public_bodies, :public_body_translations, :public_body_versions
it "should be successful" do
- get :show, :url_name => "dfh"
+ get :show, :url_name => "dfh", :view => 'all'
response.should be_success
end
it "should render with 'show' template" do
- get :show, :url_name => "dfh"
+ get :show, :url_name => "dfh", :view => 'all'
response.should render_template('show')
end
it "should assign the body" do
- get :show, :url_name => "dfh"
+ get :show, :url_name => "dfh", :view => 'all'
assigns[:public_body].should == public_bodies(:humpadink_public_body)
end
+ it "should assign the requests" do
+ get :show, :url_name => "tgq", :view => 'all'
+ assigns[:xapian_requests].results.count.should == 2
+ get :show, :url_name => "tgq", :view => 'successful'
+ assigns[:xapian_requests].results.count.should == 0
+ end
+
it "should assign the body using different locale from that used for url_name" do
PublicBody.with_locale(:es) do
- get :show, {:url_name => "dfh"}
+ get :show, {:url_name => "dfh", :view => 'all'}
assigns[:public_body].notes.should == "Baguette"
end
end
it "should assign the body using same locale as that used in url_name" do
PublicBody.with_locale(:es) do
- get :show, {:url_name => "edfh"}
+ get :show, {:url_name => "edfh", :view => 'all'}
assigns[:public_body].notes.should == "Baguette"
end
end
it "should redirect use to the relevant locale even when url_name is for a different locale" do
ActionController::Routing::Routes.filters.clear
- get :show, {:url_name => "edfh"}
+ get :show, {:url_name => "edfh", :view => 'all'}
response.should redirect_to "http://test.host/body/dfh"
end
it "should redirect to newest name if you use historic name of public body in URL" do
- get :show, :url_name => "hdink"
+ get :show, :url_name => "hdink", :view => 'all'
response.should redirect_to(:controller => 'public_body', :action => 'show', :url_name => "dfh")
end
it "should redirect to lower case name if you use mixed case name in URL" do
- get :show, :url_name => "dFh"
+ get :show, :url_name => "dFh", :view => 'all'
response.should redirect_to(:controller => 'public_body', :action => 'show', :url_name => "dfh")
end
end
@@ -68,7 +75,17 @@ describe PublicBodyController, "when listing bodies" do
assigns[:public_bodies].should == [ public_bodies(:humpadink_public_body), public_bodies(:geraldine_public_body) ]
assigns[:tag].should == "all"
- assigns[:description].should == "all"
+ assigns[:description].should == ""
+ end
+
+ it "should support simple searching of bodies by title" do
+ get :list, :public_body_query => 'quango'
+ assigns[:public_bodies].should == [ public_bodies(:geraldine_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) ]
end
it "should list bodies in alphabetical order with different locale" do
@@ -77,7 +94,7 @@ describe PublicBodyController, "when listing bodies" do
response.should render_template('list')
assigns[:public_bodies].should == [ public_bodies(:geraldine_public_body), public_bodies(:humpadink_public_body) ]
assigns[:tag].should == "all"
- assigns[:description].should == "all"
+ assigns[:description].should == ""
I18n.default_locale = :en
end
@@ -96,7 +113,7 @@ describe PublicBodyController, "when listing bodies" do
get :list
response.should render_template('list')
- assigns[:public_bodies].should == [ public_bodies(:humpadink_public_body), public_bodies(:geraldine_public_body) ]
+ assigns[:public_bodies].count.should == 2
end
@@ -128,7 +145,7 @@ describe PublicBodyController, "when showing JSON version for API" do
fixtures :public_bodies, :public_body_translations
it "should be successful" do
- get :show, :url_name => "dfh", :format => "json"
+ get :show, :url_name => "dfh", :format => "json", :view => 'all'
pb = JSON.parse(response.body)
pb.class.to_s.should == 'Hash'
@@ -139,6 +156,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