Skip to content

Commit 6479d18

Browse files
committed
Test that labels with errors uses #human_attribute_name under the hood
1 parent 6935683 commit 6479d18

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

test/bootstrap_form_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ def setup
6363
assert_equal expected, bootstrap_form_for(@user, label_errors: true, inline_errors: true) { |f| f.text_field :email }
6464
end
6565

66+
test "label error messages use humanized attribute names" do
67+
I18n.backend.store_translations(:en, {activerecord: {attributes: {user: {email: 'Your e-mail address'}}}})
68+
69+
@user.email = nil
70+
@user.valid?
71+
72+
expected = %{<form accept-charset=\"UTF-8\" action=\"/users\" class=\"new_user\" id=\"new_user\" method=\"post\" role=\"form\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /></div><div class=\"form-group has-error\"><label class=\"control-label\" for=\"user_email\">Your e-mail address can&#39;t be blank, is too short (minimum is 5 characters)</label><input class=\"form-control\" id=\"user_email\" name=\"user[email]\" type=\"text\" /><span class=\"help-block\">can&#39;t be blank, is too short (minimum is 5 characters)</span></div></form>}
73+
assert_equal expected, bootstrap_form_for(@user, label_errors: true, inline_errors: true) { |f| f.text_field :email }
74+
75+
I18n.backend.store_translations(:en, {activerecord: {attributes: {user: {email: nil}}}})
76+
end
77+
6678
test "alert message is wrapped correctly" do
6779
@user.email = nil
6880
@user.valid?

0 commit comments

Comments
 (0)