class Shoulda::Matchers::ActiveModel::AllowMassAssignmentOfMatcher
@private
Attributes
failure_message[R]
failure_message_for_should[R]
failure_message_for_should_not[R]
failure_message_when_negated[R]
Public Class Methods
new(attribute)
click to toggle source
# File lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb, line 75 def initialize(attribute) @attribute = attribute.to_s @options = {} end
Public Instance Methods
as(role)
click to toggle source
# File lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb, line 80 def as(role) if active_model_less_than_3_1? raise 'You can specify role only in Rails 3.1 or greater' end @options[:role] = role self end
description()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb, line 113 def description [base_description, role_description].compact.join(' ') end
matches?(subject)
click to toggle source
# File lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb, line 88 def matches?(subject) @subject = subject if attr_mass_assignable? if whitelisting? @failure_message_when_negated = "#{@attribute} was made accessible" else if protected_attributes.empty? @failure_message_when_negated = 'no attributes were protected' else @failure_message_when_negated = "#{class_name} is protecting " << "#{protected_attributes.to_a.to_sentence}, " << "but not #{@attribute}." end end true else if whitelisting? @failure_message = "Expected #{@attribute} to be accessible" else @failure_message = "Did not expect #{@attribute} to be protected" end false end end
Private Instance Methods
accessible_attributes()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb, line 137 def accessible_attributes @accessible_attributes ||= (@subject.class.accessible_attributes || []) end
active_model_less_than_3_1?()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb, line 161 def active_model_less_than_3_1? ::ActiveModel::VERSION::STRING.to_f < 3.1 end
attr_mass_assignable?()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb, line 145 def attr_mass_assignable? !authorizer.deny?(@attribute) end
base_description()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb, line 119 def base_description "allow mass assignment of #{@attribute}" end
class_name()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb, line 157 def class_name @subject.class.name end
protected_attributes()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb, line 133 def protected_attributes @protected_attributes ||= (@subject.class.protected_attributes || []) end
role()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb, line 129 def role @options[:role] || :default end
role_description()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb, line 123 def role_description if role != :default "as #{role}" end end
whitelisting?()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb, line 141 def whitelisting? authorizer.kind_of?(::ActiveModel::MassAssignmentSecurity::WhiteList) end