country_select 2.5.2 → 5.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path => "../"
4
+
5
+ gem "railties", "~> 6.0.2"
6
+ gem "actionpack", "~> 6.0.2"
@@ -0,0 +1,108 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ country_select (5.0.0.pre)
5
+ countries (~> 3.0)
6
+ sort_alphabetical (~> 1.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actionpack (6.0.3.5)
12
+ actionview (= 6.0.3.5)
13
+ activesupport (= 6.0.3.5)
14
+ rack (~> 2.0, >= 2.0.8)
15
+ rack-test (>= 0.6.3)
16
+ rails-dom-testing (~> 2.0)
17
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
18
+ actionview (6.0.3.5)
19
+ activesupport (= 6.0.3.5)
20
+ builder (~> 3.1)
21
+ erubi (~> 1.4)
22
+ rails-dom-testing (~> 2.0)
23
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
24
+ activesupport (6.0.3.5)
25
+ concurrent-ruby (~> 1.0, >= 1.0.2)
26
+ i18n (>= 0.7, < 2)
27
+ minitest (~> 5.1)
28
+ tzinfo (~> 1.1)
29
+ zeitwerk (~> 2.2, >= 2.2.2)
30
+ builder (3.2.4)
31
+ coderay (1.1.3)
32
+ concurrent-ruby (1.1.8)
33
+ countries (3.0.1)
34
+ i18n_data (~> 0.10.0)
35
+ sixarm_ruby_unaccent (~> 1.1)
36
+ unicode_utils (~> 1.4)
37
+ crass (1.0.6)
38
+ diff-lcs (1.4.4)
39
+ erubi (1.10.0)
40
+ i18n (1.8.9)
41
+ concurrent-ruby (~> 1.0)
42
+ i18n_data (0.10.0)
43
+ loofah (2.9.0)
44
+ crass (~> 1.0.2)
45
+ nokogiri (>= 1.5.9)
46
+ method_source (1.0.0)
47
+ mini_portile2 (2.5.0)
48
+ minitest (5.14.4)
49
+ nokogiri (1.11.1)
50
+ mini_portile2 (~> 2.5.0)
51
+ racc (~> 1.4)
52
+ pry (0.14.0)
53
+ coderay (~> 1.1)
54
+ method_source (~> 1.0)
55
+ racc (1.5.2)
56
+ rack (2.2.3)
57
+ rack-test (1.1.0)
58
+ rack (>= 1.0, < 3)
59
+ rails-dom-testing (2.0.3)
60
+ activesupport (>= 4.2.0)
61
+ nokogiri (>= 1.6)
62
+ rails-html-sanitizer (1.3.0)
63
+ loofah (~> 2.3)
64
+ railties (6.0.3.5)
65
+ actionpack (= 6.0.3.5)
66
+ activesupport (= 6.0.3.5)
67
+ method_source
68
+ rake (>= 0.8.7)
69
+ thor (>= 0.20.3, < 2.0)
70
+ rake (13.0.3)
71
+ rspec (3.10.0)
72
+ rspec-core (~> 3.10.0)
73
+ rspec-expectations (~> 3.10.0)
74
+ rspec-mocks (~> 3.10.0)
75
+ rspec-core (3.10.1)
76
+ rspec-support (~> 3.10.0)
77
+ rspec-expectations (3.10.1)
78
+ diff-lcs (>= 1.2.0, < 2.0)
79
+ rspec-support (~> 3.10.0)
80
+ rspec-mocks (3.10.2)
81
+ diff-lcs (>= 1.2.0, < 2.0)
82
+ rspec-support (~> 3.10.0)
83
+ rspec-support (3.10.2)
84
+ sixarm_ruby_unaccent (1.2.0)
85
+ sort_alphabetical (1.1.0)
86
+ unicode_utils (>= 1.2.2)
87
+ thor (1.1.0)
88
+ thread_safe (0.3.6)
89
+ tzinfo (1.2.9)
90
+ thread_safe (~> 0.1)
91
+ unicode_utils (1.4.0)
92
+ wwtd (1.4.1)
93
+ zeitwerk (2.4.2)
94
+
95
+ PLATFORMS
96
+ ruby
97
+
98
+ DEPENDENCIES
99
+ actionpack (~> 6.0.2)
100
+ country_select!
101
+ pry (~> 0)
102
+ railties (~> 6.0.2)
103
+ rake (~> 13)
104
+ rspec (~> 3)
105
+ wwtd (~> 1)
106
+
107
+ BUNDLED WITH
108
+ 2.2.13
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path => "../"
4
+
5
+ gem "railties", "~> 6.1.0"
6
+ gem "actionpack", "~> 6.1.0"
@@ -0,0 +1,107 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ country_select (5.0.0.pre)
5
+ countries (~> 3.0)
6
+ sort_alphabetical (~> 1.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actionpack (6.1.3)
12
+ actionview (= 6.1.3)
13
+ activesupport (= 6.1.3)
14
+ rack (~> 2.0, >= 2.0.9)
15
+ rack-test (>= 0.6.3)
16
+ rails-dom-testing (~> 2.0)
17
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
18
+ actionview (6.1.3)
19
+ activesupport (= 6.1.3)
20
+ builder (~> 3.1)
21
+ erubi (~> 1.4)
22
+ rails-dom-testing (~> 2.0)
23
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
24
+ activesupport (6.1.3)
25
+ concurrent-ruby (~> 1.0, >= 1.0.2)
26
+ i18n (>= 1.6, < 2)
27
+ minitest (>= 5.1)
28
+ tzinfo (~> 2.0)
29
+ zeitwerk (~> 2.3)
30
+ builder (3.2.4)
31
+ coderay (1.1.3)
32
+ concurrent-ruby (1.1.8)
33
+ countries (3.0.1)
34
+ i18n_data (~> 0.10.0)
35
+ sixarm_ruby_unaccent (~> 1.1)
36
+ unicode_utils (~> 1.4)
37
+ crass (1.0.6)
38
+ diff-lcs (1.4.4)
39
+ erubi (1.10.0)
40
+ i18n (1.8.9)
41
+ concurrent-ruby (~> 1.0)
42
+ i18n_data (0.10.0)
43
+ loofah (2.9.0)
44
+ crass (~> 1.0.2)
45
+ nokogiri (>= 1.5.9)
46
+ method_source (1.0.0)
47
+ mini_portile2 (2.5.0)
48
+ minitest (5.14.4)
49
+ nokogiri (1.11.1)
50
+ mini_portile2 (~> 2.5.0)
51
+ racc (~> 1.4)
52
+ pry (0.14.0)
53
+ coderay (~> 1.1)
54
+ method_source (~> 1.0)
55
+ racc (1.5.2)
56
+ rack (2.2.3)
57
+ rack-test (1.1.0)
58
+ rack (>= 1.0, < 3)
59
+ rails-dom-testing (2.0.3)
60
+ activesupport (>= 4.2.0)
61
+ nokogiri (>= 1.6)
62
+ rails-html-sanitizer (1.3.0)
63
+ loofah (~> 2.3)
64
+ railties (6.1.3)
65
+ actionpack (= 6.1.3)
66
+ activesupport (= 6.1.3)
67
+ method_source
68
+ rake (>= 0.8.7)
69
+ thor (~> 1.0)
70
+ rake (13.0.3)
71
+ rspec (3.10.0)
72
+ rspec-core (~> 3.10.0)
73
+ rspec-expectations (~> 3.10.0)
74
+ rspec-mocks (~> 3.10.0)
75
+ rspec-core (3.10.1)
76
+ rspec-support (~> 3.10.0)
77
+ rspec-expectations (3.10.1)
78
+ diff-lcs (>= 1.2.0, < 2.0)
79
+ rspec-support (~> 3.10.0)
80
+ rspec-mocks (3.10.2)
81
+ diff-lcs (>= 1.2.0, < 2.0)
82
+ rspec-support (~> 3.10.0)
83
+ rspec-support (3.10.2)
84
+ sixarm_ruby_unaccent (1.2.0)
85
+ sort_alphabetical (1.1.0)
86
+ unicode_utils (>= 1.2.2)
87
+ thor (1.1.0)
88
+ tzinfo (2.0.4)
89
+ concurrent-ruby (~> 1.0)
90
+ unicode_utils (1.4.0)
91
+ wwtd (1.4.1)
92
+ zeitwerk (2.4.2)
93
+
94
+ PLATFORMS
95
+ ruby
96
+
97
+ DEPENDENCIES
98
+ actionpack (~> 6.1.0)
99
+ country_select!
100
+ pry (~> 0)
101
+ railties (~> 6.1.0)
102
+ rake (~> 13)
103
+ rspec (~> 3)
104
+ wwtd (~> 1)
105
+
106
+ BUNDLED WITH
107
+ 2.2.13
@@ -6,9 +6,4 @@ require 'sort_alphabetical'
6
6
  require 'country_select/version'
7
7
  require 'country_select/formats'
8
8
  require 'country_select/tag_helper'
9
-
10
- if defined?(ActionView::Helpers::Tags::Base)
11
- require 'country_select/country_select_helper'
12
- else
13
- require 'country_select/rails3/country_select_helper'
14
- end
9
+ require 'country_select/country_select_helper'
@@ -2,6 +2,6 @@ module CountrySelect
2
2
  FORMATS = {}
3
3
 
4
4
  FORMATS[:default] = lambda do |country|
5
- country.translations[I18n.locale.to_s] || country.name
5
+ country.translations&.dig(I18n.locale.to_s) || country.name
6
6
  end
7
7
  end
@@ -2,8 +2,19 @@ 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 => @options.fetch(:selected) { value(@object) },
17
+ :selected => selected_option,
7
18
  :disabled => @options[:disabled]
8
19
  }
9
20
 
@@ -89,7 +100,11 @@ module CountrySelect
89
100
  end
90
101
 
91
102
  if sorted
92
- country_list.sort_alphabetical
103
+ if country_list.respond_to?(:sort_alphabetical)
104
+ country_list.sort_alphabetical
105
+ else
106
+ country_list.sort
107
+ end
93
108
  else
94
109
  country_list
95
110
  end
@@ -1,3 +1,3 @@
1
1
  module CountrySelect
2
- VERSION = "2.5.2"
2
+ VERSION = '5.0.0.pre'
3
3
  end
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+
3
+ require 'countries'
4
+
5
+ require 'country_select/version'
6
+ require 'country_select/formats'
7
+ require 'country_select/tag_helper'
8
+ require 'country_select/country_select_helper'
@@ -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)
@@ -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'
@@ -53,6 +62,9 @@ describe "CountrySelect" do
53
62
  end
