Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Rails 6.1 tests on master #586

Merged
merged 6 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
inherit_from: .rubocop_todo.yml
require:
- rubocop-performance
- rubocop-rails

AllCops:
DisplayCopNames: true
DisplayStyleGuide: true
TargetRubyVersion: 2.5
NewCops: enable
Exclude:
- bin/*
Expand Down
81 changes: 0 additions & 81 deletions .rubocop_todo.yml

This file was deleted.

15 changes: 8 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -18,18 +19,18 @@ 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
- bundle exec rake rubocop

allow_failures:
- rvm: ruby-head
- rvm: 2.7.1
- rvm: 2.7.2
gemfile: gemfiles/edge.gemfile
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 5 additions & 7 deletions Dangerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions bootstrap_form.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions demo/config/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down
3 changes: 1 addition & 2 deletions lib/bootstrap_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lib/bootstrap_form/components/validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions lib/bootstrap_form/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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] ||= {}
Expand Down
4 changes: 2 additions & 2 deletions lib/bootstrap_form/form_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions lib/bootstrap_form/form_group_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/bootstrap_form/helpers/bootstrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ 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
submit(name, options)
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?

Expand Down
2 changes: 1 addition & 1 deletion lib/bootstrap_form/inputs/check_box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion test/bootstrap_form_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
<form accept-charset="UTF-8" action="/users" data-remote="true" method="post" role="form">
<form accept-charset="UTF-8" action="/users" method="post" role="form"
#{'data-remote="true"' if ::Rails::VERSION::STRING < '6.1'}>
#{'<input name="utf8" type="hidden" value="&#x2713;"/>' unless ::Rails::VERSION::STRING >= '6'}
</form>
HTML
Expand Down
6 changes: 5 additions & 1 deletion test/bootstrap_rich_text_area_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ class BootstrapRichTextAreaTest < ActionView::TestCase
<div class="form-group">
<label for="user_life_story">Life story</label>
<input type="hidden" name="user[life_story]" id="user_life_story_trix_input_user"/>
<trix-editor id="user_life_story" data-blob-url-template="http://test.host/rails/active_storage/blobs/:signed_id/:filename" data-direct-upload-url="http://test.host/rails/active_storage/direct_uploads" input="user_life_story_trix_input_user" class="trix-content form-control"/>
<trix-editor id="user_life_story" data-blob-url-template="#{data_blob_url_template}" data-direct-upload-url="http://test.host/rails/active_storage/direct_uploads" input="user_life_story_trix_input_user" class="trix-content form-control"/>
</trix-editor>
</div>
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
Loading