country_select 4.0.0 → 8.0.1

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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +25 -0
  3. data/.github/workflows/codeql-analysis.yml +70 -0
  4. data/CHANGELOG.md +50 -0
  5. data/Gemfile +0 -6
  6. data/Gemfile.lock +61 -272
  7. data/README.md +31 -17
  8. data/Rakefile +29 -3
  9. data/country_select.gemspec +9 -9
  10. data/gemfiles/{actionpack5.2.gemfile → actionpack-5.2.gemfile} +1 -6
  11. data/gemfiles/actionpack-5.2.gemfile.lock +99 -0
  12. data/gemfiles/actionpack-6.0.gemfile +7 -0
  13. data/gemfiles/actionpack-6.0.gemfile.lock +101 -0
  14. data/gemfiles/actionpack-6.1.gemfile +7 -0
  15. data/gemfiles/actionpack-6.1.gemfile.lock +100 -0
  16. data/gemfiles/actionpack-7.0.gemfile +7 -0
  17. data/gemfiles/actionpack-7.0.gemfile.lock +100 -0
  18. data/lib/country_select/country_select_helper.rb +5 -0
  19. data/lib/country_select/defaults.rb +11 -0
  20. data/lib/country_select/formats.rb +3 -1
  21. data/lib/country_select/tag_helper.rb +19 -25
  22. data/lib/country_select/version.rb +1 -1
  23. data/lib/country_select.rb +2 -7
  24. data/spec/country_select_spec.rb +112 -25
  25. metadata +33 -67
  26. data/.travis.yml +0 -41
  27. data/gemfiles/actionpack.edge.gemfile +0 -15
  28. data/gemfiles/actionpack.edge.gemfile.lock +0 -310
  29. data/gemfiles/actionpack3.2.gemfile +0 -11
  30. data/gemfiles/actionpack3.2.gemfile.lock +0 -297
  31. data/gemfiles/actionpack4.0.gemfile +0 -11
  32. data/gemfiles/actionpack4.0.gemfile.lock +0 -286
  33. data/gemfiles/actionpack4.1.gemfile +0 -11
  34. data/gemfiles/actionpack4.1.gemfile.lock +0 -290
  35. data/gemfiles/actionpack4.2.gemfile +0 -14
  36. data/gemfiles/actionpack4.2.gemfile.lock +0 -306
  37. data/gemfiles/actionpack5.0.gemfile +0 -12
  38. data/gemfiles/actionpack5.0.gemfile.lock +0 -311
  39. data/gemfiles/actionpack5.1.gemfile +0 -12
  40. data/gemfiles/actionpack5.1.gemfile.lock +0 -311
  41. data/gemfiles/actionpack5.2.gemfile.lock +0 -312
  42. data/lib/country_select/rails3/country_select_helper.rb +0 -39
  43. data/lib/country_select_without_sort_alphabetical.rb +0 -13
@@ -20,7 +20,7 @@ describe "CountrySelect" do
20
20
  end
21
21
 
22
22
  let(:walrus) { Walrus.new }
23
- let!(:template) { ActionView::Base.new }
23
+ let!(:template) { ActionView::Base.new(ActionView::LookupContext.new([]), {}, nil) }
24
24
 
25
25
  let(:builder) do
26
26
  if defined?(ActionView::Helpers::Tags::Base)
@@ -61,6 +61,23 @@ describe "CountrySelect" do
61
61
  end
62
62
  end
63
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
+
64
81
  it "accepts a locale option" do
65
82
  I18n.available_locales = [:fr]
66
83
  ISO3166.reset
@@ -75,9 +92,26 @@ describe "CountrySelect" do
75
92
  it "accepts priority countries" do
