class Shoulda::Matchers::ActiveRecord::AssociationMatchers::JoinTableMatcher
@private
Attributes
association_matcher[R]
failure_message[R]
missing_option[R]
reflector[R]
Public Class Methods
new(association_matcher, reflector)
click to toggle source
# 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
Public Instance Methods
join_table_exists?()
click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb, line 26 def join_table_exists? if connection.tables.include?(join_table) true else @failure_message = missing_table_message false end end
join_table_has_correct_columns?()
click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb, line 35 def join_table_has_correct_columns? if missing_columns.empty? true else @failure_message = missing_columns_message false end end
matches?(subject)
click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb, line 21 def matches?(subject) join_table_exists? && join_table_has_correct_columns? end
Private Instance Methods
actual_join_table_columns()
click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb, line 62 def actual_join_table_columns connection.columns(join_table).map(&:name) end
column_label()
click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb, line 75 def column_label if missing_columns.count > 1 'columns' else 'column' end end
expected_join_table_columns()
click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb, line 58 def expected_join_table_columns [foreign_key, association_foreign_key] end
missing_columns()
click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb, line 52 def missing_columns @missing_columns ||= expected_join_table_columns.select do |key| !actual_join_table_columns.include?(key.to_s) end end
missing_columns_message()
click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb, line 70 def missing_columns_message missing = missing_columns.join(', ') "join table #{join_table} missing #{column_label}: #{missing}" end
missing_table_message()
click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb, line 66 def missing_table_message "join table #{join_table} doesn't exist" end