class Shoulda::Matchers::ActiveModel::Callbacks

Attributes

failure_message_for_should[R]
failure_message_for_should_not[R]

Public Class Methods

new(occures, action, method_name) click to toggle source
# File lib/shoulda/matchers/active_model/callbacks.rb, line 21
def initialize(occures, action, method_name)
  @occures = occures.to_sym
  @action = action.to_sym
  @method_name = method_name.to_sym
end

Public Instance Methods

action_callbacks() click to toggle source
# File lib/shoulda/matchers/active_model/callbacks.rb, line 46
def action_callbacks
  begin
    @subject.send("_#{@action}_callbacks")
  rescue NoMethodError
    raise "Subject must be Rails model class"
  end
end
callback_name() click to toggle source
# File lib/shoulda/matchers/active_model/callbacks.rb, line 54
def callback_name
  "#{@occures}_#{@action}"
end
callbacks() click to toggle source
# File lib/shoulda/matchers/active_model/callbacks.rb, line 42
def callbacks
  action_callbacks.select{|cb| cb.kind.eql?(@occures) }.collect(&:filter)
end
description() click to toggle source
# File lib/shoulda/matchers/active_model/callbacks.rb, line 38
def description
  "have #{@occures.to_s} #{@action.to_s} callback"
end
matches?(subject) click to toggle source
# File lib/shoulda/matchers/active_model/callbacks.rb, line 27
def matches?(subject)
  @subject = subject
  if callbacks.include?(@method_name)
    @failure_message_for_should_not = "Didn't expect #{@subject.model_name} model to have #{callback_name} callback on method :#{@method_name}"
  else
    @failure_message_for_should = "Expected #{@subject.model_name} model to have #{callback_name} callback on method :#{@method_name}"
    return false
  end
  true
end