Class: MuckEngine::Models::Matchers::SortingMatcher

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(scope, field) ⇒ SortingMatcher

Returns a new instance of SortingMatcher.



56
57
58
59
# File 'lib/muck-engine/test/models/matchers/scope_sorting_matchers.rb', line 56

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

Instance Method Details

#descriptionObject



87
88
89
# File 'lib/muck-engine/test/models/matchers/scope_sorting_matchers.rb', line 87

def description
  "sorting"
end

#failure_messageObject



83
84
85
# File 'lib/muck-engine/test/models/matchers/scope_sorting_matchers.rb', line 83

def failure_message
  "Expected #{factory_name} to scope #{@scope} on #{@field}"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/muck-engine/test/models/matchers/scope_sorting_matchers.rb', line 61

def matches?(subject)
  @subject = subject
  @subject.class.delete_all
  if @scope == :by_newest
    first = Factory(factory_name, :created_at => 1.hour.ago)
    second = Factory(factory_name, :created_at => 1.day.ago)
    first == @subject.class.send(@scope)[0] && second == @subject.class.send(@scope)[1]
  elsif @scope == :by_oldest
    first = Factory(factory_name, :created_at => 1.day.ago)
    second = Factory(factory_name, :created_at => 1.hour.ago)
    first == @subject.class.send(@scope)[0] && second == @subject.class.send(@scope)[1]            
  elsif @scope == :by_latest
    first = Factory(factory_name, :updated_at => 1.hour.ago)
    second = Factory(factory_name, :updated_at => 1.day.ago)
    first == @subject.class.send(@scope)[0] && second == @subject.class.send(@scope)[1]
  else
    first = Factory(factory_name, @field => 'a')
    second = Factory(factory_name, @field => 'b')
    first == @subject.class.send(@scope)[0] && second == @subject.class.send(@scope)[1]
  end
end