76
93
  tag = options_for_select(
77
94
  [
95
+ ['Denmark', 'DK'],
78
96
  ['Latvia','LV'],
79
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
+ [
80
112
  ['Denmark', 'DK'],
113
+ ['Latvia','LV'],
114
+ ['United States','US'],
81
115
  ['-'*15,'-'*15]
82
116
  ],
83
117
  selected: 'US',
@@ -89,6 +123,41 @@ describe "CountrySelect" do
89
123
  expect(t).to include(tag)
90
124
  end
91
125
 
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
+
138
+ walrus.country_code = 'US'
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
+
92
161
  describe "when selected options is not an array" do
93
162
  it "selects only the first matching option" do
94
163
  tag = options_for_select([["United States", "US"],["Uruguay", "UY"]], "US")
@@ -100,7 +169,6 @@ describe "CountrySelect" do
100
169
 
101
170
  describe "when selected options is an array" do
102
171
  it "selects all options but only once" do
103
- tag = options_for_select([["United States", "US"],["Uruguay", "UY"],["Spain", "ES"]], "US")
104
172
  walrus.country_code = 'US'
105
173
  t = builder.country_select(:country_code, {priority_countries: ['LV','US','ES'], selected: ['UY', 'US']}, multiple: true)
106
174
  expect(t.scan(options_for_select([["United States", "US"]], "US")).length).to be(1)
@@ -123,13 +191,42 @@ describe "CountrySelect" do
123
191
  expect(t).to_not include(tag)
124
192
  end
125
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
+
126
223
  context "using old 1.x syntax" do
127
224
  it "accepts priority countries" do
128
225
  tag = options_for_select(
129
226
  [
227
+ ['Denmark', 'DK'],
130
228
  ['Latvia','LV'],
131
229
  ['United States','US'],
132
- ['Denmark', 'DK'],
133
230
  ['-'*15,'-'*15]
134
231
  ],
135
232
  selected: 'US',
@@ -183,7 +280,14 @@ describe "CountrySelect" do
183
280
  end
184
281
 
185
282
  it "supports the include_blank option" do
186
- tag = '<option value=""></option>'
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
187
291
  t = builder.country_select(:country_code, include_blank: true)
188
292
  expect(t).to include(tag)
189
293
  end
@@ -195,27 +299,10 @@ describe "CountrySelect" do
195
299
  expect(order).to eq(['AF', 'AX', 'AL', 'ZW'])
196
300
  end
197
301
 
198
- context "without sort_alphabetical" do
199
- before do
200
- Enumerable.send(:alias_method, :_sort_alphabetical, :sort_alphabetical)
201
- Enumerable.send(:remove_method, :sort_alphabetical)
202
- end
203
-
204
- after do
205
- Enumerable.send(:alias_method, :sort_alphabetical, :_sort_alphabetical)
206
- end
207
-
208
- it 'falls back to regular sort' do
209
- tag = builder.country_select(:country_code, only: ['AX', 'AL', 'AF', 'ZW'])
210
- order = tag.scan(/value="(\w{2})"/).map { |o| o[0] }
211
- expect(order).to eq(['AF', 'AL', 'ZW', 'AX'])
212
- end
213
- end
214
-
215
302
  describe "custom formats" do
216
303
  it "accepts a custom formatter" do
217
304
  ::CountrySelect::FORMATS[:with_alpha2] = lambda do |country|
218
- "#{country.name} (#{country.alpha2})"
305
+ "#{country.iso_short_name} (#{country.alpha2})"
219
306
  end
220
307
 
221
308
  tag = options_for_select([['United States of America (US)', 'US']], 'US')
@@ -227,7 +314,7 @@ describe "CountrySelect" do
227
314
 
228
315
  it "accepts an array for formatter" do
229
316
  ::CountrySelect::FORMATS[:with_alpha3] = lambda do |country|
230
- [country.name, country.alpha3]
317
+ [country.iso_short_name, country.alpha3]
231
318
  end
232
319
 
233
320
  tag = options_for_select([['United States of America', 'USA']], 'USA')
@@ -238,7 +325,7 @@ describe "CountrySelect" do
238
325
 
239
326
  it "accepts an array for formatter + custom formatter" do
240
327
  ::CountrySelect::FORMATS[:with_alpha3] = lambda do |country|
241
- ["#{country.name} (#{country.alpha2})", country.alpha3]
328
+ ["#{country.iso_short_name} (#{country.alpha2})", country.alpha3]
242
329
  end
243
330
 
244
331
  tag = options_for_select([['United States of America (US)', 'USA']], 'USA')
@@ -249,7 +336,7 @@ describe "CountrySelect" do
249
336
 
250
337
  it "marks priority countries as selected only once" do
251
338
  ::CountrySelect::FORMATS[:with_alpha3] = lambda do |country|
252
- [country.name, country.alpha3]
339
+ [country.iso_short_name, country.alpha3]
253
340
  end
254
341
 
255
342
  tag = options_for_select([['United States of America', 'USA']], 'USA')
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.0.0
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: 2018-12-20 00:00:00.000000000 Z
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: '5'
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: '5'
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: '0'
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: '0'
54
+ version: '13'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,50 +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
73
  - - "~>"
88
74
  - !ruby/object:Gem::Version
89
- version: '3.0'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '3.0'
97
- - !ruby/object:Gem::Dependency
98
- name: sort_alphabetical
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '1.0'
75
+ version: '5.0'
104
76
  type: :runtime
105
77
  prerelease: false
106
78
  version_requirements: !ruby/object:Gem::Requirement
107
79
  requirements:
108
80
  - - "~>"
109
81
  - !ruby/object:Gem::Version
110
- version: '1.0'
111
- description: Provides a simple helper to get an HTML select list of countries. The
112
- list of countries comes from the ISO 3166 standard. While it is a relatively neutral
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
113
85
  source of country names, it will still offend some users.
114
86
  email:
115
87
  - stefan.penner@gmail.com
@@ -117,9 +89,10 @@ executables: []
117
89
  extensions: []
118
90
  extra_rdoc_files: []
119
91
  files:
92
+ - ".github/workflows/build.yml"
93
+ - ".github/workflows/codeql-analysis.yml"
120
94
  - ".gitignore"
121
95
  - ".rspec"
122
- - ".travis.yml"
123
96
  - CHANGELOG.md
124
97
  - Gemfile
125
98
  - Gemfile.lock
@@ -128,36 +101,30 @@ files:
128
101
  - Rakefile
129
102
  - UPGRADING.md
130
103
  - country_select.gemspec
131
- - gemfiles/actionpack.edge.gemfile
132
- - gemfiles/actionpack.edge.gemfile.lock
133
- - gemfiles/actionpack3.2.gemfile
134
- - gemfiles/actionpack3.2.gemfile.lock
135
- - gemfiles/actionpack4.0.gemfile
136
- - gemfiles/actionpack4.0.gemfile.lock
137
- - gemfiles/actionpack4.1.gemfile
138
- - gemfiles/actionpack4.1.gemfile.lock
139
- - gemfiles/actionpack4.2.gemfile
140
- - gemfiles/actionpack4.2.gemfile.lock
141
- - gemfiles/actionpack5.0.gemfile
142
- - gemfiles/actionpack5.0.gemfile.lock
143
- - gemfiles/actionpack5.1.gemfile
144
- - gemfiles/actionpack5.1.gemfile.lock
145
- - gemfiles/actionpack5.2.gemfile
146
- - gemfiles/actionpack5.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
147
112
  - lib/country_select.rb
148
113
  - lib/country_select/country_select_helper.rb
114
+ - lib/country_select/defaults.rb
149
115
  - lib/country_select/formats.rb
150
- - lib/country_select/rails3/country_select_helper.rb
151
116
  - lib/country_select/tag_helper.rb
152
117
  - lib/country_select/version.rb
153
- - lib/country_select_without_sort_alphabetical.rb
154
118
  - spec/country_select_spec.rb
155
119
  - spec/spec_helper.rb
156
- homepage: https://github.com/stefanpenner/country_select
120
+ homepage: https://github.com/countries/country_select
157
121
  licenses:
158
122
  - MIT
159
- metadata: {}
160
- post_install_message:
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:
161
128
  rdoc_options: []
162
129
  require_paths:
163
130
  - lib
@@ -165,16 +132,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
165
132
  requirements:
166
133
  - - ">="
167
134
  - !ruby/object:Gem::Version
168
- version: '2'
135
+ version: '2.7'
169
136
  required_rubygems_version: !ruby/object:Gem::Requirement
170
137
  requirements:
171
138
  - - ">="
172
139
  - !ruby/object:Gem::Version
173
140
  version: '0'
174
141
  requirements: []
175
- rubyforge_project: country_select
176
- rubygems_version: 2.7.6
177
- signing_key:
142
+ rubygems_version: 3.4.2
143
+ signing_key:
178
144
  specification_version: 4
179
145
  summary: Country Select Plugin
180
146
  test_files:
data/.travis.yml DELETED
@@ -1,41 +0,0 @@
1
- sudo: false
2
- cache: bundler
3
- language: ruby
4
- script: "bundle exec rspec"
5
- rvm:
6
- - 2.0
7
- - 2.1
8
- - 2.2
9
- - 2.3
10
- - 2.4
11
- - 2.5
12
- - ruby-head
13
- gemfile:
14
- - gemfiles/actionpack3.2.gemfile
15
- - gemfiles/actionpack4.0.gemfile
16
- - gemfiles/actionpack4.1.gemfile
17
- - gemfiles/actionpack4.2.gemfile
18
- - gemfiles/actionpack5.0.gemfile
19
- - gemfiles/actionpack5.1.gemfile
20
- - gemfiles/actionpack5.2.gemfile
21
- - gemfiles/actionpack.edge.gemfile
22
- matrix:
23
- allow_failures:
24
- - rvm: ruby-head
25
- exclude:
26
- - rvm: 2.0
27
- gemfile: gemfiles/actionpack.edge.gemfile
28
- - rvm: 2.0
29
- gemfile: gemfiles/actionpack5.0.gemfile
30
- - rvm: 2.0
31
- gemfile: gemfiles/actionpack5.1.gemfile
32
- - rvm: 2.0
33
- gemfile: gemfiles/actionpack5.2.gemfile
34
- - rvm: 2.1
35
- gemfile: gemfiles/actionpack.edge.gemfile
36
- - rvm: 2.1
37
- gemfile: gemfiles/actionpack5.0.gemfile
38
- - rvm: 2.1
39
- gemfile: gemfiles/actionpack5.1.gemfile
40
- - rvm: 2.1
41
- gemfile: gemfiles/actionpack5.2.gemfile
@@ -1,15 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec :path => "../"
4
-
5
- git "https://github.com/rails/rails.git" do
6
- gem "actionpack"
7
- gem "actionview"
8
- gem "activesupport"
9
- end
10
-
11
- platforms :rbx do
12
- gem "racc"
13
- gem "rubysl", "~> 2.0"
14
- gem "psych"
15
- end