54 lines
2.0 KiB
Diff
54 lines
2.0 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.rb | 4 +-
|
|
lib/shoulda/matchers/rails_shim.rb | 10 +++++
|
|
2 files changed, 12 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb b/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb
|
|
index c23302091..0c93bc3af 100644
|
|
--- a/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb
|
|
+++ b/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb
|
|
@@ -144,7 +144,7 @@ def matches?(subject)
|
|
|
|
possibly_ignore_interference_by_writer
|
|
|
|
- if secure_password_being_validated?
|
|
+ if secure_password_being_validated? && Shoulda::Matchers::RailsShim.active_model_lt_7?
|
|
ignore_interference_by_writer.default_to(when: :blank?)
|
|
|
|
disallowed_values.all? do |value|
|
|
@@ -208,7 +208,7 @@ def secure_password_being_validated?
|
|
end
|
|
|
|
def possibly_ignore_interference_by_writer
|
|
- if secure_password_being_validated?
|
|
+ if secure_password_being_validated? && RailsShim.active_model_lt_7?
|
|
ignore_interference_by_writer.default_to(when: :blank?)
|
|
end
|
|
end
|
|
diff --git a/lib/shoulda/matchers/rails_shim.rb b/lib/shoulda/matchers/rails_shim.rb
|
|
index 2474d7363..c328d9e90 100644
|
|
--- a/lib/shoulda/matchers/rails_shim.rb
|
|
+++ b/lib/shoulda/matchers/rails_shim.rb
|
|
@@ -19,6 +19,16 @@ def active_record_version
|
|
Gem::Version.new('0')
|
|
end
|
|
|
|
+ def active_model_version
|
|
+ Gem::Version.new(::ActiveModel::VERSION::STRING)
|
|
+ rescue NameError
|
|
+ Gem::Version.new('0')
|
|
+ end
|
|
+
|
|
+ def active_model_lt_7?
|
|
+ Gem::Requirement.new('< 7').satisfied_by?(active_model_version)
|
|
+ end
|
|
+
|
|
def generate_validation_message(
|
|
record,
|
|
attribute,
|