mirror of
https://github.com/heartcombo/devise.git
synced 2026-01-10 07:18:14 -05:00
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:
@@ -178,13 +178,13 @@ class ConfirmationTest < Devise::IntegrationTest
|
||||
test "should not be able to confirm an email with a blank confirmation token" do
|
||||
visit_user_confirmation_with_token("")
|
||||
|
||||
assert_contain "Confirmation token can't be blank"
|
||||
assert_contain %r{Confirmation token can['’]t be blank}
|
||||
end
|
||||
|
||||
test "should not be able to confirm an email with a nil confirmation token" do
|
||||
visit_user_confirmation_with_token(nil)
|
||||
|
||||
assert_contain "Confirmation token can't be blank"
|
||||
assert_contain %r{Confirmation token can['’]t be blank}
|
||||
end
|
||||
|
||||
test "should not be able to confirm user with blank confirmation token" do
|
||||
@@ -193,7 +193,7 @@ class ConfirmationTest < Devise::IntegrationTest
|
||||
|
||||
visit_user_confirmation_with_token("")
|
||||
|
||||
assert_contain "Confirmation token can't be blank"
|
||||
assert_contain %r{Confirmation token can['’]t be blank}
|
||||
end
|
||||
|
||||
test "should not be able to confirm user with nil confirmation token" do
|
||||
@@ -202,7 +202,7 @@ class ConfirmationTest < Devise::IntegrationTest
|
||||
|
||||
visit_user_confirmation_with_token(nil)
|
||||
|
||||
assert_contain "Confirmation token can't be blank"
|
||||
assert_contain %r{Confirmation token can['’]t be blank}
|
||||
end
|
||||
|
||||
test 'error message is configurable by resource name' do
|
||||
|
||||
@@ -173,7 +173,7 @@ class PasswordTest < Devise::IntegrationTest
|
||||
assert_response :success
|
||||
assert_current_url '/users/password'
|
||||
assert_have_selector '#error_explanation'
|
||||
assert_contain "Password confirmation doesn't match Password"
|
||||
assert_contain %r{Password confirmation doesn['’]t match Password}
|
||||
assert_not user.reload.valid_password?('987654321')
|
||||
end
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ class RegistrationTest < Devise::IntegrationTest
|
||||
assert_template 'registrations/new'
|
||||
assert_have_selector '#error_explanation'
|
||||
assert_contain "Email is invalid"
|
||||
assert_contain "Password confirmation doesn't match Password"
|
||||
assert_contain %r{Password confirmation doesn['’]t match Password}
|
||||
assert_contain "2 errors prohibited"
|
||||
assert_nil User.to_adapter.find_first
|
||||
|
||||
@@ -251,7 +251,7 @@ class RegistrationTest < Devise::IntegrationTest
|
||||
fill_in 'current password', with: '12345678'
|
||||
click_button 'Update'
|
||||
|
||||
assert_contain "Password confirmation doesn't match Password"
|
||||
assert_contain %r{Password confirmation doesn['’]t match Password}
|
||||
assert_not User.to_adapter.find_first.valid_password?('pas123')
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user