rack-user-locale 0.0.5 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rubocop.yml +25 -0
- data/.ruby-version +1 -0
- data/.travis.yml +1 -0
- data/Gemfile +12 -12
- data/Gemfile.lock +72 -31
- data/Rakefile +16 -16
- data/VERSION +1 -1
- data/lib/rack-user-locale.rb +28 -27
- data/rack-user-locale.gemspec +49 -41
- data/test/basic_rack_app.rb +7 -0
- data/test/helper.rb +20 -17
- data/test/rack-user-locale_test.rb +232 -0
- metadata +63 -68
- data/test/test_rack-user-locale.rb +0 -220
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 0c4e00a7465d3f7c676c1a3b472b5cd078ac1b890c73c23f1cb64c27ecb05894
|
|
4
|
+
data.tar.gz: dae9ce1f81036483f82de4af343afc7c81100537a7861752139c1a74ec42cc11
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: f63d485dd1d5e57ef7111354ace7930fbc4e0e24e521c9d5334a0d5392043440dc5e10ba009e0696091766ff441096fbcbe7f20cab7f159a76e83b22a0bd212d
|
|
7
|
+
data.tar.gz: 4e29c8b32cecc1aaa87643779f2240a0e46ef2b06eb4a6e0c9df0981b4ec22d0db9f7cac374333d0eca2061633f47b23b8650c69a6e14a31917c08c0349665d2
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 2.5
|
|
3
|
+
|
|
4
|
+
# Use double quotes ALL THE TIME!!!
|
|
5
|
+
Style/StringLiterals:
|
|
6
|
+
EnforcedStyle: double_quotes
|
|
7
|
+
|
|
8
|
+
# Disable Style/Documentation because...
|
|
9
|
+
Style/Documentation:
|
|
10
|
+
Enabled: false
|
|
11
|
+
|
|
12
|
+
# Increase line length to 120
|
|
13
|
+
Metrics/LineLength:
|
|
14
|
+
Max: 120
|
|
15
|
+
|
|
16
|
+
# Exclude class and method length for test
|
|
17
|
+
Metrics/BlockLength:
|
|
18
|
+
Exclude:
|
|
19
|
+
- "test/**/*"
|
|
20
|
+
Metrics/ClassLength:
|
|
21
|
+
Exclude:
|
|
22
|
+
- "test/**/*"
|
|
23
|
+
Metrics/MethodLength:
|
|
24
|
+
Exclude:
|
|
25
|
+
- "test/**/*"
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.5.1
|
data/.travis.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
language: ruby
|
data/Gemfile
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source "https://rubygems.org"
|
|
5
4
|
|
|
6
|
-
gem "rack"
|
|
7
5
|
gem "i18n"
|
|
6
|
+
gem "rack"
|
|
8
7
|
|
|
9
8
|
# Add dependencies to develop your gem here.
|
|
10
9
|
# Include everything needed to run rake, tests, features, etc.
|
|
11
10
|
group :development do
|
|
12
|
-
gem "bundler"
|
|
13
|
-
gem
|
|
14
|
-
gem "jeweler"
|
|
15
|
-
gem "minitest"
|
|
16
|
-
gem "
|
|
17
|
-
gem "
|
|
18
|
-
gem "
|
|
11
|
+
gem "bundler", "~> 1.16"
|
|
12
|
+
gem "byebug"
|
|
13
|
+
gem "jeweler", "~> 2.3"
|
|
14
|
+
gem "minitest", "~> 5.0"
|
|
15
|
+
gem "minitest-fail-fast", "~> 0.1"
|
|
16
|
+
gem "minitest-reporters", "1.3.0" # locking as current issue with 1.3.1
|
|
17
|
+
gem "rack-test", "~> 1.1"
|
|
18
|
+
gem "yard", "~> 0.9"
|
|
19
19
|
end
|
data/Gemfile.lock
CHANGED
|
@@ -1,44 +1,85 @@
|
|
|
1
1
|
GEM
|
|
2
|
-
remote:
|
|
2
|
+
remote: https://rubygems.org/
|
|
3
3
|
specs:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
git (1.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
4
|
+
addressable (2.4.0)
|
|
5
|
+
ansi (1.5.0)
|
|
6
|
+
builder (3.2.3)
|
|
7
|
+
byebug (10.0.2)
|
|
8
|
+
concurrent-ruby (1.0.5)
|
|
9
|
+
descendants_tracker (0.0.4)
|
|
10
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
|
11
|
+
faraday (0.9.2)
|
|
12
|
+
multipart-post (>= 1.2, < 3)
|
|
13
|
+
git (1.5.0)
|
|
14
|
+
github_api (0.16.0)
|
|
15
|
+
addressable (~> 2.4.0)
|
|
16
|
+
descendants_tracker (~> 0.0.4)
|
|
17
|
+
faraday (~> 0.8, < 0.10)
|
|
18
|
+
hashie (>= 3.4)
|
|
19
|
+
mime-types (>= 1.16, < 3.0)
|
|
20
|
+
oauth2 (~> 1.0)
|
|
21
|
+
hashie (3.6.0)
|
|
22
|
+
highline (2.0.0)
|
|
23
|
+
i18n (1.1.0)
|
|
24
|
+
concurrent-ruby (~> 1.0)
|
|
25
|
+
jeweler (2.3.9)
|
|
26
|
+
builder
|
|
27
|
+
bundler
|
|
17
28
|
git (>= 1.2.5)
|
|
29
|
+
github_api (~> 0.16.0)
|
|
30
|
+
highline (>= 1.6.15)
|
|
31
|
+
nokogiri (>= 1.5.10)
|
|
32
|
+
psych
|
|
18
33
|
rake
|
|
19
34
|
rdoc
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
turn (0.9.6)
|
|
35
|
+
semver2
|
|
36
|
+
jwt (1.5.6)
|
|
37
|
+
mime-types (2.99.3)
|
|
38
|
+
mini_portile2 (2.3.0)
|
|
39
|
+
minitest (5.11.3)
|
|
40
|
+
minitest-fail-fast (0.1.0)
|
|
41
|
+
minitest (~> 5)
|
|
42
|
+
minitest-reporters (1.3.0)
|
|
29
43
|
ansi
|
|
30
|
-
|
|
44
|
+
builder
|
|
45
|
+
minitest (>= 5.0)
|
|
46
|
+
ruby-progressbar
|
|
47
|
+
multi_json (1.13.1)
|
|
48
|
+
multi_xml (0.6.0)
|
|
49
|
+
multipart-post (2.0.0)
|
|
50
|
+
nokogiri (1.8.4)
|
|
51
|
+
mini_portile2 (~> 2.3.0)
|
|
52
|
+
oauth2 (1.4.0)
|
|
53
|
+
faraday (>= 0.8, < 0.13)
|
|
54
|
+
jwt (~> 1.0)
|
|
55
|
+
multi_json (~> 1.3)
|
|
56
|
+
multi_xml (~> 0.5)
|
|
57
|
+
rack (>= 1.2, < 3)
|
|
58
|
+
psych (3.0.2)
|
|
59
|
+
rack (2.0.5)
|
|
60
|
+
rack-test (1.1.0)
|
|
61
|
+
rack (>= 1.0, < 3)
|
|
62
|
+
rake (12.3.1)
|
|
63
|
+
rdoc (6.0.4)
|
|
64
|
+
ruby-progressbar (1.10.0)
|
|
65
|
+
semver2 (3.4.2)
|
|
66
|
+
thread_safe (0.3.6)
|
|
67
|
+
yard (0.9.16)
|
|
31
68
|
|
|
32
69
|
PLATFORMS
|
|
33
70
|
ruby
|
|
34
71
|
|
|
35
72
|
DEPENDENCIES
|
|
36
|
-
bundler
|
|
37
|
-
|
|
73
|
+
bundler (~> 1.16)
|
|
74
|
+
byebug
|
|
38
75
|
i18n
|
|
39
|
-
jeweler
|
|
40
|
-
minitest
|
|
76
|
+
jeweler (~> 2.3)
|
|
77
|
+
minitest (~> 5.0)
|
|
78
|
+
minitest-fail-fast (~> 0.1)
|
|
79
|
+
minitest-reporters (= 1.3.0)
|
|
41
80
|
rack
|
|
42
|
-
rack-test
|
|
43
|
-
|
|
44
|
-
|
|
81
|
+
rack-test (~> 1.1)
|
|
82
|
+
yard (~> 0.9)
|
|
83
|
+
|
|
84
|
+
BUNDLED WITH
|
|
85
|
+
1.16.3
|
data/Rakefile
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
3
|
+
require "rubygems"
|
|
4
|
+
require "bundler"
|
|
5
5
|
begin
|
|
6
6
|
Bundler.setup(:default, :development)
|
|
7
7
|
rescue Bundler::BundlerError => e
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
warn e.message
|
|
9
|
+
warn "Run `bundle install` to install missing gems"
|
|
10
10
|
exit e.status_code
|
|
11
11
|
end
|
|
12
|
-
require
|
|
12
|
+
require "rake"
|
|
13
13
|
|
|
14
|
-
require
|
|
14
|
+
require "jeweler"
|
|
15
15
|
Jeweler::Tasks.new do |gem|
|
|
16
16
|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
|
17
17
|
gem.name = "rack-user-locale"
|
|
18
18
|
gem.homepage = "http://github.com/sleepingstu/rack-user-locale"
|
|
19
19
|
gem.license = "MIT"
|
|
20
|
-
gem.summary = %
|
|
21
|
-
gem.description = %
|
|
22
|
-
gem.email = "stuart.chinery@
|
|
20
|
+
gem.summary = %(Rack module for getting and setting a user's locale)
|
|
21
|
+
gem.description = %(A Rack module for getting and setting a user's locale via a cookie or browser default language.)
|
|
22
|
+
gem.email = "stuart.chinery@gmail.com"
|
|
23
23
|
gem.authors = ["Stuart Chinery", "Dave Hrycyszyn"]
|
|
24
24
|
# dependencies defined in Gemfile
|
|
25
25
|
end
|
|
26
26
|
Jeweler::RubygemsDotOrgTasks.new
|
|
27
27
|
|
|
28
|
-
require
|
|
28
|
+
require "rake/testtask"
|
|
29
29
|
Rake::TestTask.new(:test) do |test|
|
|
30
|
-
test.libs <<
|
|
31
|
-
test.pattern =
|
|
30
|
+
test.libs << "lib" << "test"
|
|
31
|
+
test.pattern = "test/**/*_test.rb"
|
|
32
32
|
test.verbose = true
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
task :
|
|
35
|
+
task default: :test
|
|
36
36
|
|
|
37
|
-
require
|
|
38
|
-
YARD::Rake::YardocTask.new
|
|
37
|
+
require "yard"
|
|
38
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.0
|
|
1
|
+
0.1.0
|
data/lib/rack-user-locale.rb
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "i18n"
|
|
2
4
|
|
|
3
5
|
module Rack
|
|
4
6
|
class UserLocale
|
|
5
|
-
|
|
6
7
|
# TODO: Write notes
|
|
7
8
|
#
|
|
8
9
|
def initialize(app, options = {})
|
|
9
|
-
@app
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
@app = app
|
|
11
|
+
@options = {
|
|
12
|
+
accepted_locales: []
|
|
13
|
+
}.merge(options)
|
|
12
14
|
end
|
|
13
15
|
|
|
14
16
|
# TODO: Write notes
|
|
@@ -18,16 +20,12 @@ module Rack
|
|
|
18
20
|
@request = Rack::Request.new(@env)
|
|
19
21
|
set_locale
|
|
20
22
|
|
|
21
|
-
if @request.post? || @request.put? || @request.delete?
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
:value => I18n.locale,
|
|
28
|
-
:path => "/"}) if get_cookie_locale != I18n.locale.to_s
|
|
29
|
-
response.finish
|
|
30
|
-
end
|
|
23
|
+
@app.call(env) && return if @request.post? || @request.put? || @request.delete?
|
|
24
|
+
|
|
25
|
+
status, headers, body = @app.call(@env)
|
|
26
|
+
response = Rack::Response.new(body, status, headers)
|
|
27
|
+
response.set_cookie("user-locale", value: I18n.locale, path: "/") if cookie_locale != I18n.locale.to_s
|
|
28
|
+
response.finish
|
|
31
29
|
end
|
|
32
30
|
|
|
33
31
|
private
|
|
@@ -35,38 +33,40 @@ module Rack
|
|
|
35
33
|
# TODO: Write notes
|
|
36
34
|
#
|
|
37
35
|
def set_locale
|
|
38
|
-
new_locale = check_accepted? ? accepted_locale(locale.to_sym,
|
|
36
|
+
new_locale = check_accepted? ? accepted_locale(locale.to_sym, default_locale) : locale.to_sym
|
|
39
37
|
I18n.locale = @env["rack.locale"] = new_locale
|
|
40
38
|
end
|
|
41
39
|
|
|
42
40
|
# TODO: Write notes
|
|
43
41
|
#
|
|
44
42
|
def accepted_locale(locale, other_locale = nil)
|
|
45
|
-
|
|
43
|
+
@options[:accepted_locales].include?(locale) ? locale : other_locale
|
|
46
44
|
end
|
|
47
45
|
|
|
48
46
|
# TODO: Write notes
|
|
49
47
|
#
|
|
50
48
|
def locale
|
|
51
|
-
|
|
49
|
+
cookie_locale || browser_locale || default_locale
|
|
52
50
|
end
|
|
53
51
|
|
|
54
52
|
# TODO: Write notes
|
|
55
53
|
#
|
|
56
|
-
def
|
|
54
|
+
def cookie_locale
|
|
57
55
|
@request.cookies["user-locale"]
|
|
58
56
|
end
|
|
59
57
|
|
|
60
58
|
# TODO: Write notes
|
|
61
59
|
#
|
|
62
|
-
def
|
|
60
|
+
def browser_locale
|
|
63
61
|
accept_lang = @env["HTTP_ACCEPT_LANGUAGE"]
|
|
64
62
|
return if accept_lang.nil?
|
|
65
63
|
|
|
66
|
-
langs = accept_lang.split(",").map
|
|
67
|
-
l +=
|
|
68
|
-
l.split(
|
|
69
|
-
|
|
64
|
+
langs = accept_lang.split(",").map do |l|
|
|
65
|
+
l += ";q=1.0" unless l =~ /;q=\d+\.\d+$/
|
|
66
|
+
l.split(";q=")
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
langs.sort! { |a, b| b[1] <=> a[1] }
|
|
70
70
|
|
|
71
71
|
if check_accepted?
|
|
72
72
|
langs.each do |lang|
|
|
@@ -75,25 +75,26 @@ module Rack
|
|
|
75
75
|
end
|
|
76
76
|
end
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
split_lang(langs.first.first)
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
# TODO: Write notes
|
|
82
82
|
#
|
|
83
83
|
def split_lang(lang)
|
|
84
|
-
|
|
84
|
+
return if lang.nil?
|
|
85
|
+
lang.split("-").first
|
|
85
86
|
end
|
|
86
87
|
|
|
87
88
|
# TODO: Write notes
|
|
88
89
|
#
|
|
89
|
-
def
|
|
90
|
+
def default_locale
|
|
90
91
|
I18n.default_locale
|
|
91
92
|
end
|
|
92
93
|
|
|
93
94
|
# TODO: Write notes
|
|
94
95
|
#
|
|
95
96
|
def check_accepted?
|
|
96
|
-
@options[:accepted_locales].count
|
|
97
|
+
@options[:accepted_locales].count.positive?
|
|
97
98
|
end
|
|
98
99
|
end
|
|
99
100
|
end
|
data/rack-user-locale.gemspec
CHANGED
|
@@ -2,22 +2,27 @@
|
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
|
5
|
+
# stub: rack-user-locale 0.1.0 ruby lib
|
|
5
6
|
|
|
6
7
|
Gem::Specification.new do |s|
|
|
7
|
-
s.name = "rack-user-locale"
|
|
8
|
-
s.version = "0.0
|
|
8
|
+
s.name = "rack-user-locale".freeze
|
|
9
|
+
s.version = "0.1.0"
|
|
9
10
|
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
|
-
s.
|
|
12
|
-
s.
|
|
13
|
-
s.
|
|
14
|
-
s.
|
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
|
12
|
+
s.require_paths = ["lib".freeze]
|
|
13
|
+
s.authors = ["Stuart Chinery".freeze, "Dave Hrycyszyn".freeze]
|
|
14
|
+
s.date = "2018-08-15"
|
|
15
|
+
s.description = "A Rack module for getting and setting a user's locale via a cookie or browser default language.".freeze
|
|
16
|
+
s.email = "stuart.chinery@gmail.com".freeze
|
|
15
17
|
s.extra_rdoc_files = [
|
|
16
18
|
"LICENSE.txt",
|
|
17
19
|
"README.md"
|
|
18
20
|
]
|
|
19
21
|
s.files = [
|
|
20
22
|
".document",
|
|
23
|
+
".rubocop.yml",
|
|
24
|
+
".ruby-version",
|
|
25
|
+
".travis.yml",
|
|
21
26
|
"Gemfile",
|
|
22
27
|
"Gemfile.lock",
|
|
23
28
|
"LICENSE.txt",
|
|
@@ -26,49 +31,52 @@ Gem::Specification.new do |s|
|
|
|
26
31
|
"VERSION",
|
|
27
32
|
"lib/rack-user-locale.rb",
|
|
28
33
|
"rack-user-locale.gemspec",
|
|
34
|
+
"test/basic_rack_app.rb",
|
|
29
35
|
"test/helper.rb",
|
|
30
|
-
"test/
|
|
36
|
+
"test/rack-user-locale_test.rb"
|
|
31
37
|
]
|
|
32
|
-
s.homepage = "http://github.com/sleepingstu/rack-user-locale"
|
|
33
|
-
s.licenses = ["MIT"]
|
|
34
|
-
s.
|
|
35
|
-
s.
|
|
36
|
-
s.summary = "Rack module for getting and setting a user's locale"
|
|
38
|
+
s.homepage = "http://github.com/sleepingstu/rack-user-locale".freeze
|
|
39
|
+
s.licenses = ["MIT".freeze]
|
|
40
|
+
s.rubygems_version = "2.7.6".freeze
|
|
41
|
+
s.summary = "Rack module for getting and setting a user's locale".freeze
|
|
37
42
|
|
|
38
43
|
if s.respond_to? :specification_version then
|
|
39
|
-
s.specification_version =
|
|
44
|
+
s.specification_version = 4
|
|
40
45
|
|
|
41
46
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
42
|
-
s.add_runtime_dependency(%q<
|
|
43
|
-
s.add_runtime_dependency(%q<
|
|
44
|
-
s.add_development_dependency(%q<bundler
|
|
45
|
-
s.add_development_dependency(%q<
|
|
46
|
-
s.add_development_dependency(%q<jeweler
|
|
47
|
-
s.add_development_dependency(%q<minitest
|
|
48
|
-
s.add_development_dependency(%q<
|
|
49
|
-
s.add_development_dependency(%q<
|
|
50
|
-
s.add_development_dependency(%q<
|
|
47
|
+
s.add_runtime_dependency(%q<i18n>.freeze, [">= 0"])
|
|
48
|
+
s.add_runtime_dependency(%q<rack>.freeze, [">= 0"])
|
|
49
|
+
s.add_development_dependency(%q<bundler>.freeze, ["~> 1.16"])
|
|
50
|
+
s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
|
|
51
|
+
s.add_development_dependency(%q<jeweler>.freeze, ["~> 2.3"])
|
|
52
|
+
s.add_development_dependency(%q<minitest>.freeze, ["~> 5.0"])
|
|
53
|
+
s.add_development_dependency(%q<minitest-fail-fast>.freeze, ["~> 0.1"])
|
|
54
|
+
s.add_development_dependency(%q<minitest-reporters>.freeze, ["= 1.3.0"])
|
|
55
|
+
s.add_development_dependency(%q<rack-test>.freeze, ["~> 1.1"])
|
|
56
|
+
s.add_development_dependency(%q<yard>.freeze, ["~> 0.9"])
|
|
51
57
|
else
|
|
52
|
-
s.add_dependency(%q<
|
|
53
|
-
s.add_dependency(%q<
|
|
54
|
-
s.add_dependency(%q<bundler
|
|
55
|
-
s.add_dependency(%q<
|
|
56
|
-
s.add_dependency(%q<jeweler
|
|
57
|
-
s.add_dependency(%q<minitest
|
|
58
|
-
s.add_dependency(%q<
|
|
59
|
-
s.add_dependency(%q<
|
|
60
|
-
s.add_dependency(%q<
|
|
58
|
+
s.add_dependency(%q<i18n>.freeze, [">= 0"])
|
|
59
|
+
s.add_dependency(%q<rack>.freeze, [">= 0"])
|
|
60
|
+
s.add_dependency(%q<bundler>.freeze, ["~> 1.16"])
|
|
61
|
+
s.add_dependency(%q<byebug>.freeze, [">= 0"])
|
|
62
|
+
s.add_dependency(%q<jeweler>.freeze, ["~> 2.3"])
|
|
63
|
+
s.add_dependency(%q<minitest>.freeze, ["~> 5.0"])
|
|
64
|
+
s.add_dependency(%q<minitest-fail-fast>.freeze, ["~> 0.1"])
|
|
65
|
+
s.add_dependency(%q<minitest-reporters>.freeze, ["= 1.3.0"])
|
|
66
|
+
s.add_dependency(%q<rack-test>.freeze, ["~> 1.1"])
|
|
67
|
+
s.add_dependency(%q<yard>.freeze, ["~> 0.9"])
|
|
61
68
|
end
|
|
62
69
|
else
|
|
63
|
-
s.add_dependency(%q<
|
|
64
|
-
s.add_dependency(%q<
|
|
65
|
-
s.add_dependency(%q<bundler
|
|
66
|
-
s.add_dependency(%q<
|
|
67
|
-
s.add_dependency(%q<jeweler
|
|
68
|
-
s.add_dependency(%q<minitest
|
|
69
|
-
s.add_dependency(%q<
|
|
70
|
-
s.add_dependency(%q<
|
|
71
|
-
s.add_dependency(%q<
|
|
70
|
+
s.add_dependency(%q<i18n>.freeze, [">= 0"])
|
|
71
|
+
s.add_dependency(%q<rack>.freeze, [">= 0"])
|
|
72
|
+
s.add_dependency(%q<bundler>.freeze, ["~> 1.16"])
|
|
73
|
+
s.add_dependency(%q<byebug>.freeze, [">= 0"])
|
|
74
|
+
s.add_dependency(%q<jeweler>.freeze, ["~> 2.3"])
|
|
75
|
+
s.add_dependency(%q<minitest>.freeze, ["~> 5.0"])
|
|
76
|
+
s.add_dependency(%q<minitest-fail-fast>.freeze, ["~> 0.1"])
|
|
77
|
+
s.add_dependency(%q<minitest-reporters>.freeze, ["= 1.3.0"])
|
|
78
|
+
s.add_dependency(%q<rack-test>.freeze, ["~> 1.1"])
|
|
79
|
+
s.add_dependency(%q<yard>.freeze, ["~> 0.9"])
|
|
72
80
|
end
|
|
73
81
|
end
|
|
74
82
|
|
data/test/helper.rb
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rubygems"
|
|
4
|
+
require "bundler"
|
|
3
5
|
require "rack/test"
|
|
4
|
-
require "debugger"
|
|
5
6
|
|
|
6
7
|
begin
|
|
7
8
|
Bundler.setup(:default, :development)
|
|
8
9
|
rescue Bundler::BundlerError => e
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
warn e.message
|
|
11
|
+
warn "Run `bundle install` to install missing gems"
|
|
11
12
|
exit e.status_code
|
|
12
13
|
end
|
|
13
|
-
require 'minitest/autorun'
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
require "minitest/autorun"
|
|
16
|
+
require "minitest/fail_fast"
|
|
17
|
+
require "minitest/reporters"
|
|
18
|
+
require "minitest/spec"
|
|
19
|
+
|
|
20
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
|
16
21
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
17
|
-
require
|
|
18
|
-
begin; require 'turn/autorun'; rescue LoadError; end
|
|
22
|
+
require "rack-user-locale"
|
|
19
23
|
|
|
20
|
-
class
|
|
24
|
+
class Minitest::Test
|
|
25
|
+
extend Minitest::Spec::DSL
|
|
21
26
|
include Rack::Test::Methods
|
|
22
27
|
end
|
|
23
28
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
MiniTest::Unit.autorun
|
|
29
|
+
Minitest::Reporters.use!(
|
|
30
|
+
Minitest::Reporters::SpecReporter.new,
|
|
31
|
+
ENV,
|
|
32
|
+
Minitest.backtrace_filter
|
|
33
|
+
)
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "helper"
|
|
4
|
+
require "basic_rack_app"
|
|
5
|
+
require "byebug"
|
|
6
|
+
|
|
7
|
+
class RackUserLocaleTest < Minitest::Test
|
|
8
|
+
describe Rack::UserLocale do
|
|
9
|
+
before do
|
|
10
|
+
I18n.enforce_available_locales = false
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe "without accepted_locales set" do
|
|
14
|
+
before do
|
|
15
|
+
def app
|
|
16
|
+
Rack::Builder.new do
|
|
17
|
+
use Rack::UserLocale
|
|
18
|
+
|
|
19
|
+
run BasicRackApp.new
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
I18n.default_locale = :en
|
|
24
|
+
I18n.locale = :en
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "should have I18n.locale set to :en" do
|
|
28
|
+
assert_equal :en, I18n.locale
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe "when a locale cookie is set" do
|
|
32
|
+
before do
|
|
33
|
+
get "http://example.com/", {}, "HTTP_COOKIE" => "user-locale=be"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "should have I18n.locale set to :be" do
|
|
37
|
+
assert_equal :be, I18n.locale
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "should not set a cookie in the response" do
|
|
41
|
+
assert_equal nil, last_response["Set-Cookie"]
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe "when from HTTP_ACCEPT_LANGUAGE headers" do
|
|
46
|
+
describe "with a single locale" do
|
|
47
|
+
before do
|
|
48
|
+
get "http://example.com/", {}, "HTTP_ACCEPT_LANGUAGE" => "fr-be", "SCRIPT_NAME" => "/"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "should have I18n.locale set to :fr" do
|
|
52
|
+
assert_equal :fr, I18n.locale
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "should set a cookie in the response" do
|
|
56
|
+
assert_equal "user-locale=fr; path=/", last_response["Set-Cookie"]
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
describe "with an multiple locales" do
|
|
61
|
+
before do
|
|
62
|
+
get "http://example.com/", {},
|
|
63
|
+
"HTTP_ACCEPT_LANGUAGE" => "de-DE;q=0.8,de;q=0.8,no-NO;q=1.0,no;q=0.7,ru-RU;q=0.7,sv-SE;q=0.4,sv;q=0.3,nl-BE;q=0.9",
|
|
64
|
+
"SCRIPT_NAME" => "/"
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "should have I18n.locale set to :no" do
|
|
68
|
+
assert_equal :no, I18n.locale
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "should set a cookie in the response" do
|
|
72
|
+
assert_equal "user-locale=no; path=/", last_response["Set-Cookie"]
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
describe "when both a cooke and HTTP_ACCEPT_LANGUAGE headers are set" do
|
|
78
|
+
before do
|
|
79
|
+
get "http://example.com/", {}, "HTTP_COOKIE" => "user-locale=af",
|
|
80
|
+
"HTTP_ACCEPT_LANGUAGE" => "ar-sa", "SCRIPT_NAME" => "/"
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "should have I18n.locale set to :af" do
|
|
84
|
+
assert_equal :af, I18n.locale
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "should not set a cookie in the response" do
|
|
88
|
+
assert_equal nil, last_response["Set-Cookie"]
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
describe "when nothing is changed" do
|
|
93
|
+
before do
|
|
94
|
+
get "http://example.com/", {}, "SCRIPT_NAME" => "/"
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "should have I18n.locale set to :en" do
|
|
98
|
+
assert_equal :en, I18n.locale
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "should set a cookie in the response" do
|
|
102
|
+
assert_equal "user-locale=en; path=/", last_response["Set-Cookie"]
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
describe "with accepted_locales set" do
|
|
108
|
+
before do
|
|
109
|
+
def app
|
|
110
|
+
Rack::Builder.new do
|
|
111
|
+
use Rack::UserLocale, accepted_locales: %i[en es fr de ja nl]
|
|
112
|
+
|
|
113
|
+
run BasicRackApp.new
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
I18n.default_locale = :en
|
|
118
|
+
I18n.locale = :en
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it "should have I18n.locale set to :en" do
|
|
122
|
+
assert_equal :en, I18n.locale
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
describe "when a locale cookie is set" do
|
|
126
|
+
before do
|
|
127
|
+
get "http://example.com/", {}, "HTTP_COOKIE" => "user-locale=es", "SCRIPT_NAME" => "/"
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
it "should have I18n.locale set to :es" do
|
|
131
|
+
assert_equal :es, I18n.locale
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it "should not set a cookie in the response" do
|
|
135
|
+
assert_equal nil, last_response["Set-Cookie"]
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
describe "when from HTTP_ACCEPT_LANGUAGE headers" do
|
|
140
|
+
describe "with an accepted locale" do
|
|
141
|
+
before do
|
|
142
|
+
get "http://example.com/", {}, "HTTP_ACCEPT_LANGUAGE" => "fr-be", "SCRIPT_NAME" => "/"
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
it "should have I18n.locale set to :fr" do
|
|
146
|
+
assert_equal :fr, I18n.locale
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it "should set a cookie in the response" do
|
|
150
|
+
assert_equal "user-locale=fr; path=/", last_response["Set-Cookie"]
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
describe "with an multiple locales" do
|
|
155
|
+
describe "at different weights" do
|
|
156
|
+
before do
|
|
157
|
+
get "http://example.com/", {},
|
|
158
|
+
"HTTP_ACCEPT_LANGUAGE" => "de-DE;q=0.8,de;q=0.8,no-NO;q=0.7,no;q=0.7,ru-RU;q=0.7,sv-SE;q=0.4,sv;q=0.3,nl-BE;q=0.9",
|
|
159
|
+
"SCRIPT_NAME" => "/"
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it "should have I18n.locale set to :nl" do
|
|
163
|
+
assert_equal :nl, I18n.locale
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
it "should set a cookie in the response" do
|
|
167
|
+
assert_equal "user-locale=nl; path=/", last_response["Set-Cookie"]
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
describe "at the same weight" do
|
|
172
|
+
before do
|
|
173
|
+
get "http://example.com/", {},
|
|
174
|
+
"HTTP_ACCEPT_LANGUAGE" => "fr,en,ja", "SCRIPT_NAME" => "/"
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
it "should have I18n.locale set to :fr" do
|
|
178
|
+
assert_equal :fr, I18n.locale
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
it "should set a cookie in the response" do
|
|
182
|
+
assert_equal "user-locale=fr; path=/", last_response["Set-Cookie"]
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
describe "without an accepted locale" do
|
|
188
|
+
before do
|
|
189
|
+
get "http://example.com/", {}, "HTTP_ACCEPT_LANGUAGE" => "ar-sa", "SCRIPT_NAME" => "/"
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
it "should have I18n.locale set to :en" do
|
|
193
|
+
assert_equal :en, I18n.locale
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
it "should set a cookie in the response" do
|
|
197
|
+
assert_equal "user-locale=en; path=/", last_response["Set-Cookie"]
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
describe "when both a cooke and HTTP_ACCEPT_LANGUAGE headers are set" do
|
|
203
|
+
before do
|
|
204
|
+
get "http://example.com/", {}, "HTTP_COOKIE" => "user-locale=ja",
|
|
205
|
+
"HTTP_ACCEPT_LANGUAGE" => "fr-be", "SCRIPT_NAME" => "/"
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
it "should have I18n.locale set to :ja" do
|
|
209
|
+
assert_equal :ja, I18n.locale
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
it "should not set a cookie in the response" do
|
|
213
|
+
assert_equal nil, last_response["Set-Cookie"]
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
describe "when nothing is changed" do
|
|
218
|
+
before do
|
|
219
|
+
get "http://example.com/", {}, "SCRIPT_NAME" => "/"
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
it "should have I18n.locale set to :en" do
|
|
223
|
+
assert_equal :en, I18n.locale
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
it "should set a cookie in the response" do
|
|
227
|
+
assert_equal "user-locale=en; path=/", last_response["Set-Cookie"]
|
|
228
|
+
end
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
end
|
metadata
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rack-user-locale
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
5
|
-
prerelease:
|
|
4
|
+
version: 0.1.0
|
|
6
5
|
platform: ruby
|
|
7
6
|
authors:
|
|
8
7
|
- Stuart Chinery
|
|
@@ -10,162 +9,161 @@ authors:
|
|
|
10
9
|
autorequire:
|
|
11
10
|
bindir: bin
|
|
12
11
|
cert_chain: []
|
|
13
|
-
date:
|
|
12
|
+
date: 2018-08-15 00:00:00.000000000 Z
|
|
14
13
|
dependencies:
|
|
15
14
|
- !ruby/object:Gem::Dependency
|
|
16
|
-
name:
|
|
15
|
+
name: i18n
|
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
|
18
|
-
none: false
|
|
19
17
|
requirements:
|
|
20
|
-
- -
|
|
18
|
+
- - ">="
|
|
21
19
|
- !ruby/object:Gem::Version
|
|
22
20
|
version: '0'
|
|
23
21
|
type: :runtime
|
|
24
22
|
prerelease: false
|
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
-
none: false
|
|
27
24
|
requirements:
|
|
28
|
-
- -
|
|
25
|
+
- - ">="
|
|
29
26
|
- !ruby/object:Gem::Version
|
|
30
27
|
version: '0'
|
|
31
28
|
- !ruby/object:Gem::Dependency
|
|
32
|
-
name:
|
|
29
|
+
name: rack
|
|
33
30
|
requirement: !ruby/object:Gem::Requirement
|
|
34
|
-
none: false
|
|
35
31
|
requirements:
|
|
36
|
-
- -
|
|
32
|
+
- - ">="
|
|
37
33
|
- !ruby/object:Gem::Version
|
|
38
34
|
version: '0'
|
|
39
35
|
type: :runtime
|
|
40
36
|
prerelease: false
|
|
41
37
|
version_requirements: !ruby/object:Gem::Requirement
|
|
42
|
-
none: false
|
|
43
38
|
requirements:
|
|
44
|
-
- -
|
|
39
|
+
- - ">="
|
|
45
40
|
- !ruby/object:Gem::Version
|
|
46
41
|
version: '0'
|
|
47
42
|
- !ruby/object:Gem::Dependency
|
|
48
43
|
name: bundler
|
|
49
44
|
requirement: !ruby/object:Gem::Requirement
|
|
50
|
-
none: false
|
|
51
45
|
requirements:
|
|
52
|
-
- -
|
|
46
|
+
- - "~>"
|
|
53
47
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '
|
|
48
|
+
version: '1.16'
|
|
55
49
|
type: :development
|
|
56
50
|
prerelease: false
|
|
57
51
|
version_requirements: !ruby/object:Gem::Requirement
|
|
58
|
-
none: false
|
|
59
52
|
requirements:
|
|
60
|
-
- -
|
|
53
|
+
- - "~>"
|
|
61
54
|
- !ruby/object:Gem::Version
|
|
62
|
-
version: '
|
|
55
|
+
version: '1.16'
|
|
63
56
|
- !ruby/object:Gem::Dependency
|
|
64
|
-
name:
|
|
57
|
+
name: byebug
|
|
65
58
|
requirement: !ruby/object:Gem::Requirement
|
|
66
|
-
none: false
|
|
67
59
|
requirements:
|
|
68
|
-
- -
|
|
60
|
+
- - ">="
|
|
69
61
|
- !ruby/object:Gem::Version
|
|
70
62
|
version: '0'
|
|
71
63
|
type: :development
|
|
72
64
|
prerelease: false
|
|
73
65
|
version_requirements: !ruby/object:Gem::Requirement
|
|
74
|
-
none: false
|
|
75
66
|
requirements:
|
|
76
|
-
- -
|
|
67
|
+
- - ">="
|
|
77
68
|
- !ruby/object:Gem::Version
|
|
78
69
|
version: '0'
|
|
79
70
|
- !ruby/object:Gem::Dependency
|
|
80
71
|
name: jeweler
|
|
81
72
|
requirement: !ruby/object:Gem::Requirement
|
|
82
|
-
none: false
|
|
83
73
|
requirements:
|
|
84
|
-
- -
|
|
74
|
+
- - "~>"
|
|
85
75
|
- !ruby/object:Gem::Version
|
|
86
|
-
version: '
|
|
76
|
+
version: '2.3'
|
|
87
77
|
type: :development
|
|
88
78
|
prerelease: false
|
|
89
79
|
version_requirements: !ruby/object:Gem::Requirement
|
|
90
|
-
none: false
|
|
91
80
|
requirements:
|
|
92
|
-
- -
|
|
81
|
+
- - "~>"
|
|
93
82
|
- !ruby/object:Gem::Version
|
|
94
|
-
version: '
|
|
83
|
+
version: '2.3'
|
|
95
84
|
- !ruby/object:Gem::Dependency
|
|
96
85
|
name: minitest
|
|
97
86
|
requirement: !ruby/object:Gem::Requirement
|
|
98
|
-
none: false
|
|
99
87
|
requirements:
|
|
100
|
-
- -
|
|
88
|
+
- - "~>"
|
|
101
89
|
- !ruby/object:Gem::Version
|
|
102
|
-
version: '0'
|
|
90
|
+
version: '5.0'
|
|
103
91
|
type: :development
|
|
104
92
|
prerelease: false
|
|
105
93
|
version_requirements: !ruby/object:Gem::Requirement
|
|
106
|
-
none: false
|
|
107
94
|
requirements:
|
|
108
|
-
- -
|
|
95
|
+
- - "~>"
|
|
109
96
|
- !ruby/object:Gem::Version
|
|
110
|
-
version: '0'
|
|
97
|
+
version: '5.0'
|
|
111
98
|
- !ruby/object:Gem::Dependency
|
|
112
|
-
name:
|
|
99
|
+
name: minitest-fail-fast
|
|
113
100
|
requirement: !ruby/object:Gem::Requirement
|
|
114
|
-
none: false
|
|
115
101
|
requirements:
|
|
116
|
-
- -
|
|
102
|
+
- - "~>"
|
|
117
103
|
- !ruby/object:Gem::Version
|
|
118
|
-
version: '0'
|
|
104
|
+
version: '0.1'
|
|
119
105
|
type: :development
|
|
120
106
|
prerelease: false
|
|
121
107
|
version_requirements: !ruby/object:Gem::Requirement
|
|
122
|
-
none: false
|
|
123
108
|
requirements:
|
|
124
|
-
- -
|
|
109
|
+
- - "~>"
|
|
125
110
|
- !ruby/object:Gem::Version
|
|
126
|
-
version: '0'
|
|
111
|
+
version: '0.1'
|
|
127
112
|
- !ruby/object:Gem::Dependency
|
|
128
|
-
name:
|
|
113
|
+
name: minitest-reporters
|
|
129
114
|
requirement: !ruby/object:Gem::Requirement
|
|
130
|
-
none: false
|
|
131
115
|
requirements:
|
|
132
|
-
- -
|
|
116
|
+
- - '='
|
|
133
117
|
- !ruby/object:Gem::Version
|
|
134
|
-
version:
|
|
118
|
+
version: 1.3.0
|
|
135
119
|
type: :development
|
|
136
120
|
prerelease: false
|
|
137
121
|
version_requirements: !ruby/object:Gem::Requirement
|
|
138
|
-
none: false
|
|
139
122
|
requirements:
|
|
140
|
-
- -
|
|
123
|
+
- - '='
|
|
141
124
|
- !ruby/object:Gem::Version
|
|
142
|
-
version:
|
|
125
|
+
version: 1.3.0
|
|
126
|
+
- !ruby/object:Gem::Dependency
|
|
127
|
+
name: rack-test
|
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
|
129
|
+
requirements:
|
|
130
|
+
- - "~>"
|
|
131
|
+
- !ruby/object:Gem::Version
|
|
132
|
+
version: '1.1'
|
|
133
|
+
type: :development
|
|
134
|
+
prerelease: false
|
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
136
|
+
requirements:
|
|
137
|
+
- - "~>"
|
|
138
|
+
- !ruby/object:Gem::Version
|
|
139
|
+
version: '1.1'
|
|
143
140
|
- !ruby/object:Gem::Dependency
|
|
144
141
|
name: yard
|
|
145
142
|
requirement: !ruby/object:Gem::Requirement
|
|
146
|
-
none: false
|
|
147
143
|
requirements:
|
|
148
|
-
- -
|
|
144
|
+
- - "~>"
|
|
149
145
|
- !ruby/object:Gem::Version
|
|
150
|
-
version: '0'
|
|
146
|
+
version: '0.9'
|
|
151
147
|
type: :development
|
|
152
148
|
prerelease: false
|
|
153
149
|
version_requirements: !ruby/object:Gem::Requirement
|
|
154
|
-
none: false
|
|
155
150
|
requirements:
|
|
156
|
-
- -
|
|
151
|
+
- - "~>"
|
|
157
152
|
- !ruby/object:Gem::Version
|
|
158
|
-
version: '0'
|
|
153
|
+
version: '0.9'
|
|
159
154
|
description: A Rack module for getting and setting a user's locale via a cookie or
|
|
160
155
|
browser default language.
|
|
161
|
-
email: stuart.chinery@
|
|
156
|
+
email: stuart.chinery@gmail.com
|
|
162
157
|
executables: []
|
|
163
158
|
extensions: []
|
|
164
159
|
extra_rdoc_files:
|
|
165
160
|
- LICENSE.txt
|
|
166
161
|
- README.md
|
|
167
162
|
files:
|
|
168
|
-
- .document
|
|
163
|
+
- ".document"
|
|
164
|
+
- ".rubocop.yml"
|
|
165
|
+
- ".ruby-version"
|
|
166
|
+
- ".travis.yml"
|
|
169
167
|
- Gemfile
|
|
170
168
|
- Gemfile.lock
|
|
171
169
|
- LICENSE.txt
|
|
@@ -174,34 +172,31 @@ files:
|
|
|
174
172
|
- VERSION
|
|
175
173
|
- lib/rack-user-locale.rb
|
|
176
174
|
- rack-user-locale.gemspec
|
|
175
|
+
- test/basic_rack_app.rb
|
|
177
176
|
- test/helper.rb
|
|
178
|
-
- test/
|
|
177
|
+
- test/rack-user-locale_test.rb
|
|
179
178
|
homepage: http://github.com/sleepingstu/rack-user-locale
|
|
180
179
|
licenses:
|
|
181
180
|
- MIT
|
|
181
|
+
metadata: {}
|
|
182
182
|
post_install_message:
|
|
183
183
|
rdoc_options: []
|
|
184
184
|
require_paths:
|
|
185
185
|
- lib
|
|
186
186
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
187
|
-
none: false
|
|
188
187
|
requirements:
|
|
189
|
-
- -
|
|
188
|
+
- - ">="
|
|
190
189
|
- !ruby/object:Gem::Version
|
|
191
190
|
version: '0'
|
|
192
|
-
segments:
|
|
193
|
-
- 0
|
|
194
|
-
hash: 1351284199224301544
|
|
195
191
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
196
|
-
none: false
|
|
197
192
|
requirements:
|
|
198
|
-
- -
|
|
193
|
+
- - ">="
|
|
199
194
|
- !ruby/object:Gem::Version
|
|
200
195
|
version: '0'
|
|
201
196
|
requirements: []
|
|
202
197
|
rubyforge_project:
|
|
203
|
-
rubygems_version:
|
|
198
|
+
rubygems_version: 2.7.6
|
|
204
199
|
signing_key:
|
|
205
|
-
specification_version:
|
|
200
|
+
specification_version: 4
|
|
206
201
|
summary: Rack module for getting and setting a user's locale
|
|
207
202
|
test_files: []
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
require "helper"
|
|
2
|
-
|
|
3
|
-
describe "RackUserLocale" do
|
|
4
|
-
describe "without accepted_locales set" do
|
|
5
|
-
before do
|
|
6
|
-
def app
|
|
7
|
-
app = Rack::Builder.new {
|
|
8
|
-
use Rack::UserLocale
|
|
9
|
-
|
|
10
|
-
run BasicRackApp.new
|
|
11
|
-
}
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
I18n.default_locale = :en
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "should have I18n.locale set to :en initially" do
|
|
18
|
-
assert_equal :en, I18n.locale
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
describe "when a locale cookie is set" do
|
|
22
|
-
before do
|
|
23
|
-
get "http://example.com/", {}, "HTTP_COOKIE" => "user-locale=be"
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it "should have I18n.locale set to :be" do
|
|
27
|
-
assert_equal :be, I18n.locale
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "should not set a cookie in the response" do
|
|
31
|
-
assert_equal nil, last_response["Set-Cookie"]
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
describe "when from HTTP_ACCEPT_LANGUAGE headers" do
|
|
36
|
-
describe "with a single locale" do
|
|
37
|
-
before do
|
|
38
|
-
get "http://example.com/", {}, { "HTTP_ACCEPT_LANGUAGE" => "fr-be", "SCRIPT_NAME" => "/" }
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it "should have I18n.locale set to :fr" do
|
|
42
|
-
assert_equal :fr, I18n.locale
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it "should set a cookie in the response" do
|
|
46
|
-
assert_equal "user-locale=fr; path=/", last_response["Set-Cookie"]
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
describe "with an multiple locales" do
|
|
51
|
-
before do
|
|
52
|
-
get "http://example.com/", {}, {
|
|
53
|
-
"HTTP_ACCEPT_LANGUAGE" => "de-DE;q=0.8,de;q=0.8,no-NO;q=1.0,no;q=0.7,ru-RU;q=0.7,sv-SE;q=0.4,sv;q=0.3,nl-BE;q=0.9",
|
|
54
|
-
"SCRIPT_NAME" => "/" }
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
it "should have I18n.locale set to :no" do
|
|
58
|
-
assert_equal :no, I18n.locale
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it "should set a cookie in the response" do
|
|
62
|
-
assert_equal "user-locale=no; path=/", last_response["Set-Cookie"]
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
describe "when both a cooke and HTTP_ACCEPT_LANGUAGE headers are set" do
|
|
68
|
-
before do
|
|
69
|
-
get "http://example.com/", {}, { "HTTP_COOKIE" => "user-locale=af",
|
|
70
|
-
"HTTP_ACCEPT_LANGUAGE" => "ar-sa", "SCRIPT_NAME" => "/" }
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
it "should have I18n.locale set to :af" do
|
|
74
|
-
assert_equal :af, I18n.locale
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
it "should not set a cookie in the response" do
|
|
78
|
-
assert_equal nil, last_response["Set-Cookie"]
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
describe "when nothing is changed" do
|
|
83
|
-
before do
|
|
84
|
-
get "http://example.com/", {}, { "SCRIPT_NAME" => "/" }
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
it "should have I18n.locale set to :en" do
|
|
88
|
-
assert_equal :en, I18n.locale
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
it "should set a cookie in the response" do
|
|
92
|
-
assert_equal "user-locale=en; path=/", last_response["Set-Cookie"]
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
describe "with accepted_locales set" do
|
|
98
|
-
before do
|
|
99
|
-
def app
|
|
100
|
-
app = Rack::Builder.new {
|
|
101
|
-
use Rack::UserLocale, :accepted_locales => [:en, :es, :fr, :de, :ja, :nl]
|
|
102
|
-
|
|
103
|
-
run BasicRackApp.new
|
|
104
|
-
}
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
I18n.default_locale = :en
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
it "should have I18n.locale set to :en initially" do
|
|
111
|
-
assert_equal :en, I18n.locale
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
describe "when a locale cookie is set" do
|
|
115
|
-
before do
|
|
116
|
-
get "http://example.com/", {}, { "HTTP_COOKIE" => "user-locale=es", "SCRIPT_NAME" => "/" }
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
it "should have I18n.locale set to :es" do
|
|
120
|
-
assert_equal :es, I18n.locale
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
it "should not set a cookie in the response" do
|
|
124
|
-
assert_equal nil, last_response["Set-Cookie"]
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
describe "when from HTTP_ACCEPT_LANGUAGE headers" do
|
|
129
|
-
describe "with an accepted locale" do
|
|
130
|
-
before do
|
|
131
|
-
get "http://example.com/", {}, { "HTTP_ACCEPT_LANGUAGE" => "fr-be", "SCRIPT_NAME" => "/" }
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
it "should have I18n.locale set to :fr" do
|
|
135
|
-
assert_equal :fr, I18n.locale
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
it "should set a cookie in the response" do
|
|
139
|
-
assert_equal "user-locale=fr; path=/", last_response["Set-Cookie"]
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
describe "with an multiple locales" do
|
|
144
|
-
describe "at different weights" do
|
|
145
|
-
before do
|
|
146
|
-
get "http://example.com/", {}, {
|
|
147
|
-
"HTTP_ACCEPT_LANGUAGE" => "de-DE;q=0.8,de;q=0.8,no-NO;q=0.7,no;q=0.7,ru-RU;q=0.7,sv-SE;q=0.4,sv;q=0.3,nl-BE;q=0.9",
|
|
148
|
-
"SCRIPT_NAME" => "/" }
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
it "should have I18n.locale set to :nl" do
|
|
152
|
-
assert_equal :nl, I18n.locale
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
it "should set a cookie in the response" do
|
|
156
|
-
assert_equal "user-locale=nl; path=/", last_response["Set-Cookie"]
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
describe "at the same weight" do
|
|
161
|
-
before do
|
|
162
|
-
get "http://example.com/", {}, {
|
|
163
|
-
"HTTP_ACCEPT_LANGUAGE" => "fr,en,ja", "SCRIPT_NAME" => "/" }
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
it "should have I18n.locale set to :fr" do
|
|
167
|
-
assert_equal :fr, I18n.locale
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
it "should set a cookie in the response" do
|
|
171
|
-
assert_equal "user-locale=fr; path=/", last_response["Set-Cookie"]
|
|
172
|
-
end
|
|
173
|
-
end
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
describe "without an accepted locale" do
|
|
177
|
-
before do
|
|
178
|
-
get "http://example.com/", {}, { "HTTP_ACCEPT_LANGUAGE" => "ar-sa", "SCRIPT_NAME" => "/" }
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
it "should have I18n.locale set to :en" do
|
|
182
|
-
assert_equal :en, I18n.locale
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
it "should set a cookie in the response" do
|
|
186
|
-
assert_equal "user-locale=en; path=/", last_response["Set-Cookie"]
|
|
187
|
-
end
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
describe "when both a cooke and HTTP_ACCEPT_LANGUAGE headers are set" do
|
|
192
|
-
before do
|
|
193
|
-
get "http://example.com/", {}, { "HTTP_COOKIE" => "user-locale=ja",
|
|
194
|
-
"HTTP_ACCEPT_LANGUAGE" => "fr-be", "SCRIPT_NAME" => "/" }
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
it "should have I18n.locale set to :ja" do
|
|
198
|
-
assert_equal :ja, I18n.locale
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
it "should not set a cookie in the response" do
|
|
202
|
-
assert_equal nil, last_response["Set-Cookie"]
|
|
203
|
-
end
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
describe "when nothing is changed" do
|
|
207
|
-
before do
|
|
208
|
-
get "http://example.com/", {}, { "SCRIPT_NAME" => "/" }
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
it "should have I18n.locale set to :en" do
|
|
212
|
-
assert_equal :en, I18n.locale
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
it "should set a cookie in the response" do
|
|
216
|
-
assert_equal "user-locale=en; path=/", last_response["Set-Cookie"]
|
|
217
|
-
end
|
|
218
|
-
end
|
|
219
|
-
end
|
|
220
|
-
end
|