Class: MuckEngine::Models::Matchers::TimeMatcher

Inherits:
MuckMatcherBase show all
Defined in:
lib/muck-engine/test/models/matchers/scope_time_matchers.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(scope, field = :created_at) ⇒ TimeMatcher

Returns a new instance of TimeMatcher.



27
28
29
30
# File 'lib/muck-engine/test/models/matchers/scope_time_matchers.rb', line 27

def initialize(scope, field = :created_at)
  @scope = scope
  @field = field
end

Instance Method Details

#descriptionObject



51
52
53
# File 'lib/muck-engine/test/models/matchers/scope_time_matchers.rb', line 51

def description
  "items scoped #{@scope}"
end

#failure_messageObject



47
48
49
# File 'lib/muck-engine/test/models/matchers/scope_time_matchers.rb', line 47

def failure_message
  "Expected #{factory_name} to scope by #{@scope} on #{@field} and be successful. But the call failed"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/muck-engine/test/models/matchers/scope_time_matchers.rb', line 32

def matches?(subject)
  @subject = subject
  @subject.class.delete_all
  old_item = Factory(factory_name, @field => 1.month.ago)
  new_item = Factory(factory_name, @field => 1.day.ago)
  items = @subject.class.send(@scope, 1.week.ago)          
  if @scope == :newer_than
    items.include?(new_item) && !items.include?(old_item)
  elsif @scope == :older_than
    !items.include?(new_item) && items.include?(old_item)
  else
    raise "matcher not implemented for #{@scope}"
  end
end