Class: Mongoid::Matchers::HaveTimestamps
- Inherits:
-
Object
- Object
- Mongoid::Matchers::HaveTimestamps
- Defined in:
- lib/matchers/have_timestamps.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
- #for(phase) ⇒ Object
-
#initialize ⇒ HaveTimestamps
constructor
A new instance of HaveTimestamps.
- #matches?(actual) ⇒ Boolean
- #shortened ⇒ Object
Constructor Details
#initialize ⇒ HaveTimestamps
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
#description ⇒ Object
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_message ⇒ Object
43 44 45 |
# File 'lib/matchers/have_timestamps.rb', line 43 def "Expected #{@model.inspect} class to #{description}" end |
#failure_message_when_negated ⇒ Object
47 48 49 |
# File 'lib/matchers/have_timestamps.rb', line 47 def "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
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 |
#shortened ⇒ Object
30 31 32 33 |
# File 'lib/matchers/have_timestamps.rb', line 30 def shortened @shortened = true self end |