class Mongoid::Matchers::HaveTimestamps

Public Class Methods

new() click to toggle source
# File lib/matchers/have_timestamps.rb, line 8
def initialize
  @root_module = 'Mongoid::Timestamps'
end

Public Instance Methods

description() click to toggle source
# File lib/matchers/have_timestamps.rb, line 35
def description
  desc = 'be a Mongoid document with'
  desc << ' shorted' if @shortened
  desc << " #{@phase}" if @phase
  desc << ' timestamps'
  desc
end
failure_message() click to toggle source
# File lib/matchers/have_timestamps.rb, line 43
def failure_message
  "Expected #{@model.inspect} class to #{description}"
end
failure_message_when_negated() click to toggle source
# File lib/matchers/have_timestamps.rb, line 47
def failure_message_when_negated
  "Expected #{@model.inspect} class to not #{description}"
end
for(phase) click to toggle source
# File lib/matchers/have_timestamps.rb, line 17
def for(phase)
  raise('You\'ve already declared timetamp\'s sub-module via "for" clause') if @submodule

  case @phase = phase.to_sym
  when :creating then @submodule = 'Created'
  when :updating then @submodule = 'Updated'
  else
    raise('Timestamps can be declared only for creating or updating')
  end

  self
end
matches?(actual) click to toggle source
# File lib/matchers/have_timestamps.rb, line 12
def matches?(actual)
  @model = actual.is_a?(Class) ? actual : actual.class
  @model.included_modules.include?(expected_module)
end
shortened() click to toggle source
# File lib/matchers/have_timestamps.rb, line 30
def shortened
  @shortened = true
  self
end

Private Instance Methods

expected_module() click to toggle source
# File lib/matchers/have_timestamps.rb, line 53
def expected_module
  expected_module = @root_module
  expected_module << "::#{@submodule}" if @submodule
  expected_module << '::Short' if @shortened
  expected_module.constantize
end