54
63
 
55
64
  it "accepts a locale option" do
65
+ I18n.available_locales = [:fr]
66
+ ISO3166.reset
67
+
56
68
  tag = options_for_select([['États-Unis', 'US']], 'US')
57
69
 
58
70
  walrus.country_code = 'US'
@@ -88,7 +100,6 @@ describe "CountrySelect" do
88
100
 
89
101
  describe "when selected options is an array" do
90
102
  it "selects all options but only once" do
91
- tag = options_for_select([["United States", "US"],["Uruguay", "UY"],["Spain", "ES"]], "US")
92
103
  walrus.country_code = 'US'
93
104
  t = builder.country_select(:country_code, {priority_countries: ['LV','US','ES'], selected: ['UY', 'US']}, multiple: true)
94
105
  expect(t.scan(options_for_select([["United States", "US"]], "US")).length).to be(1)
@@ -171,7 +182,14 @@ describe "CountrySelect" do
171
182
  end
172
183
 
173
184
  it "supports the include_blank option" do
174
- tag = '<option value=""></option>'
185
+ # Rails 6.1 more closely follows the HTML spec for
186
+ # empty option tags.
187
+ # https://github.com/rails/rails/pull/39808
188
+ tag = if ActionView::VERSION::STRING >= '6.1'
189
+ '<option value="" label=" "></option>'
190
+ else
191
+ '<option value=""></option>'
192
+ end
175
193
  t = builder.country_select(:country_code, include_blank: true)
