Class: MuckEngine::Models::Matchers::SortingMatcher
- Inherits:
-
MuckMatcherBase
- Object
- MuckMatcherBase
- MuckEngine::Models::Matchers::SortingMatcher
- Defined in:
- lib/muck-engine/test/models/matchers/scope_sorting_matchers.rb
Overview
:nodoc:
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(scope, field) ⇒ SortingMatcher
constructor
A new instance of SortingMatcher.
- #matches?(subject) ⇒ Boolean
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
#description ⇒ Object
87 88 89 |
# File 'lib/muck-engine/test/models/matchers/scope_sorting_matchers.rb', line 87 def description "sorting" end |
#failure_message ⇒ Object
83 84 85 |
# File 'lib/muck-engine/test/models/matchers/scope_sorting_matchers.rb', line 83 def "Expected #{factory_name} to scope #{@scope} on #{@field}" end |
#matches?(subject) ⇒ 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 |