Fix tests with Rails main

Rails main / 7.1.0.alpha introduced a change to improve typography by
default, by converting all apostrophes to be single quotation marks.
https://github.com/rails/rails/pull/45463

The change caused all our text based matching to fail, this updates the
tests to ensure compatibility.

Model tests were changed to test against the error type & information
rather than the translated string, which I think is an improvement
overall that should make them a little less brittle. I thought of using
[of_kind?] but that isn't available on all Rails versions we currently
support, while `added?` is. The drawback is that `added?` require full
details like the `:confirmation` example which requires the related
attribute that is being confirmed, but that's a small price to pay.

Integration tests were changed to match on a regexp that accepts both
quotes. I could've used a simple `.` to match anything there, but
thought I'd just keep it specific for clarity on what it is really
expected to match there. Plus, since it's integration testing against a
rendered response body, it's better to match the actual text rather than
resort on other ways. (like using I18n directly, etc.)

[of_kind?] https://api.rubyonrails.org/classes/ActiveModel/Errors.html#method-i-of_kind-3F
This commit is contained in:
Carlos Antonio da Silva
2023-03-17 10:42:29 -03:00
parent afec6655c7
commit 232c855c54
9 changed files with 32 additions and 32 deletions

View File

@@ -30,12 +30,12 @@ class AuthenticatableTest < ActiveSupport::TestCase
test 'find_or_initialize_with_errors adds blank error' do
user_with_error = User.find_or_initialize_with_errors([:email], { email: "" })
assert_equal ["Email can't be blank"], user_with_error.errors.full_messages_for(:email)
assert user_with_error.errors.added?(:email, :blank)
end
test 'find_or_initialize_with_errors adds invalid error' do
user_with_error = User.find_or_initialize_with_errors([:email], { email: "example@example.com" })
assert_equal ["Email is invalid"], user_with_error.errors.full_messages_for(:email)
assert user_with_error.errors.added?(:email, :invalid)
end
if defined?(ActionController::Parameters)