From 021845dafffb65bb51bb6ebc0e40c540a9e83b1a Mon Sep 17 00:00:00 2001 From: Pedro Moreira Date: Sat, 17 Feb 2024 12:03:46 +0000 Subject: [PATCH 1/3] Remove support for deprecated 1.x syntax --- lib/country_select/country_select_helper.rb | 17 +---- spec/country_select_spec.rb | 70 ++------------------- 2 files changed, 6 insertions(+), 81 deletions(-) diff --git a/lib/country_select/country_select_helper.rb b/lib/country_select/country_select_helper.rb index f0ae3db..2840b2d 100644 --- a/lib/country_select/country_select_helper.rb +++ b/lib/country_select/country_select_helper.rb @@ -3,21 +3,8 @@ 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 - end - + def country_select(method, options = {}, html_options = {}) + raise ArgumentError, "Invalid syntax for country_select method. options must be a hash" unless options.is_a?(Hash) @template.country_select(@object_name, method, objectify_options(options), @default_options.merge(html_options)) end end diff --git a/spec/country_select_spec.rb b/spec/country_select_spec.rb index 05fdf01..6503770 100644 --- a/spec/country_select_spec.rb +++ b/spec/country_select_spec.rb @@ -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 = '' - 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' - '' - else - '' - 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 From 7832527e9cca1bedb02e9a623d528333afd6b0a6 Mon Sep 17 00:00:00 2001 From: Pedro Moreira Date: Sat, 17 Feb 2024 17:17:48 +0000 Subject: [PATCH 2/3] Update codeclimate-action version --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fa70ae1..1e46890 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 From 63fdf094b06ed0d26911070b2d37deb49f324d21 Mon Sep 17 00:00:00 2001 From: Pedro Moreira Date: Sat, 17 Feb 2024 17:20:01 +0000 Subject: [PATCH 3/3] Rubocop issues --- lib/country_select/country_select_helper.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/country_select/country_select_helper.rb b/lib/country_select/country_select_helper.rb index 2840b2d..7e5ae89 100644 --- a/lib/country_select/country_select_helper.rb +++ b/lib/country_select/country_select_helper.rb @@ -4,7 +4,10 @@ module ActionView module Helpers class FormBuilder def country_select(method, options = {}, html_options = {}) - raise ArgumentError, "Invalid syntax for country_select method. options must be a hash" unless options.is_a?(Hash) + 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)) end end