Class: ClosureTree::Test::Matcher::ClosureTree

Inherits:
Object
  • Object
show all
Defined in:
lib/closure_tree/test/matcher.rb

Instance Method Summary collapse

Instance Method Details

#descriptionObject


79
80
81
# File 'lib/closure_tree/test/matcher.rb', line 79

def description
  "be a#{@ordered} closure tree#{@with_advisory_lock}"
end

#failure_messageObject Also known as: failure_message_for_should


67
68
69
# File 'lib/closure_tree/test/matcher.rb', line 67

def failure_message
  @message || "expected #{@subject.name} to #{description}"
end

#failure_message_when_negatedObject Also known as: failure_message_for_should_not


73
74
75
# File 'lib/closure_tree/test/matcher.rb', line 73

def failure_message_when_negated
  "expected #{@subject.name} not be a closure tree, but it is."
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)

9
10
11
12
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
# File 'lib/closure_tree/test/matcher.rb', line 9

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.options.include?(:order)
        @message = "expected #{@subject.name} to be an ordered closure tree"
        return false
      end
      unless @subject.column_names.include?(@subject._ct.options[:order].to_s)
        @message = "expected #{@subject.name} to have #{@subject._ct.options[:order]} as column"
        return false
      end
    end

    if @with_advisory_lock && !@subject._ct.options[:with_advisory_lock]
        @message = "expected #{@subject.name} to have advisory lock"
        return false
    end

    if @without_advisory_lock && @subject._ct.options[:with_advisory_lock]
        @message = "expected #{@subject.name} to not have advisory lock"
        return false
    end

    return true
  end
  false
end

#ordered(column = nil) ⇒ Object


51
52
53
54
55
# File 'lib/closure_tree/test/matcher.rb', line 51

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

#with_advisory_lockObject


57
58
59
60
# File 'lib/closure_tree/test/matcher.rb', line 57

def with_advisory_lock
  @with_advisory_lock = ' with advisory lock'
  self
end

#without_advisory_lockObject


62
63
64
65
# File 'lib/closure_tree/test/matcher.rb', line 62

def without_advisory_lock
  @without_advisory_lock = ' without advisory lock'
  self
end