Class: Shoulda::Matchers::ActiveRecord::AssociationMatchers::JoinTableMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(association_matcher, reflector) ⇒ JoinTableMatcher

Returns a new instance of JoinTableMatcher.



16
17
18
19
# File 'lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb', line 16

def initialize(association_matcher, reflector)
  @association_matcher = association_matcher
  @reflector = reflector
end

Instance Attribute Details

#failure_messageObject (readonly) Also known as: missing_option

Returns the value of attribute failure_message.



7
8
9
# File 'lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb', line 7

def failure_message
  @failure_message
end

Instance Method Details

#join_table_exists?Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
51
52
# File 'lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb', line 44

def join_table_exists?
  if connection.data_sources.
      include?(join_table_name.to_s)
    true
  else
    @failure_message = missing_table_message
    false
  end
end

#join_table_has_correct_columns?Boolean

Returns:

  • (Boolean)


54
55
56
57
58
59
60
61
# File 'lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb', line 54

def join_table_has_correct_columns?
  if missing_columns.empty?
    true
  else
    @failure_message = missing_columns_message
    false
  end
end

#join_table_option_correct?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb', line 27

def join_table_option_correct?
  if options.key?(:join_table_name)
    if option_verifier.correct_for_string?(
      :join_table,
      options[:join_table_name],
    )
      true
    else
      @failure_message = "#{name} should use"\
        " #{options[:join_table_name].inspect} for :join_table option"
      false
    end
  else
    true
  end
end

#matches?(_subject) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
# File 'lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb', line 21

def matches?(_subject)
  join_table_option_correct? &&
    join_table_exists? &&
    join_table_has_correct_columns?
end