Class: Shoulda::ActiveRecord::Matchers::AllowMassAssignmentOfMatcher
- Inherits:
-
Object
- Object
- Shoulda::ActiveRecord::Matchers::AllowMassAssignmentOfMatcher
- Defined in:
- lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#failure_message ⇒ Object
readonly
Returns the value of attribute failure_message.
-
#negative_failure_message ⇒ Object
readonly
Returns the value of attribute negative_failure_message.
Instance Method Summary collapse
- #description ⇒ Object
-
#initialize(attribute) ⇒ AllowMassAssignmentOfMatcher
constructor
A new instance of AllowMassAssignmentOfMatcher.
- #matches?(subject) ⇒ Boolean
Constructor Details
#initialize(attribute) ⇒ AllowMassAssignmentOfMatcher
Returns a new instance of AllowMassAssignmentOfMatcher.
16 17 18 |
# File 'lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb', line 16 def initialize(attribute) @attribute = attribute.to_s end |
Instance Attribute Details
#failure_message ⇒ Object (readonly)
Returns the value of attribute failure_message.
47 48 49 |
# File 'lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb', line 47 def @failure_message end |
#negative_failure_message ⇒ Object (readonly)
Returns the value of attribute negative_failure_message.
47 48 49 |
# File 'lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb', line 47 def @negative_failure_message end |
Instance Method Details
#description ⇒ Object
49 50 51 |
# File 'lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb', line 49 def description "allow mass assignment of #{@attribute}" end |
#matches?(subject) ⇒ Boolean
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb', line 20 def matches?(subject) @subject = subject if attr_mass_assignable? if whitelisting? @failure_message = "#{@attribute} was made accessible" else if protected_attributes.empty? @negative_failure_message = "no attributes were protected" else @failure_message = "#{class_name} is protecting " << "#{protected_attributes.to_a.to_sentence}, " << "but not #{@attribute}." end end true else if whitelisting? @negative_failure_message = "Expected #{@attribute} to be accessible" else @negative_failure_message = "Did not expect #{@attribute} to be protected" end false end end |