country_select 2.0.0 → 2.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.
@@ -31,7 +31,7 @@ module ActionView
31
31
  else
32
32
  html_options = @html_options.stringify_keys
33
33
  add_default_name_and_id(html_options)
34
- content_tag(:select, country_option_tags, html_options)
34
+ content_tag(:select, add_options(country_option_tags, options, value(object)), html_options)
35
35
  end
36
36
  end
37
37
  end
@@ -1,4 +1,5 @@
1
1
  module CountrySelect
2
+ class CountryNotFoundError < StandardError;end
2
3
  module TagHelper
3
4
  def country_option_tags
4
5
  option_tags_options = {
@@ -61,14 +62,20 @@ module CountrySelect
61
62
 
62
63
  def country_options_for(country_codes, sorted=true)
63
64
  I18n.with_locale(locale) do
64
- country_list = country_codes.map do |code|
65
- code = code.to_s.upcase
65
+ country_list = country_codes.map do |code_or_name|
66
+ if country = ISO3166::Country.new(code_or_name)
67
+ code = country.alpha2
68
+ elsif country = ISO3166::Country.find_by_name(code_or_name)
69
+ code = country.first
70
+ end
71
+
72
+ country = ISO3166::Country.new(code)
66
73
 
67
- unless country = ISO3166::Country.new(code)
68
- code = ISO3166::Country.find_by_name(code).first
74
+ unless country.present?
75
+ msg = "Could not find Country with string '#{code_or_name}'"
76
+ raise CountryNotFoundError.new(msg)
69
77
  end
70
78
 
71
- country ||= ISO3166::Country.new(code)
72
79
  default_name = country.name
73
80
  localized_name = country.translations[I18n.locale.to_s]
74
81
 
@@ -1,3 +1,3 @@
1
1
  module CountrySelect
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.1"
3
3
  end
@@ -135,5 +135,33 @@ describe "CountrySelect" do
135
135
  t = builder.country_select(:country_code, country_names)
136
136
  expect(t).to include(tag)
137
137
  end
138
+
139
+ it "raises an error when a country code or name is not found" do
140
+ country_names = [
141
+ "United States",
142
+ "Canada",
143
+ "United Kingdom",
144
+ "Mexico",
145
+ "Australia",
146
+ "South Korea"
147
+ ]
148
+ error_msg = "Could not find Country with string 'South Korea'"
149
+
150
+ expect do
151
+ builder.country_select(:country_code, country_names)
152
+ end.to raise_error(CountrySelect::CountryNotFoundError, error_msg)
153
+ end
154
+
155
+ it "supports the select prompt" do
156
+ tag = '<option value="">Select your country</option>'
157
+ t = builder.country_select(:country_code, prompt: 'Select your country')
158
+ expect(t).to include(tag)
159
+ end
160
+
161
+ it "supports the include_blank option" do
162
+ tag = '<option value=""></option>'
163
+ t = builder.country_select(:country_code, include_blank: true)
164
+ expect(t).to include(tag)
165
+ end
138
166
  end
139
167
  end
data/spec/spec_helper.rb CHANGED
@@ -1,20 +1,98 @@
1
+ require 'pry'
2
+
1
3
  # This file was generated by the `rspec --init` command. Conventionally, all
2
4
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # Require this file using `require "spec_helper"` to ensure that it is only
4
- # loaded once.
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.
5
17
  #
6
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
7
33
 
8
- require 'pry'
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
9
42
 
10
- RSpec.configure do |config|
11
- config.treat_symbols_as_metadata_keys_with_true_values = true
12
- config.run_all_when_everything_filtered = true
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.
13
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
14
78
 
15
79
  # Run specs in random order to surface order dependencies. If you find an
16
80
  # order dependency and want to debug it, you can fix the order by providing
17
81
  # the seed, which is printed after each run.
18
82
  # --seed 1234
19
- config.order = 'random'
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
20
98
  end
metadata CHANGED
@@ -1,77 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: country_select
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Penner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-25 00:00:00.000000000 Z
11
+ date: 2014-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
14
+ name: actionpack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2'
19
+ version: '3'
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: '2'
26
+ version: '3'
27
27
  - !ruby/object:Gem::Dependency
28
- name: actionpack
28
+ name: pry
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3'
33
+ version: '0.10'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '3'
40
+ version: '0.10'
41
41
  - !ruby/object:Gem::Dependency
42
- name: appraisal
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.0'
48
- - - ">="
49
- - !ruby/object:Gem::Version
50
- version: 1.0.0
47
+ version: '10.3'
51
48
  type: :development
52
49
  prerelease: false
53
50
  version_requirements: !ruby/object:Gem::Requirement
54
51
  requirements:
55
52
  - - "~>"
56
53
  - !ruby/object:Gem::Version
57
- version: '1.0'
58
- - - ">="
54
+ version: '10.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
59
60
  - !ruby/object:Gem::Version
60
- version: 1.0.0
61
+ version: '3.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.1'
61
69
  - !ruby/object:Gem::Dependency
62
- name: pry
70
+ name: wwtd
63
71
  requirement: !ruby/object:Gem::Requirement
64
72
  requirements:
65
73
  - - "~>"
66
74
  - !ruby/object:Gem::Version
67
- version: '0'
75
+ version: '0.5'
68
76
  type: :development
69
77
  prerelease: false
70
78
  version_requirements: !ruby/object:Gem::Requirement
71
79
  requirements:
72
80
  - - "~>"
73
81
  - !ruby/object:Gem::Version
74
- version: '0'
82
+ version: '0.5'
75
83
  - !ruby/object:Gem::Dependency
76
84
  name: countries
77
85
  requirement: !ruby/object:Gem::Requirement
@@ -104,19 +112,26 @@ files:
104
112
  - ".gitignore"
105
113
  - ".rspec"
106
114
  - ".travis.yml"
107
- - Appraisals
108
115
  - CHANGELOG.md
109
116
  - Gemfile
117
+ - Gemfile.lock
110
118
  - MIT-LICENSE
111
119
  - README.md
112
120
  - Rakefile
113
121
  - UPGRADING.md
114
122
  - country_select.gemspec
123
+ - gemfiles/actionpack.edge.gemfile
124
+ - gemfiles/actionpack.edge.gemfile.lock
115
125
  - gemfiles/actionpack3.0.gemfile
116
126
  - gemfiles/actionpack3.1.gemfile
117
127
  - gemfiles/actionpack3.2.gemfile
128
+ - gemfiles/actionpack3.2.gemfile.lock
118
129
  - gemfiles/actionpack4.0.gemfile
130
+ - gemfiles/actionpack4.0.gemfile.lock
119
131
  - gemfiles/actionpack4.1.gemfile
132
+ - gemfiles/actionpack4.1.gemfile.lock
133
+ - gemfiles/actionpack4.2.gemfile
134
+ - gemfiles/actionpack4.2.gemfile.lock
120
135
  - lib/country_select.rb
121
136
  - lib/country_select/country_select_helper.rb
122
137
  - lib/country_select/rails3/country_select_helper.rb
data/Appraisals DELETED
@@ -1,19 +0,0 @@
1
- appraise 'actionpack3.0' do
2
- gem 'actionpack', '~> 3.0.20'
3
- end
4
-
5
- appraise 'actionpack3.1' do
6
- gem 'actionpack', '~> 3.1.12'
7
- end
8
-
9
- appraise 'actionpack3.2' do
10
- gem 'actionpack', '~> 3.2.17'
11
- end
12
-
13
- appraise 'actionpack4.0' do
14
- gem 'actionpack', '~> 4.0.0'
15
- end
16
-
17
- appraise 'actionpack4.1' do
18
- gem 'actionpack', '~> 4.1.0'
19
- end