country_select 8.0.1 → 8.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,15 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
5
  require 'action_view'
6
6
  require 'country_select'
7
7
 
8
- describe "CountrySelect" do
8
+ class Walrus
9
+ attr_accessor :country_code
10
+ end
11
+
12
+ describe 'CountrySelect' do
9
13
  include ActionView::Helpers::TagHelper
10
14
  include ActionView::Helpers::FormOptionsHelper
11
15
 
@@ -15,10 +19,6 @@ describe "CountrySelect" do
15
19
  ISO3166.reset
16
20
  end
17
21
 
18
- class Walrus
19
- attr_accessor :country_code
20
- end
21
-
22
22
  let(:walrus) { Walrus.new }
23
23
  let!(:template) { ActionView::Base.new(ActionView::LookupContext.new([]), {}, nil) }
24
24
 
@@ -26,17 +26,17 @@ describe "CountrySelect" do
26
26
  if defined?(ActionView::Helpers::Tags::Base)
27
27
  ActionView::Helpers::FormBuilder.new(:walrus, walrus, template, {})
28
28
  else
29
- ActionView::Helpers::FormBuilder.new(:walrus, walrus, template, {}, Proc.new { })
29
+ ActionView::Helpers::FormBuilder.new(:walrus, walrus, template, {}, proc {})
30
30
  end
31
31
  end
32
32
 
33
33
  let(:select_tag) do
34
- <<-EOS.chomp.strip
34
+ <<-HTML.chomp.strip
35
35
  <select id="walrus_country_code" name="walrus[country_code]">
36
- EOS
36
+ HTML
37
37
  end
38
38
 
39
- it "selects the value of country_code" do
39
+ it 'selects the value of country_code' do
40
40
  tag = options_for_select([['United States', 'US']], 'US')
41
41
 
42
42
  walrus.country_code = 'US'
@@ -44,8 +44,8 @@ describe "CountrySelect" do
44
44
  expect(t).to include(tag)
45
45
  end
46
46
 
47
- it "uses the locale specified by I18n.locale" do
48
- I18n.available_locales = [:en, :es]
47
+ it 'uses the locale specified by I18n.locale' do
48
+ I18n.available_locales = %i[en es]
49
49
  ISO3166.reset
50
50
 
51
51
  tag = options_for_select([['Estados Unidos', 'US']], 'US')
@@ -62,10 +62,10 @@ describe "CountrySelect" do
62
62
  end
63
63
 
64
64
  it 'falls back when given a country-specific locale' do
65
- I18n.available_locales = [:en, :de, :'de-AT']
65
+ I18n.available_locales = %i[en de de-AT]
66
66
  ISO3166.reset
67
67
 
68
- tag = options_for_select([['Deutschland', 'DE']], 'DE')
68
+ tag = options_for_select([%w[Deutschland DE]], 'DE')
69
69
 
70
70
  walrus.country_code = 'DE'
71
71
  original_locale = I18n.locale
@@ -78,140 +78,142 @@ describe "CountrySelect" do
78
78
  end
79
79
  end
80
80
 
81
- it "accepts a locale option" do
81
+ it 'accepts a locale option' do
82
82
  I18n.available_locales = [:fr]
83
83
  ISO3166.reset
84
84
 
85
- tag = options_for_select([['États-Unis', 'US']], 'US')
85
+ tag = options_for_select([%w[États-Unis US]], 'US')
86
86
 
87
87
  walrus.country_code = 'US'
88
88
  t = builder.country_select(:country_code, locale: :fr)
89
89
  expect(t).to include(tag)
90
90
  end
91
91
 
92
- it "accepts priority countries" do
92
+ it 'accepts priority countries' do
93
93
  tag = options_for_select(
94
94
  [
95
95
  ['Denmark', 'DK'],
96
- ['Latvia','LV'],
97
- ['United States','US'],
98
- ['-'*15,'-'*15]
96
+ ['Latvia', 'LV'],
97
+ ['United States', 'US'],
98
+ ['-' * 15, '-' * 15]
99
99
  ],
100
100
  selected: 'US',
101
- disabled: '-'*15
101
+ disabled: '-' * 15
102
102
  )
103
103
 
104
104
  walrus.country_code = 'US'
105
- t = builder.country_select(:country_code, priority_countries: ['LV','US','DK'])
105
+ t = builder.country_select(:country_code, priority_countries: %w[LV US DK])
106
106
  expect(t).to include(tag)