176
194
  expect(t).to include(tag)
177
195
  end
@@ -183,13 +201,30 @@ describe "CountrySelect" do
183
201
  expect(order).to eq(['AF', 'AX', 'AL', 'ZW'])
184
202
  end
185
203
 
204
+ context "without sort_alphabetical" do
205
+ before do
206
+ Enumerable.send(:alias_method, :_sort_alphabetical, :sort_alphabetical)
207
+ Enumerable.send(:remove_method, :sort_alphabetical)
208
+ end
209
+
210
+ after do
211
+ Enumerable.send(:alias_method, :sort_alphabetical, :_sort_alphabetical)
212
+ end
213
+
214
+ it 'falls back to regular sort' do
215
+ tag = builder.country_select(:country_code, only: ['AX', 'AL', 'AF', 'ZW'])
216
+ order = tag.scan(/value="(\w{2})"/).map { |o| o[0] }
217
+ expect(order).to eq(['AF', 'AL', 'ZW', 'AX'])
218
+ end
219
+ end
220
+
186
221
  describe "custom formats" do
187
222
  it "accepts a custom formatter" do
188
223
  ::CountrySelect::FORMATS[:with_alpha2] = lambda do |country|
189
224
  "#{country.name} (#{country.alpha2})"
190
225
  end
