class Mongoid::Matchers::HaveAssociationCallbackMatcher

Create an matcher for set_callback method

Usage:

it { is_expected.to association_callback(:has_many,

:add,
:after,
:send_email_to_subscribers)  }

Constants

CONTEXTS
OPERATIONS
RELATIONS

Public Class Methods

new(*args) click to toggle source
# File lib/matchers/association_callbacks.rb, line 18
def initialize(*args)
  @relation = args[0]
  @type = args[1]
  @hook = args[2]
  @method = args[3]
end

Public Instance Methods

description() click to toggle source
# File lib/matchers/association_callbacks.rb, line 37
def description
  "be association_callback(:#{@type}, :#{@hook})"
end
failure_message() click to toggle source
# File lib/matchers/association_callbacks.rb, line 41
def failure_message
  message_error
end
failure_message_when_negated() click to toggle source
# File lib/matchers/association_callbacks.rb, line 45
def failure_message_when_negated
  message_error
end
matches?(klass) click to toggle source
# File lib/matchers/association_callbacks.rb, line 25
def matches?(klass)
  @model = klass

  return false unless \
    relation_is_correct? ||
    context_is_correct? ||
    operation_is_correct? ||
    callback_is_correct?

  testings_presence_method_callback
end

Private Instance Methods

callback_is_correct?() click to toggle source
# File lib/matchers/association_callbacks.rb, line 63
def callback_is_correct?
  @model.class.respond_to?(:"_#{@type}_callbacks")
end
context_is_correct?() click to toggle source
# File lib/matchers/association_callbacks.rb, line 55
def context_is_correct?
  CONTEXTS.include?(@hook)
end
message_error() click to toggle source
# File lib/matchers/association_callbacks.rb, line 71
      def message_error
        <<-ERROR
  expected #{@model} have method callback to association :
    has_many <relation>, #{@hook}: :#{@method}

    def #{@method}
    end
        ERROR
      end
operation_is_correct?() click to toggle source
# File lib/matchers/association_callbacks.rb, line 59
def operation_is_correct?
  OPERATIONS.include?(@type)
end
relation_is_correct?() click to toggle source
# File lib/matchers/association_callbacks.rb, line 51
def relation_is_correct?
  RELATIONS.include?(@relation)
end
testings_presence_method_callback() click to toggle source
# File lib/matchers/association_callbacks.rb, line 67
def testings_presence_method_callback
  @model.methods.include?(:"#{@method}")
end