rubygem-shoulda-matchers/rubygem-shoulda-matchers-3.1.2-Fix-uniqueness-tests-to-not-use-attr_accessible.patch
2020-08-28 14:20:55 +08:00

62 lines
2.6 KiB
Diff

From 45ac5f5d754dae58708f4baef550e4986132d1ec Mon Sep 17 00:00:00 2001
From: Elliot Winkler <elliot.winkler@gmail.com>
Date: Mon, 24 Jul 2017 22:37:01 -0500
Subject: [PATCH] Rails 5: Fix uniqueness tests to not use attr_accessible
---
.../validate_uniqueness_of_matcher_spec.rb | 20 ++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb
index 114537bc..b8a72af6 100644
--- a/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb
+++ b/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb
@@ -1266,7 +1266,10 @@ def configure_validation_matcher(matcher)
favoriteable_type: { type: :string, options: { null: false } }
}
favorite_model = define_model 'Favorite', favorite_columns do
- attr_accessible :favoriteable
+ if respond_to?(:attr_accessible)
+ attr_accessible :favoriteable
+ end
+
belongs_to :favoriteable, polymorphic: true
validates :favoriteable, presence: true
validates :favoriteable_id, uniqueness: { scope: :favoriteable_type }
@@ -1291,7 +1294,10 @@ def configure_validation_matcher(matcher)
favoriteable_type: { type: :string, options: { null: false } }
}
favorite_model = define_model 'Models::Favorite', favorite_columns do
- attr_accessible :favoriteable
+ if respond_to?(:attr_accessible)
+ attr_accessible :favoriteable
+ end
+
belongs_to :favoriteable, polymorphic: true
validates :favoriteable, presence: true
validates :favoriteable_id, uniqueness: { scope: :favoriteable_type }
@@ -1547,8 +1553,10 @@ def define_model_validating_uniqueness(options = {}, &block)
m.validates_uniqueness_of attribute_name,
validation_options.merge(scope: scope_attribute_names)
- attributes.each do |attr|
- m.attr_accessible(attr[:name])
+ if m.respond_to?(:attr_accessible)
+ attributes.each do |attr|
+ m.attr_accessible(attr[:name])
+ end
end
block.call(m) if block
@@ -1591,7 +1599,9 @@ def build_record_validating_scoped_uniqueness_with_enum(options = {})
def define_model_without_validation
define_model(:example, attribute_name => :string) do |model|
- model.attr_accessible(attribute_name)
+ if model.respond_to?(:attr_accessible)
+ model.attr_accessible(attribute_name)
+ end
end
end