diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 83397ea5b..ffa9fc3ef 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -31,6 +31,7 @@ jobs: gemfile: [ '6.1', '6.0', '5.2', 'edge' ] exclude: - { ruby-version: '3.0', gemfile: "5.2" } + - { ruby-version: '2.6', gemfile: "edge" } env: BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile steps: diff --git a/.rubocop.yml b/.rubocop.yml index 209cc189b..03983762e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,3 @@ -inherit_from: .rubocop_todo.yml require: - rubocop-performance - rubocop-rails @@ -6,6 +5,7 @@ require: AllCops: DisplayCopNames: true DisplayStyleGuide: true + TargetRubyVersion: 2.5 NewCops: enable Exclude: - bin/* diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml deleted file mode 100644 index 775bf8161..000000000 --- a/.rubocop_todo.yml +++ /dev/null @@ -1,81 +0,0 @@ -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2021-01-13 19:40:22 UTC using RuboCop version 1.8.1. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 1 -# Configuration parameters: AllowedMethods. -# AllowedMethods: enums -Lint/ConstantDefinitionInBlock: - Exclude: - - 'bootstrap_form.gemspec' - -# Offense count: 2 -# Cop supports --auto-correct. -Lint/RedundantCopDisableDirective: - Exclude: - - 'lib/bootstrap_form/form_builder.rb' - - 'lib/bootstrap_form/helpers/bootstrap.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Performance/BlockGivenWithExplicitBlock: - Exclude: - - 'lib/bootstrap_form/helpers/bootstrap.rb' - - 'lib/bootstrap_form/inputs/check_box.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: IgnoredMethods. -# IgnoredMethods: ==, equal?, eql? -Style/ClassEqualityComparison: - Exclude: - - 'lib/bootstrap_form/components/validation.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/ExplicitBlockArgument: - Exclude: - - 'lib/bootstrap_form/form_group_builder.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/RedundantAssignment: - Exclude: - - 'lib/bootstrap_form/form_group_builder.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: SafeForConstants. -Style/RedundantFetchBlock: - Exclude: - - 'demo/config/puma.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/RedundantFileExtensionInRequire: - Exclude: - - 'test/test_helper.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/RedundantRegexpEscape: - Exclude: - - 'Dangerfile' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: AllowModifier. -Style/SoleNestedConditional: - Exclude: - - 'Dangerfile' - - 'lib/bootstrap_form/form_group_builder.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/StringConcatenation: - Exclude: - - 'lib/bootstrap_form.rb' diff --git a/.travis.yml b/.travis.yml index 6a9867a25..d6c7e1a95 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,10 @@ language: ruby rvm: - - 2.7.1 - - 2.6.5 - - 2.5.7 + - 2.7.2 + - 2.6.6 + - 2.5.8 gemfile: + - gemfiles/6.1.gemfile - gemfiles/6.0.gemfile - gemfiles/5.2.gemfile cache: @@ -18,12 +19,12 @@ matrix: gemfile: gemfiles/edge.gemfile # Next version of Rails - - rvm: 2.7.1 + - rvm: 2.7.2 gemfile: gemfiles/edge.gemfile # Running one job to execute DANGER bot and linting - - rvm: 2.7.1 - gemfile: gemfiles/6.0.gemfile + - rvm: 2.7.2 + gemfile: gemfiles/6.1.gemfile script: - gem install danger - danger @@ -31,5 +32,5 @@ matrix: allow_failures: - rvm: ruby-head - - rvm: 2.7.1 + - rvm: 2.7.2 gemfile: gemfiles/edge.gemfile diff --git a/CHANGELOG.md b/CHANGELOG.md index fe0dff508..94953b0ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ ### Bugfixes -* Your contribution here! +* [#586](https://github.com/bootstrap-ruby/bootstrap_form/pull/586): Fix Rails 6.1 tests on master - [@thimo](https://github.com/thimo). ## [4.5.0][] (2020-04-29) diff --git a/Dangerfile b/Dangerfile index 121167be4..615126bfe 100644 --- a/Dangerfile +++ b/Dangerfile @@ -44,11 +44,9 @@ end # ------------------------------------------------------------------------------ # Did you remove the CHANGELOG's "Your contribution here!" line? # ------------------------------------------------------------------------------ -if has_changelog_changes - if IO.read("CHANGELOG.md").scan(/^\s*[-\*] Your contribution here/i).count < 3 - raise( - "Please put the `- Your contribution here!` line back into CHANGELOG.md.", - sticky: false - ) - end +if has_changelog_changes && (IO.read("CHANGELOG.md").scan(/^\s*[-*] Your contribution here/i).count < 3) + raise( + "Please put the `- Your contribution here!` line back into CHANGELOG.md.", + sticky: false + ) end diff --git a/bootstrap_form.gemspec b/bootstrap_form.gemspec index 7f02f0bc1..874945563 100644 --- a/bootstrap_form.gemspec +++ b/bootstrap_form.gemspec @@ -3,6 +3,8 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "bootstrap_form/version" +REQUIRED_RAILS_VERSION = ">= 5.2".freeze + Gem::Specification.new do |s| s.name = "bootstrap_form" s.version = BootstrapForm::VERSION @@ -26,8 +28,6 @@ Gem::Specification.new do |s| s.required_ruby_version = ">= 2.5" - REQUIRED_RAILS_VERSION = ">= 5.2".freeze - s.add_dependency("actionpack", REQUIRED_RAILS_VERSION) s.add_dependency("activemodel", REQUIRED_RAILS_VERSION) diff --git a/demo/config/puma.rb b/demo/config/puma.rb index 1e19380dc..44256ac09 100644 --- a/demo/config/puma.rb +++ b/demo/config/puma.rb @@ -4,12 +4,12 @@ # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +threads_count = ENV.fetch("RAILS_MAX_THREADS", 5) threads threads_count, threads_count # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch("PORT") { 3000 } +port ENV.fetch("PORT", 3000) # Specifies the `environment` that Puma will run in. # diff --git a/lib/bootstrap_form.rb b/lib/bootstrap_form.rb index 0de892db9..a50d077bd 100644 --- a/lib/bootstrap_form.rb +++ b/lib/bootstrap_form.rb @@ -2,8 +2,7 @@ # name and not in the usual autoload-reachable way. # The following line is definitely need to make `bootstrap_form` work. if ::Rails::VERSION::STRING > "6" - require Gem::Specification.find_by_name("actiontext").gem_dir + - "/app/helpers/action_text/tag_helper" + require "#{Gem::Specification.find_by_name('actiontext').gem_dir}/app/helpers/action_text/tag_helper" end require "action_view" require "action_pack" diff --git a/lib/bootstrap_form/components/validation.rb b/lib/bootstrap_form/components/validation.rb index 1c7facfc4..215d8b76f 100644 --- a/lib/bootstrap_form/components/validation.rb +++ b/lib/bootstrap_form/components/validation.rb @@ -14,7 +14,7 @@ def error?(name) def required_attribute?(obj, attribute) return false unless obj && attribute - target = obj.class == Class ? obj : obj.class + target = obj.instance_of?(Class) ? obj : obj.class target_validators = if target.respond_to? :validators_on target.validators_on(attribute).map(&:class) diff --git a/lib/bootstrap_form/form_builder.rb b/lib/bootstrap_form/form_builder.rb index 429802c78..fae358822 100644 --- a/lib/bootstrap_form/form_builder.rb +++ b/lib/bootstrap_form/form_builder.rb @@ -45,7 +45,6 @@ class FormBuilder < ActionView::Helpers::FormBuilder delegate :content_tag, :capture, :concat, :tag, to: :@template - # rubocop:disable Metrics/AbcSize def initialize(object_name, object, template, options) @layout = options[:layout] || default_layout @label_col = options[:label_col] || default_label_col @@ -61,7 +60,6 @@ def initialize(object_name, object, template, options) add_default_form_attributes_and_form_inline options super end - # rubocop:enable Metrics/AbcSize def add_default_form_attributes_and_form_inline(options) options[:html] ||= {} diff --git a/lib/bootstrap_form/form_group.rb b/lib/bootstrap_form/form_group.rb index 7c1c03664..d300cefc7 100644 --- a/lib/bootstrap_form/form_group.rb +++ b/lib/bootstrap_form/form_group.rb @@ -11,8 +11,8 @@ def form_group(*args, &block) options[:class] = form_group_classes(options) tag.div(**options.except(:append, :id, :label, :help, :icon, - :input_group_class, :label_col, :control_col, - :add_control_col_class, :layout, :prepend)) do + :input_group_class, :label_col, :control_col, + :add_control_col_class, :layout, :prepend)) do form_group_content( generate_label(options[:id], name, options[:label], options[:label_col], options[:layout]), generate_help(name, options[:help]), options, &block diff --git a/lib/bootstrap_form/form_group_builder.rb b/lib/bootstrap_form/form_group_builder.rb index 4407266c0..094011353 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) + def form_group_builder(method, options, html_options=nil, &block) no_wrapper = options[:wrapper] == false options = form_group_builder_options(options, method) @@ -21,16 +21,14 @@ def form_group_builder(method, options, html_options=nil) if no_wrapper yield else - form_group(method, form_group_options) { yield } + form_group(method, form_group_options, &block) end end def form_group_builder_options(options, method) options.symbolize_keys! options = convert_form_tag_options(method, options) if acts_like_form_tag - unless options[:skip_label] - options[:required] = form_group_required(options) if options.key?(:skip_required) - end + options[:required] = form_group_required(options) if !options[:skip_label] && options.key?(:skip_required) options end @@ -57,12 +55,11 @@ def form_group_opts(options, css_options) end def form_group_label(options, css_options) - hash = { + { text: form_group_label_text(options[:label]), class: form_group_label_class(options), required: options[:required] }.merge(css_options[:id].present? ? { for: css_options[:id] } : {}) - hash end def form_group_label_text(label) diff --git a/lib/bootstrap_form/helpers/bootstrap.rb b/lib/bootstrap_form/helpers/bootstrap.rb index 3e5554632..4a4521764 100644 --- a/lib/bootstrap_form/helpers/bootstrap.rb +++ b/lib/bootstrap_form/helpers/bootstrap.rb @@ -14,7 +14,7 @@ def submit(name=nil, options={}) def primary(name=nil, options={}, &block) setup_css_class "btn btn-primary", options - if options[:render_as_button] || block_given? + if options[:render_as_button] || block options.except! :render_as_button button(name, options, &block) else @@ -22,7 +22,7 @@ def primary(name=nil, options={}, &block) end end - def alert_message(title, options={}) # rubocop:disable Metrics/AbcSize + def alert_message(title, options={}) css = options[:class] || "alert alert-danger" return unless object.respond_to?(:errors) && object.errors.full_messages.any? diff --git a/lib/bootstrap_form/inputs/check_box.rb b/lib/bootstrap_form/inputs/check_box.rb index abfd44bfd..0bff2014c 100644 --- a/lib/bootstrap_form/inputs/check_box.rb +++ b/lib/bootstrap_form/inputs/check_box.rb @@ -38,7 +38,7 @@ def check_box_label(name, options, checked_value, &block) end def check_box_description(name, options, &block) - content = block_given? ? capture(&block) : options[:label] + content = block ? capture(&block) : options[:label] content || object&.class&.human_attribute_name(name) || name.to_s.humanize end diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index 546f81d1e..f4604d219 100644 --- a/test/bootstrap_form_test.rb +++ b/test/bootstrap_form_test.rb @@ -120,7 +120,8 @@ class BootstrapFormTest < ActionView::TestCase # generate a default ID for the form element. test "default-style forms bootstrap_form_with Rails 5.1+" do expected = <<-HTML.strip_heredoc -
+ #{'' unless ::Rails::VERSION::STRING >= '6'}
HTML diff --git a/test/bootstrap_rich_text_area_test.rb b/test/bootstrap_rich_text_area_test.rb index 8e3b2aca9..0ed8fe321 100644 --- a/test/bootstrap_rich_text_area_test.rb +++ b/test/bootstrap_rich_text_area_test.rb @@ -12,11 +12,15 @@ class BootstrapRichTextAreaTest < ActionView::TestCase
- +
HTML assert_equivalent_xml expected, form_with_builder.rich_text_area(:life_story) end + + def data_blob_url_template + "http://test.host/rails/active_storage/blobs/#{'redirect/' if ::Rails::VERSION::STRING >= '6.1'}:signed_id/:filename" + end end end diff --git a/test/bootstrap_selects_test.rb b/test/bootstrap_selects_test.rb index e369b04ec..818fb6b96 100644 --- a/test/bootstrap_selects_test.rb +++ b/test/bootstrap_selects_test.rb @@ -398,15 +398,15 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
@@ -424,15 +424,15 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
@@ -503,12 +503,12 @@ def options_range(start: 1, stop: 31, selected: nil, months: false) : @@ -528,12 +528,12 @@ def options_range(start: 1, stop: 31, selected: nil, months: false) : @@ -615,25 +615,25 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
:
@@ -650,25 +650,25 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
:
@@ -697,4 +697,12 @@ def options_range(start: 1, stop: 31, selected: nil, months: false) }, class: "selectpicker") end + + def blank_option + if ::Rails::VERSION::STRING < "6.1" + '' + else + '' + end + end end diff --git a/test/test_helper.rb b/test/test_helper.rb index c7d8c37f8..c6f925643 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -4,7 +4,7 @@ require "nokogiri" require "equivalent-xml" -require_relative "../demo/config/environment.rb" +require_relative "../demo/config/environment" require "rails/test_help" require "mocha/minitest"