Skip to content

Commit

Permalink
Fix build_association on rails 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurnn committed Dec 22, 2014
1 parent 454e871 commit 957895f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.0.9

* Fixes build_association method on rails 4.2.0+

Fixes https://github.com/rails/rails/issues/18121

## 1.0.8 (June 16, 2014)

* Support Rails 4.0.6+ and 4.1.2+.
Expand Down
14 changes: 11 additions & 3 deletions lib/active_record/mass_assignment_security/reflection.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
module ActiveRecord
module Reflection
class AssociationReflection
def build_association(*options, &block)
klass.new(*options, &block)
if defined?(AbstractReflection)
class AbstractReflection
def build_association(*options, &block)
klass.new(*options, &block)
end
end
else
class AssociationReflection
def build_association(*options, &block)
klass.new(*options, &block)
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions test/ar_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
end

create_table :pirates, :force => true do |t|
t.string :name
end

create_table :groups, :force => true do |t|
Expand Down
6 changes: 6 additions & 0 deletions test/attribute_sanitization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,12 @@ def test_has_many_build_with_strict_sanitizer
end
end

def test_has_many_through_build_with_attr_accessible_attributes
group = Group.create!
pirate = group.members.build(name: "Murphy")
assert_equal "Murphy", pirate.name
end

# new

def test_has_many_new_with_attr_protected_attributes
Expand Down
2 changes: 1 addition & 1 deletion test/models/pirate.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Pirate < ActiveRecord::Base
self.mass_assignment_sanitizer = :strict

attr_accessible :name
has_many :memberships
end

0 comments on commit 957895f

Please sign in to comment.