From f38c6a1d3acca8e3b5bd650fd92a6466d468eb71 Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Wed, 6 Jul 2022 14:01:46 +0300 Subject: [PATCH 1/3] Split country and timezone inputs to fix deprecated way of passing priority countries to country input. It still uses SimpleForm's PriorityInput for backward compatibility. --- CHANGELOG.md | 1 + Gemfile.lock | 14 ++------ lib/simple_form/inputs/priority_input.rb | 18 ++++++++-- test/inputs/country_input_test.rb | 36 +++++++++++++++++++ ..._input_test.rb => time_zone_input_test.rb} | 24 +++---------- 5 files changed, 61 insertions(+), 32 deletions(-) create mode 100644 test/inputs/country_input_test.rb rename test/inputs/{priority_input_test.rb => time_zone_input_test.rb} (55%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a9c54c01..1b8f3e492 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Update Bootstrap install generator version 5. [@mhw](https://github.com/mhw) * Accept proc as `group_method` for grouped collection select * Honor `include_hidden` option on inline boolean inputs [@yboulkaid](https://github.com/yboulkaid) +* Fix deprecation error when using country_select input. ## 5.1.0 diff --git a/Gemfile.lock b/Gemfile.lock index 502eb539e..58e46bca9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -30,18 +30,14 @@ GEM tzinfo (~> 2.0) builder (3.2.4) concurrent-ruby (1.1.9) - countries (4.2.2) - i18n_data (~> 0.15.0) + countries (5.1.0) sixarm_ruby_unaccent (~> 1.1) - country_select (6.1.1) - countries (~> 4.2) - sort_alphabetical (~> 1.1) + country_select (8.0.0) + countries (~> 5.0) crass (1.0.6) erubi (1.10.0) i18n (1.10.0) concurrent-ruby (~> 1.0) - i18n_data (0.15.0) - simple_po_parser (~> 1.1) loofah (2.14.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -68,14 +64,10 @@ GEM thor (~> 1.0) zeitwerk (~> 2.5) rake (13.0.6) - simple_po_parser (1.1.5) sixarm_ruby_unaccent (1.2.0) - sort_alphabetical (1.1.0) - unicode_utils (>= 1.2.2) thor (1.2.1) tzinfo (2.0.4) concurrent-ruby (~> 1.0) - unicode_utils (1.4.0) zeitwerk (2.5.4) PLATFORMS diff --git a/lib/simple_form/inputs/priority_input.rb b/lib/simple_form/inputs/priority_input.rb index 397f54b88..872f3a813 100644 --- a/lib/simple_form/inputs/priority_input.rb +++ b/lib/simple_form/inputs/priority_input.rb @@ -5,8 +5,7 @@ class PriorityInput < CollectionSelectInput def input(wrapper_options = nil) merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) - @builder.send(:"#{input_type}_select", attribute_name, input_priority, - input_options, merged_input_options) + send(:"#{input_type}_input", merged_input_options) end def input_priority @@ -15,6 +14,21 @@ def input_priority protected + def country_input(merged_input_options) + @builder.send(:country_select, + attribute_name, + input_options.merge(priority_countries: input_priority), + merged_input_options) + end + + def time_zone_input(merged_input_options) + @builder.send(:time_zone_select, + attribute_name, + input_priority, + input_options, + merged_input_options) + end + def skip_include_blank? super || input_priority.present? end diff --git a/test/inputs/country_input_test.rb b/test/inputs/country_input_test.rb new file mode 100644 index 000000000..c8968894c --- /dev/null +++ b/test/inputs/country_input_test.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true +# encoding: UTF-8 +require 'test_helper' + +class CountryInputTest < ActionView::TestCase + test 'input generates a country select field' do + with_input_for @user, :country, :country + assert_select 'select#user_country' + assert_select 'select option[value=BR]', 'Brazil' + assert_no_select 'select option[value=""][disabled=disabled]' + end + + test 'input generates a country select with SimpleForm default' do + swap SimpleForm, country_priority: [ 'Brazil' ] do + with_input_for @user, :country, :country + assert_select 'select option[value="BR"] + option[value="---------------"][disabled=disabled]' + end + end + + test 'input generates a country select using options priority' do + with_input_for @user, :country, :country, priority: [ 'Ukraine' ] + assert_select 'select option[value="UA"] + option[value="---------------"][disabled=disabled]' + end + + test 'input does generate select element with required html attribute' do + with_input_for @user, :country, :country + assert_select 'select.required' + assert_select 'select[required]' + end + + test 'input does generate select element with aria-required html attribute' do + with_input_for @user, :country, :country + assert_select 'select.required' + assert_select 'select[aria-required]' + end +end diff --git a/test/inputs/priority_input_test.rb b/test/inputs/time_zone_input_test.rb similarity index 55% rename from test/inputs/priority_input_test.rb rename to test/inputs/time_zone_input_test.rb index a90ca3610..89051d3ec 100644 --- a/test/inputs/priority_input_test.rb +++ b/test/inputs/time_zone_input_test.rb @@ -2,21 +2,7 @@ # encoding: UTF-8 require 'test_helper' -class PriorityInputTest < ActionView::TestCase - test 'input generates a country select field' do - with_input_for @user, :country, :country - assert_select 'select#user_country' - assert_select 'select option[value=BR]', 'Brazil' - assert_no_select 'select option[value=""][disabled=disabled]' - end - - test 'input generates a country select with SimpleForm default' do - swap SimpleForm, country_priority: [ 'Brazil' ] do - with_input_for @user, :country, :country - assert_select 'select option[value="---------------"][disabled=disabled]' - end - end - +class TimeZoneInputTest < ActionView::TestCase test 'input generates a time zone select field' do with_input_for @user, :time_zone, :time_zone assert_select 'select#user_time_zone' @@ -36,14 +22,14 @@ class PriorityInputTest < ActionView::TestCase assert_no_select 'select option[value=""]', /^$/ end - test 'priority input does generate select element with required html attribute' do - with_input_for @user, :country, :country + test 'input does generate select element with required html attribute' do + with_input_for @user, :time_zone, :time_zone assert_select 'select.required' assert_select 'select[required]' end - test 'priority input does generate select element with aria-required html attribute' do - with_input_for @user, :country, :country + test 'input does generate select element with aria-required html attribute' do + with_input_for @user, :time_zone, :time_zone assert_select 'select.required' assert_select 'select[aria-required]' end From 2b77e9cb000cf9c2aec2b7c67247f52384f3cb08 Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Sat, 24 Sep 2022 10:18:47 +0200 Subject: [PATCH 2/3] Specify main branch for Rails edge. --- gemfiles/Gemfile-rails-main | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gemfiles/Gemfile-rails-main b/gemfiles/Gemfile-rails-main index 3c833220d..e3e6dd684 100644 --- a/gemfiles/Gemfile-rails-main +++ b/gemfiles/Gemfile-rails-main @@ -3,8 +3,8 @@ source 'https://rubygems.org' gemspec path: '..' gem 'country_select' -gem 'railties', github: 'rails/rails' -gem 'activemodel', github: 'rails/rails' -gem 'actionpack', github: 'rails/rails' +gem 'railties', github: 'rails/rails', branch: 'main' +gem 'activemodel', github: 'rails/rails', branch: 'main' +gem 'actionpack', github: 'rails/rails', branch: 'main' gem 'rake' gem 'tzinfo' From b472e19b5d344405e224d7ec6264a2d4793c54e1 Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Sat, 24 Sep 2022 10:19:31 +0200 Subject: [PATCH 3/3] ActionView::OutputBuffer doesn't have #replace method anymore. See https://github.com/rails/rails/commit/4e8e82829182cc2c1dc07997acc210bc0656eda4 --- test/form_builder/wrapper_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/form_builder/wrapper_test.rb b/test/form_builder/wrapper_test.rb index 5958cc3bf..9c7786ee6 100644 --- a/test/form_builder/wrapper_test.rb +++ b/test/form_builder/wrapper_test.rb @@ -195,12 +195,12 @@ class WrapperTest < ActionView::TestCase with_form_for @user, :name assert_no_select "section.custom_wrapper div.another_wrapper label" assert_no_select "section.custom_wrapper div.another_wrapper input.string" - output_buffer.replace "" + output_buffer.to_s.replace "" with_form_for @user, :name, wrapper: :another assert_select "section.custom_wrapper div.another_wrapper label" assert_select "section.custom_wrapper div.another_wrapper input.string" - output_buffer.replace "" + output_buffer.to_s.replace "" end with_form_for @user, :name, wrapper: custom_wrapper