country_select 1.1.3 → 2.5.2

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.
@@ -0,0 +1,232 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ require 'action_view'
6
+ require 'country_select'
7
+
8
+ describe "CountrySelect" do
9
+ include ActionView::Helpers::TagHelper
10
+ include ActionView::Helpers::FormOptionsHelper
11
+
12
+ class Walrus
13
+ attr_accessor :country_code
14
+ end
15
+
16
+ let(:walrus) { Walrus.new }
17
+ let!(:template) { ActionView::Base.new }
18
+
19
+ let(:builder) do
20
+ if defined?(ActionView::Helpers::Tags::Base)
21
+ ActionView::Helpers::FormBuilder.new(:walrus, walrus, template, {})
22
+ else
23
+ ActionView::Helpers::FormBuilder.new(:walrus, walrus, template, {}, Proc.new { })
24
+ end
25
+ end
26
+
27
+ let(:select_tag) do
28
+ <<-EOS.chomp.strip
29
+ <select id="walrus_country_code" name="walrus[country_code]">
30
+ EOS
31
+ end
32
+
33
+ it "selects the value of country_code" do
34
+ tag = options_for_select([['United States', 'US']], 'US')
35
+
36
+ walrus.country_code = 'US'
37
+ t = builder.country_select(:country_code)
38
+ expect(t).to include(tag)
39
+ end
40
+
41
+ it "uses the locale specified by I18n.locale" do
42
+ tag = options_for_select([['Estados Unidos', 'US']], 'US')
43
+
44
+ walrus.country_code = 'US'
45
+ original_locale = I18n.locale
46
+ begin
47
+ I18n.locale = :es
48
+ t = builder.country_select(:country_code)
49
+ expect(t).to include(tag)
50
+ ensure
51
+ I18n.locale = original_locale
52
+ end
53
+ end
54
+
55
+ it "accepts a locale option" do
56
+ tag = options_for_select([['États-Unis', 'US']], 'US')
57
+
58
+ walrus.country_code = 'US'
59
+ t = builder.country_select(:country_code, locale: :fr)
60
+ expect(t).to include(tag)
61
+ end
62
+
63
+ it "accepts priority countries" do
64
+ tag = options_for_select(
65
+ [
66
+ ['Latvia','LV'],
67
+ ['United States','US'],
68
+ ['Denmark', 'DK'],
69
+ ['-'*15,'-'*15]
70
+ ],
71
+ selected: 'US',
72
+ disabled: '-'*15
73
+ )
74
+
75
+ walrus.country_code = 'US'
76
+ t = builder.country_select(:country_code, priority_countries: ['LV','US','DK'])
77
+ expect(t).to include(tag)
78
+ end
79
+
80
+ describe "when selected options is not an array" do
81
+ it "selects only the first matching option" do
82
+ tag = options_for_select([["United States", "US"],["Uruguay", "UY"]], "US")
83
+ walrus.country_code = 'US'
84
+ t = builder.country_select(:country_code, priority_countries: ['LV','US'])
85
+ expect(t).to_not include(tag)
86
+ end
87
+ end
88
+
89
+ describe "when selected options is an array" do
90
+ it "selects all options but only once" do
91
+ tag = options_for_select([["United States", "US"],["Uruguay", "UY"],["Spain", "ES"]], "US")
92
+ walrus.country_code = 'US'
93
+ t = builder.country_select(:country_code, {priority_countries: ['LV','US','ES'], selected: ['UY', 'US']}, multiple: true)
94
+ expect(t.scan(options_for_select([["United States", "US"]], "US")).length).to be(1)
95
+ expect(t.scan(options_for_select([["Uruguay", "UY"]], "UY")).length).to be(1)
96
+ end
97
+ end
98
+
99
+ it "displays only the chosen countries" do
100
+ options = [["Denmark", "DK"],["Germany", "DE"]]
101
+ tag = builder.select(:country_code, options)
102
+ walrus.country_code = 'US'
103
+ t = builder.country_select(:country_code, only: ['DK','DE'])
104
+ expect(t).to eql(tag)
105
+ end
106
+
107
+ it "discards some countries" do
108
+ tag = options_for_select([["United States", "US"]])
109
+ walrus.country_code = 'DE'
110
+ t = builder.country_select(:country_code, except: ['US'])
111
+ expect(t).to_not include(tag)
112
+ end
113
+
114
+ context "using old 1.x syntax" do
115
+ it "accepts priority countries" do
116
+ tag = options_for_select(
117
+ [
118
+ ['Latvia','LV'],
119
+ ['United States','US'],
120
+ ['Denmark', 'DK'],
121
+ ['-'*15,'-'*15]
122
+ ],
123
+ selected: 'US',
124
+ disabled: '-'*15
125
+ )
126
+
127
+ walrus.country_code = 'US'
128
+ t = builder.country_select(:country_code, ['LV','US','DK'])
129
+ expect(t).to include(tag)
130
+ end
131
+
132
+ it "selects only the first matching option" do
133
+ tag = options_for_select([["United States", "US"],["Uruguay", "UY"]], "US")
134
+ walrus.country_code = 'US'
135
+ t = builder.country_select(:country_code, ['LV','US'])
136
+ expect(t).to_not include(tag)
137
+ end
138
+
139
+ it "supports the country names as provided by default in Formtastic" do
140
+ tag = options_for_select([
141
+ ["Australia", "AU"],
142
+ ["Canada", "CA"],
143
+ ["United Kingdom", "GB"],
144
+ ["United States", "US"]
145
+ ])
146
+ country_names = ["Australia", "Canada", "United Kingdom", "United States"]
147
+ t = builder.country_select(:country_code, country_names)
148
+ expect(t).to include(tag)
149
+ end
150
+
151
+ it "raises an error when a country code or name is not found" do
152
+ country_names = [
153
+ "United States",
154
+ "Canada",
155
+ "United Kingdom",
156
+ "Mexico",
157
+ "Australia",
158
+ "Freedonia"
159
+ ]
160
+ error_msg = "Could not find Country with string 'Freedonia'"
161
+
162
+ expect do
163
+ builder.country_select(:country_code, country_names)
164
+ end.to raise_error(CountrySelect::CountryNotFoundError, error_msg)
165
+ end
166
+
167
+ it "supports the select prompt" do
168
+ tag = '<option value="">Select your country</option>'
169
+ t = builder.country_select(:country_code, prompt: 'Select your country')
170
+ expect(t).to include(tag)
171
+ end
172
+
173
+ it "supports the include_blank option" do
174
+ tag = '<option value=""></option>'
175
+ t = builder.country_select(:country_code, include_blank: true)
176
+ expect(t).to include(tag)
177
+ end
178
+ end
179
+
180
+ it 'sorts unicode' do
181
+ tag = builder.country_select(:country_code, only: ['AX', 'AL', 'AF', 'ZW'])
182
+ order = tag.scan(/value="(\w{2})"/).map { |o| o[0] }
183
+ expect(order).to eq(['AF', 'AX', 'AL', 'ZW'])
184
+ end
185
+
186
+ describe "custom formats" do
187
+ it "accepts a custom formatter" do
188
+ ::CountrySelect::FORMATS[:with_alpha2] = lambda do |country|
189
+ "#{country.name} (#{country.alpha2})"
190
+ end
191
+
192
+ tag = options_for_select([['United States (US)', 'US']], 'US')
193
+
194
+ walrus.country_code = 'US'
195
+ t = builder.country_select(:country_code, format: :with_alpha2)
196
+ expect(t).to include(tag)
197
+ end
198
+
199
+ it "accepts an array for formatter" do
200
+ ::CountrySelect::FORMATS[:with_alpha3] = lambda do |country|
201
+ [country.name, country.alpha3]
202
+ end
203
+
204
+ tag = options_for_select([['United States', 'USA']], 'USA')
205
+ walrus.country_code = 'USA'
206
+ t = builder.country_select(:country_code, format: :with_alpha3)
207
+ expect(t).to include(tag)
208
+ end
209
+
210
+ it "accepts an array for formatter + custom formatter" do
211
+ ::CountrySelect::FORMATS[:with_alpha3] = lambda do |country|
212
+ ["#{country.name} (#{country.alpha2})", country.alpha3]
213
+ end
214
+
215
+ tag = options_for_select([['United States (US)', 'USA']], 'USA')
216
+ walrus.country_code = 'USA'
217
+ t = builder.country_select(:country_code, format: :with_alpha3)
218
+ expect(t).to include(tag)
219
+ end
220
+
221
+ it "marks priority countries as selected only once" do
222
+ ::CountrySelect::FORMATS[:with_alpha3] = lambda do |country|
223
+ [country.name, country.alpha3]
224
+ end
225
+
226
+ tag = options_for_select([['United States', 'USA']], 'USA')
227
+ walrus.country_code = 'USA'
228
+ t = builder.country_select(:country_code, format: :with_alpha3, priority_countries: ['US'])
229
+ expect(t.scan(Regexp.new(Regexp.escape(tag))).size).to eq 1
230
+ end
231
+ end
232
+ end
@@ -0,0 +1,98 @@
1
+ require 'pry'
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
6
+ # file to always be loaded, without a need to explicitly require it in any files.
7
+ #
8
+ # Given that it is always loaded, you are encouraged to keep this file as
9
+ # light-weight as possible. Requiring heavyweight dependencies from this file
10
+ # will add to the boot time of your test suite on EVERY test run, even for an
11
+ # individual file that may not need all of that loaded. Instead, consider making
12
+ # a separate helper file that requires the additional dependencies and performs
13
+ # the additional setup, and require it from the spec files that actually need it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+ #=begin
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
54
+ # For more details, see:
55
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
56
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
57
+ # - 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!
59
+
60
+ # This setting enables warnings. It's recommended, but in some cases may
61
+ # be too noisy due to issues in dependencies.
62
+ #config.warnings = true
63
+
64
+ # Many RSpec users commonly either run the entire suite or an individual
65
+ # file, and it's useful to allow more verbose output when running an
66
+ # individual spec file.
67
+ if config.files_to_run.one?
68
+ # Use the documentation formatter for detailed output,
69
+ # unless a formatter has already been configured
70
+ # (e.g. via a command-line flag).
71
+ config.default_formatter = 'doc'
72
+ end
73
+
74
+ # Print the 10 slowest examples and example groups at the
75
+ # end of the spec run, to help surface which specs are running
76
+ # particularly slow.
77
+ #config.profile_examples = 10
78
+
79
+ # Run specs in random order to surface order dependencies. If you find an
80
+ # order dependency and want to debug it, you can fix the order by providing
81
+ # the seed, which is printed after each run.
82
+ # --seed 1234
83
+ config.order = :random
84
+
85
+ # Seed global randomization in this process using the `--seed` CLI option.
86
+ # Setting this allows you to use `--seed` to deterministically reproduce
87
+ # test failures related to randomization by passing the same `--seed` value
88
+ # as the one that triggered the failure.
89
+ Kernel.srand config.seed
90
+ #=end
91
+
92
+ # non-default settings
93
+ config.raise_errors_for_deprecations!
94
+
95
+ config.before do
96
+ I18n.config.enforce_available_locales = false
97
+ end
98
+ end
metadata CHANGED
@@ -1,16 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: country_select
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
5
- prerelease:
4
+ version: 2.5.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Stefan Penner
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-12-28 00:00:00.000000000 Z
13
- dependencies: []
11
+ date: 2016-03-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionpack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
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
+ - !ruby/object:Gem::Dependency
84
+ name: countries
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.2.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.2.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'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.0'
14
111
  description: Provides a simple helper to get an HTML select list of countries. The
