Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/active_record/mass_assignment_security/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ def initialize(attributes = nil, options = {})
initialize_internals_callback

# +options+ argument is only needed to make protected_attributes gem easier to hook.
init_attributes(attributes, options) if attributes
assign_attributes(attributes, options) if attributes

yield self if block_given?
_run_initialize_callbacks
end

private

def init_attributes(attributes, options)
assign_attributes(attributes, options)
if ActiveRecord.gem_version < Gem::Version.new('7.2')
# unsure if needed
def init_attributes(attributes, options = {})
assign_attributes(attributes, options)
end
end

def init_internals
Expand Down
4 changes: 4 additions & 0 deletions test/mass_assignment_security/association_relation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ class AssociationRelationTest < ActiveSupport::TestCase
membership = group.memberships.where(pirate_id: 1).create!
assert_equal(1, membership.pirate_id)
end

test "dup works" do
assert_nothing_raised { Group.create!.dup }
end
end