File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
lib/active_record/mass_assignment_security Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ class CollectionProxy
54
54
def build ( attributes = { } , options = { } , &block )
55
55
@association . build ( attributes , options , &block )
56
56
end
57
+ alias_method :new , :build
57
58
58
59
def create ( attributes = { } , options = { } , &block )
59
60
@association . create ( attributes , options , &block )
Original file line number Diff line number Diff line change @@ -595,6 +595,40 @@ def test_has_many_build_with_strict_sanitizer
595
595
end
596
596
end
597
597
598
+ # new
599
+
600
+ def test_has_many_build_with_attr_protected_attributes
601
+ best_friend = @person . best_friends . new ( attributes_hash )
602
+ assert_default_attributes ( best_friend )
603
+ end
604
+
605
+ def test_has_many_build_with_attr_accessible_attributes
606
+ best_friend = @person . best_friends . new ( attributes_hash )
607
+ assert_default_attributes ( best_friend )
608
+ end
609
+
610
+ def test_has_many_build_with_admin_role_with_attr_protected_attributes
611
+ best_friend = @person . best_friends . new ( attributes_hash , :as => :admin )
612
+ assert_admin_attributes ( best_friend )
613
+ end
614
+
615
+ def test_has_many_build_with_admin_role_with_attr_accessible_attributes
616
+ best_friend = @person . best_friends . new ( attributes_hash , :as => :admin )
617
+ assert_admin_attributes ( best_friend )
618
+ end
619
+
620
+ def test_has_many_build_without_protection
621
+ best_friend = @person . best_friends . new ( attributes_hash , :without_protection => true )
622
+ assert_all_attributes ( best_friend )
623
+ end
624
+
625
+ def test_has_many_build_with_strict_sanitizer
626
+ with_strict_sanitizer do
627
+ best_friend = @person . best_friends . new ( attributes_hash . except ( :id , :comments ) )
628
+ assert_equal @person . id , best_friend . best_friend_id
629
+ end
630
+ end
631
+
598
632
# create
599
633
600
634
def test_has_many_create_with_attr_protected_attributes
You can’t perform that action at this time.
0 commit comments