aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers')
-rw-r--r--spec/controllers/admin_public_body_controller_spec.rb90
-rw-r--r--spec/controllers/public_body_controller_spec.rb35
-rw-r--r--spec/controllers/request_controller_spec.rb56
3 files changed, 151 insertions, 30 deletions
diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb
index 357564211..53db4f412 100644
--- a/spec/controllers/admin_public_body_controller_spec.rb
+++ b/spec/controllers/admin_public_body_controller_spec.rb
@@ -109,28 +109,34 @@ describe AdminPublicBodyController, "when administering public bodies with i18n"
get :show, {:id => 2, :locale => "es" }
end
- it "creates a new public body" do
- I18n.default_locale = :es
- PublicBody.count.should == 2
- post :create, { :public_body => { :name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' } }
- PublicBody.count.should == 3
- I18n.default_locale = :en
- end
-
it "edits a public body" do
- I18n.default_locale = :es
- get :edit, {:id => 3, :locale => :es}
- response.body.should include('Baguette')
- I18n.default_locale = :en
+ get :edit, {:id => 3, :locale => :en}
+
+ # When editing a body, the controller returns all available translations
+ assigns[:public_body].translation("es").name.should == 'El Department for Humpadinking'
+ assigns[:public_body].name.should == 'Department for Humpadinking'
+ response.should render_template('edit')
end
it "saves edits to a public body" do
- I18n.default_locale = :es
- pb = PublicBody.find(id=3)
- pb.name.should == "El Department for Humpadinking"
- post :update, { :id => 3, :public_body => { :name => "Renamed", :short_name => "", :tag_string => "some tags", :request_email => 'edited@localhost', :last_edit_comment => 'From test code' }}
- response.flash[:notice].should include('successful')
- I18n.default_locale = :en
+ PublicBody.with_locale(:es) do
+ pb = PublicBody.find(id=3)
+ pb.name.should == "El Department for Humpadinking"
+ post :update, {
+ :id => 3,
+ :public_body => {
+ :name => "Department for Humpadinking",
+ :short_name => "",
+ :tag_string => "some tags",
+ :request_email => 'edited@localhost',
+ :last_edit_comment => 'From test code',
+ :translated_versions => {
+ 3 => {:locale => "es", :name => "Renamed",:short_name => "", :request_email => 'edited@localhost'}
+ }
+ }
+ }
+ response.flash[:notice].should include('successful')
+ end
pb = PublicBody.find(public_bodies(:humpadink_public_body).id)
PublicBody.with_locale(:es) do
@@ -148,3 +154,51 @@ describe AdminPublicBodyController, "when administering public bodies with i18n"
end
end
+
+describe AdminPublicBodyController, "when creating public bodies with i18n" do
+ integrate_views
+ fixtures :public_bodies, :public_body_translations
+
+ before do
+ username = MySociety::Config.get('ADMIN_USERNAME', '')
+ password = MySociety::Config.get('ADMIN_PASSWORD', '')
+ basic_auth_login @request
+
+ ActionController::Routing::Routes.filters.clear # don't auto-insert locale, complicates assertions
+ end
+
+ it "creates a new public body in one locale" do
+ PublicBody.count.should == 2
+ post :create, { :public_body => { :name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' } }
+ PublicBody.count.should == 3
+
+ body = PublicBody.find_by_name("New Quango")
+ response.should redirect_to(:controller=>'admin_public_body', :action=>'show', :id=>body.id)
+ end
+
+ it "creates a new public body with multiple locales" do
+ PublicBody.count.should == 2
+ post :create, {
+ :public_body => {
+ :name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code',
+ :translated_versions => [{ :locale => "es", :name => "Mi Nuevo Quango", :short_name => "", :request_email => 'newquango@localhost' }]
+ }
+ }
+ PublicBody.count.should == 3
+
+ body = PublicBody.find_by_name("New Quango")
+ body.translations.map {|t| t.locale.to_s}.sort.should == ["en", "es"]
+ PublicBody.with_locale(:en) do
+ body.name.should == "New Quango"
+ body.url_name.should == "new_quango"
+ body.first_letter.should == "N"
+ end
+ PublicBody.with_locale(:es) do
+ body.name.should == "Mi Nuevo Quango"
+ body.url_name.should == "mi_nuevo_quango"
+ body.first_letter.should == "M"
+ end
+
+ response.should redirect_to(:controller=>'admin_public_body', :action=>'show', :id=>body.id)
+ end
+end
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb
index 0050678d2..dd5fbb8bd 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 f69cf414c..51936d0de 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -337,7 +337,20 @@ describe RequestController, "when creating a new request" do
response.should render_template('new')
end
+ it "should redirect to sign in page when input is good and nobody is logged in" do
+ params = { :info_request => { :public_body_id => @body.id,
+ :title => "Why is your quango called Geraldine?", :tag_string => "" },
+ :outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." },
+ :submitted_new_request => 1, :preview => 1
+ }
+ post :new, params
+ post_redirect = PostRedirect.get_last_post_redirect
+ response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token)
+ # post_redirect.post_params.should == params # XXX get this working. there's a : vs '' problem amongst others
+ end
+
it "should show preview when input is good" do
+ session[:user_id] = @user.id
post :new, { :info_request => { :public_body_id => @body.id,
:title => "Why is your quango called Geraldine?", :tag_string => "" },
:outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." },
@@ -355,18 +368,6 @@ describe RequestController, "when creating a new request" do
response.should render_template('new')
end
- it "should redirect to sign in page when input is good and nobody is logged in" do
- params = { :info_request => { :public_body_id => @body.id,
- :title => "Why is your quango called Geraldine?", :tag_string => "" },
- :outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." },
- :submitted_new_request => 1, :preview => 0
- }
- post :new, params
- post_redirect = PostRedirect.get_last_post_redirect
- response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token)
- # post_redirect.post_params.should == params # XXX get this working. there's a : vs '' problem amongst others
- end
-
it "should create the request and outgoing message, and send the outgoing message by email, and redirect to request page when input is good and somebody is logged in" do
session[:user_id] = @user.id
post :new, :info_request => { :public_body_id => @body.id,
@@ -1309,5 +1310,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