Permalink
Browse files

allow_mass_assignment_of should fail if nothing was declared but expe…

…cted an attributes to be protected [#92 status:resolved].
  • Loading branch information...
1 parent 37fb412 commit 9eb9cff4849da75b94edd3eec7c2600284866d49 @josevalim josevalim committed Aug 25, 2009
@@ -18,16 +18,16 @@ def allows?
protected_attributes.empty?
end
- def is_protected?
- return positive? if protected_attributes.empty?
- !protected_attributes.include?(@attribute.to_s)
- end
-
def is_accessible?
return positive? if accessible_attributes.empty?
accessible_attributes.include?(@attribute.to_s)
end
+ def is_protected?
+ return accessible_attributes.empty? || positive? if protected_attributes.empty?
+ !protected_attributes.include?(@attribute.to_s)
+ end
+
def interpolation_options
if @subject
if positive?
@@ -78,21 +78,29 @@ def define_and_validate(options={})
end
describe 'failures' do
- it "should fail if not all attributes are accessible on should not" do
+ it "should fail if some attribute is accessible when it shuold be protected" do
define_and_validate(:accessible => true)
lambda {
should_not allow_mass_assignment_of :title, :another
}.should raise_error(Spec::Expectations::ExpectationNotMetError, /Product has made title accessible/)
end
- it "should fail if accessible when protecting" do
+ it "should fail if attributes are accessible when none should" do
define_and_validate(:accessible => true)
lambda {
should_not allow_mass_assignment_of
}.should raise_error(Spec::Expectations::ExpectationNotMetError, /Product made category and title accessible/)
end
+
+ it "should fail if nothing was declared but expected to be protected" do
+ define_and_validate
+
+ lambda {
+ should_not allow_mass_assignment_of(:title)
+ }.should raise_error(Spec::Expectations::ExpectationNotMetError, /Did not expect Product to allow mass assignment of title/)
+ end
end
end

0 comments on commit 9eb9cff

Please sign in to comment.