Skip to content

Commit

Permalink
Rails 5: Fix uniqueness tests to not use attr_accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmire committed Sep 17, 2017
1 parent df04f87 commit 45ac5f5
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 }
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 45ac5f5

Please sign in to comment.