Class: Remarkable::ActiveRecord::Matchers::AssociationMatcher

Inherits:
Matcher::Base
  • Object
show all
Defined in:
lib/remarkable/active_record/macros/associations/association_matcher.rb

Instance Method Summary collapse

Methods inherited from Matcher::Base

#negative, #spec

Methods included from Matcher::DSL

included

Constructor Details

#initialize(macro, *associations) ⇒ AssociationMatcher

Returns a new instance of AssociationMatcher.



6
7
8
9
10
# File 'lib/remarkable/active_record/macros/associations/association_matcher.rb', line 6

def initialize(macro, *associations)
  @options = associations.extract_options!
  @macro = macro
  @associations = associations
end

Instance Method Details

#dependent(dependent) ⇒ Object



17
18
19
20
# File 'lib/remarkable/active_record/macros/associations/association_matcher.rb', line 17

def dependent(dependent)
  @options[:dependent] = dependent
  self
end

#descriptionObject



38
39
40
41
42
43
# File 'lib/remarkable/active_record/macros/associations/association_matcher.rb', line 38

def description
  description = "#{macro_description} #{@associations.to_sentence}"
  description += " through #{@options[:through]}" if @options[:through]
  description += " dependent => #{@options[:dependent]}" if @options[:dependent]
  description
end

#failure_messageObject



30
31
32
# File 'lib/remarkable/active_record/macros/associations/association_matcher.rb', line 30

def failure_message
  "Expected #{expectation} (#{@missing})"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
# File 'lib/remarkable/active_record/macros/associations/association_matcher.rb', line 22

def matches?(subject)
  @subject = subject
  
  assert_matcher_for(@associations) do |association|
    association_correct?(association)
  end
end

#negative_failure_messageObject



34
35
36
# File 'lib/remarkable/active_record/macros/associations/association_matcher.rb', line 34

def negative_failure_message
  "Did not expect #{expectation}"
end

#through(through) ⇒ Object



12
13
14
15
# File 'lib/remarkable/active_record/macros/associations/association_matcher.rb', line 12

def through(through)
  @options[:through] = through
  self
end