forked from sidekiq/sidekiq
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update web locale determination, fixes sidekiq#2243
The code worked with "fr,en" but did not work with "fr-FR,fr,en"
- Loading branch information
Showing
3 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require_relative 'helper' | ||
require 'sidekiq' | ||
require 'sidekiq/web_helpers' | ||
|
||
class TestWebHelpers < Sidekiq::Test | ||
|
||
class Helpers | ||
include Sidekiq::WebHelpers | ||
|
||
def initialize(params={}) | ||
@thehash = default.merge(params) | ||
end | ||
|
||
def request | ||
self | ||
end | ||
|
||
def settings | ||
self | ||
end | ||
|
||
def locales | ||
['web/locales'] | ||
end | ||
|
||
def env | ||
@thehash | ||
end | ||
|
||
def default | ||
{ | ||
} | ||
end | ||
end | ||
|
||
def test_locale_determination | ||
obj = Helpers.new | ||
assert_equal 'en', obj.locale | ||
|
||
obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4,ru;q=0.2') | ||
assert_equal 'fr', obj.locale | ||
|
||
obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4,ru;q=0.2') | ||
assert_equal 'zh-cn', obj.locale | ||
end | ||
end |