aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/api_controller_spec.rb3
-rw-r--r--spec/controllers/general_controller_spec.rb88
-rw-r--r--spec/controllers/help_controller_spec.rb6
-rw-r--r--spec/controllers/public_body_controller_spec.rb40
-rw-r--r--spec/controllers/request_controller_spec.rb15
-rw-r--r--spec/controllers/track_controller_spec.rb5
-rw-r--r--spec/controllers/user_controller_spec.rb49
-rw-r--r--spec/fixtures/files/unrecognized-encoding-mail.email36
-rw-r--r--spec/fixtures/public_body_translations.yml14
-rw-r--r--spec/helpers/link_to_helper_spec.rb5
-rw-r--r--spec/integration/localisation_spec.rb88
-rw-r--r--spec/lib/mail_handler/mail_handler_spec.rb5
-rw-r--r--spec/models/incoming_message_spec.rb13
-rw-r--r--spec/models/info_request_spec.rb251
-rw-r--r--spec/models/public_body_spec.rb2
-rw-r--r--spec/models/xapian_spec.rb5
-rw-r--r--spec/spec_helper.rb14
17 files changed, 480 insertions, 159 deletions
diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb
index 66b8e33f0..8e9d17fbe 100644
--- a/spec/controllers/api_controller_spec.rb
+++ b/spec/controllers/api_controller_spec.rb
@@ -83,6 +83,9 @@ describe ApiController, "when using the API" do
new_request.last_event_forming_initial_request.outgoing_message.body.should == request_data["body"].strip
new_request.public_body_id.should == public_bodies(:geraldine_public_body).id
+ new_request.info_request_events.size.should == 1
+ new_request.info_request_events[0].event_type.should == 'sent'
+ new_request.info_request_events[0].calculated_state.should == 'waiting_response'
end
def _create_request
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index 0eda73c51..8c86ad0be 100644
--- a/spec/controllers/general_controller_spec.rb
+++ b/spec/controllers/general_controller_spec.rb
@@ -108,97 +108,15 @@ describe GeneralController, "when showing the frontpage" do
response.should be_success
end
- describe 'when there is more than one locale' do
-
- describe 'when using the default locale' do
-
- before do
- @default_lang_home_link = /href=".*\/en\//
- @other_lang_home_link = /href=".*\/es\//
- @old_include_default_locale_in_urls = AlaveteliConfiguration::include_default_locale_in_urls
- end
-
- def set_default_locale_in_urls(value)
- AlaveteliConfiguration.stub!(:include_default_locale_in_urls).and_return(value)
- load Rails.root.join("config/initializers/fast_gettext.rb")
- end
-
- describe 'when the config value INCLUDE_DEFAULT_LOCALE_IN_URLS is false' do
-
- before do
- set_default_locale_in_urls(false)
- end
-
- it 'should generate URLs without a locale prepended' do
- get :frontpage
- response.should_not contain @default_lang_home_link
- end
-
- it 'should render the front page in the default language when no locale param
- is present and the session locale is not the default' do
- get(:frontpage, {}, {:locale => 'es'})
- response.should_not contain @other_lang_home_link
- end
- end
-
- it 'should generate URLs with a locale prepended when the config value
- INCLUDE_DEFAULT_LOCALE_IN_URLS is true' do
- set_default_locale_in_urls(true)
- get :frontpage
- response.body.should match /#{@default_lang_home_link}/
- end
-
- after do
- set_default_locale_in_urls(@old_include_default_locale_in_urls)
- end
-
- end
- end
-
-
- describe "when using different locale settings" do
- home_link_regex = /href=".*\/en\//
-
- it "should generate URLs with a locale prepended when there's more than one locale set" do
- get :frontpage
- response.body.should match home_link_regex
- end
+ describe 'when using locales' do
it "should use our test PO files rather than the application one" do
- I18n.default_locale = :es
- get :frontpage
+ get :frontpage, :locale => 'es'
response.body.should match /XOXO/
- I18n.default_locale = :en
- end
-
- it "should generate URLs that include the locale when using one that includes an underscore" do
- I18n.default_locale = :"en_GB"
- get :frontpage
- response.body.should match /href="\/en_GB\//
- I18n.default_locale = :en
- end
-
- it "should fall back to the language if the territory is unknown" do
- I18n.default_locale = :"en_US"
- get :frontpage
- response.body.should match /href="\/en\//
- response.body.should_not match /href="\/en_US\//
- I18n.default_locale = :en
- end
-
- it "should generate URLs without a locale prepended when there's only one locale set" do
- old_fgt_available_locales = FastGettext.default_available_locales
- old_i18n_available_locales = I18n.available_locales
- FastGettext.default_available_locales = I18n.available_locales = ['en']
-
- get :frontpage
- response.should_not contain home_link_regex
-
- FastGettext.default_available_locales = old_fgt_available_locales
- I18n.available_locales = old_i18n_available_locales
end
end
+
end
describe GeneralController, "when showing the front page with fixture data" do
diff --git a/spec/controllers/help_controller_spec.rb b/spec/controllers/help_controller_spec.rb
index c47e1abd3..cc024f840 100644
--- a/spec/controllers/help_controller_spec.rb
+++ b/spec/controllers/help_controller_spec.rb
@@ -31,17 +31,11 @@ describe HelpController, "when using help" do
describe 'when requesting a page in a supported locale ' do
before do
- # Allow us to supply the locale manually
- RoutingFilter.active = false
# Prepend our fixture templates
fixture_theme_path = File.join(Rails.root, 'spec', 'fixtures', 'theme_views', 'theme_one')
controller.prepend_view_path fixture_theme_path
end
- after do
- RoutingFilter.active = true
- end
-
it 'should render the locale-specific template if available' do
get :contact, {:locale => 'es'}
response.body.should match('contáctenos theme one')
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb
index e01bcb0a6..4e1841164 100644
--- a/spec/controllers/public_body_controller_spec.rb
+++ b/spec/controllers/public_body_controller_spec.rb
@@ -43,28 +43,20 @@ describe PublicBodyController, "when showing a body" do
:conditions => ["public_body_id = ?", public_bodies(:humpadink_public_body).id])
end
- it "should redirect to the canonical name in the chosen locale" do
- get :show, {:url_name => "dfh", :view => 'all', :show_locale => "es"}
- response.should redirect_to "http://test.host/es/body/edfh"
+ it "should display the body using same locale as that used in url_name" do
+ get :show, {:url_name => "edfh", :view => 'all', :locale => "es"}
+ response.should contain("Baguette")
end
- it "should assign the body using same locale as that used in url_name" do
- get :show, {:url_name => "edfh", :view => 'all', :show_locale => "es"}
- response.should contain("Baguette")
+ it 'should show public body names in the selected locale language if present for a locale with underscores' do
+ AlaveteliLocalization.set_locales('he_IL en', 'en')
+ get :show, {:url_name => 'dfh', :view => 'all', :locale => 'he_IL'}
+ response.should contain('Hebrew Humpadinking')
end
it "should redirect use to the relevant locale even when url_name is for a different locale" do
- RoutingFilter.active = false
-
get :show, {:url_name => "edfh", :view => 'all'}
response.should redirect_to "http://test.host/body/dfh"
-
- RoutingFilter.active = true
- end
-
- it "should remember the filter (view) setting on redirecting" do
- get :show, :show_locale => "es", :url_name => "tgq", :view => 'successful'
- response.should redirect_to 'http://test.host/es/body/etgq/successful'
end
it "should redirect to newest name if you use historic name of public body in URL" do
@@ -95,12 +87,22 @@ describe PublicBodyController, "when listing bodies" do
:last_edit_comment => '')
@english_only.save
end
- I18n.with_locale(:es) do
- get :list
- assigns[:public_bodies].include?(@english_only).should == true
- end
+ get :list, {:locale => 'es'}
+ assigns[:public_bodies].include?(@english_only).should == true
+ end
+
+ it 'should show public body names in the selected locale language if present' do
+ get :list, {:locale => 'es'}
+ response.should contain('El Department for Humpadinking')
end
+ it 'should show public body names in the selected locale language if present for a locale with underscores' do
+ AlaveteliLocalization.set_locales('he_IL en', 'en')
+ get :list, {:locale => 'he_IL'}
+ response.should contain('Hebrew Humpadinking')
+ end
+
+
it "should list bodies in alphabetical order" do
# Note that they are alphabetised by localised name
get :list
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index c73576c50..2c605a139 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -1519,8 +1519,8 @@ describe RequestController, "when classifying an information request" do
post_status('rejected')
end
- it 'should not log a status update event' do
- @dog_request.should_not_receive(:log_event)
+ it 'should log a status update event' do
+ @dog_request.should_receive(:log_event)
post_status('rejected')
end
@@ -1573,11 +1573,12 @@ describe RequestController, "when classifying an information request" do
@dog_request.awaiting_description.should == false
@dog_request.described_state.should == 'rejected'
@dog_request.get_last_response_event.should == info_request_events(:useless_incoming_message_event)
- @dog_request.get_last_response_event.calculated_state.should == 'rejected'
+ @dog_request.info_request_events.last.event_type.should == "status_update"
+ @dog_request.info_request_events.last.calculated_state.should == 'rejected'
end
- it 'should not log a status update event' do
- @dog_request.should_not_receive(:log_event)
+ it 'should log a status update event' do
+ @dog_request.should_receive(:log_event)
post_status('rejected')
end
@@ -1645,10 +1646,6 @@ describe RequestController, "when classifying an information request" do
@dog_request = info_requests(:fancy_dog_request)
@dog_request.stub!(:each).and_return([@dog_request])
InfoRequest.stub!(:find).and_return(@dog_request)
- RoutingFilter.active = false
- end
- after do
- RoutingFilter.active = true
end
def request_url
diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb
index 1575bc84e..a16024828 100644
--- a/spec/controllers/track_controller_spec.rb
+++ b/spec/controllers/track_controller_spec.rb
@@ -64,8 +64,6 @@ describe TrackController, "when sending alerts for a track" do
end
it "should send alerts" do
- # Don't do clever locale-insertion-unto-URL stuff
- RoutingFilter.active = false
# set the time the comment event happened at to within the last week
ire = info_request_events(:silly_comment_event)
@@ -111,9 +109,6 @@ describe TrackController, "when sending alerts for a track" do
TrackMailer.alert_tracks
deliveries = ActionMailer::Base.deliveries
deliveries.size.should == 0
-
- # Restore the routing filters
- RoutingFilter.active = true
end
it "should send localised alerts" do
diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb
index b09594b9c..0033309a5 100644
--- a/spec/controllers/user_controller_spec.rb
+++ b/spec/controllers/user_controller_spec.rb
@@ -3,6 +3,31 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
# XXX Use route_for or params_from to check /c/ links better
# http://rspec.rubyforge.org/rspec-rails/1.1.12/classes/Spec/Rails/Example/ControllerExampleGroup.html
+describe UserController, "when redirecting a show request to a canonical url" do
+
+ it "should redirect to lower case name if given one with capital letters" do
+ get :show, :url_name => "Bob_Smith"
+ response.should redirect_to(:controller => 'user', :action => 'show', :url_name => "bob_smith")
+ end
+
+ it 'should redirect a long non-canonical name that has a numerical suffix,
+ retaining the suffix' do
+ get :show, :url_name => 'Bob_SmithBob_SmithBob_SmithBob_S_2'
+ response.should redirect_to(:controller => 'user',
+ :action => 'show',
+ :url_name => 'bob_smithbob_smithbob_smithbob_s_2')
+ end
+
+ it 'should not redirect a long canonical name that has a numerical suffix' do
+ User.stub!(:find).with(:first, anything()).and_return(mock_model(User,
+ :url_name => 'bob_smithbob_smithbob_smithbob_s_2',
+ :name => 'Bob Smith Bob Smith Bob Smith Bob Smith'))
+ User.stub!(:find).with(:all, anything()).and_return([])
+ get :show, :url_name => 'bob_smithbob_smithbob_smithbob_s_2'
+ response.should be_success
+ end
+
+end
describe UserController, "when showing a user" do
render_views
@@ -16,11 +41,6 @@ describe UserController, "when showing a user" do
response.should be_success
end
- it "should redirect to lower case name if given one with capital letters" do
- get :show, :url_name => "Bob_Smith"
- response.should redirect_to(:controller => 'user', :action => 'show', :url_name => "bob_smith")
- end
-
it "should render with 'show' template" do
get :show, :url_name => "bob_smith"
response.should render_template('show')
@@ -105,8 +125,6 @@ describe UserController, "when signing in" do
end
it "should log in when you give right email/password, and redirect to where you were" do
- RoutingFilter.active = false
-
get :signin, :r => "/list"
response.should render_template('sign')
post_redirect = get_last_postredirect
@@ -117,13 +135,9 @@ describe UserController, "when signing in" do
# response doesn't contain /en/ but redirect_to does...
response.should redirect_to(:controller => 'request', :action => 'list', :post_redirect => 1)
ActionMailer::Base.deliveries.should be_empty
-
- RoutingFilter.active = true
end
it "should not log you in if you use an invalid PostRedirect token, and shouldn't give 500 error either" do
- RoutingFilter.active = false
-
post_redirect = "something invalid"
lambda {
post :signin, { :user_signin => { :email => 'bob@localhost', :password => 'jonespassword' },
@@ -134,8 +148,6 @@ describe UserController, "when signing in" do
:token => post_redirect }
response.should render_template('sign')
assigns[:post_redirect].should == nil
-
- RoutingFilter.active = true
end
# No idea how to test this in the test framework :(
@@ -159,8 +171,6 @@ describe UserController, "when signing in" do
end
it "should confirm your email, log you in and redirect you to where you were after you click an email link" do
- RoutingFilter.active = false
-
get :signin, :r => "/list"
post_redirect = get_last_postredirect
@@ -186,13 +196,9 @@ describe UserController, "when signing in" do
get :confirm, :email_token => post_redirect.email_token
session[:user_id].should == users(:unconfirmed_user).id
response.should redirect_to(:controller => 'request', :action => 'list', :post_redirect => 1)
-
- RoutingFilter.active = true
end
it "should keep you logged in if you click a confirmation link and are already logged in as an admin" do
- RoutingFilter.active = false
-
get :signin, :r => "/list"
post_redirect = get_last_postredirect
@@ -223,7 +229,6 @@ describe UserController, "when signing in" do
# And the redirect should still work, of course
response.should redirect_to(:controller => 'request', :action => 'list', :post_redirect => 1)
- RoutingFilter.active = true
end
end
@@ -301,14 +306,10 @@ describe UserController, "when signing out" do
end
it "should log you out and redirect you to where you were" do
- RoutingFilter.active = false
-
session[:user_id] = users(:bob_smith_user).id
get :signout, :r => '/list'
session[:user_id].should be_nil
response.should redirect_to(:controller => 'request', :action => 'list')
-
- RoutingFilter.active = true
end
end
diff --git a/spec/fixtures/files/unrecognized-encoding-mail.email b/spec/fixtures/files/unrecognized-encoding-mail.email
new file mode 100644
index 000000000..266a90fbc
--- /dev/null
+++ b/spec/fixtures/files/unrecognized-encoding-mail.email
@@ -0,0 +1,36 @@
+From xxx@example.com Fri Jun 21 07:50:52 2013
+Return-path: <xxx@example.com>
+Envelope-to: xxx@example.com
+Delivery-date: Fri, 21 Jun 2013 07:50:52 +0100
+Message-ID: <185C0D48380D7AE612DD38A527D5EAF2@tmvbalem>
+From: "cttlqvx" <xxx@example.com>
+To: <xxx@example.com>
+Subject: =?hz-gb-2312?B?fntPck9ISXpWQn59c3J5dW95d3MoQUQpICAgIA==?=
+Date: Fri, 21 Jun 2013 14:48:20 +0800
+MIME-Version: 1.0
+Content-Type: multipart/related;
+ type="multipart/alternative";
+ boundary="----=_NextPart_000_02ED_01A0462A.178683F0"
+X-Priority: 1
+X-MSMail-Priority: High
+X-Mailer: Microsoft Outlook Express 6.00.2900.5512
+X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
+
+This is a multi-part message in MIME format.
+
+------=_NextPart_000_02ED_01A0462A.178683F0
+Content-Type: multipart/alternative;
+ boundary="----=_NextPart_001_09EC_01A0462A.178683F0"
+
+------=_NextPart_001_09EC_01A0462A.178683F0
+Content-Type: text/plain;
+ charset="hz-gb-2312"
+Content-Transfer-Encoding: base64
+
+
+------=_NextPart_001_09EC_01A0462A.178683F0
+Content-Type: text/html;
+ charset="hz-gb-2312"
+Content-Transfer-Encoding: base64
+
+------=_NextPart_001_09EC_01A0462A.178683F0--
diff --git a/spec/fixtures/public_body_translations.yml b/spec/fixtures/public_body_translations.yml
index 61e07fb5b..de1bf2f18 100644
--- a/spec/fixtures/public_body_translations.yml
+++ b/spec/fixtures/public_body_translations.yml
@@ -101,3 +101,17 @@ other_public_body_translation:
notes: More notes
publication_scheme: ""
disclosure_log: ""
+
+humpadink_he_IL_public_body_translation:
+ name: "Hebrew Humpadinking"
+ first_letter: D
+ request_email: humpadink-requests@localhost
+ id: 9
+ public_body_id: 3
+ short_name: DfH
+ url_name: dfh
+ locale: he_IL
+ notes: An albatross told me!!!
+ publication_scheme: ""
+ disclosure_log: ""
+
diff --git a/spec/helpers/link_to_helper_spec.rb b/spec/helpers/link_to_helper_spec.rb
index 4cc1d415b..b29419ef3 100644
--- a/spec/helpers/link_to_helper_spec.rb
+++ b/spec/helpers/link_to_helper_spec.rb
@@ -8,12 +8,7 @@ describe LinkToHelper do
before do
@mock_request = mock_model(InfoRequest, :url_title => 'test_title')
- RoutingFilter.active = false
end
- after do
- RoutingFilter.active = true
- end
-
it 'should return a path like /request/test_title' do
request_path(@mock_request).should == '/request/test_title'
diff --git a/spec/integration/localisation_spec.rb b/spec/integration/localisation_spec.rb
new file mode 100644
index 000000000..4f6b61ae1
--- /dev/null
+++ b/spec/integration/localisation_spec.rb
@@ -0,0 +1,88 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe "when generating urls" do
+
+ before do
+ @home_link_regex = /href=".*\/en\//
+ end
+
+ it "should generate URLs that include the locale when using one that includes an underscore" do
+ get('/en_GB')
+ response.body.should match /href="\/en_GB\//
+ end
+
+ it "should fall back to the language if the territory is unknown" do
+ AlaveteliLocalization.set_locales(available_locales='es en', default_locale='en')
+ get('/', {}, {'HTTP_ACCEPT_LANGUAGE' => 'en_US'})
+ response.body.should match /href="\/en\//
+ response.body.should_not match /href="\/en_US\//
+ end
+
+ it "should generate URLs without a locale prepended when there's only one locale set" do
+ AlaveteliLocalization.set_locales(available_locales='en', default_locale='en')
+ get('/')
+ response.should_not contain @home_link_regex
+ end
+
+ it 'should redirect requests for a public body in a locale to the canonical name in that locale' do
+ get('/es/body/dfh')
+ response.should redirect_to "/es/body/edfh"
+ end
+
+ it 'should remember a filter view when redirecting a public body request to the canonical name' do
+ get('/es/body/tgq/successful')
+ response.should redirect_to "/es/body/etgq/successful"
+ end
+
+ describe 'when there is more than one locale' do
+
+ before do
+ AlaveteliLocalization.set_locales(available_locales='es en', default_locale='en')
+ end
+
+ it "should generate URLs with a locale prepended when there's more than one locale set" do
+ get('/')
+ response.body.should match @home_link_regex
+ end
+
+ describe 'when using the default locale' do
+
+ before do
+ @default_lang_home_link = /href=".*\/en\//
+ @other_lang_home_link = /href=".*\/es\//
+ @old_include_default_locale_in_urls = AlaveteliConfiguration::include_default_locale_in_urls
+ end
+
+ describe 'when the config value INCLUDE_DEFAULT_LOCALE_IN_URLS is false' do
+
+ before do
+ AlaveteliLocalization.set_default_locale_urls(false)
+ end
+
+ it 'should generate URLs without a locale prepended' do
+ get '/'
+ response.should_not contain @default_lang_home_link
+ end
+
+ it 'should render the front page in the default language when no locale param
+ is present and the session locale is not the default' do
+ get('/', {:locale => 'es'})
+ response.should_not contain @other_lang_home_link
+ end
+ end
+
+ it 'should generate URLs with a locale prepended when the config value
+ INCLUDE_DEFAULT_LOCALE_IN_URLS is true' do
+ AlaveteliLocalization.set_default_locale_urls(true)
+ get '/'
+ response.body.should match /#{@default_lang_home_link}/
+ end
+
+ after do
+ AlaveteliLocalization.set_default_locale_urls(@old_include_default_locale_in_urls)
+ end
+
+ end
+ end
+
+end
diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb
index 3e5176e87..aa351bd94 100644
--- a/spec/lib/mail_handler/mail_handler_spec.rb
+++ b/spec/lib/mail_handler/mail_handler_spec.rb
@@ -67,6 +67,11 @@ describe 'when creating a mail object from raw data' do
body.should match(/ \xe2\x80\x93 /)
end
+ it 'should not error on a subject line with an encoding encoding not recognized by iconv' do
+ mail = get_fixture_mail('unrecognized-encoding-mail.email')
+ lambda{ mail.subject }.should_not raise_error
+ end
+
end
describe 'when asked for the from name' do
diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb
index 3c924dcb3..ff6a8e34e 100644
--- a/spec/models/incoming_message_spec.rb
+++ b/spec/models/incoming_message_spec.rb
@@ -328,7 +328,18 @@ describe IncomingMessage, " when censoring data" do
data.should == "His email was x\000x\000x\000@\000x\000x\000x\000.\000x\000x\000x\000, indeed"
end
-
+ it 'should handle multibyte characters correctly', :focus => true do
+ orig_data = 'á'
+ data = orig_data.dup
+ @regex_censor_rule = CensorRule.new()
+ @regex_censor_rule.text = 'á'
+ @regex_censor_rule.regexp = true
+ @regex_censor_rule.replacement = 'cat'
+ @regex_censor_rule.last_edit_editor = 'unknown'
+ @regex_censor_rule.last_edit_comment = 'none'
+ @im.info_request.censor_rules << @regex_censor_rule
+ lambda{ @im.binary_mask_stuff!(data, "text/plain") }.should_not raise_error
+ end
def pdf_replacement_test(use_ghostscript_compression)
config = MySociety::Config.load_default()
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index f9ca44657..3451e018f 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -156,6 +156,7 @@ describe InfoRequest do
end
it "should cope with indexing after item is deleted" do
+ load_raw_emails_data
IncomingMessage.find(:all).each{|x| x.parse_raw_email!}
rebuild_xapian_index
# delete event from underneath indexing; shouldn't cause error
@@ -606,4 +607,254 @@ describe InfoRequest do
@info_request.user_json_for_api.should == {:name => 'Anonymous user'}
end
end
+ describe "#set_described_state and #log_event" do
+ context "a request" do
+ let(:request) { InfoRequest.create!(:title => "my request",
+ :public_body => public_bodies(:geraldine_public_body),
+ :user => users(:bob_smith_user)) }
+
+ context "a series of events on a request" do
+ it "should have sensible events after the initial request has been made" do
+ # An initial request is sent
+ # The logic that changes the status when a message is sent is mixed up
+ # in OutgoingMessage#send_message. So, rather than extract it (or call it)
+ # let's just duplicate what it does here for the time being.
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+
+ events = request.info_request_events
+ events.count.should == 1
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ end
+
+ it "should have sensible events after a response is received to a request" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+ # A response is received
+ # This is normally done in InfoRequest#receive
+ request.awaiting_description = true
+ request.log_event("response", {})
+
+ events = request.info_request_events
+ events.count.should == 2
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ events[1].event_type.should == "response"
+ events[1].described_state.should be_nil
+ # TODO: Should calculated_status in this situation be "waiting_classification"?
+ # This would allow searches like "latest_status: waiting_classification" to be
+ # available to the user in "Advanced search"
+ events[1].calculated_state.should be_nil
+ end
+
+ it "should have sensible events after a request is classified by the requesting user" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+ # A response is received
+ request.awaiting_description = true
+ request.log_event("response", {})
+ # The request is classified by the requesting user
+ # This is normally done in RequestController#describe_state
+ request.log_event("status_update", {})
+ request.set_described_state("waiting_response")
+
+ events = request.info_request_events
+ events.count.should == 3
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ events[1].event_type.should == "response"
+ events[1].described_state.should be_nil
+ events[1].calculated_state.should == 'waiting_response'
+ events[2].event_type.should == "status_update"
+ events[2].described_state.should == "waiting_response"
+ events[2].calculated_state.should == "waiting_response"
+ end
+
+ it "should have sensible events after a normal followup is sent" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+ # A response is received
+ request.awaiting_description = true
+ request.log_event("response", {})
+ # The request is classified by the requesting user
+ request.log_event("status_update", {})
+ request.set_described_state("waiting_response")
+ # A normal follow up is sent
+ # This is normally done in OutgoingMessage#send_message
+ request.log_event('followup_sent', {})
+ request.set_described_state('waiting_response')
+
+ events = request.info_request_events
+ events.count.should == 4
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ events[1].event_type.should == "response"
+ events[1].described_state.should be_nil
+ events[1].calculated_state.should == 'waiting_response'
+ events[2].event_type.should == "status_update"
+ events[2].described_state.should == "waiting_response"
+ events[2].calculated_state.should == "waiting_response"
+ events[3].event_type.should == "followup_sent"
+ events[3].described_state.should == "waiting_response"
+ events[3].calculated_state.should == "waiting_response"
+ end
+
+ it "should have sensible events after a user classifies the request after a follow up" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+ # A response is received
+ request.awaiting_description = true
+ request.log_event("response", {})
+ # The request is classified by the requesting user
+ request.log_event("status_update", {})
+ request.set_described_state("waiting_response")
+ # A normal follow up is sent
+ request.log_event('followup_sent', {})
+ request.set_described_state('waiting_response')
+ # The request is classified by the requesting user
+ request.log_event("status_update", {})
+ request.set_described_state("waiting_response")
+
+ events = request.info_request_events
+ events.count.should == 5
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ events[1].event_type.should == "response"
+ events[1].described_state.should be_nil
+ events[1].calculated_state.should == 'waiting_response'
+ events[2].event_type.should == "status_update"
+ events[2].described_state.should == "waiting_response"
+ events[2].calculated_state.should == "waiting_response"
+ events[3].event_type.should == "followup_sent"
+ events[3].described_state.should == "waiting_response"
+ events[3].calculated_state.should == "waiting_response"
+ events[4].event_type.should == "status_update"
+ events[4].described_state.should == "waiting_response"
+ events[4].calculated_state.should == "waiting_response"
+ end
+ end
+
+ context "another series of events on a request" do
+ it "should have sensible event states" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+ # An internal review is requested
+ request.log_event('followup_sent', {})
+ request.set_described_state('internal_review')
+
+ events = request.info_request_events
+ events.count.should == 2
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ events[1].event_type.should == "followup_sent"
+ events[1].described_state.should == "internal_review"
+ events[1].calculated_state.should == "internal_review"
+ end
+
+ it "should have sensible event states" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+ # An internal review is requested
+ request.log_event('followup_sent', {})
+ request.set_described_state('internal_review')
+ # The user marks the request as rejected
+ request.log_event("status_update", {})
+ request.set_described_state("rejected")
+
+ events = request.info_request_events
+ events.count.should == 3
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ events[1].event_type.should == "followup_sent"
+ events[1].described_state.should == "internal_review"
+ events[1].calculated_state.should == "internal_review"
+ events[2].event_type.should == "status_update"
+ events[2].described_state.should == "rejected"
+ events[2].calculated_state.should == "rejected"
+ end
+ end
+
+ context "another series of events on a request" do
+ it "should have sensible event states" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+ # The user marks the request as successful (I know silly but someone did
+ # this in https://www.whatdotheyknow.com/request/family_support_worker_redundanci)
+ request.log_event("status_update", {})
+ request.set_described_state("successful")
+
+ events = request.info_request_events
+ events.count.should == 2
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ events[1].event_type.should == "status_update"
+ events[1].described_state.should == "successful"
+ events[1].calculated_state.should == "successful"
+ end
+
+ it "should have sensible event states" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+
+ # A response is received
+ request.awaiting_description = true
+ request.log_event("response", {})
+
+ # The user marks the request as successful
+ request.log_event("status_update", {})
+ request.set_described_state("successful")
+
+ events = request.info_request_events
+ events.count.should == 3
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ events[1].event_type.should == "response"
+ events[1].described_state.should be_nil
+ events[1].calculated_state.should == "successful"
+ events[2].event_type.should == "status_update"
+ events[2].described_state.should == "successful"
+ events[2].calculated_state.should == "successful"
+ end
+ end
+
+ context "another series of events on a request", :focus => true do
+ it "should have sensible event states" do
+ # An initial request is sent
+ request.log_event('sent', {})
+ request.set_described_state('waiting_response')
+ # An admin sets the status of the request to 'gone postal' using
+ # the admin interface
+ request.log_event("edit", {})
+ request.set_described_state("gone_postal")
+
+ events = request.info_request_events
+ events.count.should == 2
+ events[0].event_type.should == "sent"
+ events[0].described_state.should == "waiting_response"
+ events[0].calculated_state.should == "waiting_response"
+ events[1].event_type.should == "edit"
+ events[1].described_state.should == "gone_postal"
+ events[1].calculated_state.should == "gone_postal"
+ end
+ end
+ end
+ end
end
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index e17cf8e63..90affaaaa 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -468,7 +468,7 @@ end
describe PublicBody, " when override all public body request emails set" do
it "should return the overridden request email" do
- MySociety::Config.should_receive(:get).with("OVERRIDE_ALL_PUBLIC_BODY_REQUEST_EMAILS", "").twice.and_return("catch_all_test_email@foo.com")
+ AlaveteliConfiguration.should_receive(:override_all_public_body_request_emails).twice.and_return("catch_all_test_email@foo.com")
@geraldine = public_bodies(:geraldine_public_body)
@geraldine.request_email.should == "catch_all_test_email@foo.com"
end
diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb
index c40334142..7aab9cdc6 100644
--- a/spec/models/xapian_spec.rb
+++ b/spec/models/xapian_spec.rb
@@ -373,6 +373,11 @@ end
# I would expect ActsAsXapian to have some tests under vendor/plugins/acts_as_xapian, but
# it looks like this is not the case. Putting a test here instead.
describe ActsAsXapian::Search, "#words_to_highlight" do
+ before(:each) do
+ load_raw_emails_data
+ get_fixtures_xapian_index
+ end
+
it "should return a list of words used in the search" do
s = ActsAsXapian::Search.new([PublicBody], "albatross words", :limit => 100)
s.words_to_highlight.should == ["albatross", "words"]
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index a3b06cea8..86ca5150a 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -31,8 +31,7 @@ Spork.prefork do
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
# Use test-specific translations
- FastGettext.add_text_domain 'app', :path => File.join(File.dirname(__FILE__), 'fixtures', 'locale'), :type => :po
- FastGettext.default_text_domain = 'app'
+ AlaveteliLocalization.set_default_text_domain('app', File.join(File.dirname(__FILE__), 'fixtures', 'locale'))
RSpec.configure do |config|
# ## Mock Framework
@@ -88,12 +87,19 @@ Spork.prefork do
# ApplicationController#set_gettext_locale which sets the locale and so you may be setting
# the locale in your tests and not even realising it. So, let's make things easier for
# ourselves and just always restore the locale for all tests.
+ config.after(:each) do
+ AlaveteliLocalization.set_locales(AlaveteliConfiguration::available_locales,
+ AlaveteliConfiguration::default_locale)
+ end
+
+ # Turn routing-filter off in functional and unit tests as per
+ # https://github.com/svenfuchs/routing-filter/blob/master/README.markdown#testing
config.before(:each) do
- @save_i18n_locale = I18n.locale
+ RoutingFilter.active = false if [:controller, :helper, :model].include? example.metadata[:type]
end
config.after(:each) do
- I18n.locale = @save_i18n_locale
+ RoutingFilter.active = true if [:controller, :helper, :model].include? example.metadata[:type]
end
# This section makes the garbage collector run less often to speed up tests