Class: MuckEngine::Models::Matchers::ActiveMatcher

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(scope, field = :active) ⇒ ActiveMatcher

Returns a new instance of ActiveMatcher.



17
18
19
20
# File 'lib/muck-engine/test/models/matchers/scope_active_matchers.rb', line 17

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

Instance Method Details

#descriptionObject



35
36
37
# File 'lib/muck-engine/test/models/matchers/scope_active_matchers.rb', line 35

def description
  "active items"
end

#failure_messageObject



31
32
33
# File 'lib/muck-engine/test/models/matchers/scope_active_matchers.rb', line 31

def failure_message
  "Expected #{factory_name} to scope by #{@scope} on #{@field} and only find active items. But the call failed"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
# File 'lib/muck-engine/test/models/matchers/scope_active_matchers.rb', line 22

def matches?(subject)
  @subject = subject
  @subject.class.delete_all
  active_item = Factory(factory_name, @field => true)
  not_active_item = Factory(factory_name, @field => false)
  @subject.class.send(@scope).include?(active_item) &&
    !@subject.class.send(@scope).include?(not_active_item)
end