107
107
  end
108
108
 
109
- it "priority countries are sorted by name by default" do
109
+ it 'priority countries are sorted by name by default' do
110
110
  tag = options_for_select(
111
111
  [
112
112
  ['Denmark', 'DK'],
113
- ['Latvia','LV'],
114
- ['United States','US'],
115
- ['-'*15,'-'*15]
113
+ ['Latvia', 'LV'],
114
+ ['United States', 'US'],
115
+ ['-' * 15, '-' * 15]
116
116
  ],
117
117
  selected: 'US',
118
- disabled: '-'*15
118
+ disabled: '-' * 15
119
119
  )
120
120
 
121
121
  walrus.country_code = 'US'
122
- t = builder.country_select(:country_code, priority_countries: ['LV','US','DK'])
122
+ t = builder.country_select(:country_code, priority_countries: %w[LV US DK])
123
123
  expect(t).to include(tag)
124
124
  end
125
125
 
126
- it "priority countries with `sort_provided: false` preserves the provided order" do
126
+ it 'priority countries with `sort_provided: false` preserves the provided order' do
127
127
  tag = options_for_select(
128
128
  [
129
- ['Latvia','LV'],
130
- ['United States','US'],
129
+ ['Latvia', 'LV'],
130
+ ['United States', 'US'],
131
131
  ['Denmark', 'DK'],
132
- ['-'*15,'-'*15]
132
+ ['-' * 15, '-' * 15]
133
133
  ],
134
134
  selected: 'US',
135
- disabled: '-'*15
135
+ disabled: '-' * 15
136
136
  )
137
137
 
138
138
  walrus.country_code = 'US'
139
- t = builder.country_select(:country_code, priority_countries: ['LV','US','DK'], sort_provided: false)
139
+ t = builder.country_select(:country_code, priority_countries: %w[LV US DK], sort_provided: false)
140
140
  expect(t).to include(tag)
141
141
  end
142
142
 
143
- it "priority countries with `sort_provided: false` still sorts the non-priority countries by name" do
143
+ it 'priority countries with `sort_provided: false` still sorts the non-priority countries by name' do
144
144
  tag = options_for_select(
145
145
  [
146
- ['Latvia','LV'],
147
- ['United States','US'],
146
+ ['Latvia', 'LV'],
147
+ ['United States', 'US'],
148
148
  ['Denmark', 'DK'],
149
- ['-'*15,'-'*15],
150
- ['Afghanistan','AF']
149
+ ['-' * 15, '-' * 15],
150
+ ['Afghanistan', 'AF']
151
151
  ],
152
152
  selected: 'AF',
153
- disabled: '-'*15
153
+ disabled: '-' * 15
154
154
  )
155
155
 
156
156
  walrus.country_code = 'AF'
157
- t = builder.country_select(:country_code, priority_countries: ['LV','US','DK'], sort_provided: false)
157
+ t = builder.country_select(:country_code, priority_countries: %w[LV US DK], sort_provided: false)
158
158
  expect(t).to include(tag)
159
159
  end
160
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")
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
164
  walrus.country_code = 'US'
165
- t = builder.country_select(:country_code, priority_countries: ['LV','US'])
165
+ t = builder.country_select(:country_code, priority_countries: %w[LV US])
166
166
  expect(t).to_not include(tag)
167
167
  end
168
168
  end
169
169
 
170
- describe "when selected options is an array" do
171
- it "selects all options but only once" do
170
+ describe 'when selected options is an array' do
171
+ it 'selects all options but only once' do
172
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)
173
+ t = builder.country_select(:country_code,
174
+ { priority_countries: %w[LV US ES], selected: %w[UY US] },
175
+ multiple: true)
176
+ expect(t.scan(options_for_select([['United States', 'US']], 'US')).length).to be(1)
177
+ expect(t.scan(options_for_select([%w[Uruguay UY]], 'UY')).length).to be(1)
176
178
  end
177
179
  end
178
180
 
179
- it "displays only the chosen countries" do
180
- options = [["Denmark", "DK"],["Germany", "DE"]]
181
+ it 'displays only the chosen countries' do
182
+ options = [%w[Denmark DK], %w[Germany DE]]
181
183
  tag = builder.select(:country_code, options)
182
184
  walrus.country_code = 'US'
