Skip to content

Commit

Permalink
Merge pull request #224 from countries/remove_deprecated_syntax
Browse files Browse the repository at this point in the history
Remove support for deprecated 1.x syntax
  • Loading branch information
pmor authored Feb 17, 2024
2 parents 9133286 + 63fdf09 commit 0c71bf5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ jobs:

run: bundle exec rake
- name: Publish code coverage
uses: paambaati/codeclimate-action@v4.0.0
uses: paambaati/codeclimate-action@v5.0.0

16 changes: 3 additions & 13 deletions lib/country_select/country_select_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,9 @@
module ActionView
module Helpers
class FormBuilder
def country_select(method, priority_or_options = {}, options = {}, html_options = {})
if priority_or_options.is_a? Hash
html_options = options
options = priority_or_options
else
if RUBY_VERSION =~ /^3\.\d\.\d/
warn 'DEPRECATION WARNING: Setting priority countries with the 1.x syntax is deprecated. \
Please use the `priority_countries:` option.', uplevel: 1, category: :deprecated
else
warn 'DEPRECATION WARNING: Setting priority countries with the 1.x syntax is deprecated. \
Please use the `priority_countries:` option.', uplevel: 1
end
options[:priority_countries] = priority_or_options
def country_select(method, options = {}, html_options = {})
unless options.is_a?(Hash)
raise ArgumentError, 'Invalid syntax for country_select method. options must be a hash'
end

@template.country_select(@object_name, method, objectify_options(options), @default_options.merge(html_options))
Expand Down
70 changes: 4 additions & 66 deletions spec/country_select_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,73 +223,11 @@ class Walrus
end

context 'using old 1.x syntax' do
it 'accepts priority countries' do
tag = options_for_select(
[
['Denmark', 'DK'],
['Latvia', 'LV'],
['United States', 'US'],
['-' * 15, '-' * 15]
],
selected: 'US',
disabled: '-' * 15
)

walrus.country_code = 'US'
t = builder.country_select(:country_code, %w[LV US DK])
expect(t).to include(tag)
end

it 'selects only the first matching option' do
tag = options_for_select([['United States', 'US'], ['Uruguay', 'UY']], 'US')
it 'raises ArgumentError' do
walrus.country_code = 'US'
t = builder.country_select(:country_code, %w[LV US])
expect(t).to_not include(tag)
end

it 'supports the country names as provided by default in Formtastic' do
tag = options_for_select([['Australia', 'AU'],
['Canada', 'CA'],
['United Kingdom', 'GB'],
['United States', 'US']])
country_names = ['Australia', 'Canada', 'United Kingdom', 'United States']
t = builder.country_select(:country_code, country_names)
expect(t).to include(tag)
end

it 'raises an error when a country code or name is not found' do
country_names = [
'United States',
'Canada',
'United Kingdom',
'Mexico',
'Australia',
'Freedonia'
]
error_msg = "Could not find Country with string 'Freedonia'"

expect do
builder.country_select(:country_code, country_names)
end.to raise_error(CountrySelect::CountryNotFoundError, error_msg)
end

it 'supports the select prompt' do
tag = '<option value="">Select your country</option>'
t = builder.country_select(:country_code, prompt: 'Select your country')
expect(t).to include(tag)
end

it 'supports the include_blank option' do
# Rails 6.1 more closely follows the HTML spec for
# empty option tags.
# https://github.com/rails/rails/pull/39808
tag = if ActionView::VERSION::STRING >= '6.1'
'<option value="" label=" "></option>'
else
'<option value=""></option>'
end
t = builder.country_select(:country_code, include_blank: true)
expect(t).to include(tag)
expect {
builder.country_select(:country_code, %w[LV US DK])
}.to raise_error(ArgumentError, 'Invalid syntax for country_select method. options must be a hash')
end
end

Expand Down

0 comments on commit 0c71bf5

Please sign in to comment.