public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
attr_protected and _accessible use sets of strings instead of arrays of 
symbols internally. Closes #10300.


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8231 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
jeremy (author)
Wed Nov 28 12:13:17 -0800 2007
commit  3a3e7efee9443fad159dc88a670ad28f12b98438
tree    a2fb297ad82927e69debf40d60f23241e3e9c498
parent  a33007d31a539ef5365ee13455f386c4e0b658fe
...
628
629
630
631
 
632
633
634
...
662
663
664
665
 
666
667
668
...
2084
2085
2086
2087
 
2088
2089
 
2090
2091
2092
...
628
629
630
 
631
632
633
634
...
662
663
664
 
665
666
667
668
...
2084
2085
2086
 
2087
2088
 
2089
2090
2091
2092
0
@@ -628,7 +628,7 @@ module ActiveRecord #:nodoc:
0
       #
0
       # To start from an all-closed default and enable attributes as needed, have a look at attr_accessible.
0
       def attr_protected(*attributes)
0
- write_inheritable_array("attr_protected", attributes - (protected_attributes || []))
0
+ write_inheritable_attribute("attr_protected", Set.new(attributes.map(&:to_s)) + (protected_attributes || []))
0
       end
0
 
0
       # Returns an array of all the attributes that have been protected from mass-assignment.
0
@@ -662,7 +662,7 @@ module ActiveRecord #:nodoc:
0
       # customer.credit_rating = "Average"
0
       # customer.credit_rating # => "Average"
0
       def attr_accessible(*attributes)
0
- write_inheritable_array("attr_accessible", attributes - (accessible_attributes || []))
0
+ write_inheritable_attribute("attr_accessible", Set.new(attributes.map(&:to_s)) + (accessible_attributes || []))
0
       end
0
 
0
       # Returns an array of all the attributes that have been made accessible to mass-assignment.
0
@@ -2084,9 +2084,9 @@ module ActiveRecord #:nodoc:
0
           if self.class.accessible_attributes.nil? && self.class.protected_attributes.nil?
0
             attributes.reject { |key, value| attributes_protected_by_default.include?(key.gsub(/\(.+/, "")) }
0
           elsif self.class.protected_attributes.nil?
0
- attributes.reject { |key, value| !self.class.accessible_attributes.include?(key.gsub(/\(.+/, "").intern) || attributes_protected_by_default.include?(key.gsub(/\(.+/, "")) }
0
+ attributes.reject { |key, value| !self.class.accessible_attributes.include?(key.gsub(/\(.+/, "")) || attributes_protected_by_default.include?(key.gsub(/\(.+/, "")) }
0
           elsif self.class.accessible_attributes.nil?
0
- attributes.reject { |key, value| self.class.protected_attributes.include?(key.gsub(/\(.+/,"").intern) || attributes_protected_by_default.include?(key.gsub(/\(.+/, "")) }
0
+ attributes.reject { |key, value| self.class.protected_attributes.include?(key.gsub(/\(.+/,"")) || attributes_protected_by_default.include?(key.gsub(/\(.+/, "")) }
0
           else
0
             raise "Declare either attr_protected or attr_accessible for #{self.class}, but not both."
0
           end
...
40
41
42
 
 
 
 
 
43
44
45
...
843
844
845
846
 
847
848
849
 
 
 
 
850
851
852
 
853
854
855
 
856
857
858
...
40
41
42
43
44
45
46
47
48
49
50
...
848
849
850
 
851
852
853
 
854
855
856
857
858
859
 
860
861
862
 
863
864
865
866
0
@@ -40,6 +40,11 @@ class LooseDescendant < LoosePerson
0
   attr_protected :phone_number
0
 end
0
 
0
+class LooseDescendantSecond< LoosePerson
0
+ attr_protected :phone_number
0
+ attr_protected :name
0
+end
0
+
0
 class TightPerson < ActiveRecord::Base
0
   self.table_name = 'people'
0
   attr_accessible :name, :address
0
@@ -843,16 +848,19 @@ class BasicsTest < Test::Unit::TestCase
0
   
0
   def test_mass_assignment_protection_inheritance
0
     assert_nil LoosePerson.accessible_attributes
0
- assert_equal [ :credit_rating, :administrator ], LoosePerson.protected_attributes
0
+ assert_equal Set.new([ 'credit_rating', 'administrator' ]), LoosePerson.protected_attributes
0
 
0
     assert_nil LooseDescendant.accessible_attributes
0
- assert_equal [ :credit_rating, :administrator, :phone_number ], LooseDescendant.protected_attributes
0
+ assert_equal Set.new([ 'credit_rating', 'administrator', 'phone_number' ]), LooseDescendant.protected_attributes
0
+
0
+ assert_nil LooseDescendantSecond.accessible_attributes
0
+ assert_equal Set.new([ 'credit_rating', 'administrator', 'phone_number', 'name' ]), LooseDescendantSecond.protected_attributes, 'Running attr_protected twice in one class should merge the protections'
0
 
0
     assert_nil TightPerson.protected_attributes
0
- assert_equal [ :name, :address ], TightPerson.accessible_attributes
0
+ assert_equal Set.new([ 'name', 'address' ]), TightPerson.accessible_attributes
0
 
0
     assert_nil TightDescendant.protected_attributes
0
- assert_equal [ :name, :address, :phone_number ], TightDescendant.accessible_attributes
0
+ assert_equal Set.new([ 'name', 'address', 'phone_number' ]), TightDescendant.accessible_attributes
0
   end
0
   
0
   def test_readonly_attributes

Comments

    No one has commented yet.