From 19377b8662de0304166eb56930054da95a47495e Mon Sep 17 00:00:00 2001 From: Larry Reid Date: Wed, 12 Mar 2025 15:56:06 +0000 Subject: [PATCH 1/6] Update supported versions and RuboCop offenses --- .github/workflows/ruby.yml | 17 +++++------------ .rubocop.yml | 6 +++--- README.md | 4 ++-- bootstrap_form.gemspec | 2 +- demo/.ruby-version | 2 +- demo/Gemfile.lock | 4 ++-- demo/app/helpers/bootstrap_helper.rb | 4 ++-- gemfiles/6.1.gemfile | 10 ---------- gemfiles/7.0.gemfile | 11 ----------- .../action_view_extensions/form_helper.rb | 12 ++++++------ lib/bootstrap_form/components/labels.rb | 2 +- lib/bootstrap_form/form_builder.rb | 6 +++--- lib/bootstrap_form/form_group.rb | 6 +++--- lib/bootstrap_form/form_group_builder.rb | 4 ++-- lib/bootstrap_form/helpers/bootstrap.rb | 12 ++++++------ lib/bootstrap_form/inputs/check_box.rb | 4 ++-- lib/bootstrap_form/inputs/submit.rb | 2 +- lib/bootstrap_form/version.rb | 2 +- test/bootstrap_rich_text_area_test.rb | 4 ++-- 19 files changed, 43 insertions(+), 71 deletions(-) delete mode 100644 gemfiles/6.1.gemfile delete mode 100644 gemfiles/7.0.gemfile diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 7a8e47a4f..59f545c55 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -9,14 +9,14 @@ jobs: Lint: runs-on: ubuntu-latest env: - BUNDLE_GEMFILE: gemfiles/6.1.gemfile + BUNDLE_GEMFILE: gemfiles/7.1.gemfile steps: - uses: actions/checkout@v3 with: fetch-depth: 0 - uses: ruby/setup-ruby@v1 with: - ruby-version: 3.0.6 + ruby-version: 3.2.7 bundler-cache: true # Disabled since it requires access not granted by GitHub Actions for PRs # - name: Danger @@ -32,15 +32,8 @@ jobs: strategy: fail-fast: false matrix: - ruby-version: [ '3.3', '3.2', '3.1', '3.0', 'ruby-head' ] - gemfile: [ '7.2', '7.1', '7.0', '6.1', 'edge' ] - exclude: - - ruby-version: '3.1' - gemfile: 'edge' - - ruby-version: '3.0' - gemfile: 'edge' - - ruby-version: '3.0' - gemfile: '7.2' + ruby-version: [ '3.4', '3.3', '3.2', 'ruby-head' ] + gemfile: [ '7.2', '7.1', 'edge' ] env: BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile steps: @@ -61,7 +54,7 @@ jobs: with: working-directory: demo bundler-cache: true - ruby-version: 3.3.2 + ruby-version: 3.4.2 - name: Run tests working-directory: demo run: bundle exec rake test:all diff --git a/.rubocop.yml b/.rubocop.yml index f9e797b99..15e25d3ff 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,12 +1,12 @@ -require: +plugins: - rubocop-performance - rubocop-rails AllCops: DisplayCopNames: true DisplayStyleGuide: true - TargetRubyVersion: 3.0 - TargetRailsVersion: 6.1 + TargetRubyVersion: 3.2 + TargetRailsVersion: 7.1 NewCops: enable Exclude: - bin/* diff --git a/README.md b/README.md index 3780d6c98..738be31d1 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,8 @@ Some other nice things that `bootstrap_form` does for you are: `bootstrap_form` supports at a minimum the currently supported versions of Ruby and Rails: -* Ruby 3.0+ (https://www.ruby-lang.org/en/downloads/branches/) -* Rails 6.1+ (https://guides.rubyonrails.org/maintenance_policy.html) +* Ruby 3.2+ (https://www.ruby-lang.org/en/downloads/branches/) +* Rails 7.1+ (https://guides.rubyonrails.org/maintenance_policy.html) * Bootstrap 5.0+ ## Installation diff --git a/bootstrap_form.gemspec b/bootstrap_form.gemspec index 4118aaf8e..9cfabe09b 100644 --- a/bootstrap_form.gemspec +++ b/bootstrap_form.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |s| s.bindir = "exe" s.require_paths = ["lib"] - s.required_ruby_version = ">= 3.0" + s.required_ruby_version = ">= 3.2" s.add_dependency("actionpack", BootstrapForm::REQUIRED_RAILS_VERSION) s.add_dependency("activemodel", BootstrapForm::REQUIRED_RAILS_VERSION) diff --git a/demo/.ruby-version b/demo/.ruby-version index 14dbd3772..fb72f061b 100644 --- a/demo/.ruby-version +++ b/demo/.ruby-version @@ -1 +1 @@ -ruby-3.0.6 +ruby-3.2.7 diff --git a/demo/Gemfile.lock b/demo/Gemfile.lock index 410156e63..1c62e95f4 100644 --- a/demo/Gemfile.lock +++ b/demo/Gemfile.lock @@ -2,8 +2,8 @@ PATH remote: .. specs: bootstrap_form (5.4.0) - actionpack (>= 6.1) - activemodel (>= 6.1) + actionpack (>= 7.1) + activemodel (>= 7.1) GEM remote: https://rubygems.org/ diff --git a/demo/app/helpers/bootstrap_helper.rb b/demo/app/helpers/bootstrap_helper.rb index a69c77156..b28a0573d 100644 --- a/demo/app/helpers/bootstrap_helper.rb +++ b/demo/app/helpers/bootstrap_helper.rb @@ -1,6 +1,6 @@ module BootstrapHelper - def form_with_source(&block) - form_html = capture(&block) + def form_with_source(&) + form_html = capture(&) tag.div(class: "example") do concat(form_html) diff --git a/gemfiles/6.1.gemfile b/gemfiles/6.1.gemfile deleted file mode 100644 index fc548c835..000000000 --- a/gemfiles/6.1.gemfile +++ /dev/null @@ -1,10 +0,0 @@ -gems = "#{__dir__}/common.gemfile" -eval File.read(gems), binding, gems # rubocop: disable Security/Eval - -gem "base64" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") -gem "bigdecimal" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") -gem "drb" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") -gem "logger" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") -gem "mutex_m" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") -gem "rails", "~> 6.1.0" -gem "sqlite3", "~> 1.4" diff --git a/gemfiles/7.0.gemfile b/gemfiles/7.0.gemfile deleted file mode 100644 index 2a3524da2..000000000 --- a/gemfiles/7.0.gemfile +++ /dev/null @@ -1,11 +0,0 @@ -gems = "#{__dir__}/common.gemfile" -eval File.read(gems), binding, gems # rubocop: disable Security/Eval - -gem "base64" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") -gem "bigdecimal" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") -gem "drb" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") -gem "logger" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") -gem "mutex_m" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") -gem "rails", "~> 7.0.2" -gem "sprockets-rails", require: "sprockets/railtie" -gem "sqlite3", "~> 1.4" diff --git a/lib/bootstrap_form/action_view_extensions/form_helper.rb b/lib/bootstrap_form/action_view_extensions/form_helper.rb index c60b8bcf3..a0ebf1620 100644 --- a/lib/bootstrap_form/action_view_extensions/form_helper.rb +++ b/lib/bootstrap_form/action_view_extensions/form_helper.rb @@ -33,20 +33,20 @@ def bootstrap_form_with(options={}, &block) end end - def bootstrap_form_tag(options={}, &block) + def bootstrap_form_tag(options={}, &) options[:acts_like_form_tag] = true - bootstrap_form_for("", options, &block) + bootstrap_form_for("", options, &) end - def bootstrap_fields_for(record_name, record_object=nil, options={}, &block) + def bootstrap_fields_for(record_name, record_object=nil, options={}, &) options[:builder] = BootstrapForm::FormBuilder - fields_for(record_name, record_object, options, &block) + fields_for(record_name, record_object, options, &) end - def bootstrap_fields(scope=nil, model: nil, **options, &block) + def bootstrap_fields(scope=nil, model: nil, **options, &) options[:builder] = BootstrapForm::FormBuilder - fields(scope, model: model, **options, &block) + fields(scope, model: model, **options, &) end private diff --git a/lib/bootstrap_form/components/labels.rb b/lib/bootstrap_form/components/labels.rb index f496d80fa..579957ed8 100644 --- a/lib/bootstrap_form/components/labels.rb +++ b/lib/bootstrap_form/components/labels.rb @@ -43,7 +43,7 @@ def label_layout_classes(custom_label_col, group_layout) end def label_text(name, options) - label = options[:text] || object&.class&.try(:human_attribute_name, name)&.html_safe # rubocop:disable Rails/OutputSafety + label = options[:text] || object&.class&.try(:human_attribute_name, name)&.html_safe # rubocop:disable Rails/OutputSafety, Style/SafeNavigationChainLength if label_errors && error?(name) (" ".html_safe + get_error_messages(name)).prepend(label) else diff --git a/lib/bootstrap_form/form_builder.rb b/lib/bootstrap_form/form_builder.rb index fbc2fcf94..c4b425479 100644 --- a/lib/bootstrap_form/form_builder.rb +++ b/lib/bootstrap_form/form_builder.rb @@ -72,10 +72,10 @@ def add_default_form_attributes_and_form_inline(options) .compact.uniq, " ") end - def fields_for_with_bootstrap(record_name, record_object=nil, fields_options={}, &block) + def fields_for_with_bootstrap(record_name, record_object=nil, fields_options={}, &) fields_options = fields_for_options(record_object, fields_options) record_object = nil if record_object.is_a?(Hash) && record_object.extractable_options? - fields_for_without_bootstrap(record_name, record_object, fields_options, &block) + fields_for_without_bootstrap(record_name, record_object, fields_options, &) end bootstrap_alias :fields_for @@ -92,7 +92,7 @@ def fields_for_options(record_object, fields_options) %i[layout control_col inline_errors label_errors].each do |option| field_options[option] ||= options[option] end - field_options[:label_col] = field_options[:label_col].present? ? (field_options[:label_col]).to_s : options[:label_col] + field_options[:label_col] = field_options[:label_col].present? ? field_options[:label_col].to_s : options[:label_col] field_options end diff --git a/lib/bootstrap_form/form_group.rb b/lib/bootstrap_form/form_group.rb index c06a7e9c9..5039aa71a 100644 --- a/lib/bootstrap_form/form_group.rb +++ b/lib/bootstrap_form/form_group.rb @@ -29,15 +29,15 @@ def form_group_content_tag(name, field_name, without_field_name, options, html_o end end - def form_group_content(label, help_text, options, &block) # rubocop:disable Metrics/AbcSize + def form_group_content(label, help_text, options, &) # rubocop:disable Metrics/AbcSize label ||= ActiveSupport::SafeBuffer.new if group_layout_horizontal?(options[:layout]) - label + tag.div(capture(&block) + help_text, class: form_group_control_class(options)) + label + tag.div(capture(&) + help_text, class: form_group_control_class(options)) else content = ActiveSupport::SafeBuffer.new # Floating labels need to be rendered after the field content << label unless options[:floating] - content << capture(&block) + content << capture(&) content << label if options[:floating] content << help_text if help_text content diff --git a/lib/bootstrap_form/form_group_builder.rb b/lib/bootstrap_form/form_group_builder.rb index c465c1d7c..79eff7e56 100644 --- a/lib/bootstrap_form/form_group_builder.rb +++ b/lib/bootstrap_form/form_group_builder.rb @@ -6,7 +6,7 @@ module FormGroupBuilder private - def form_group_builder(method, options, html_options=nil, &block) + def form_group_builder(method, options, html_options=nil, &) no_wrapper = options[:wrapper] == false options = form_group_builder_options(options, method) @@ -21,7 +21,7 @@ def form_group_builder(method, options, html_options=nil, &block) if no_wrapper yield else - form_group(method, form_group_options, &block) + form_group(method, form_group_options, &) end end diff --git a/lib/bootstrap_form/helpers/bootstrap.rb b/lib/bootstrap_form/helpers/bootstrap.rb index 38934b235..3ed6bf13c 100644 --- a/lib/bootstrap_form/helpers/bootstrap.rb +++ b/lib/bootstrap_form/helpers/bootstrap.rb @@ -56,17 +56,17 @@ def static_control(*args) text_field_with_bootstrap(name, static_options) end - def custom_control(*args, &block) + def custom_control(*args, &) options = args.extract_options! name = args.first - form_group_builder(name, options, &block) + form_group_builder(name, options, &) end - def prepend_and_append_input(name, options, &block) + def prepend_and_append_input(name, options, &) options = options.extract!(:prepend, :append, :input_group_class).compact - input = capture(&block) || ActiveSupport::SafeBuffer.new + input = capture(&) || ActiveSupport::SafeBuffer.new input = attach_input(options, :prepend) + input + attach_input(options, :append) input << generate_error(name) @@ -75,8 +75,8 @@ def prepend_and_append_input(name, options, &block) input end - def input_with_error(name, &block) - input = capture(&block) + def input_with_error(name, &) + input = capture(&) input << generate_error(name) end diff --git a/lib/bootstrap_form/inputs/check_box.rb b/lib/bootstrap_form/inputs/check_box.rb index b095b75d6..eb2a2cff0 100644 --- a/lib/bootstrap_form/inputs/check_box.rb +++ b/lib/bootstrap_form/inputs/check_box.rb @@ -42,7 +42,7 @@ def check_box_options(name, options) check_box_options.merge!(required_field_options(options, name)) end - def check_box_label(name, options, checked_value, &block) + def check_box_label(name, options, checked_value, &) label_name = if options[:multiple] check_box_value(name, checked_value) else @@ -50,7 +50,7 @@ def check_box_label(name, options, checked_value, &block) end label_options = { class: check_box_label_class(options) } label_options[:for] = options[:id] if options[:id].present? - label(label_name, check_box_description(name, options, &block), label_options) + label(label_name, check_box_description(name, options, &), label_options) end def check_box_description(name, options, &block) diff --git a/lib/bootstrap_form/inputs/submit.rb b/lib/bootstrap_form/inputs/submit.rb index 272b0795b..cddad6636 100644 --- a/lib/bootstrap_form/inputs/submit.rb +++ b/lib/bootstrap_form/inputs/submit.rb @@ -1,7 +1,7 @@ module BootstrapForm module Inputs module Submit - def button(value=nil, options={}, &block) + def button(value=nil, options={}, &) value = setup_css_class "btn btn-secondary", value, options super end diff --git a/lib/bootstrap_form/version.rb b/lib/bootstrap_form/version.rb index 309980fa2..2b3d295c5 100644 --- a/lib/bootstrap_form/version.rb +++ b/lib/bootstrap_form/version.rb @@ -1,4 +1,4 @@ module BootstrapForm VERSION = "5.4.0".freeze - REQUIRED_RAILS_VERSION = ">= 6.1".freeze + REQUIRED_RAILS_VERSION = ">= 7.1".freeze end diff --git a/test/bootstrap_rich_text_area_test.rb b/test/bootstrap_rich_text_area_test.rb index f95d3dad8..bd33e9e69 100644 --- a/test/bootstrap_rich_text_area_test.rb +++ b/test/bootstrap_rich_text_area_test.rb @@ -36,13 +36,13 @@ def data_blob_url_template "http://test.host/rails/active_storage/blobs/#{'redirect/' if ::Rails::VERSION::STRING >= '6.1'}:signed_id/:filename" end - def with_stub_token(&block) + def with_stub_token(&) unless defined?(ActiveStorage::DirectUploadToken) yield return end - ActiveStorage::DirectUploadToken.stub(:generate_direct_upload_token, "token", &block) + ActiveStorage::DirectUploadToken.stub(:generate_direct_upload_token, "token", &) end end end From dbb6b32cf0201123dfa35c6f2b0cc24b6412a012 Mon Sep 17 00:00:00 2001 From: Larry Reid Date: Wed, 12 Mar 2025 16:10:41 +0000 Subject: [PATCH 2/6] Remove checks for now-unsupported Rails versions --- demo/app/models/user.rb | 2 +- demo/app/views/bootstrap/form.html.erb | 2 +- test/bootstrap_checkbox_test.rb | 10 ++--- test/bootstrap_fields_for_test.rb | 4 -- test/bootstrap_fields_test.rb | 6 --- test/bootstrap_form_group_test.rb | 4 -- test/bootstrap_form_test.rb | 35 +-------------- test/bootstrap_radio_button_test.rb | 3 -- test/bootstrap_rich_text_area_test.rb | 60 +++++++++++++------------- test/bootstrap_selects_test.rb | 21 +++------ test/test_helper.rb | 2 +- 11 files changed, 42 insertions(+), 107 deletions(-) diff --git a/demo/app/models/user.rb b/demo/app/models/user.rb index 67a627e1f..fea3172bf 100644 --- a/demo/app/models/user.rb +++ b/demo/app/models/user.rb @@ -13,7 +13,7 @@ class User < ApplicationRecord has_one :address accepts_nested_attributes_for :address - has_rich_text(:life_story) if Rails::VERSION::STRING > "6" + has_rich_text(:life_story) def always true diff --git a/demo/app/views/bootstrap/form.html.erb b/demo/app/views/bootstrap/form.html.erb index 74d8bf654..105e462e4 100644 --- a/demo/app/views/bootstrap/form.html.erb +++ b/demo/app/views/bootstrap/form.html.erb @@ -48,7 +48,7 @@ <%= form.password_field :password, placeholder: "Password" %> <%= form.check_box :terms, label: "Agree to Terms" %> <%= form.collection_check_boxes :misc, @collection, :id, :street %> - <%= form.rich_text_area(:life_story) if Rails::VERSION::STRING > "6" %> + <%= form.rich_text_area(:life_story) %> <%= form.submit %> <% end %> <% end %> diff --git a/test/bootstrap_checkbox_test.rb b/test/bootstrap_checkbox_test.rb index 7fb61ce6e..6fdfd4549 100644 --- a/test/bootstrap_checkbox_test.rb +++ b/test/bootstrap_checkbox_test.rb @@ -124,7 +124,6 @@ class BootstrapCheckboxTest < ActionView::TestCase test "inline checkboxes from form layout" do expected = <<~HTML
- #{'' unless ::Rails::VERSION::STRING >= '6'}
@@ -519,8 +518,7 @@ class BootstrapCheckboxTest < ActionView::TestCase expected = <<~HTML - #{'' unless ::Rails::VERSION::STRING >= '6'} - +
@@ -570,8 +568,7 @@ class BootstrapCheckboxTest < ActionView::TestCase collection = [Address.new(id: 1, street: "Foo"), Address.new(id: 2, street: "Bar")] expected = <<~HTML - #{'' unless ::Rails::VERSION::STRING >= '6'} - +
@@ -597,8 +594,7 @@ class BootstrapCheckboxTest < ActionView::TestCase @user.errors.add(:terms, "You must accept the terms.") expected = <<~HTML - #{'' unless ::Rails::VERSION::STRING >= '6'} -
+