Class: Shoulda::Matchers::ActiveRecord::AssociationMatchers::JoinTableMatcher
- Inherits:
-
Object
- Object
- Shoulda::Matchers::ActiveRecord::AssociationMatchers::JoinTableMatcher
- Defined in:
- lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb
Instance Attribute Summary collapse
-
#failure_message ⇒ Object
(also: #missing_option)
readonly
Returns the value of attribute failure_message.
Instance Method Summary collapse
-
#initialize(association_matcher, reflector) ⇒ JoinTableMatcher
constructor
A new instance of JoinTableMatcher.
- #join_table_exists? ⇒ Boolean
- #join_table_has_correct_columns? ⇒ Boolean
- #join_table_option_correct? ⇒ Boolean
- #matches?(_subject) ⇒ Boolean
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_message ⇒ Object (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 end |
Instance Method Details
#join_table_exists? ⇒ 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 = false end end |
#join_table_has_correct_columns? ⇒ 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 = false end end |
#join_table_option_correct? ⇒ 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 .key?(:join_table_name) if option_verifier.correct_for_string?( :join_table, [:join_table_name], ) true else @failure_message = "#{name} should use"\ " #{[:join_table_name].inspect} for :join_table option" false end else true end end |
#matches?(_subject) ⇒ 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 |