Class: Mongoid::Matchers::AllowMassAssignmentOfMatcher
- Inherits:
-
Object
- Object
- Mongoid::Matchers::AllowMassAssignmentOfMatcher
- Defined in:
- lib/matchers/allow_mass_assignment.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#failure_message ⇒ Object
readonly
Returns the value of attribute failure_message.
-
#negative_failure_message ⇒ Object
(also: #failure_message_when_negated)
readonly
Returns the value of attribute negative_failure_message.
Instance Method Summary collapse
- #as(role) ⇒ Object
- #description ⇒ Object
-
#initialize(attribute) ⇒ AllowMassAssignmentOfMatcher
constructor
A new instance of AllowMassAssignmentOfMatcher.
- #matches?(klass) ⇒ Boolean
Constructor Details
#initialize(attribute) ⇒ AllowMassAssignmentOfMatcher
Returns a new instance of AllowMassAssignmentOfMatcher.
8 9 10 11 |
# File 'lib/matchers/allow_mass_assignment.rb', line 8 def initialize(attribute) @attribute = attribute.to_s @options = {} end |
Instance Attribute Details
#failure_message ⇒ Object (readonly)
Returns the value of attribute failure_message.
5 6 7 |
# File 'lib/matchers/allow_mass_assignment.rb', line 5 def @failure_message end |
#negative_failure_message ⇒ Object (readonly) Also known as: failure_message_when_negated
Returns the value of attribute negative_failure_message.
5 6 7 |
# File 'lib/matchers/allow_mass_assignment.rb', line 5 def @negative_failure_message end |
Instance Method Details
#as(role) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/matchers/allow_mass_assignment.rb', line 13 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 ⇒ Object
46 47 48 |
# File 'lib/matchers/allow_mass_assignment.rb', line 46 def description "allow mass assignment of #{@attribute}" end |
#matches?(klass) ⇒ Boolean
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/matchers/allow_mass_assignment.rb', line 21 def matches?(klass) @klass = klass if attr_mass_assignable? if whitelisting? @negative_failure_message = "#{@attribute} was made accessible" else if protected_attributes.empty? @negative_failure_message = 'no attributes were protected' else @negative_failure_message = "#{class_name} is protecting " \ "#{protected_attributes.to_a.to_sentence}, " \ "but not #{@attribute}." end end true else @failure_message = if whitelisting? "Expected #{@attribute} to be accessible" else "Did not expect #{@attribute} to be protected" end false end end |