Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

adapt feature spec to altered accept language precedence

ulferts1c81ff519cdb
diff --git a/app/helpers/user_consent_helper.rb b/app/helpers/user_consent_helper.rb
index a0c3c3b1400..f7aaa07de5f 100644
--- a/app/helpers/user_consent_helper.rb
+++ b/app/helpers/user_consent_helper.rb
@@ -28,7 +28,6 @@
#++
module ::UserConsentHelper
-
def consent_param?
params[:consent_check].present?
end
diff --git a/app/services/set_localization_service.rb b/app/services/set_localization_service.rb
index 3decce3504f..c226f408102 100644
--- a/app/services/set_localization_service.rb
+++ b/app/services/set_localization_service.rb
@@ -29,6 +29,7 @@ class SetLocalizationService
def header_language
return unless http_accept_header
+
accept_lang = parse_qvalues(http_accept_header).first
find_language_or_prefix accept_lang
end
@@ -54,13 +55,15 @@ class SetLocalizationService
tmp = tmp.sort_by { |_val, q| -q }
tmp.map! { |val, _q| val }
end
- return tmp
+
+ tmp
rescue
nil
end
def find_language_or_prefix(language)
return nil unless language
+
language = language.to_s.downcase
find_language(language) || find_language(language.split('-').first)
end
diff --git a/spec/features/auth/consent_auth_stage_spec.rb b/spec/features/auth/consent_auth_stage_spec.rb
index 86a104ef785..322c2a1ff04 100644
--- a/spec/features/auth/consent_auth_stage_spec.rb
+++ b/spec/features/auth/consent_auth_stage_spec.rb
@@ -28,7 +28,7 @@
require 'spec_helper'
-describe 'Authentication Stages', type: :feature, js: true do
+describe 'Authentication Stages', type: :feature do
let(:language) { 'en' }
let(:user_password) { 'bob' * 4 }
let(:user) do
@@ -84,12 +84,16 @@ describe 'Authentication Stages', type: :feature, js: true do
expect_logged_in
end
end
+
context 'when enabled, localized consent exists',
with_settings: { consent_info: { de: '# Einwilligung', en: '# Consent header!' } } do
let(:consent_required) { true }
- let(:language) { 'de' }
- it 'should show localized consent' do
+ before do
+ Capybara.current_session.driver.header('Accept-Language', 'de')
+ end
+
+ it 'should show localized consent as defined by the accept language header (ignoring users language)' do
login_with user.login, user_password
expect(page).to have_selector('.account-consent')
@@ -97,7 +101,7 @@ describe 'Authentication Stages', type: :feature, js: true do
end
end
- context 'when enabled, but consent exists', with_settings: { consent_info: { en: '# Consent header!' } } do
+ context 'when enabled, but consent exists', js: true, with_settings: { consent_info: { en: '# Consent header!' } } do
let(:consent_required) { true }
after do