183
- t = builder.country_select(:country_code, only: ['DK','DE'])
185
+ t = builder.country_select(:country_code, only: %w[DK DE])
184
186
  expect(t).to eql(tag)
185
187
  end
186
188
 
187
- it "discards some countries" do
188
- tag = options_for_select([["United States", "US"]])
189
+ it 'discards some countries' do
190
+ tag = options_for_select([['United States', 'US']])
189
191
  walrus.country_code = 'DE'
190
192
  t = builder.country_select(:country_code, except: ['US'])
191
193
  expect(t).to_not include(tag)
192
194
  end
193
195
 
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
+ it 'countries provided in `only` are sorted by name by default' do
197
+ t = builder.country_select(:country_code, only: %w[PT DE AR])
196
198
  order = t.scan(/value="(\w{2})"/).map { |o| o[0] }
197
- expect(order).to eq(['AR', 'DE', 'PT'])
199
+ expect(order).to eq(%w[AR DE PT])
198
200
  end
199
201
 
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
+ it 'countries provided in `only` with `sort_provided` to false keeps the order of the provided countries' do
203
+ t = builder.country_select(:country_code, only: %w[PT DE AR], sort_provided: false)
202
204
  order = t.scan(/value="(\w{2})"/).map { |o| o[0] }
203
- expect(order).to eq(['PT','DE','AR'])
205
+ expect(order).to eq(%w[PT DE AR])
204
206
  end
205
207
 
206
208
  context "when there is a default 'except' configured" do
207
209
  around do |example|
208
- old_value = ::CountrySelect::DEFAULTS[:except]
210
+ old_value = CountrySelect::DEFAULTS[:except]
209
211
  example.run
210
- ::CountrySelect::DEFAULTS[:except] = old_value
212
+ CountrySelect::DEFAULTS[:except] = old_value
211
213
  end
212
214
 
213
- it "discards countries when configured to" do
214
- ::CountrySelect::DEFAULTS[:except] = ['US']
215
+ it 'discards countries when configured to' do
216
+ CountrySelect::DEFAULTS[:except] = ['US']
215
217
 
216
218
  tag = options_for_select([['United States', 'US']])
217
219
  walrus.country_code = 'DE'
@@ -220,51 +222,49 @@ describe "CountrySelect" do
220
222
  end
221
223
  end
222
224
 
223
- context "using old 1.x syntax" do
224
- it "accepts priority countries" do
225
+ context 'using old 1.x syntax' do
226
+ it 'accepts priority countries' do
225
227
  tag = options_for_select(
226
228
  [
227
229
  ['Denmark', 'DK'],
228
- ['Latvia','LV'],
229
- ['United States','US'],
230
- ['-'*15,'-'*15]
230
+ ['Latvia', 'LV'],
231
+ ['United States', 'US'],
232
+ ['-' * 15, '-' * 15]
231
233
  ],
232
234
  selected: 'US',
233
- disabled: '-'*15
235
+ disabled: '-' * 15
234
236
  )
235
237
 
236
238
  walrus.country_code = 'US'
237
- t = builder.country_select(:country_code, ['LV','US','DK'])
239
+ t = builder.country_select(:country_code, %w[LV US DK])
238
240
  expect(t).to include(tag)
239
241
  end
240
242
 
241
- it "selects only the first matching option" do
242
- tag = options_for_select([["United States", "US"],["Uruguay", "UY"]], "US")
243
+ it 'selects only the first matching option' do
244
+ tag = options_for_select([['United States', 'US'], ['Uruguay', 'UY']], 'US')
243
245
  walrus.country_code = 'US'
244
- t = builder.country_select(:country_code, ['LV','US'])
246
+ t = builder.country_select(:country_code, %w[LV US])
245
247
  expect(t).to_not include(tag)
246
248
  end
247
249
 
248
- it "supports the country names as provided by default in Formtastic" do
249
- tag = options_for_select([
250
- ["Australia", "AU"],
251
- ["Canada", "CA"],
252
- ["United Kingdom", "GB"],
253
- ["United States", "US"]
254
- ])
255
- country_names = ["Australia", "Canada", "United Kingdom", "United States"]
250
+ it 'supports the country names as provided by default in Formtastic' do
251
+ tag = options_for_select([['Australia', 'AU'],
252
+ ['Canada', 'CA'],
253
+ ['United Kingdom', 'GB'],
254
+ ['United States', 'US']])
255
+ country_names = ['Australia', 'Canada', 'United Kingdom', 'United States']
256
256
  t = builder.country_select(:country_code, country_names)
