aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/admin_public_body_controller_spec.rb90
-rw-r--r--spec/controllers/admin_request_controller_spec.rb2
-rw-r--r--spec/controllers/general_controller_spec.rb30
-rw-r--r--spec/controllers/public_body_controller_spec.rb76
-rw-r--r--spec/controllers/request_controller_spec.rb91
-rw-r--r--spec/controllers/services_controller_spec.rb31
-rw-r--r--spec/controllers/track_controller_spec.rb15
-rw-r--r--spec/controllers/user_controller_spec.rb20
-rw-r--r--spec/fixtures/files/fake-authority-type-with-field-names.csv6
-rw-r--r--spec/fixtures/users.yml3
-rw-r--r--spec/integration/errors_spec.rb45
-rw-r--r--spec/integration/search_request_spec.rb53
-rw-r--r--spec/models/customstates.rb20
-rw-r--r--spec/models/public_body_spec.rb49
-rw-r--r--spec/models/track_mailer_spec.rb1
-rw-r--r--spec/models/track_thing_spec.rb10
-rw-r--r--spec/views/public_body/show.rhtml_spec.rb13
-rw-r--r--spec/views/request/list.rhtml_spec.rb6
18 files changed, 461 insertions, 100 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/admin_request_controller_spec.rb b/spec/controllers/admin_request_controller_spec.rb
index 423c2fb49..6f9af0525 100644
--- a/spec/controllers/admin_request_controller_spec.rb
+++ b/spec/controllers/admin_request_controller_spec.rb
@@ -71,7 +71,7 @@ describe AdminRequestController, "when administering the holding pen" do
post :redeliver_incoming, :redeliver_incoming_message_id => new_im.id, :url_title => ir.url_title
ir = InfoRequest.find_by_url_title(ir.url_title)
ir.incoming_messages.length.should == 2
- response.should redirect_to('http://test.host/admin/request/show/101')
+ response.should redirect_to(:controller=>'admin_request', :action=>'show', :id=>101)
InfoRequest.holding_pen_request.incoming_messages.length.should == 0
end
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index 3640a8148..1ffbda90d 100644
--- a/spec/controllers/general_controller_spec.rb
+++ b/spec/controllers/general_controller_spec.rb
@@ -64,7 +64,7 @@ describe GeneralController, "when searching" do
it "should redirect from search query URL to pretty URL" do
post :search_redirect, :query => "mouse" # query hidden in POST parameters
- response.should redirect_to(:action => 'search', :combined => "mouse") # URL /search/:query
+ response.should redirect_to(:action => 'search', :combined => "mouse", :view => "requests") # URL /search/:query/all
end
describe "when using different locale settings" do
@@ -122,6 +122,34 @@ describe GeneralController, "when searching" do
end
+ it "should filter results based on end of URL being 'all'" do
+ get :search, :combined => ['"bob"', "all"]
+ assigns[:xapian_requests].results.size.should == 2
+ assigns[:xapian_users].results.size.should == 1
+ assigns[:xapian_bodies].results.size.should == 0
+ end
+
+ it "should filter results based on end of URL being 'users'" do
+ get :search, :combined => ['"bob"', "users"]
+ assigns[:xapian_requests].should == nil
+ assigns[:xapian_users].results.size.should == 1
+ assigns[:xapian_bodies].should == nil
+ end
+
+ it "should filter results based on end of URL being 'requests'" do
+ get :search, :combined => ['"bob"', "requests"]
+ assigns[:xapian_requests].results.size.should == 2
+ assigns[:xapian_users].should == nil
+ assigns[:xapian_bodies].should == nil
+ end
+
+ it "should filter results based on end of URL being 'bodies'" do
+ get :search, :combined => ['"quango"', "bodies"]
+ assigns[:xapian_requests].should == nil
+ assigns[:xapian_users].should == nil
+ assigns[:xapian_bodies].results.size.should == 1
+ end
+
it "should show help when searching for nothing" do
get :search_redirect, :query => nil
response.should render_template('search')
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
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index f69cf414c..63e86b525 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -1,7 +1,3 @@
-# £2k p/a
-# talk about margins
-#
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'json'
@@ -24,13 +20,29 @@ describe RequestController, "when listing recent requests" do
response.should render_template('list')
end
+ it "should filter requests" do
+ get :list, :view => 'all'
+ assigns[:list_results].size.should == 2
+ get :list, :view => 'successful'
+ assigns[:list_results].size.should == 0
+ end
+
+ it "should filter requests by date" do
+ get :list, :view => 'all', :request_date_before => '13/10/2007'
+ assigns[:list_results].size.should == 1
+ get :list, :view => 'all', :request_date_after => '13/10/2007'
+ assigns[:list_results].size.should == 1
+ get :list, :view => 'all', :request_date_after => '10/10/2007', :request_date_before => '01/01/2010'
+ assigns[:list_results].size.should == 2
+ end
+
it "should assign the first page of results" do
xap_results = mock_model(ActsAsXapian::Search,
:results => (1..25).to_a.map { |m| { :model => m } },
:matches_estimated => 103)
InfoRequest.should_receive(:full_search).
- with([InfoRequestEvent],"variety:sent", "created_at", anything, anything, anything, anything).
+ with([InfoRequestEvent]," variety:sent", "created_at", anything, anything, anything, anything).
and_return(xap_results)
get :list, :view => 'recent'
assigns[:list_results].size.should == 25
@@ -149,7 +161,7 @@ describe RequestController, "when showing one request" do
lambda {
get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2,
:file_name => ['http://trying.to.hack']
- }.should raise_error(RuntimeError)
+ }.should raise_error(ActiveRecord::RecordNotFound)
end
it "should censor attachments downloaded as binary" do
@@ -337,7 +349,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 => 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 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 +380,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,
@@ -438,6 +451,7 @@ describe RequestController, "when making a new request" do
@user.stub!(:get_undescribed_requests).and_return([])
@user.stub!(:can_leave_requests_undescribed?).and_return(false)
@user.stub!(:can_file_requests?).and_return(true)
+ @user.stub!(:locale).and_return("en")
User.stub!(:find).and_return(@user)
@body = mock_model(PublicBody, :id => 314, :eir_only? => false, :is_requestable? => true, :name => "Test Quango")
@@ -735,18 +749,16 @@ describe RequestController, "when classifying an information request" do
response.should redirect_to(:controller => 'help', :action => 'unhappy', :url_title => @dog_request.url_title)
end
- describe "when using custom statuses from the theme" do
+ it "knows about extended states" do
InfoRequest.send(:require, File.expand_path(File.join(File.dirname(__FILE__), '..', 'models', 'customstates')))
InfoRequest.send(:include, InfoRequestCustomStates)
InfoRequest.class_eval('@@custom_states_loaded = true')
RequestController.send(:require, File.expand_path(File.join(File.dirname(__FILE__), '..', 'models', 'customstates')))
RequestController.send(:include, RequestControllerCustomStates)
RequestController.class_eval('@@custom_states_loaded = true')
- it "knows about extended states" do
- Time.stub!(:now).and_return(Time.utc(2007, 11, 10, 00, 01))
- post_status('deadline_extended')
- flash[:notice].should == 'Authority has requested extension of the deadline.'
- end
+ Time.stub!(:now).and_return(Time.utc(2007, 11, 10, 00, 01))
+ post_status('deadline_extended')
+ flash[:notice].should == 'Authority has requested extension of the deadline.'
end
end
@@ -1309,5 +1321,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
diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb
new file mode 100644
index 000000000..1bafd0c8f
--- /dev/null
+++ b/spec/controllers/services_controller_spec.rb
@@ -0,0 +1,31 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe ServicesController, "when using web services" do
+ integrate_views
+
+ it "should show no alaveteli message when in the deployed country" do
+ config = MySociety::Config.load_default()
+ config['ISO_COUNTRY_CODE'] = "DE"
+ controller.stub!(:country_from_ip).and_return('DE')
+ get :other_country_message
+ response.body.should == ""
+ end
+
+ it "should show an alaveteli message when not in the deployed country and in a country with no FOI website" do
+ config = MySociety::Config.load_default()
+ config['ISO_COUNTRY_CODE'] = "DE"
+ controller.stub!(:country_from_ip).and_return('ZZ')
+ get :other_country_message
+ response.body.should match(/outside Germany/)
+ end
+
+ it "should show link to other FOI website when not in the deployed country" do
+ config = MySociety::Config.load_default()
+ config['ISO_COUNTRY_CODE'] = "ZZ"
+ controller.stub!(:country_from_ip).and_return('DE')
+ get :other_country_message
+ response.body.should match(/within Germany/)
+ end
+
+
+end
diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb
index 32cacb0a8..435d9a0d3 100644
--- a/spec/controllers/track_controller_spec.rb
+++ b/spec/controllers/track_controller_spec.rb
@@ -16,6 +16,7 @@ describe TrackController, "when making a new track on a request" do
@user = mock_model(User)
User.stub!(:find).and_return(@user)
+ @user.stub!(:locale).and_return("en")
end
it "should require login when making new track" do
@@ -69,7 +70,6 @@ describe TrackController, "when sending alerts for a track" do
mail.body.should include('added an annotation') # comment included
mail.body.should =~ /This a the daftest comment the world has ever seen/ # comment text included
-
# Check subscription managing link
# XXX We can't do this, as it is redirecting to another controller. I'm
# apparently meant to be writing controller unit tests here, not functional
@@ -93,6 +93,19 @@ describe TrackController, "when sending alerts for a track" do
deliveries.size.should == 0
end
+ it "should send localised alerts" do
+ # set the time the comment event happened at to within the last week
+ ire = info_request_events(:silly_comment_event)
+ ire.created_at = Time.now - 3.days
+ ire.save!
+ user = users(:silly_name_user)
+ user.locale = "es"
+ user.save!
+ TrackMailer.alert_tracks
+ deliveries = ActionMailer::Base.deliveries
+ mail = deliveries[0]
+ mail.body.should include('el equipo de ')
+ end
end
describe TrackController, "when viewing RSS feed for a track" do
diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb
index a12d79e82..b4cc0d6e3 100644
--- a/spec/controllers/user_controller_spec.rb
+++ b/spec/controllers/user_controller_spec.rb
@@ -32,6 +32,13 @@ describe UserController, "when showing a user" do
assigns[:display_user].should == users(:bob_smith_user)
end
+ it "should search the user's contributions" do
+ get :show, :url_name => "bob_smith"
+ assigns[:xapian_requests].results.count.should == 2
+ get :show, :url_name => "bob_smith", :user_query => "money"
+ assigns[:xapian_requests].results.count.should == 1
+ end
+
# Error handling not quite good enough for this yet
# it "should not show unconfirmed users" do
# get :show, :url_name => "silly_emnameem"
@@ -171,6 +178,19 @@ describe UserController, "when signing up" do
deliveries[0].body.should include("not reveal your email")
end
+ it "should send confirmation mail in other languages or different locales" do
+ session[:locale] = "es"
+ post :signup, {:user_signup => { :email => 'new@localhost', :name => 'New Person',
+ :password => 'sillypassword', :password_confirmation => 'sillypassword',
+ }
+ }
+ response.should render_template('confirm')
+
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ deliveries[0].body.should include("No revelaremos su dirección de correo")
+ end
+
it "should send special 'already signed up' mail if you fill the form in with existing registered email " do
post :signup, { :user_signup => { :email => 'silly@localhost', :name => 'New Person',
:password => 'sillypassword', :password_confirmation => 'sillypassword' }
diff --git a/spec/fixtures/files/fake-authority-type-with-field-names.csv b/spec/fixtures/files/fake-authority-type-with-field-names.csv
index 93ce00a25..9e82308fb 100644
--- a/spec/fixtures/files/fake-authority-type-with-field-names.csv
+++ b/spec/fixtures/files/fake-authority-type-with-field-names.csv
@@ -1,4 +1,4 @@
-#id,email,name,name.es
-,north_west_foi@localhost,North West Fake Authority,Autoridad del Nordeste
-,scottish_foi@localhost,Scottish Fake Authority,Autoridad Escocesa
+#id,request_email,name,name.es,home_page
+,north_west_foi@localhost,North West Fake Authority,Autoridad del Nordeste,http://northwest.org
+,scottish_foi@localhost,Scottish Fake Authority,Autoridad Escocesa,http://scottish.org
,ni_foi@localhost,Fake Authority of Northern Ireland,Autoridad Irlandesa
diff --git a/spec/fixtures/users.yml b/spec/fixtures/users.yml
index e80183c9f..16ffec034 100644
--- a/spec/fixtures/users.yml
+++ b/spec/fixtures/users.yml
@@ -10,6 +10,7 @@ bob_smith_user:
email_confirmed: true
admin_level: 'none'
ban_text: ''
+ locale: 'en'
about_me: 'I like making requests about fancy dogs and naughty chickens and stuff.'
silly_name_user:
id: "2"
@@ -23,6 +24,7 @@ silly_name_user:
email_confirmed: true
admin_level: 'none'
ban_text: ''
+ locale: 'en'
about_me: ''
admin_user:
id: "3"
@@ -36,6 +38,7 @@ admin_user:
email_confirmed: false
admin_level: 'super'
ban_text: ''
+ locale: ''
about_me: ''
unconfirmed_user:
id: "4"
diff --git a/spec/integration/errors_spec.rb b/spec/integration/errors_spec.rb
new file mode 100644
index 000000000..c64ca79e8
--- /dev/null
+++ b/spec/integration/errors_spec.rb
@@ -0,0 +1,45 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe "When rendering errors" do
+
+ fixtures [ :info_requests,
+ :info_request_events,
+ :public_bodies,
+ :public_body_translations,
+ :users,
+ :raw_emails,
+ :outgoing_messages,
+ :incoming_messages,
+ :comments ]
+
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ ActionController::Base.consider_all_requests_local = false
+ end
+
+ after(:each) do
+ ActionController::Base.consider_all_requests_local = true
+ end
+
+ it "should render a 404 for unrouteable URLs" do
+ get("/frobsnasm")
+ response.code.should == "404"
+ response.body.should include("The page doesn't exist")
+ end
+ it "should render a 404 for users that don't exist" do
+ get("/user/wobsnasm")
+ response.code.should == "404"
+ end
+ it "should render a 404 for bodies that don't exist" do
+ get("/body/wobsnasm")
+ response.code.should == "404"
+ end
+ it "should render a 500 for general errors" do
+ ir = info_requests(:naughty_chicken_request)
+ # Set an invalid state for the request. Note that update_attribute doesn't run the validations
+ ir.update_attribute(:described_state, "crotchety")
+ get("/request/#{ir.url_title}")
+ response.code.should == "500"
+ end
+end
+
diff --git a/spec/integration/search_request_spec.rb b/spec/integration/search_request_spec.rb
index 9398519b7..25c091111 100644
--- a/spec/integration/search_request_spec.rb
+++ b/spec/integration/search_request_spec.rb
@@ -1,9 +1,62 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe "When searching" do
+
+ fixtures [ :info_requests,
+ :info_request_events,
+ :public_bodies,
+ :public_body_translations,
+ :users,
+ :raw_emails,
+ :outgoing_messages,
+ :incoming_messages,
+ :comments ]
+
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ end
+
it "should not strip quotes from quoted query" do
request_via_redirect("post", "/search", :query => '"mouse stilton"')
response.body.should include(""mouse stilton"")
end
+
+ it "should correctly execute simple search" do
+ request_via_redirect("post", "/search",
+ :query => 'bob'
+ )
+ response.body.should include("FOI requests")
+ end
+
+ it "should correctly filter searches for requests" do
+ request_via_redirect("post", "/search/bob/requests")
+ response.body.should_not include("One person found")
+ response.body.should include("FOI requests 1 to 2 of 2")
+ end
+ it "should correctly filter searches for users" do
+ request_via_redirect("post", "/search/bob/users")
+ response.body.should include("One person found")
+ response.body.should_not include("FOI requests 1 to 2 of 2")
+ end
+
+ it "should correctly filter searches for successful requests" do
+ request_via_redirect("post", "/search",
+ :query => "bob",
+ :latest_status => ['successful'])
+ response.body.should include("no requests matching your query")
+ end
+
+ it "should correctly filter searches for comments" do
+ request_via_redirect("post", "/search",
+ :query => "daftest",
+ :request_variety => ['comments'])
+ response.body.should include("One FOI request found")
+
+ request_via_redirect("post", "/search",
+ :query => "daftest",
+ :request_variety => ['response','sent'])
+ response.body.should include("no requests matching your query")
+ end
+
end
diff --git a/spec/models/customstates.rb b/spec/models/customstates.rb
index 406d4ead9..3488e6730 100644
--- a/spec/models/customstates.rb
+++ b/spec/models/customstates.rb
@@ -5,16 +5,6 @@ module InfoRequestCustomStates
end
# Mixin methods for InfoRequest
- def theme_display_status(status)
- if status == 'deadline_extended'
- _("Deadline extended.")
- elsif status == 'wrong_response'
- _("Wrong Response.")
- else
- raise _("unknown status ") + status
- end
- end
-
def theme_calculate_status
return 'waiting_classification' if self.awaiting_description
waiting_response = self.described_state == "waiting_response" || self.described_state == "deadline_extended"
@@ -41,6 +31,16 @@ module InfoRequestCustomStates
end
module ClassMethods
+ def theme_display_status(status)
+ if status == 'deadline_extended'
+ _("Deadline extended.")
+ elsif status == 'wrong_response'
+ _("Wrong Response.")
+ else
+ raise _("unknown status ") + status
+ end
+ end
+
def theme_extra_states
return ['deadline_extended',
'wrong_response']
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index 3d00d37fb..3902e3662 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -234,9 +234,11 @@ describe PublicBody, " when loading CSV files" do
errors, notes = PublicBody.import_csv(csv_contents, 'fake', true, 'someadmin') # true means dry run
errors.should == []
notes.size.should == 3
- notes.should == ["line 1: new authority 'North West Fake Authority' with email north_west_foi@localhost",
- "line 2: new authority 'Scottish Fake Authority' with email scottish_foi@localhost",
- "line 3: new authority 'Fake Authority of Northern Ireland' with email ni_foi@localhost"]
+ notes.should == [
+ "line 1: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"request_email\":\"north_west_foi@localhost\"\}",
+ "line 2: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"request_email\":\"scottish_foi@localhost\"\}",
+ "line 3: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"request_email\":\"ni_foi@localhost\"\}"
+ ]
PublicBody.count.should == original_count
end
@@ -248,9 +250,11 @@ describe PublicBody, " when loading CSV files" do
errors, notes = PublicBody.import_csv(csv_contents, 'fake', false, 'someadmin') # false means real run
errors.should == []
notes.size.should == 3
- notes.should == ["line 1: new authority 'North West Fake Authority' with email north_west_foi@localhost",
- "line 2: new authority 'Scottish Fake Authority' with email scottish_foi@localhost",
- "line 3: new authority 'Fake Authority of Northern Ireland' with email ni_foi@localhost"]
+ notes.should == [
+ "line 1: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"request_email\":\"north_west_foi@localhost\"\}",
+ "line 2: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"request_email\":\"scottish_foi@localhost\"\}",
+ "line 3: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"request_email\":\"ni_foi@localhost\"\}"
+ ]
PublicBody.count.should == original_count + 3
end
@@ -262,9 +266,11 @@ describe PublicBody, " when loading CSV files" do
errors, notes = PublicBody.import_csv(csv_contents, 'fake', true, 'someadmin') # true means dry run
errors.should == []
notes.size.should == 3
- notes.should == ["line 2: new authority 'North West Fake Authority' with email north_west_foi@localhost",
- "line 3: new authority 'Scottish Fake Authority' with email scottish_foi@localhost",
- "line 4: new authority 'Fake Authority of Northern Ireland' with email ni_foi@localhost"]
+ notes.should == [
+ "line 2: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"request_email\":\"north_west_foi@localhost\",\"home_page\":\"http://northwest.org\"\}",
+ "line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\"\}",
+ "line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"request_email\":\"ni_foi@localhost\"\}"
+ ]
PublicBody.count.should == original_count
end
@@ -273,16 +279,17 @@ describe PublicBody, " when loading CSV files" do
original_count = PublicBody.count
csv_contents = load_file_fixture("fake-authority-type-with-field-names.csv")
- errors, notes = PublicBody.import_csv(csv_contents, 'fake', false, 'someadmin', ['es'])
+ errors, notes = PublicBody.import_csv(csv_contents, 'fake', false, 'someadmin', [:en, :es])
errors.should == []
notes.size.should == 6
notes.should == [
- "line 2: new authority 'North West Fake Authority' with email north_west_foi@localhost",
- "line 2: (aka 'Autoridad del Nordeste' in locale es)",
- "line 3: new authority 'Scottish Fake Authority' with email scottish_foi@localhost",
- "line 3: (aka 'Autoridad Escocesa' in locale es)",
- "line 4: new authority 'Fake Authority of Northern Ireland' with email ni_foi@localhost",
- "line 4: (aka 'Autoridad Irlandesa' in locale es)"]
+ "line 2: creating new authority 'North West Fake Authority' (locale: en):\n\t{\"request_email\":\"north_west_foi@localhost\",\"home_page\":\"http://northwest.org\"}",
+ "line 2: creating new authority 'North West Fake Authority' (locale: es):\n\t{\"name\":\"Autoridad del Nordeste\"}",
+ "line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t{\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\"}",
+ "line 3: creating new authority 'Scottish Fake Authority' (locale: es):\n\t{\"name\":\"Autoridad Escocesa\"}",
+ "line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t{\"request_email\":\"ni_foi@localhost\"}",
+ "line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: es):\n\t{\"name\":\"Autoridad Irlandesa\"}"
+ ]
PublicBody.count.should == original_count + 3
@@ -297,12 +304,14 @@ describe PublicBody, " when loading CSV files" do
original_count = PublicBody.count
csv_contents = load_file_fixture("fake-authority-type-with-field-names.csv")
- errors, notes = PublicBody.import_csv(csv_contents, 'fake', true, 'someadmin', ['xx']) # true means dry run
+ errors, notes = PublicBody.import_csv(csv_contents, 'fake', true, 'someadmin', [:en, :xx]) # true means dry run
errors.should == []
notes.size.should == 3
- notes.should == ["line 2: new authority 'North West Fake Authority' with email north_west_foi@localhost",
- "line 3: new authority 'Scottish Fake Authority' with email scottish_foi@localhost",
- "line 4: new authority 'Fake Authority of Northern Ireland' with email ni_foi@localhost"]
+ notes.should == [
+ "line 2: creating new authority 'North West Fake Authority' (locale: en):\n\t{\"request_email\":\"north_west_foi@localhost\",\"home_page\":\"http://northwest.org\"}",
+ "line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t{\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\"}",
+ "line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t{\"request_email\":\"ni_foi@localhost\"}"
+ ]
PublicBody.count.should == original_count
end
diff --git a/spec/models/track_mailer_spec.rb b/spec/models/track_mailer_spec.rb
index 504d65144..6612641c1 100644
--- a/spec/models/track_mailer_spec.rb
+++ b/spec/models/track_mailer_spec.rb
@@ -22,6 +22,7 @@ describe TrackMailer do
:last_daily_track_email= => true,
:save! => true,
:url_name => 'test-name',
+ :get_locale => 'en',
:should_be_emailed? => true)
User.stub!(:find).and_return([@user])
@user.stub!(:no_xapian_reindex=)
diff --git a/spec/models/track_thing_spec.rb b/spec/models/track_thing_spec.rb
index 6b9cd6d4a..1a0324a78 100644
--- a/spec/models/track_thing_spec.rb
+++ b/spec/models/track_thing_spec.rb
@@ -28,5 +28,15 @@ describe TrackThing, "when tracking changes" do
found_track.should == @track_thing
end
+ it "will make some sane descriptions of search-based tracks" do
+ tests = [['bob variety:user', "users matching text 'bob'"],
+ ['bob (variety:sent OR variety:followup_sent OR variety:response OR variety:comment) (latest_status:successful OR latest_status:partially_successful OR latest_status:rejected OR latest_status:not_held)', "requests which are successful or unsuccessful or comments matching text 'bob'"],
+ ['(latest_status:waiting_response OR latest_status:waiting_clarification OR waiting_classification:true)', 'requests which are awaiting a response']]
+ for query, description in tests
+ track_thing = TrackThing.create_track_for_search_query(query)
+ track_thing.track_query_description.should == description
+ end
+ end
+
end
diff --git a/spec/views/public_body/show.rhtml_spec.rb b/spec/views/public_body/show.rhtml_spec.rb
index 7793b9b38..797923c5d 100644
--- a/spec/views/public_body/show.rhtml_spec.rb
+++ b/spec/views/public_body/show.rhtml_spec.rb
@@ -1,7 +1,6 @@
require File.dirname(__FILE__) + '/../../spec_helper'
describe "when viewing a body" do
-
before do
@pb = mock_model(PublicBody,
:name => 'Test Quango',
@@ -28,6 +27,8 @@ describe "when viewing a body" do
assigns[:xapian_requests] = @xap
assigns[:page] = 1
assigns[:per_page] = 10
+ # work round a bug in ActionController::TestRequest; allows request.query_string to work in the template
+ request.env["REQUEST_URI"] = ""
end
it "should be successful" do
@@ -51,7 +52,7 @@ describe "when viewing a body" do
end
it "should cope with no results" do
- @xap.stub!(:results).and_return([])
+ @pb.stub!(:info_requests).and_return([])
render "public_body/show"
response.should have_tag("p", /Nobody has made any Freedom of Information requests/m)
end
@@ -67,10 +68,10 @@ describe "when viewing a body" do
@pb.stub!(:get_tag_values).and_return(['98765', '12345'])
render "public_body/show"
- response.should have_tag("div#request_sidebar") do
+ response.should have_tag("div#header_right") do
with_tag("a[href*=?]", /charity-commission.gov.uk.*RegisteredCharityNumber=98765$/)
end
- response.should have_tag("div#request_sidebar") do
+ response.should have_tag("div#header_right") do
with_tag("a[href*=?]", /charity-commission.gov.uk.*RegisteredCharityNumber=12345$/)
end
end
@@ -80,7 +81,7 @@ describe "when viewing a body" do
@pb.stub!(:get_tag_values).and_return(['SC1234'])
render "public_body/show"
- response.should have_tag("div#request_sidebar") do
+ response.should have_tag("div#header_right") do
with_tag("a[href*=?]", /www.oscr.org.uk.*id=SC1234$/)
end
end
@@ -88,7 +89,7 @@ describe "when viewing a body" do
it "should not link to Charity Commission site if we don't have number" do
render "public_body/show"
- response.should have_tag("div#request_sidebar") do
+ response.should have_tag("div#header_right") do
without_tag("a[href*=?]", /charity-commission.gov.uk/)
end
end
diff --git a/spec/views/request/list.rhtml_spec.rb b/spec/views/request/list.rhtml_spec.rb
index 578bd5cc8..60a28eec5 100644
--- a/spec/views/request/list.rhtml_spec.rb
+++ b/spec/views/request/list.rhtml_spec.rb
@@ -5,7 +5,8 @@ describe "when listing recent requests" do
before do
assigns[:page] = 1
assigns[:per_page] = 10
-
+ # work round a bug in ActionController::TestRequest; allows request.query_string to work in the template
+ request.env["REQUEST_URI"] = ""
# we're not testing the interlock plugin's cache
template.stub!(:view_cache).and_yield
end
@@ -32,9 +33,7 @@ describe "when listing recent requests" do
it "should be successful" do
assigns[:list_results] = [ make_mock_event, make_mock_event ]
assigns[:matches_estimated] = 2
-
render "request/list"
-
response.should have_tag("div.request_listing")
response.should_not have_tag("p", /No requests of this sort yet/m)
end
@@ -42,7 +41,6 @@ describe "when listing recent requests" do
it "should cope with no results" do
assigns[:list_results] = [ ]
assigns[:matches_estimated] = 0
-
render "request/list"
response.should have_tag("p", /No requests of this sort yet/m)
response.should_not have_tag("div.request_listing")