country_select 2.1.1 → 8.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/build.yml +25 -0
- data/.github/workflows/codeql-analysis.yml +70 -0
- data/CHANGELOG.md +93 -0
- data/Gemfile +0 -6
- data/Gemfile.lock +74 -271
- data/README.md +89 -11
- data/Rakefile +29 -3
- data/country_select.gemspec +10 -7
- data/gemfiles/actionpack-5.2.gemfile +7 -0
- data/gemfiles/actionpack-5.2.gemfile.lock +99 -0
- data/gemfiles/actionpack-6.0.gemfile +7 -0
- data/gemfiles/actionpack-6.0.gemfile.lock +101 -0
- data/gemfiles/actionpack-6.1.gemfile +7 -0
- data/gemfiles/actionpack-6.1.gemfile.lock +100 -0
- data/gemfiles/actionpack-7.0.gemfile +7 -0
- data/gemfiles/actionpack-7.0.gemfile.lock +100 -0
- data/lib/country_select/country_select_helper.rb +5 -0
- data/lib/country_select/defaults.rb +11 -0
- data/lib/country_select/formats.rb +3 -1
- data/lib/country_select/tag_helper.rb +44 -28
- data/lib/country_select/version.rb +1 -1
- data/lib/country_select.rb +3 -7
- data/spec/country_select_spec.rb +184 -17
- metadata +35 -54
- data/.travis.yml +0 -22
- data/gemfiles/actionpack.edge.gemfile +0 -15
- data/gemfiles/actionpack.edge.gemfile.lock +0 -303
- data/gemfiles/actionpack3.2.gemfile +0 -11
- data/gemfiles/actionpack3.2.gemfile.lock +0 -286
- data/gemfiles/actionpack4.0.gemfile +0 -11
- data/gemfiles/actionpack4.0.gemfile.lock +0 -275
- data/gemfiles/actionpack4.1.gemfile +0 -11
- data/gemfiles/actionpack4.1.gemfile.lock +0 -279
- data/gemfiles/actionpack4.2.gemfile +0 -12
- data/gemfiles/actionpack4.2.gemfile.lock +0 -299
- data/lib/country_select/rails3/country_select_helper.rb +0 -39
@@ -6,6 +6,11 @@ module ActionView
|
|
6
6
|
html_options = options
|
7
7
|
options = priority_or_options
|
8
8
|
else
|
9
|
+
if RUBY_VERSION =~ /^3\.\d\.\d/
|
10
|
+
warn "DEPRECATION WARNING: Setting priority countries with the 1.x syntax is deprecated. Please use the `priority_countries:` option.", uplevel: 1, category: :deprecated
|
11
|
+
else
|
12
|
+
warn "DEPRECATION WARNING: Setting priority countries with the 1.x syntax is deprecated. Please use the `priority_countries:` option.", uplevel: 1
|
13
|
+
end
|
9
14
|
options[:priority_countries] = priority_or_options
|
10
15
|
end
|
11
16
|
|
@@ -2,6 +2,8 @@ module CountrySelect
|
|
2
2
|
FORMATS = {}
|
3
3
|
|
4
4
|
FORMATS[:default] = lambda do |country|
|
5
|
-
|
5
|
+
# Need to use :[] specifically, not :dig, because country.translations is a
|
6
|
+
# ISO3166::Translations object, which overrides :[] to support i18n locale fallbacks
|
7
|
+
country.translations&.send(:[], I18n.locale.to_s) || country.common_name || country.iso_short_name
|
6
8
|
end
|
7
9
|
end
|
@@ -2,20 +2,30 @@ module CountrySelect
|
|
2
2
|
class CountryNotFoundError < StandardError;end
|
3
3
|
module TagHelper
|
4
4
|
def country_option_tags
|
5
|
+
# In Rails 5.2+, `value` accepts no arguments and must also be called
|
6
|
+
# with parens to avoid the local variable of the same name
|
7
|
+
# https://github.com/rails/rails/pull/29791
|
8
|
+
selected_option = @options.fetch(:selected) do
|
9
|
+
if self.method(:value).arity == 0
|
10
|
+
value()
|
11
|
+
else
|
12
|
+
value(@object)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
5
16
|
option_tags_options = {
|
6
|
-
:selected =>
|
17
|
+
:selected => selected_option,
|
7
18
|
:disabled => @options[:disabled]
|
8
19
|
}
|
9
20
|
|
10
21
|
if priority_countries.present?
|
11
|
-
priority_countries_options = country_options_for(priority_countries,
|
22
|
+
priority_countries_options = country_options_for(priority_countries, @options.fetch(:sort_provided, ::CountrySelect::DEFAULTS[:sort_provided]))
|
12
23
|
|
13
24
|
option_tags = options_for_select(priority_countries_options, option_tags_options)
|
14
25
|
option_tags += html_safe_newline + options_for_select([priority_countries_divider], disabled: priority_countries_divider)
|
15
26
|
|
16
|
-
|
17
|
-
|
18
|
-
end
|
27
|
+
option_tags_options[:selected] = [option_tags_options[:selected]] unless option_tags_options[:selected].kind_of?(Array)
|
28
|
+
option_tags_options[:selected].delete_if{|selected| priority_countries_options.map(&:second).include?(selected)}
|
19
29
|
|
20
30
|
option_tags += html_safe_newline + options_for_select(country_options, option_tags_options)
|
21
31
|
else
|
@@ -25,43 +35,42 @@ module CountrySelect
|
|
25
35
|
|
26
36
|
private
|
27
37
|
def locale
|
28
|
-
@options[:locale]
|
38
|
+
@options.fetch(:locale, ::CountrySelect::DEFAULTS[:locale])
|
29
39
|
end
|
30
40
|
|
31
41
|
def priority_countries
|
32
|
-
@options[:priority_countries]
|
42
|
+
@options.fetch(:priority_countries, ::CountrySelect::DEFAULTS[:priority_countries])
|
33
43
|
end
|
34
44
|
|
35
45
|
def priority_countries_divider
|
36
|
-
@options[:priority_countries_divider]
|
46
|
+
@options.fetch(:priority_countries_divider, ::CountrySelect::DEFAULTS[:priority_countries_divider])
|
37
47
|
end
|
38
48
|
|
39
49
|
def only_country_codes
|
40
|
-
@options[:only]
|
50
|
+
@options.fetch(:only, ::CountrySelect::DEFAULTS[:only])
|
41
51
|
end
|
42
52
|
|
43
53
|
def except_country_codes
|
44
|
-
@options[:except]
|
54
|
+
@options.fetch(:except, ::CountrySelect::DEFAULTS[:except])
|
45
55
|
end
|
46
56
|
|
47
57
|
def format
|
48
|
-
@options[:format]
|
58
|
+
@options.fetch(:format, ::CountrySelect::DEFAULTS[:format])
|
49
59
|
end
|
50
60
|
|
51
61
|
def country_options
|
52
|
-
country_options_for(all_country_codes, true)
|
53
|
-
end
|
54
|
-
|
55
|
-
def all_country_codes
|
56
|
-
codes = ISO3166::Country.all.map(&:last)
|
57
|
-
|
58
62
|
if only_country_codes.present?
|
59
|
-
codes &
|
63
|
+
codes = only_country_codes & ISO3166::Country.codes
|
64
|
+
sort = @options.fetch(:sort_provided, ::CountrySelect::DEFAULTS[:sort_provided])
|
60
65
|
elsif except_country_codes.present?
|
61
|
-
codes - except_country_codes
|
66
|
+
codes = ISO3166::Country.codes - except_country_codes
|
67
|
+
sort = true
|
62
68
|
else
|
63
|
-
codes
|
69
|
+
codes = ISO3166::Country.codes
|
70
|
+
sort = true
|
64
71
|
end
|
72
|
+
|
73
|
+
country_options_for(codes, sort)
|
65
74
|
end
|
66
75
|
|
67
76
|
def country_options_for(country_codes, sorted=true)
|
@@ -69,22 +78,30 @@ module CountrySelect
|
|
69
78
|
country_list = country_codes.map do |code_or_name|
|
70
79
|
if country = ISO3166::Country.new(code_or_name)
|
71
80
|
code = country.alpha2
|
72
|
-
elsif country = ISO3166::Country.
|
73
|
-
code = country.
|
81
|
+
elsif country = ISO3166::Country.find_country_by_any_name(code_or_name)
|
82
|
+
code = country.alpha2
|
74
83
|
end
|
75
84
|
|
76
|
-
country = ISO3166::Country.new(code)
|
77
|
-
|
78
85
|
unless country.present?
|
79
86
|
msg = "Could not find Country with string '#{code_or_name}'"
|
80
87
|
raise CountryNotFoundError.new(msg)
|
81
88
|
end
|
82
89
|
|
83
|
-
|
90
|
+
formatted_country = ::CountrySelect::FORMATS[format].call(country)
|
91
|
+
|
92
|
+
if formatted_country.is_a?(Array)
|
93
|
+
formatted_country
|
94
|
+
else
|
95
|
+
[formatted_country, code]
|
96
|
+
end
|
84
97
|
|
85
|
-
[name,code]
|
86
98
|
end
|
87
|
-
|
99
|
+
|
100
|
+
if sorted
|
101
|
+
country_list.sort_by { |name, code| [I18n.transliterate(name), name] }
|
102
|
+
else
|
103
|
+
country_list
|
104
|
+
end
|
88
105
|
end
|
89
106
|
end
|
90
107
|
|
@@ -93,4 +110,3 @@ module CountrySelect
|
|
93
110
|
end
|
94
111
|
end
|
95
112
|
end
|
96
|
-
|
data/lib/country_select.rb
CHANGED
@@ -1,13 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'countries'
|
4
4
|
|
5
5
|
require 'country_select/version'
|
6
|
+
require 'country_select/defaults'
|
6
7
|
require 'country_select/formats'
|
7
8
|
require 'country_select/tag_helper'
|
8
|
-
|
9
|
-
if defined?(ActionView::Helpers::Tags::Base)
|
10
|
-
require 'country_select/country_select_helper'
|
11
|
-
else
|
12
|
-
require 'country_select/rails3/country_select_helper'
|
13
|
-
end
|
9
|
+
require 'country_select/country_select_helper'
|
data/spec/country_select_spec.rb
CHANGED
@@ -9,12 +9,18 @@ describe "CountrySelect" do
|
|
9
9
|
include ActionView::Helpers::TagHelper
|
10
10
|
include ActionView::Helpers::FormOptionsHelper
|
11
11
|
|
12
|
+
before do
|
13
|
+
I18n.available_locales = [:en]
|
14
|
+
I18n.locale = :en
|
15
|
+
ISO3166.reset
|
16
|
+
end
|
17
|
+
|
12
18
|
class Walrus
|
13
19
|
attr_accessor :country_code
|
14
20
|
end
|
15
21
|
|
16
22
|
let(:walrus) { Walrus.new }
|
17
|
-
let!(:template) { ActionView::Base.new }
|
23
|
+
let!(:template) { ActionView::Base.new(ActionView::LookupContext.new([]), {}, nil) }
|
18
24
|
|
19
25
|
let(:builder) do
|
20
26
|
if defined?(ActionView::Helpers::Tags::Base)
|
@@ -31,7 +37,7 @@ describe "CountrySelect" do
|
|
31
37
|
end
|
32
38
|
|
33
39
|
it "selects the value of country_code" do
|
34
|
-
tag = options_for_select([['United States
|
40
|
+
tag = options_for_select([['United States', 'US']], 'US')
|
35
41
|
|
36
42
|
walrus.country_code = 'US'
|
37
43
|
t = builder.country_select(:country_code)
|
@@ -39,6 +45,9 @@ describe "CountrySelect" do
|
|
39
45
|
end
|
40
46
|
|
41
47
|
it "uses the locale specified by I18n.locale" do
|
48
|
+
I18n.available_locales = [:en, :es]
|
49
|
+
ISO3166.reset
|
50
|
+
|
42
51
|
tag = options_for_select([['Estados Unidos', 'US']], 'US')
|
43
52
|
|
44
53
|
walrus.country_code = 'US'
|
@@ -52,7 +61,27 @@ describe "CountrySelect" do
|
|
52
61
|
end
|
53
62
|
end
|
54
63
|
|
64
|
+
it 'falls back when given a country-specific locale' do
|
65
|
+
I18n.available_locales = [:en, :de, :'de-AT']
|
66
|
+
ISO3166.reset
|
67
|
+
|
68
|
+
tag = options_for_select([['Deutschland', 'DE']], 'DE')
|
69
|
+
|
70
|
+
walrus.country_code = 'DE'
|
71
|
+
original_locale = I18n.locale
|
72
|
+
begin
|
73
|
+
I18n.locale = :'de-AT'
|
74
|
+
t = builder.country_select(:country_code)
|
75
|
+
expect(t).to include(tag)
|
76
|
+
ensure
|
77
|
+
I18n.locale = original_locale
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
55
81
|
it "accepts a locale option" do
|
82
|
+
I18n.available_locales = [:fr]
|
83
|
+
ISO3166.reset
|
84
|
+
|
56
85
|
tag = options_for_select([['États-Unis', 'US']], 'US')
|
57
86
|
|
58
87
|
walrus.country_code = 'US'
|
@@ -63,9 +92,26 @@ describe "CountrySelect" do
|
|
63
92
|
it "accepts priority countries" do
|
64
93
|
tag = options_for_select(
|
65
94
|
[
|
95
|
+
['Denmark', 'DK'],
|
66
96
|
['Latvia','LV'],
|
67
|
-
['United States
|
97
|
+
['United States','US'],
|
98
|
+
['-'*15,'-'*15]
|
99
|
+
],
|
100
|
+
selected: 'US',
|
101
|
+
disabled: '-'*15
|
102
|
+
)
|
103
|
+
|
104
|
+
walrus.country_code = 'US'
|
105
|
+
t = builder.country_select(:country_code, priority_countries: ['LV','US','DK'])
|
106
|
+
expect(t).to include(tag)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "priority countries are sorted by name by default" do
|
110
|
+
tag = options_for_select(
|
111
|
+
[
|
68
112
|
['Denmark', 'DK'],
|
113
|
+
['Latvia','LV'],
|
114
|
+
['United States','US'],
|
69
115
|
['-'*15,'-'*15]
|
70
116
|
],
|
71
117
|
selected: 'US',
|
@@ -77,11 +123,57 @@ describe "CountrySelect" do
|
|
77
123
|
expect(t).to include(tag)
|
78
124
|
end
|
79
125
|
|
80
|
-
it "
|
81
|
-
tag = options_for_select(
|
126
|
+
it "priority countries with `sort_provided: false` preserves the provided order" do
|
127
|
+
tag = options_for_select(
|
128
|
+
[
|
129
|
+
['Latvia','LV'],
|
130
|
+
['United States','US'],
|
131
|
+
['Denmark', 'DK'],
|
132
|
+
['-'*15,'-'*15]
|
133
|
+
],
|
134
|
+
selected: 'US',
|
135
|
+
disabled: '-'*15
|
136
|
+
)
|
137
|
+
|
82
138
|
walrus.country_code = 'US'
|
83
|
-
t = builder.country_select(:country_code, priority_countries: ['LV','US'])
|
84
|
-
expect(t).
|
139
|
+
t = builder.country_select(:country_code, priority_countries: ['LV','US','DK'], sort_provided: false)
|
140
|
+
expect(t).to include(tag)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "priority countries with `sort_provided: false` still sorts the non-priority countries by name" do
|
144
|
+
tag = options_for_select(
|
145
|
+
[
|
146
|
+
['Latvia','LV'],
|
147
|
+
['United States','US'],
|
148
|
+
['Denmark', 'DK'],
|
149
|
+
['-'*15,'-'*15],
|
150
|
+
['Afghanistan','AF']
|
151
|
+
],
|
152
|
+
selected: 'AF',
|
153
|
+
disabled: '-'*15
|
154
|
+
)
|
155
|
+
|
156
|
+
walrus.country_code = 'AF'
|
157
|
+
t = builder.country_select(:country_code, priority_countries: ['LV','US','DK'], sort_provided: false)
|
158
|
+
expect(t).to include(tag)
|
159
|
+
end
|
160
|
+
|
161
|
+
describe "when selected options is not an array" do
|
162
|
+
it "selects only the first matching option" do
|
163
|
+
tag = options_for_select([["United States", "US"],["Uruguay", "UY"]], "US")
|
164
|
+
walrus.country_code = 'US'
|
165
|
+
t = builder.country_select(:country_code, priority_countries: ['LV','US'])
|
166
|
+
expect(t).to_not include(tag)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe "when selected options is an array" do
|
171
|
+
it "selects all options but only once" do
|
172
|
+
walrus.country_code = 'US'
|
173
|
+
t = builder.country_select(:country_code, {priority_countries: ['LV','US','ES'], selected: ['UY', 'US']}, multiple: true)
|
174
|
+
expect(t.scan(options_for_select([["United States", "US"]], "US")).length).to be(1)
|
175
|
+
expect(t.scan(options_for_select([["Uruguay", "UY"]], "UY")).length).to be(1)
|
176
|
+
end
|
85
177
|
end
|
86
178
|
|
87
179
|
it "displays only the chosen countries" do
|
@@ -93,19 +185,48 @@ describe "CountrySelect" do
|
|
93
185
|
end
|
94
186
|
|
95
187
|
it "discards some countries" do
|
96
|
-
tag = options_for_select([["United States
|
188
|
+
tag = options_for_select([["United States", "US"]])
|
97
189
|
walrus.country_code = 'DE'
|
98
190
|
t = builder.country_select(:country_code, except: ['US'])
|
99
191
|
expect(t).to_not include(tag)
|
100
192
|
end
|
101
193
|
|
194
|
+
it "countries provided in `only` are sorted by name by default" do
|
195
|
+
t = builder.country_select(:country_code, only: ['PT','DE','AR'])
|
196
|
+
order = t.scan(/value="(\w{2})"/).map { |o| o[0] }
|
197
|
+
expect(order).to eq(['AR', 'DE', 'PT'])
|
198
|
+
end
|
199
|
+
|
200
|
+
it "countries provided in `only` with `sort_provided` to false keeps the order of the provided countries" do
|
201
|
+
t = builder.country_select(:country_code, only: ['PT','DE','AR'], sort_provided: false)
|
202
|
+
order = t.scan(/value="(\w{2})"/).map { |o| o[0] }
|
203
|
+
expect(order).to eq(['PT','DE','AR'])
|
204
|
+
end
|
205
|
+
|
206
|
+
context "when there is a default 'except' configured" do
|
207
|
+
around do |example|
|
208
|
+
old_value = ::CountrySelect::DEFAULTS[:except]
|
209
|
+
example.run
|
210
|
+
::CountrySelect::DEFAULTS[:except] = old_value
|
211
|
+
end
|
212
|
+
|
213
|
+
it "discards countries when configured to" do
|
214
|
+
::CountrySelect::DEFAULTS[:except] = ['US']
|
215
|
+
|
216
|
+
tag = options_for_select([['United States', 'US']])
|
217
|
+
walrus.country_code = 'DE'
|
218
|
+
t = builder.country_select(:country_code)
|
219
|
+
expect(t).to_not include(tag)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
102
223
|
context "using old 1.x syntax" do
|
103
224
|
it "accepts priority countries" do
|
104
225
|
tag = options_for_select(
|
105
226
|
[
|
106
|
-
['Latvia','LV'],
|
107
|
-
['United States of America','US'],
|
108
227
|
['Denmark', 'DK'],
|
228
|
+
['Latvia','LV'],
|
229
|
+
['United States','US'],
|
109
230
|
['-'*15,'-'*15]
|
110
231
|
],
|
111
232
|
selected: 'US',
|
@@ -118,7 +239,7 @@ describe "CountrySelect" do
|
|
118
239
|
end
|
119
240
|
|
120
241
|
it "selects only the first matching option" do
|
121
|
-
tag = options_for_select([["United States
|
242
|
+
tag = options_for_select([["United States", "US"],["Uruguay", "UY"]], "US")
|
122
243
|
walrus.country_code = 'US'
|
123
244
|
t = builder.country_select(:country_code, ['LV','US'])
|
124
245
|
expect(t).to_not include(tag)
|
@@ -129,7 +250,7 @@ describe "CountrySelect" do
|
|
129
250
|
["Australia", "AU"],
|
130
251
|
["Canada", "CA"],
|
131
252
|
["United Kingdom", "GB"],
|
132
|
-
["United States
|
253
|
+
["United States", "US"]
|
133
254
|
])
|
134
255
|
country_names = ["Australia", "Canada", "United Kingdom", "United States"]
|
135
256
|
t = builder.country_select(:country_code, country_names)
|
@@ -143,9 +264,9 @@ describe "CountrySelect" do
|
|
143
264
|
"United Kingdom",
|
144
265
|
"Mexico",
|
145
266
|
"Australia",
|
146
|
-
"
|
267
|
+
"Freedonia"
|
147
268
|
]
|
148
|
-
error_msg = "Could not find Country with string '
|
269
|
+
error_msg = "Could not find Country with string 'Freedonia'"
|
149
270
|
|
150
271
|
expect do
|
151
272
|
builder.country_select(:country_code, country_names)
|
@@ -159,23 +280,69 @@ describe "CountrySelect" do
|
|
159
280
|
end
|
160
281
|
|
161
282
|
it "supports the include_blank option" do
|
162
|
-
|
283
|
+
# Rails 6.1 more closely follows the HTML spec for
|
284
|
+
# empty option tags.
|
285
|
+
# https://github.com/rails/rails/pull/39808
|
286
|
+
tag = if ActionView::VERSION::STRING >= '6.1'
|
287
|
+
'<option value="" label=" "></option>'
|
288
|
+
else
|
289
|
+
'<option value=""></option>'
|
290
|
+
end
|
163
291
|
t = builder.country_select(:country_code, include_blank: true)
|
164
292
|
expect(t).to include(tag)
|
165
293
|
end
|
166
294
|
end
|
167
295
|
|
296
|
+
it 'sorts unicode' do
|
297
|
+
tag = builder.country_select(:country_code, only: ['AX', 'AL', 'AF', 'ZW'])
|
298
|
+
order = tag.scan(/value="(\w{2})"/).map { |o| o[0] }
|
299
|
+
expect(order).to eq(['AF', 'AX', 'AL', 'ZW'])
|
300
|
+
end
|
301
|
+
|
168
302
|
describe "custom formats" do
|
169
303
|
it "accepts a custom formatter" do
|
170
304
|
::CountrySelect::FORMATS[:with_alpha2] = lambda do |country|
|
171
|
-
"#{country.
|
305
|
+
"#{country.iso_short_name} (#{country.alpha2})"
|
172
306
|
end
|
173
307
|
|
174
|
-
tag = options_for_select([['United States (US)', 'US']], 'US')
|
308
|
+
tag = options_for_select([['United States of America (US)', 'US']], 'US')
|
175
309
|
|
176
310
|
walrus.country_code = 'US'
|
177
311
|
t = builder.country_select(:country_code, format: :with_alpha2)
|
178
312
|
expect(t).to include(tag)
|
179
313
|
end
|
314
|
+
|
315
|
+
it "accepts an array for formatter" do
|
316
|
+
::CountrySelect::FORMATS[:with_alpha3] = lambda do |country|
|
317
|
+
[country.iso_short_name, country.alpha3]
|
318
|
+
end
|
319
|
+
|
320
|
+
tag = options_for_select([['United States of America', 'USA']], 'USA')
|
321
|
+
walrus.country_code = 'USA'
|
322
|
+
t = builder.country_select(:country_code, format: :with_alpha3)
|
323
|
+
expect(t).to include(tag)
|
324
|
+
end
|
325
|
+
|
326
|
+
it "accepts an array for formatter + custom formatter" do
|
327
|
+
::CountrySelect::FORMATS[:with_alpha3] = lambda do |country|
|
328
|
+
["#{country.iso_short_name} (#{country.alpha2})", country.alpha3]
|
329
|
+
end
|
330
|
+
|
331
|
+
tag = options_for_select([['United States of America (US)', 'USA']], 'USA')
|
332
|
+
walrus.country_code = 'USA'
|
333
|
+
t = builder.country_select(:country_code, format: :with_alpha3)
|
334
|
+
expect(t).to include(tag)
|
335
|
+
end
|
336
|
+
|
337
|
+
it "marks priority countries as selected only once" do
|
338
|
+
::CountrySelect::FORMATS[:with_alpha3] = lambda do |country|
|
339
|
+
[country.iso_short_name, country.alpha3]
|
340
|
+
end
|
341
|
+
|
342
|
+
tag = options_for_select([['United States of America', 'USA']], 'USA')
|
343
|
+
walrus.country_code = 'USA'
|
344
|
+
t = builder.country_select(:country_code, format: :with_alpha3, priority_countries: ['US'])
|
345
|
+
expect(t.scan(Regexp.new(Regexp.escape(tag))).size).to eq 1
|
346
|
+
end
|
180
347
|
end
|
181
348
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: country_select
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 8.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Penner
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '7.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '7.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: pry
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '13'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,42 +66,22 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: wwtd
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: countries
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
|
-
- - "
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 0.9.3
|
90
|
-
- - "<"
|
73
|
+
- - "~>"
|
91
74
|
- !ruby/object:Gem::Version
|
92
|
-
version:
|
75
|
+
version: '5.0'
|
93
76
|
type: :runtime
|
94
77
|
prerelease: false
|
95
78
|
version_requirements: !ruby/object:Gem::Requirement
|
96
79
|
requirements:
|
97
|
-
- - "
|
98
|
-
- !ruby/object:Gem::Version
|
99
|
-
version: 0.9.3
|
100
|
-
- - "<"
|
80
|
+
- - "~>"
|
101
81
|
- !ruby/object:Gem::Version
|
102
|
-
version:
|
103
|
-
description: Provides a simple helper to get an HTML select list of countries.
|
104
|
-
list of countries comes from the ISO 3166 standard.
|
82
|
+
version: '5.0'
|
83
|
+
description: Provides a simple helper to get an HTML select list of countries. The
|
84
|
+
list of countries comes from the ISO 3166 standard. While it is a relatively neutral
|
105
85
|
source of country names, it will still offend some users.
|
106
86
|
email:
|
107
87
|
- stefan.penner@gmail.com
|
@@ -109,9 +89,10 @@ executables: []
|
|
109
89
|
extensions: []
|
110
90
|
extra_rdoc_files: []
|
111
91
|
files:
|
92
|
+
- ".github/workflows/build.yml"
|
93
|
+
- ".github/workflows/codeql-analysis.yml"
|
112
94
|
- ".gitignore"
|
113
95
|
- ".rspec"
|
114
|
-
- ".travis.yml"
|
115
96
|
- CHANGELOG.md
|
116
97
|
- Gemfile
|
117
98
|
- Gemfile.lock
|
@@ -120,29 +101,30 @@ files:
|
|
120
101
|
- Rakefile
|
121
102
|
- UPGRADING.md
|
122
103
|
- country_select.gemspec
|
123
|
-
- gemfiles/actionpack.
|
124
|
-
- gemfiles/actionpack.
|
125
|
-
- gemfiles/
|
126
|
-
- gemfiles/
|
127
|
-
- gemfiles/
|
128
|
-
- gemfiles/
|
129
|
-
- gemfiles/
|
130
|
-
- gemfiles/
|
131
|
-
- gemfiles/actionpack4.2.gemfile
|
132
|
-
- gemfiles/actionpack4.2.gemfile.lock
|
104
|
+
- gemfiles/actionpack-5.2.gemfile
|
105
|
+
- gemfiles/actionpack-5.2.gemfile.lock
|
106
|
+
- gemfiles/actionpack-6.0.gemfile
|
107
|
+
- gemfiles/actionpack-6.0.gemfile.lock
|
108
|
+
- gemfiles/actionpack-6.1.gemfile
|
109
|
+
- gemfiles/actionpack-6.1.gemfile.lock
|
110
|
+
- gemfiles/actionpack-7.0.gemfile
|
111
|
+
- gemfiles/actionpack-7.0.gemfile.lock
|
133
112
|
- lib/country_select.rb
|
134
113
|
- lib/country_select/country_select_helper.rb
|
114
|
+
- lib/country_select/defaults.rb
|
135
115
|
- lib/country_select/formats.rb
|
136
|
-
- lib/country_select/rails3/country_select_helper.rb
|
137
116
|
- lib/country_select/tag_helper.rb
|
138
117
|
- lib/country_select/version.rb
|
139
118
|
- spec/country_select_spec.rb
|
140
119
|
- spec/spec_helper.rb
|
141
|
-
homepage: https://github.com/
|
120
|
+
homepage: https://github.com/countries/country_select
|
142
121
|
licenses:
|
143
122
|
- MIT
|
144
|
-
metadata:
|
145
|
-
|
123
|
+
metadata:
|
124
|
+
bug_tracker_uri: http://github.com/countries/country_select/issues
|
125
|
+
changelog_uri: https://github.com/countries/country_select/blob/master/CHANGELOG.md
|
126
|
+
source_code_uri: https://github.com/countries/country_select
|
127
|
+
post_install_message:
|
146
128
|
rdoc_options: []
|
147
129
|
require_paths:
|
148
130
|
- lib
|
@@ -150,16 +132,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
150
132
|
requirements:
|
151
133
|
- - ">="
|
152
134
|
- !ruby/object:Gem::Version
|
153
|
-
version: '
|
135
|
+
version: '2.7'
|
154
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
137
|
requirements:
|
156
138
|
- - ">="
|
157
139
|
- !ruby/object:Gem::Version
|
158
140
|
version: '0'
|
159
141
|
requirements: []
|
160
|
-
|
161
|
-
|
162
|
-
signing_key:
|
142
|
+
rubygems_version: 3.4.2
|
143
|
+
signing_key:
|
163
144
|
specification_version: 4
|
164
145
|
summary: Country Select Plugin
|
165
146
|
test_files:
|