Parent

Class/Module Index [+]

Quicksearch

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 81
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 86
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 119
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 94
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

[Validate]

Generated with the Darkfish Rdoc Generator 2.