Skip to content
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
10 changes: 7 additions & 3 deletions lib/bootstrap_form/components/validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,20 @@ def generate_error(name)
content_tag(help_tag, help_text, class: help_klass)
end

# rubocop:disable Metrics/AbcSize
def get_error_messages(name)
messages = object.errors[name]
object.class.try(:reflections)&.each do |association_name, a|
next unless a.is_a?(ActiveRecord::Reflection::BelongsToReflection)
next unless a.foreign_key == name.to_s

messages << object.errors[association_name]
object.errors[association_name].each do |error|
object.errors.add(name, error)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was intrigued by your comment that it didn't say anything at version 7. You would think it should have errored, if the deprecation warning was in 6.1. You're right. << seems to still work, and without a deprecation message. Very strange.

I was unable to get it to show me the deprecation message, even with version 6.1. (I tweaked the code to run your test case, but with the << operator instead of #add.) Also strange. At any time, did you see the deprecation warning when running the test you added?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If i revert my changes to get_error_messages but leave the new testcase in place i get the following:

Screenshot 2023-08-10 at 09 28 03

end
end
messages.join(", ")

object.errors[name].join(", ")
end
# rubocop:enable Metrics/AbcSize
end
end
end
2 changes: 1 addition & 1 deletion test/bootstrap_checkbox_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative "./test_helper"
require_relative "test_helper"

class BootstrapCheckboxTest < ActionView::TestCase
include BootstrapForm::ActionViewExtensions::FormHelper
Expand Down
2 changes: 1 addition & 1 deletion test/bootstrap_configuration_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative "./test_helper"
require_relative "test_helper"

class BootstrapConfigurationTest < ActionView::TestCase
test "has default form attributes" do
Expand Down
18 changes: 17 additions & 1 deletion test/bootstrap_fields_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative "./test_helper"
require_relative "test_helper"

class BootstrapFieldsTest < ActionView::TestCase
include BootstrapForm::ActionViewExtensions::FormHelper
Expand Down Expand Up @@ -100,6 +100,22 @@ class BootstrapFieldsTest < ActionView::TestCase
assert_equivalent_html expected, bootstrap_form_for(@user) { |f| f.file_field(:misc) }
end

test "errors are correctly displayed for belongs_to assoication fields" do
@address.valid?

expected = <<~HTML
<form accept-charset="UTF-8" action="/users" class="new_address" id="new_address" method="post">
#{'<input name="utf8" type="hidden" value="&#x2713;"/>' unless ::Rails::VERSION::STRING >= '6'}
<div class="mb-3">
<label class="form-label required" for="address_user_id">User</label>
<input aria-required="true" class="form-control is-invalid" id="address_user_id" name="address[user_id]" required="required" type="text"/>
<div class="invalid-feedback">must exist</div>
</div>
</form>
HTML
assert_equivalent_html expected, bootstrap_form_for(@address, url: users_path) { |f| f.text_field(:user_id) }
end

test "hidden fields are supported" do
expected = <<~HTML
<input #{autocomplete_attr} id="user_misc" name="user[misc]" type="hidden" />
Expand Down
2 changes: 1 addition & 1 deletion test/bootstrap_form_group_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative "./test_helper"
require_relative "test_helper"

class BootstrapFormGroupTest < ActionView::TestCase
include BootstrapForm::ActionViewExtensions::FormHelper
Expand Down
2 changes: 1 addition & 1 deletion test/bootstrap_form_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative "./test_helper"
require_relative "test_helper"

class BootstrapFormTest < ActionView::TestCase
include BootstrapForm::ActionViewExtensions::FormHelper
Expand Down
2 changes: 1 addition & 1 deletion test/bootstrap_other_components_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative "./test_helper"
require_relative "test_helper"

class BootstrapOtherComponentsTest < ActionView::TestCase
include BootstrapForm::ActionViewExtensions::FormHelper
Expand Down
2 changes: 1 addition & 1 deletion test/bootstrap_radio_button_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative "./test_helper"
require_relative "test_helper"

class BootstrapRadioButtonTest < ActionView::TestCase
include BootstrapForm::ActionViewExtensions::FormHelper
Expand Down
2 changes: 1 addition & 1 deletion test/bootstrap_rich_text_area_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative "./test_helper"
require_relative "test_helper"
require "minitest/mock"

if Rails::VERSION::STRING > "6"
Expand Down
2 changes: 1 addition & 1 deletion test/bootstrap_selects_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative "./test_helper"
require_relative "test_helper"

class BootstrapSelectsTest < ActionView::TestCase
include BootstrapForm::ActionViewExtensions::FormHelper
Expand Down
2 changes: 1 addition & 1 deletion test/bootstrap_without_fields_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative "./test_helper"
require_relative "test_helper"

class BootstrapWithoutFieldsTest < ActionView::TestCase
include BootstrapForm::ActionViewExtensions::FormHelper
Expand Down
2 changes: 1 addition & 1 deletion test/special_form_class_models_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative "./test_helper"
require_relative "test_helper"

class SpecialFormClassModelsTest < ActionView::TestCase
include BootstrapForm::ActionViewExtensions::FormHelper
Expand Down
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

class ActionView::TestCase
def setup_test_fixture
@address = Address.new(street: "Foo")
@user = User.new(email: "steve@example.com", password: "secret", comments: "my comment")
@builder = BootstrapForm::FormBuilder.new(:user, @user, self, {})
@horizontal_builder = BootstrapForm::FormBuilder.new(:user, @user, self,
Expand Down