aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/views/general/_locale_switcher.html.erb2
-rw-r--r--app/views/layouts/default.html.erb2
-rw-r--r--config/initializers/alaveteli.rb12
-rw-r--r--config/initializers/fast_gettext.rb5
-rw-r--r--lib/alaveteli_localization.rb21
-rw-r--r--lib/i18n_fixes.rb23
-rw-r--r--lib/routing_filters.rb2
-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.rb4
-rw-r--r--spec/controllers/track_controller_spec.rb5
-rw-r--r--spec/controllers/user_controller_spec.rb19
-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/models/info_request_spec.rb1
-rw-r--r--spec/models/public_body_spec.rb2
-rw-r--r--spec/models/xapian_spec.rb5
-rw-r--r--spec/spec_helper.rb14
20 files changed, 190 insertions, 168 deletions
diff --git a/app/views/general/_locale_switcher.html.erb b/app/views/general/_locale_switcher.html.erb
index d0040bb0d..a318f61f3 100644
--- a/app/views/general/_locale_switcher.html.erb
+++ b/app/views/general/_locale_switcher.html.erb
@@ -2,7 +2,7 @@
<div id="user_locale_switcher">
<div class="btn-group">
<% for possible_locale in FastGettext.default_available_locales %>
- <% if possible_locale == I18n.locale.to_s %>
+ <% if possible_locale == FastGettext.locale %>
<a href="#" class="btn disabled"><%= locale_name(possible_locale) %></a>
<% else %>
<a href="<%= url_for params.merge(:locale => possible_locale) %>" class="btn"><%= locale_name(possible_locale) %></a>
diff --git a/app/views/layouts/default.html.erb b/app/views/layouts/default.html.erb
index 688816fa9..472fa8ec1 100644
--- a/app/views/layouts/default.html.erb
+++ b/app/views/layouts/default.html.erb
@@ -52,7 +52,7 @@
'width': 920,
'height': 400,
'type': 'iframe',
- 'href': '/<%= I18n.locale %>/profile/sign_in?modal=1',
+ 'href': '/<%= FastGettext.locale %>/profile/sign_in?modal=1',
'onClosed': function() {
// modal_signin_successful variable set by modal dialog box
if (typeof modal_signin_successful != 'undefined' ) {
diff --git a/config/initializers/alaveteli.rb b/config/initializers/alaveteli.rb
index d78bc3925..deee3f6da 100644
--- a/config/initializers/alaveteli.rb
+++ b/config/initializers/alaveteli.rb
@@ -34,14 +34,6 @@ if AlaveteliConfiguration::force_ssl
ActionMailer::Base.default_url_options[:protocol] = "https"
end
-# fallback locale and available locales
-available_locales = AlaveteliConfiguration::available_locales.split(/ /)
-default_locale = AlaveteliConfiguration::default_locale
-
-FastGettext.default_available_locales = available_locales
-I18n.locale = default_locale
-I18n.available_locales = available_locales.map {|locale_name| locale_name.to_sym}
-I18n.default_locale = default_locale
# Load monkey patches and other things from lib/
require 'ruby19.rb'
@@ -57,6 +49,10 @@ require 'public_body_categories'
require 'ability'
require 'normalize_string'
require 'alaveteli_file_types'
+require 'alaveteli_localization'
+
+AlaveteliLocalization.set_locales(AlaveteliConfiguration::available_locales,
+ AlaveteliConfiguration::default_locale)
# Allow tests to be run under a non-superuser database account if required
if Rails.env == 'test' and ActiveRecord::Base.configurations['test']['constraint_disabling'] == false
diff --git a/config/initializers/fast_gettext.rb b/config/initializers/fast_gettext.rb
index 752448a41..b00524993 100644
--- a/config/initializers/fast_gettext.rb
+++ b/config/initializers/fast_gettext.rb
@@ -1,6 +1,5 @@
-FastGettext.add_text_domain 'app', :path => File.join(Rails.root, 'locale'), :type => :po
-FastGettext.default_text_domain = 'app'
+AlaveteliLocalization.set_default_text_domain('app', File.join(Rails.root, 'locale'))
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
-RoutingFilter::Locale.include_default_locale = AlaveteliConfiguration::include_default_locale_in_urls
+AlaveteliLocalization.set_default_locale_urls(AlaveteliConfiguration::include_default_locale_in_urls)
diff --git a/lib/alaveteli_localization.rb b/lib/alaveteli_localization.rb
new file mode 100644
index 000000000..6daab124a
--- /dev/null
+++ b/lib/alaveteli_localization.rb
@@ -0,0 +1,21 @@
+class AlaveteliLocalization
+ class << self
+ def set_locales(available_locales, default_locale)
+ # fallback locale and available locales
+ available_locales = available_locales.split(/ /)
+ FastGettext.default_available_locales = available_locales
+ I18n.locale = default_locale
+ I18n.available_locales = available_locales.map { |locale_name| locale_name.to_sym }
+ I18n.default_locale = default_locale
+ end
+
+ def set_default_text_domain(name, path)
+ FastGettext.add_text_domain name, :path => path, :type => :po
+ FastGettext.default_text_domain = name
+ end
+
+ def set_default_locale_urls(include_default_locale_in_urls)
+ RoutingFilter::Locale.include_default_locale = include_default_locale_in_urls
+ end
+ end
+end
diff --git a/lib/i18n_fixes.rb b/lib/i18n_fixes.rb
index 82d1b2c3a..9c1206215 100644
--- a/lib/i18n_fixes.rb
+++ b/lib/i18n_fixes.rb
@@ -17,7 +17,7 @@ end
def n_(*keys)
# The last parameter should be the values to do the interpolation with
if keys.count > 3
- options = keys.pop
+ options = keys.pop
else
options = {}
end
@@ -33,7 +33,7 @@ def gettext_interpolate(string, values)
safe = string.html_safe?
string = string.to_str.gsub(MATCH) do
pattern, key = $1, $1.to_sym
-
+
if !values.include?(key)
raise I18n::MissingInterpolationArgument.new(pattern, string)
else
@@ -50,7 +50,7 @@ end
module I18n
- # used by Globalize plugin.
+ # used by Globalize plugin.
# XXX much of this stuff should (might?) be in newer versions of Rails
@@fallbacks = nil
class << self
@@ -120,7 +120,7 @@ module I18n
@defaults = defaults.map { |default| compute(default, false) }.flatten
end
attr_reader :defaults
-
+
def [](locale)
raise InvalidLocale.new(locale) if locale.nil?
locale = locale.to_sym
@@ -138,7 +138,7 @@ module I18n
end
protected
-
+
def compute(tags, include_defaults = true)
result = Array(tags).collect do |tag|
tags = I18n::Locale::Tag::Simple.tag(tag).self_and_parents.map! { |t| t.to_sym }
@@ -161,7 +161,18 @@ module GettextI18nRails
class Backend
def available_locales
FastGettext.available_locales.map{|l| l.to_sym} || []
- end
+ end
end
end
+# Monkeypatch Globalize to compensate for the way gettext_i18n_rails patches
+# I18n.locale= so that it changes underscores in locale names (as used in the gettext world)
+# to the dashes that I18n prefers
+module Globalize
+ class << self
+ def locale
+ read_locale || I18n.locale.to_s.gsub('-', '_').to_sym
+ end
+ end
+end
+
diff --git a/lib/routing_filters.rb b/lib/routing_filters.rb
index 32dafc651..a9a62b8db 100644
--- a/lib/routing_filters.rb
+++ b/lib/routing_filters.rb
@@ -7,7 +7,7 @@ module RoutingFilter
end
# And override the generation logic to use FastGettext.locale
# rather than I18n.locale (the latter is what rails uses
- # internally and may look like `en_US`, whereas the latter is
+ # internally and may look like `en-US`, whereas the latter is
# was FastGettext and other POSIX-based systems use, and will
# look like `en_US`
def around_generate(*args, &block)
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 387b040d6..2c605a139 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -1646,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..fe95aa31c 100644
--- a/spec/controllers/user_controller_spec.rb
+++ b/spec/controllers/user_controller_spec.rb
@@ -105,8 +105,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 +115,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 +128,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 +151,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 +176,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 +209,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 +286,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/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/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index 0ba8abd75..c9ee57c74 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
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index bc693b4da..34a91a2c9 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -464,7 +464,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