65 lines
2.3 KiB
Diff
65 lines
2.3 KiB
Diff
|
|
From c52f0483ab803fb7db6af20bf6bc80890af8d504 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Josh Nichols <josh.nichols@gusto.com>
|
||
|
|
Date: Sat, 29 Jan 2022 11:01:02 -0500
|
||
|
|
Subject: [PATCH] Address differences in has_secure_password in Rails 7+
|
||
|
|
|
||
|
|
---
|
||
|
|
.../validate_presence_of_matcher_spec.rb | 40 +++++++++++++------
|
||
|
|
1 file changed, 28 insertions(+), 12 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb
|
||
|
|
index 818a57320..5c7841e67 100644
|
||
|
|
--- a/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb
|
||
|
|
+++ b/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb
|
||
|
|
@@ -860,22 +860,38 @@ def record_belonging_to(
|
||
|
|
end
|
||
|
|
|
||
|
|
context 'against a pre-set password in a model that has_secure_password' do
|
||
|
|
- it 'raises a CouldNotSetPasswordError' do
|
||
|
|
- user_class = define_model :user, password_digest: :string do
|
||
|
|
- has_secure_password validations: false
|
||
|
|
- validates_presence_of :password
|
||
|
|
- end
|
||
|
|
+ if Shoulda::Matchers::RailsShim.active_model_lt_7?
|
||
|
|
+ it 'raises a CouldNotSetPasswordError' do
|
||
|
|
+ user_class = define_model :user, password_digest: :string do
|
||
|
|
+ has_secure_password :password, validations: false
|
||
|
|
+ validates_presence_of :password
|
||
|
|
+ end
|
||
|
|
|
||
|
|
- user = user_class.new
|
||
|
|
- user.password = 'something'
|
||
|
|
+ user = user_class.new
|
||
|
|
+ user.password = 'something'
|
||
|
|
|
||
|
|
- assertion = lambda do
|
||
|
|
- expect(user).to validate_presence_of(:password)
|
||
|
|
+ assertion = lambda do
|
||
|
|
+ expect(user).to validate_presence_of(:password)
|
||
|
|
+ end
|
||
|
|
+
|
||
|
|
+ expect(&assertion).to raise_error(
|
||
|
|
+ Shoulda::Matchers::ActiveModel::CouldNotSetPasswordError,
|
||
|
|
+ )
|
||
|
|
end
|
||
|
|
+ else
|
||
|
|
+ it 'does not raises a CouldNotSetPasswordError' do
|
||
|
|
+ user_class = define_model :user, password_digest: :string do
|
||
|
|
+ has_secure_password :password, validations: false
|
||
|
|
+ validates_presence_of :password
|
||
|
|
+ end
|
||
|
|
|
||
|
|
- expect(&assertion).to raise_error(
|
||
|
|
- Shoulda::Matchers::ActiveModel::CouldNotSetPasswordError,
|
||
|
|
- )
|
||
|
|
+ user = user_class.new
|
||
|
|
+ user.password = 'something'
|
||
|
|
+
|
||
|
|
+ assertion = lambda do
|
||
|
|
+ expect(user).to validate_presence_of(:password)
|
||
|
|
+ end
|
||
|
|
+ end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|