257
257
  expect(t).to include(tag)
258
258
  end
259
259
 
260
- it "raises an error when a country code or name is not found" do
260
+ it 'raises an error when a country code or name is not found' do
261
261
  country_names = [
262
- "United States",
263
- "Canada",
264
- "United Kingdom",
265
- "Mexico",
266
- "Australia",
267
- "Freedonia"
262
+ 'United States',
263
+ 'Canada',
264
+ 'United Kingdom',
265
+ 'Mexico',
266
+ 'Australia',
267
+ 'Freedonia'
268
268
  ]
269
269
  error_msg = "Could not find Country with string 'Freedonia'"
270
270
 
@@ -273,13 +273,13 @@ describe "CountrySelect" do
273
273
  end.to raise_error(CountrySelect::CountryNotFoundError, error_msg)
274
274
  end
275
275
 
276
- it "supports the select prompt" do
276
+ it 'supports the select prompt' do
277
277
  tag = '<option value="">Select your country</option>'
278
278
  t = builder.country_select(:country_code, prompt: 'Select your country')
279
279
  expect(t).to include(tag)
280
280
  end
281
281
 
282
- it "supports the include_blank option" do
282
+ it 'supports the include_blank option' do
283
283
  # Rails 6.1 more closely follows the HTML spec for
284
284
  # empty option tags.
285
285
  # https://github.com/rails/rails/pull/39808
@@ -294,14 +294,14 @@ describe "CountrySelect" do
294
294
  end
295
295
 
296
296
  it 'sorts unicode' do
297
- tag = builder.country_select(:country_code, only: ['AX', 'AL', 'AF', 'ZW'])
297
+ tag = builder.country_select(:country_code, only: %w[AX AL AF ZW])
298
298
  order = tag.scan(/value="(\w{2})"/).map { |o| o[0] }
299
- expect(order).to eq(['AF', 'AX', 'AL', 'ZW'])
299
+ expect(order).to eq(%w[AF AX AL ZW])
300
300
  end
301
301
 
302
- describe "custom formats" do
303
- it "accepts a custom formatter" do
304
- ::CountrySelect::FORMATS[:with_alpha2] = lambda do |country|
302
+ describe 'custom formats' do
303
+ it 'accepts a custom formatter' do
304
+ CountrySelect::FORMATS[:with_alpha2] = lambda do |country|
305
305
  "#{country.iso_short_name} (#{country.alpha2})"
306
306
  end
307
307
 
@@ -312,8 +312,8 @@ describe "CountrySelect" do
312
312
  expect(t).to include(tag)
313
313
  end
314
314
 
315
- it "accepts an array for formatter" do
316
- ::CountrySelect::FORMATS[:with_alpha3] = lambda do |country|
315
+ it 'accepts an array for formatter' do
316
+ CountrySelect::FORMATS[:with_alpha3] = lambda do |country|
317
317
  [country.iso_short_name, country.alpha3]
318
318
  end
319
319
 
@@ -323,8 +323,8 @@ describe "CountrySelect" do
323
323
  expect(t).to include(tag)
324
324
  end
325
325
 
326
- it "accepts an array for formatter + custom formatter" do
327
- ::CountrySelect::FORMATS[:with_alpha3] = lambda do |country|
326
+ it 'accepts an array for formatter + custom formatter' do
327
+ CountrySelect::FORMATS[:with_alpha3] = lambda do |country|
328
328
  ["#{country.iso_short_name} (#{country.alpha2})", country.alpha3]
329
329
  end
330
330
 
@@ -334,8 +334,8 @@ describe "CountrySelect" do
334
334
  expect(t).to include(tag)
335
335
  end
336
336
 
337
- it "marks priority countries as selected only once" do
338
- ::CountrySelect::FORMATS[:with_alpha3] = lambda do |country|
337
+ it 'marks priority countries as selected only once' do
338
+ CountrySelect::FORMATS[:with_alpha3] = lambda do |country|
339
339
  [country.iso_short_name, country.alpha3]
340
340
  end
341
341
 
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pry'
4
+ require 'simplecov'
5
+ SimpleCov.start
2
6
 
3
7
  # This file was generated by the `rspec --init` command. Conventionally, all
