diff --git a/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb b/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb index 84fa1f44..cdac0677 100644 --- a/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +++ b/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb @@ -61,23 +61,21 @@ module Shoulda # :nodoc: end def whitelisting? - !accessible_attributes.empty? + authorizer.kind_of?(::ActiveModel::MassAssignmentSecurity::WhiteList) end def attr_mass_assignable? - if whitelisting? - accessible_attributes.include?(@attribute) - else - !protected_attributes.include?(@attribute) - end + !authorizer.deny?(@attribute) + end + + def authorizer + @subject.class.active_authorizer end def class_name @subject.class.name end - end - end end end diff --git a/spec/shoulda/active_model/allow_mass_assignment_of_matcher_spec.rb b/spec/shoulda/active_model/allow_mass_assignment_of_matcher_spec.rb index b5774518..60f029c2 100644 --- a/spec/shoulda/active_model/allow_mass_assignment_of_matcher_spec.rb +++ b/spec/shoulda/active_model/allow_mass_assignment_of_matcher_spec.rb @@ -71,4 +71,16 @@ describe Shoulda::Matchers::ActiveModel::AllowMassAssignmentOfMatcher do end end + context "an attribute on a class with all protected attributes" do + before do + define_model :example, :attr => :string do + attr_accessible + end + @model = Example.new + end + + it "should reject being mass-assignable" do + @model.should_not allow_mass_assignment_of(:attr) + end + end end