public
Rubygem
Description: Makes tests easy on the fingers and the eyes
Homepage: http://www.thoughtbot.com/projects/shoulda
Clone URL: git://github.com/thoughtbot/shoulda.git
should_protect_attributes works with attr_accessible

Applied Luke Francl's patch from this Lighthouse ticket:
http://thoughtbot.lighthouseapp.com/projects/5807/tickets/25-patch-make-sh
ould_protect_attributes-with-attr_accessible

Also modified to tag model to use attr_accessible and added a
should_protect_attributes test to tag's unit test.
boone (author)
Sun May 11 16:48:57 -0700 2008
commit  2a7de9cca8fc688bd9f6741128005ab91af37e9a
tree    6acfe9c7d96e1ea8a1ceec6e5a82dbcf00e8e94f
parent  051edf42e8d5d8ccddffe96660a4effe5efac25f
...
106
107
108
109
110
111
 
 
 
 
 
 
 
112
113
114
...
106
107
108
 
 
 
109
110
111
112
113
114
115
116
117
118
0
@@ -106,9 +106,13 @@ module ThoughtBot # :nodoc:
0
         attributes.each do |attribute|
0
           attribute = attribute.to_sym
0
           should "protect #{attribute} from mass updates" do
0
- protected_attributes = klass.protected_attributes || []
0
- assert protected_attributes.include?(attribute.to_s),
0
- "#{klass} is protecting #{protected_attributes.to_a.to_sentence}, but not #{attribute}."
0
+ protected = klass.protected_attributes || []
0
+ accessible = klass.accessible_attributes || []
0
+
0
+ assert protected.include?(attribute.to_s) || !accessible.include?(attribute.to_s),
0
+ (accessible.empty? ?
0
+ "#{klass} is protecting #{protected.to_a.to_sentence}, but not #{attribute}." :
0
+ "#{klass} has made #{attribute} accessible")
0
           end
0
         end
0
       end
...
3
4
5
 
 
6
...
3
4
5
6
7
8
0
@@ -3,4 +3,6 @@ class Tag < ActiveRecord::Base
0
   has_many :posts, :through => :taggings
0
   
0
   validates_length_of :name, :minimum => 2
0
+
0
+ attr_accessible :name
0
 end
...
7
8
9
 
 
10
...
7
8
9
10
11
12
0
@@ -7,4 +7,6 @@ class TagTest < Test::Unit::TestCase
0
   should_have_many :posts
0
   
0
   should_ensure_length_at_least :name, 2
0
+
0
+ should_protect_attributes :secret
0
 end

Comments

    No one has commented yet.