15
112
  list of countries comes from the ISO 3166 standard. While it is a relatively neutral
16
113
  source of country names, it will still offend some users.
@@ -20,43 +117,59 @@ executables: []
20
117
  extensions: []
21
118
  extra_rdoc_files: []
22
119
  files:
23
- - .gitignore
120
+ - ".gitignore"
121
+ - ".rspec"
122
+ - ".travis.yml"
123
+ - CHANGELOG.md
24
124
  - Gemfile
125
+ - Gemfile.lock
25
126
  - MIT-LICENSE
26
127
  - README.md
27
128
  - Rakefile
28
- - VERSION
129
+ - UPGRADING.md
29
130
  - 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
30
141
  - lib/country_select.rb
142
+ - lib/country_select/country_select_helper.rb
143
+ - lib/country_select/formats.rb
144
+ - lib/country_select/rails3/country_select_helper.rb
145
+ - lib/country_select/tag_helper.rb
31
146
  - lib/country_select/version.rb
32
- homepage: ''
33
- licenses: []
147
+ - spec/country_select_spec.rb
148
+ - spec/spec_helper.rb
149
+ homepage: https://github.com/stefanpenner/country_select
150
+ licenses:
151
+ - MIT
152
+ metadata: {}
34
153
  post_install_message:
35
154
  rdoc_options: []
36
155
  require_paths:
37
156
  - lib
38
157
  required_ruby_version: !ruby/object:Gem::Requirement
39
- none: false
40
158
  requirements:
41
- - - ! '>='
159
+ - - ">="
42
160
  - !ruby/object:Gem::Version
43
161
  version: '0'
44
- segments:
45
- - 0
46
- hash: -229501016986175763
47
162
  required_rubygems_version: !ruby/object:Gem::Requirement
48
- none: false
49
163
  requirements:
50
- - - ! '>='
164
+ - - ">="
51
165
  - !ruby/object:Gem::Version
52
166
  version: '0'
53
- segments:
54
- - 0
55
- hash: -229501016986175763
56
167
  requirements: []
57
168
  rubyforge_project: country_select
58
- rubygems_version: 1.8.24
169
+ rubygems_version: 2.4.5.1
59
170
  signing_key:
60
- specification_version: 3
171
+ specification_version: 4
61
172
  summary: Country Select Plugin
62
- test_files: []
173
+ test_files:
174
+ - spec/country_select_spec.rb
175
+ - spec/spec_helper.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.0