191
226
 
192
- tag = options_for_select([['United States (US)', 'US']], 'US')
227
+ tag = options_for_select([['United States of America (US)', 'US']], 'US')
193
228
 
194
229
  walrus.country_code = 'US'
195
230
  t = builder.country_select(:country_code, format: :with_alpha2)
@@ -201,7 +236,7 @@ describe "CountrySelect" do
201
236
  [country.name, country.alpha3]
202
237
  end
203
238
 
204
- tag = options_for_select([['United States', 'USA']], 'USA')
239
+ tag = options_for_select([['United States of America', 'USA']], 'USA')
205
240
  walrus.country_code = 'USA'
206
241
  t = builder.country_select(:country_code, format: :with_alpha3)
207
242
  expect(t).to include(tag)
@@ -212,7 +247,7 @@ describe "CountrySelect" do
212
247
  ["#{country.name} (#{country.alpha2})", country.alpha3]
213
248
  end
214
249
 
215
- tag = options_for_select([['United States (US)', 'USA']], 'USA')
250
+ tag = options_for_select([['United States of America (US)', 'USA']], 'USA')
216
251
  walrus.country_code = 'USA'
217
252
  t = builder.country_select(:country_code, format: :with_alpha3)
218
253
  expect(t).to include(tag)
@@ -223,7 +258,7 @@ describe "CountrySelect" do
223
258
  [country.name, country.alpha3]
224
259
  end
225
260
 
226
- tag = options_for_select([['United States', 'USA']], 'USA')
261
+ tag = options_for_select([['United States of America', 'USA']], 'USA')
227
262
  walrus.country_code = 'USA'
228
263
  t = builder.country_select(:country_code, format: :with_alpha3, priority_countries: ['US'])
229
264
  expect(t.scan(Regexp.new(Regexp.escape(tag))).size).to eq 1
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: 2.5.2
4
+ version: 5.0.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Penner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-03 00:00:00.000000000 Z
11
+ date: 2021-03-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: '3'
19
+ version: '6.1'
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: '3'
26
+ version: '6.1'
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
@@ -70,46 +70,46 @@ dependencies:
70
70
  name: wwtd
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '1'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '1'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: countries
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 1.2.0
89
+ version: '3.0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 1.2.0
96
+ version: '3.0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: sort_alphabetical
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '1.0'
103
+ version: '1.1'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !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
110
+ version: '1.1'
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
113
113
  source of country names, it will still offend some users.
114
114
  email:
115
115
  - stefan.penner@gmail.com
@@ -130,20 +130,18 @@ files:
130
130
  - country_select.gemspec
131
131
  - gemfiles/actionpack.edge.gemfile
132
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
133
+ - gemfiles/actionpack5.2.gemfile
134
+ - gemfiles/actionpack5.2.gemfile.lock
135
+ - gemfiles/actionpack6.0.gemfile
136
+ - gemfiles/actionpack6.0.gemfile.lock
137
+ - gemfiles/actionpack6.1.gemfile
138
+ - gemfiles/actionpack6.1.gemfile.lock
141
139
  - lib/country_select.rb
142
140
  - lib/country_select/country_select_helper.rb
143
141
  - lib/country_select/formats.rb
144
- - lib/country_select/rails3/country_select_helper.rb
145
142
  - lib/country_select/tag_helper.rb
146
143
  - lib/country_select/version.rb
144
+ - lib/country_select_without_sort_alphabetical.rb
147
145
  - spec/country_select_spec.rb
148
146
  - spec/spec_helper.rb
149
147
  homepage: https://github.com/stefanpenner/country_select
@@ -158,15 +156,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
156
  requirements:
159
157
  - - ">="
160
158
  - !ruby/object:Gem::Version
161
- version: '0'
159
+ version: '2.5'
162
160
  required_rubygems_version: !ruby/object:Gem::Requirement
163
161
  requirements:
164
- - - ">="
162
+ - - ">"
165
163
  - !ruby/object:Gem::Version
166
- version: '0'
164
+ version: 1.3.1
167
165
  requirements: []
168
- rubyforge_project: country_select
169
- rubygems_version: 2.4.5.1
166
+ rubygems_version: 3.2.13
170
167
  signing_key:
171
168
  specification_version: 4
172
169
  summary: Country Select Plugin