Class: ClosureTree::Test::Matcher::ClosureTree
- Inherits:
-
Object
- Object
- ClosureTree::Test::Matcher::ClosureTree
- Defined in:
- lib/closure_tree/test/matcher.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object (also: #failure_message_for_should)
- #failure_message_when_negated ⇒ Object (also: #failure_message_for_should_not)
- #matches?(subject) ⇒ Boolean
- #ordered(column = nil) ⇒ Object
- #with_advisory_lock ⇒ Object
- #without_advisory_lock ⇒ Object
Instance Method Details
#description ⇒ Object
83 84 85 |
# File 'lib/closure_tree/test/matcher.rb', line 83 def description "be a#{@ordered} closure tree#{@with_advisory_lock}" end |
#failure_message ⇒ Object Also known as: failure_message_for_should
71 72 73 |
# File 'lib/closure_tree/test/matcher.rb', line 71 def @message || "expected #{@subject.name} to #{description}" end |
#failure_message_when_negated ⇒ Object Also known as: failure_message_for_should_not
77 78 79 |
# File 'lib/closure_tree/test/matcher.rb', line 77 def "expected #{@subject.name} not be a closure tree, but it is." end |
#matches?(subject) ⇒ Boolean
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/closure_tree/test/matcher.rb', line 13 def matches?(subject) @subject = subject.is_a?(Class) ? subject : subject.class # OPTIMIZE if @subject.respond_to?(:_ct) unless @subject.column_names.include?(@subject._ct.parent_column_name) @message = "expected #{@subject.name} to respond to #{@subject._ct.parent_column_name}" return false end # Checking if hierarchy table exists (common error) unless @subject.hierarchy_class.table_exists? @message = "expected #{@subject.name}'s hierarchy table '#{@subject.hierarchy_class.table_name}' to exist" return false end if @ordered unless @subject._ct..include?(:order) @message = "expected #{@subject.name} to be an ordered closure tree" return false end unless @subject.column_names.include?(@subject._ct.[:order].to_s) @message = "expected #{@subject.name} to have #{@subject._ct.[:order]} as column" return false end end if @with_advisory_lock && !@subject._ct.[:with_advisory_lock] @message = "expected #{@subject.name} to have advisory lock" return false end if @without_advisory_lock && @subject._ct.[:with_advisory_lock] @message = "expected #{@subject.name} to not have advisory lock" return false end return true end false end |
#ordered(column = nil) ⇒ Object
55 56 57 58 59 |
# File 'lib/closure_tree/test/matcher.rb', line 55 def ordered(column = nil) @ordered = 'n ordered' @order_colum = column self end |
#with_advisory_lock ⇒ Object
61 62 63 64 |
# File 'lib/closure_tree/test/matcher.rb', line 61 def with_advisory_lock @with_advisory_lock = ' with advisory lock' self end |
#without_advisory_lock ⇒ Object
66 67 68 69 |
# File 'lib/closure_tree/test/matcher.rb', line 66 def without_advisory_lock @without_advisory_lock = ' without advisory lock' self end |