Class: Mongoid::Matchers::HaveTimestamps

Inherits:
Object
  • Object
show all
Defined in:
lib/matchers/have_timestamps.rb

Instance Method Summary collapse

Constructor Details

#initializeHaveTimestamps

Returns a new instance of HaveTimestamps.



8
9
10
# File 'lib/matchers/have_timestamps.rb', line 8

def initialize
  @root_module = 'Mongoid::Timestamps'
end

Instance Method Details

#descriptionObject



35
36
37
38
39
40
41
# 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_messageObject



43
44
45
# File 'lib/matchers/have_timestamps.rb', line 43

def failure_message
  "Expected #{@model.inspect} class to #{description}"
end

#failure_message_when_negatedObject



47
48
49
# File 'lib/matchers/have_timestamps.rb', line 47

def failure_message_when_negated
  "Expected #{@model.inspect} class to not #{description}"
end

#for(phase) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# 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) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
# 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

#shortenedObject



30
31
32
33
# File 'lib/matchers/have_timestamps.rb', line 30

def shortened
  @shortened = true
  self
end