Skip to content

Commit

Permalink
Fixing specs to remove locale prefixes
Browse files Browse the repository at this point in the history
This commit includes updating specs to omit any references to
methods that have since been removed, as well as updating
fixtures and specs which have specs in hard-coded urls to no
longer have locale prefixes in them.
  • Loading branch information
alexander-griffen committed Feb 26, 2024
1 parent 6e9bc63 commit 2c1683c
Show file tree
Hide file tree
Showing 22 changed files with 56 additions and 143 deletions.
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def set_gettext_locale

locale = AlaveteliLocalization.set_session_locale(
params[:locale],
current_user&.locale, # FIXME: Do we really want to use the user locale, or prioritise the session?
session[:locale],
cookies[:locale],
browser_locale,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ We’ll attempt to bill your card again over the coming days.

If payment continues to fail, unfortunately your account will revert back to a free account, and you’ll no longer have access to Alaveteli Professional.

If you wish to preserve your access to Alaveteli Professional, please could you check that your card has sufficient funds, and that the card details are correct on your subscriptions page: http://test.host/en/profile/subscriptions
If you wish to preserve your access to Alaveteli Professional, please could you check that your card has sufficient funds, and that the card details are correct on your subscriptions page: http://test.host/profile/subscriptions

-- the Alaveteli Professional team
34 changes: 17 additions & 17 deletions spec/fixtures/files/notification_mailer/daily-summary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ You have a new response to the Freedom of Information request 'The cost of paper

To view the response, click on the link below.

http://test.host/en/request/the_cost_of_paperclips?nocache=incoming-$THE_COST_OF_PAPERCLIPS_MOF_INCOMING_ID$#incoming-$THE_COST_OF_PAPERCLIPS_MOF_INCOMING_ID$
http://test.host/request/the_cost_of_paperclips?nocache=incoming-$THE_COST_OF_PAPERCLIPS_MOF_INCOMING_ID$#incoming-$THE_COST_OF_PAPERCLIPS_MOF_INCOMING_ID$


Thefts of stationary
Expand All @@ -19,11 +19,11 @@ You have a new response to the Freedom of Information request 'Thefts of station

To view the response, click on the link below.

http://test.host/en/request/thefts_of_stationary?nocache=incoming-$THEFTS_OF_STATIONARY_MIQ_INCOMING_ID$#incoming-$THEFTS_OF_STATIONARY_MIQ_INCOMING_ID$
http://test.host/request/thefts_of_stationary?nocache=incoming-$THEFTS_OF_STATIONARY_MIQ_INCOMING_ID$#incoming-$THEFTS_OF_STATIONARY_MIQ_INCOMING_ID$

This request will be made public on Alaveteli in the next week. If you do not wish this request to go public at that time, please click on the link below to keep it private for longer.

http://test.host/en/request/thefts_of_stationary
http://test.host/request/thefts_of_stationary


Missing staplers
Expand All @@ -32,7 +32,7 @@ Missing staplers
What's happened:
This request will be made public on Alaveteli in the next week. If you do not wish this request to go public at that time, please click on the link below to keep it private for longer.

http://test.host/en/request/missing_staplers
http://test.host/request/missing_staplers


Late expenses claims
Expand All @@ -41,7 +41,7 @@ Late expenses claims
What's happened:
Ministry of fact keeping have not replied to your FOI request Late expenses claims promptly, as normally required by law. Click on the link below to remind them to reply.

http://test.host/en/profile/sign_in?r=%2Fen%2Frequest%2F$LATE_EXPENSES_CLAIMS_MOF_URL_TITLE$%2Ffollowups%2Fnew
http://test.host/profile/sign_in?r=%2Frequest%2F$LATE_EXPENSES_CLAIMS_MOF_URL_TITLE$%2Ffollowups%2Fnew


Extremely late expenses claims
Expand All @@ -50,7 +50,7 @@ Extremely late expenses claims
What's happened:
Ministry of fact keeping have still not replied to your FOI request Extremely late expenses claims, as normally required by law. Click on the link below to tell them to reply. You might like to ask for an internal review, asking them to find out why their response to the request has been so slow.

http://test.host/en/profile/sign_in?r=%2Fen%2Frequest%2F$EXTREMELY_LATE_EXPENSES_CLAIMS_MOF_URL_TITLE$%2Ffollowups%2Fnew
http://test.host/profile/sign_in?r=%2Frequest%2F$EXTREMELY_LATE_EXPENSES_CLAIMS_MOF_URL_TITLE$%2Ffollowups%2Fnew


Misdelivered letters
Expand All @@ -59,7 +59,7 @@ Misdelivered letters
What's happened:
This request has been made public on Alaveteli.

http://test.host/en/request/misdelivered_letters
http://test.host/request/misdelivered_letters


Zero hours employees
Expand All @@ -72,8 +72,8 @@ Zero hours employees
What's happened:
2 requests had new responses:
You can see the responses with the following links:
Ministry of fact keeping: http://test.host/en/request/zero_hours_employees?nocache=incoming-$ZERO_HOURS_EMPLOYEES_MOF_INCOMING_ID$#incoming-$ZERO_HOURS_EMPLOYEES_MOF_INCOMING_ID$
Minor infractions quango: http://test.host/en/request/zero_hours_employees_2?nocache=incoming-$ZERO_HOURS_EMPLOYEES_2_MIQ_INCOMING_ID$#incoming-$ZERO_HOURS_EMPLOYEES_2_MIQ_INCOMING_ID$
Ministry of fact keeping: http://test.host/request/zero_hours_employees?nocache=incoming-$ZERO_HOURS_EMPLOYEES_MOF_INCOMING_ID$#incoming-$ZERO_HOURS_EMPLOYEES_MOF_INCOMING_ID$
Minor infractions quango: http://test.host/request/zero_hours_employees_2?nocache=incoming-$ZERO_HOURS_EMPLOYEES_2_MIQ_INCOMING_ID$#incoming-$ZERO_HOURS_EMPLOYEES_2_MIQ_INCOMING_ID$


Employees caught stealing stationary
Expand All @@ -85,8 +85,8 @@ Employees caught stealing stationary

What's happened:
2 requests will be made public on Alaveteli in the next week. If you do not wish these requests to go public at that time, please click on the links below to keep them private for longer.
Ministry of fact keeping: http://test.host/en/request/employees_caught_stealing_statio
Minor infractions quango: http://test.host/en/request/employees_caught_stealing_statio_2
Ministry of fact keeping: http://test.host/request/employees_caught_stealing_statio
Minor infractions quango: http://test.host/request/employees_caught_stealing_statio_2


Employee of the month awards
Expand All @@ -98,8 +98,8 @@ Employee of the month awards

What's happened:
2 requests have been made public on Alaveteli.
Ministry of fact keeping: http://test.host/en/request/employee_of_the_month_awards
Minor infractions quango: http://test.host/en/request/employee_of_the_month_awards_2
Ministry of fact keeping: http://test.host/request/employee_of_the_month_awards
Minor infractions quango: http://test.host/request/employee_of_the_month_awards_2


Late FOI requests
Expand All @@ -114,8 +114,8 @@ What's happened:

You can see the requests and remind the bodies to respond with the following links:

Ministry of fact keeping: http://test.host/en/profile/sign_in?r=%2Fen%2Frequest%2F$LATE_FOI_REQUESTS_MOF_URL_TITLE$%2Ffollowups%2Fnew
Minor infractions quango: http://test.host/en/profile/sign_in?r=%2Fen%2Frequest%2F$LATE_FOI_REQUESTS_2_MIQ_URL_TITLE$%2Ffollowups%2Fnew
Ministry of fact keeping: http://test.host/profile/sign_in?r=%2Frequest%2F$LATE_FOI_REQUESTS_MOF_URL_TITLE$%2Ffollowups%2Fnew
Minor infractions quango: http://test.host/profile/sign_in?r=%2Frequest%2F$LATE_FOI_REQUESTS_2_MIQ_URL_TITLE$%2Ffollowups%2Fnew


Ignored FOI requests
Expand All @@ -130,8 +130,8 @@ What's happened:

You can see the requests and tell the bodies to respond with the following links. You might like to ask for internal reviews, asking the bodies to find out why responses to the requests have been so slow.

Ministry of fact keeping: http://test.host/en/profile/sign_in?r=%2Fen%2Frequest%2F$IGNORED_FOI_REQUESTS_MOF_URL_TITLE$%2Ffollowups%2Fnew
Minor infractions quango: http://test.host/en/profile/sign_in?r=%2Fen%2Frequest%2F$IGNORED_FOI_REQUESTS_2_MIQ_URL_TITLE$%2Ffollowups%2Fnew
Ministry of fact keeping: http://test.host/profile/sign_in?r=%2Frequest%2F$IGNORED_FOI_REQUESTS_MOF_URL_TITLE$%2Ffollowups%2Fnew
Minor infractions quango: http://test.host/profile/sign_in?r=%2Frequest%2F$IGNORED_FOI_REQUESTS_2_MIQ_URL_TITLE$%2Ffollowups%2Fnew



Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The following request will be made public on Alaveteli in the next week. If you do not wish this request to go public at that time, please click on the link below to keep it private for longer.

http://test.host/en/request/here_is_a_character_that_needs_q
http://test.host/request/here_is_a_character_that_needs_q

-- the Alaveteli team
2 changes: 1 addition & 1 deletion spec/fixtures/files/notification_mailer/expire_embargo.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The following request has been made public on Alaveteli.

http://test.host/en/request/here_is_a_character_that_needs_q
http://test.host/request/here_is_a_character_that_needs_q

-- the Alaveteli team
2 changes: 1 addition & 1 deletion spec/fixtures/files/notification_mailer/new_response.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ You have a new response to the Freedom of Information request 'Here is a charact

To view the response, click on the link below.

http://test.host/en/request/here_is_a_character_that_needs_q?nocache=incoming-INCOMING_MESSAGE_ID#incoming-INCOMING_MESSAGE_ID
http://test.host/request/here_is_a_character_that_needs_q?nocache=incoming-INCOMING_MESSAGE_ID#incoming-INCOMING_MESSAGE_ID

When you get there, please update the status to say if the response contains any useful information.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ You have a new response to the Freedom of Information request 'Here is a charact

To view the response, click on the link below.

http://test.host/en/profile/sign_in?r=http%3A%2F%2Ftest.host%2Fen%2Frequest%2Fhere_is_a_character_that_needs_q%3Fnocache%3Dincoming-INCOMING_MESSAGE_ID%23incoming-INCOMING_MESSAGE_ID
http://test.host/profile/sign_in?r=http%3A%2F%2Ftest.host%2Frequest%2Fhere_is_a_character_that_needs_q%3Fnocache%3Dincoming-INCOMING_MESSAGE_ID%23incoming-INCOMING_MESSAGE_ID

When you get there, please update the status to say if the response contains any useful information.

Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/files/notification_mailer/overdue.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ They have not replied to your FOI request Here is a character that needs quoting

Click on the link below to send a message to Test public body reminding them to reply to your request.

http://test.host/en/profile/sign_in?r=%2Fen%2Frequest%2FINFO_REQUEST_URL_TITLE%2Ffollowups%2Fnew
http://test.host/profile/sign_in?r=%2Frequest%2FINFO_REQUEST_URL_TITLE%2Ffollowups%2Fnew


-- the Alaveteli team
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/files/notification_mailer/very_overdue.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ They have still not replied to your FOI request Here is a character that needs q

Click on the link below to send a message to Test public body telling them to reply to your request. You might like to ask for an internal review, asking them to find out why their response to the request has been so slow.

http://test.host/en/profile/sign_in?r=%2Fen%2Frequest%2FINFO_REQUEST_URL_TITLE%2Ffollowups%2Fnew
http://test.host/profile/sign_in?r=%2Frequest%2FINFO_REQUEST_URL_TITLE%2Ffollowups%2Fnew

-- the Alaveteli team
12 changes: 1 addition & 11 deletions spec/helpers/link_to_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,6 @@
RoutingFilter.active = @was_routing_filter_active
end

it 'prepends current path with new locale' do
allow(controller).to receive(:params).and_return(
ActionController::Parameters.new(
controller: 'public_body', action: 'show',
url_name: 'welsh_government', view: 'all'
)
)
expect(current_path_with_locale('cy')).to eq '/cy/body/welsh_government'
end

it 'ignores current protocol and host' do
allow(controller).to receive(:params).and_return(
ActionController::Parameters.new(
Expand All @@ -252,7 +242,7 @@
protocol: 'http', host: 'example.com'
)
)
expect(current_path_with_locale('cy')).to eq '/cy/body/welsh_government'
expect(current_path_with_locale('cy')).to eq '/body/welsh_government?locale=cy'
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/integration/change_email_address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

# Check confirmation URL works
visit confirmation_url_from_email
expect(page).to have_current_path("/en/user/#{user.url_name}")
expect(page).to have_current_path("/user/#{user.url_name}")
expect(page).to have_content('You have now changed your email address')
user.reload
expect(user.email).to eq('newbob@localhost')
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/errors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

it 'should assign the locale for the general/exception_caught template' do
allow(InfoRequest).to receive(:find_by_url_title!).and_raise("An example error")
get "/es/request/example"
get "/request/example?locale=es"
expect(response).to render_template('general/exception_caught')
expect(response.body).to match('Lo sentimos, hubo un problema procesando esta página')
end
Expand Down
101 changes: 19 additions & 82 deletions spec/integration/localisation_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
require 'spec_helper'

RSpec.describe "when generating urls" do
before do
@home_link_regex = /href=".*\/en\//
end

it 'sets Content-Language header' do
get '/'
expect(response.headers['Content-Language']).to eq('en')
Expand All @@ -13,38 +9,39 @@
expect(response.headers['Content-Language']).to eq('es')

get '/es'
follow_redirect!
expect(response.headers['Content-Language']).to eq('es')
end

it "should generate URLs that include the locale when using one that includes an underscore" do
it "sets the content language header when locale includes an underscore" do
AlaveteliLocalization.set_locales('es en_GB', 'es')
get '/en-GB'
get '/en_GB'
expect(page).to have_current_path('/')
expect(response).to redirect_to('/?locale=en_GB')

follow_redirect!
expect(response.headers['Content-Language']).to eq('en-GB')
end

it "returns a 404 error if passed the locale with a hyphen instead of an underscore", local_requests: false do
it "sets the content language header when the locale includes an hyphen" do
AlaveteliLocalization.set_locales('es en_GB', 'es')
get '/en-GB'
expect(response.status).to eq(404)
expect(page).to have_current_path('/')
expect(response).to redirect_to('/?locale=en-GB')

follow_redirect!
expect(response.headers['Content-Language']).to eq('en-GB')
end

it "should fall back to the language if the territory is unknown" do
AlaveteliLocalization.set_locales('es en', 'en')
get '/', headers: { 'HTTP_ACCEPT_LANGUAGE' => 'en_US' }
expect(response.body).to match(/href="\/en\//)
expect(response.body).not_to match(/href="\/en_US\//)
expect(response.headers['Content-Language']).to eq('en')
end

it 'falls back to the default if the requested locale is unavailable' do
get '/', params: { locale: "unknown" }
expect(response.body).to match(/href="\/en\//)
expect(response.body).not_to match(/href="\/unknown\//)
end

it "should generate URLs without a locale prepended when there's only one locale set" do
AlaveteliLocalization.set_locales('en', 'en')
get '/'
expect(response).not_to match(/#{@home_link_regex}/)
expect(response.headers['Content-Language']).to eq('en')
end

context 'when handling public body requests' do
Expand All @@ -59,75 +56,15 @@

it 'should redirect requests for a public body in a locale to the canonical name in that locale' do
get '/es/body/english_short'
expect(response).to redirect_to "/es/body/spanish_short"
follow_redirect!
expect(response).to redirect_to "/body/spanish_short"
end

it 'should remember a filter view when redirecting a public body request to the canonical name' do
AlaveteliLocalization.set_locales(available_locales='es en', default_locale='en')
get '/es/body/english_short/successful'
expect(response).to redirect_to "/es/body/spanish_short/successful"
end
end

describe 'when there is more than one locale' do
before do
AlaveteliLocalization.set_locales('es en', 'en')
end

it "should generate URLs with a locale prepended when there's more than one locale set" do
get '/'
expect(response.body).to match @home_link_regex
end

describe 'when using the default locale' do
before do
@default_lang_home_link = /href=".*\/en\//
@old_include_default_locale_in_urls = AlaveteliConfiguration.include_default_locale_in_urls
end

after do
AlaveteliLocalization.set_default_locale_urls(@old_include_default_locale_in_urls)
end

describe 'when the config value INCLUDE_DEFAULT_LOCALE_IN_URLS is false' do
before do
allow(AlaveteliConfiguration).to receive(:include_default_locale_in_urls).and_return false
AlaveteliLocalization.set_default_locale_urls(false)
end

it 'should generate URLs without a locale prepended' do
get '/'
expect(response.body).to match(/class="current-locale">English/)
expect(response.body).not_to match(/#{@default_lang_home_link}/)
end

describe "when the default url contains an underscore" do
it "generates URLs without a locale prepended" do
AlaveteliLocalization.set_locales('en_GB es', 'en_GB')
get '/'
expect(response.body).not_to match(/href="\/en_GB\//)
end
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 '/', headers: { locale: 'es' }
expect(response.body).to match(/class="current-locale">English/)
end
end

describe 'when the config value INCLUDE_DEFAULT_LOCALE_IN_URLS is true' do
before do
allow(AlaveteliConfiguration).to receive(:include_default_locale_in_urls).and_return true
AlaveteliLocalization.set_default_locale_urls(true)
end

it 'should generate URLs with a locale prepended' do
get '/'
expect(response.body).to match(/class="current-locale">English/)
expect(response.body).to match(/#{@default_lang_home_link}/)
end
end
follow_redirect!
expect(response).to redirect_to "/body/spanish_short/successful"
end
end
end
2 changes: 1 addition & 1 deletion spec/integration/search_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

it "should redirect requests with search in query string to URL-based page" do
get '/search/all?query=bob'
expect(response).to redirect_to "/en/search/bob/all"
expect(response).to redirect_to "/search/bob/all"
end

it "should correctly execute simple search" do
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/signin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def try_login(user, options = {})
default_options = { email: user.email,
password: 'jonespassword' }
options = default_options.merge(options)
login_url = 'en/profile/sign_in'
login_url = '/profile/sign_in'
login_url += "?r=#{options[:redirect]}" if options[:redirect]
visit login_url
within '#signin_form' do
Expand Down
Loading

0 comments on commit 2c1683c

Please sign in to comment.