4
8
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
@@ -55,11 +59,11 @@ RSpec.configure do |config|
55
59
  # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
56
60
  # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
57
61
  # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
58
- #config.disable_monkey_patching!
62
+ # config.disable_monkey_patching!
59
63
 
60
64
  # This setting enables warnings. It's recommended, but in some cases may
61
65
  # be too noisy due to issues in dependencies.
62
- #config.warnings = true
66
+ # config.warnings = true
63
67
 
64
68
  # Many RSpec users commonly either run the entire suite or an individual
65
69
  # file, and it's useful to allow more verbose output when running an
@@ -74,7 +78,7 @@ RSpec.configure do |config|
74
78
  # Print the 10 slowest examples and example groups at the
75
79
  # end of the spec run, to help surface which specs are running
76
80
  # particularly slow.
77
- #config.profile_examples = 10
81
+ # config.profile_examples = 10
78
82
 
79
83
  # Run specs in random order to surface order dependencies. If you find an
80
84
  # order dependency and want to debug it, you can fix the order by providing
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: 8.0.1
4
+ version: 8.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Penner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-03 00:00:00.000000000 Z
11
+ date: 2023-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.22'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.22'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: countries
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -80,19 +94,22 @@ dependencies:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
96
  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
85
- source of country names, it will still offend some users.
97
+ description: |-
98
+ Provides a simple helper to get an HTML select list of countries. \
99
+ The list of countries comes from the ISO 3166 standard. \
100
+ While it is a relatively neutral source of country names, it will still offend some users.
86
101
  email:
87
102
  - stefan.penner@gmail.com
88
103
  executables: []
89
104
  extensions: []
90
105
  extra_rdoc_files: []
91
106
  files:
92
- - ".github/workflows/build.yml"
107
+ - ".codeclimate.yml"
93
108
  - ".github/workflows/codeql-analysis.yml"
109
+ - ".github/workflows/test.yml"
94
110
  - ".gitignore"
95
111
  - ".rspec"
112
+ - ".rubocop.yml"
96
113
  - CHANGELOG.md
97
114
  - Gemfile
98
115
  - Gemfile.lock
@@ -109,6 +126,8 @@ files:
109
126
  - gemfiles/actionpack-6.1.gemfile.lock
110
127
  - gemfiles/actionpack-7.0.gemfile
111
128
  - gemfiles/actionpack-7.0.gemfile.lock
129
+ - gemfiles/actionpack-7.1.gemfile
130
+ - gemfiles/actionpack-7.1.gemfile.lock
112
131
  - lib/country_select.rb
113
132
  - lib/country_select/country_select_helper.rb
114
133
  - lib/country_select/defaults.rb
@@ -124,6 +143,7 @@ metadata:
124
143
  bug_tracker_uri: http://github.com/countries/country_select/issues
125
144
  changelog_uri: https://github.com/countries/country_select/blob/master/CHANGELOG.md
126
145
  source_code_uri: https://github.com/countries/country_select
146
+ rubygems_mfa_required: 'true'
127
147
  post_install_message:
128
148
  rdoc_options: []
129
149
  require_paths:
@@ -139,10 +159,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
159
  - !ruby/object:Gem::Version
140
160
  version: '0'
141
161
  requirements: []
142
- rubygems_version: 3.4.2
162
+ rubygems_version: 3.4.12
143
163
  signing_key:
144
164
  specification_version: 4
145
165
  summary: Country Select Plugin
146
- test_files:
147
- - spec/country_select_spec.rb
148
- - spec/spec_helper.rb
166
+ test_files: []
@@ -1,25 +0,0 @@
1
- name: build
2
- on:
3
- pull_request:
4
- branches:
5
- - '*'
6
- push:
7
- branches:
8
- - master
9
- jobs:
10
- build:
11
- runs-on: ubuntu-latest
12
- strategy:
13
- fail-fast: false
14
- matrix:
15
- ruby: [2.7, '3.0', 3.1, 3.2]
16
- gemfile: [5.2, '6.0', 6.1, '7.0']
17
- env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
18
- BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/actionpack-${{ matrix.gemfile }}.gemfile
19
- steps:
20
- - uses: actions/checkout@v3
21
- - uses: ruby/setup-ruby@v1
22
- with:
23
- ruby-version: ${{ matrix.ruby }}
24
- bundler-cache: true
25
- - run: bundle exec rake