Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/closure_tree/test/matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def matches?(subject)
@message = "expected #{@subject.name} to have #{@subject._ct.options[:order]} as column"
return false
end
if @order_column && @subject._ct.order_column != @order_column.to_s
@message = "expected #{@subject.name} to be ordered by #{@order_column}, " \
"but it is ordered by #{@subject._ct.order_column}"
return false
end
end

if @with_advisory_lock && !@subject._ct.options[:with_advisory_lock]
Expand All @@ -54,7 +59,7 @@ def matches?(subject)

def ordered(column = nil)
@ordered = 'n ordered'
@order_colum = column
@order_column = column
self
end

Expand Down
11 changes: 11 additions & 0 deletions test/closure_tree/matcher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ class MatcherTest < ActiveSupport::TestCase
assert_closure_tree Metal, ordered: :sort_order
end

test 'ordered matcher checks the given order column' do
assert be_a_closure_tree.ordered.matches?(Metal)
assert be_a_closure_tree.ordered(:sort_order).matches?(Metal)
assert be_a_closure_tree.ordered('sort_order').matches?(Metal)
assert be_a_closure_tree.ordered(:column_whereby_ordering_is_inferred).matches?(Label)

matcher = be_a_closure_tree.ordered(:value)
refute matcher.matches?(Metal)
assert_equal 'expected Metal to be ordered by value, but it is ordered by sort_order', matcher.failure_message
end

test 'advisory_lock option' do
# SQLite doesn't support advisory locks, so skip these tests when using SQLite
if ActiveRecord::Base.connection.adapter_name.downcase.include?('sqlite')
Expand Down