Class: Shoulda::Matchers::ActiveRecord::HaveDbIndexMatcher
- Inherits:
-
Object
- Object
- Shoulda::Matchers::ActiveRecord::HaveDbIndexMatcher
- Defined in:
- lib/shoulda/matchers/active_record/have_db_index_matcher.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(columns) ⇒ HaveDbIndexMatcher
constructor
A new instance of HaveDbIndexMatcher.
- #matches?(subject) ⇒ Boolean
- #unique(unique = true) ⇒ Object
Constructor Details
#initialize(columns) ⇒ HaveDbIndexMatcher
Returns a new instance of HaveDbIndexMatcher.
116 117 118 119 |
# File 'lib/shoulda/matchers/active_record/have_db_index_matcher.rb', line 116 def initialize(columns) @expected_columns = normalize_columns_to_array(columns) @qualifiers = {} end |
Instance Method Details
#description ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/shoulda/matchers/active_record/have_db_index_matcher.rb', line 154 def description String.new('have ').tap do |description| description << if qualifiers.include?(:unique) "#{Shoulda::Matchers::Util.a_or_an(index_type)} " else 'an ' end description << 'index on ' description << inspected_expected_columns end end |
#failure_message ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/shoulda/matchers/active_record/have_db_index_matcher.rb', line 131 def = "Expected #{described_table_name} to #{positive_expectation}" << if index_exists? ". The index does exist, but #{reason}." elsif reason ", but #{reason}." else ', but it does not.' end Shoulda::Matchers.word_wrap() end |
#failure_message_when_negated ⇒ Object
147 148 149 150 151 152 |
# File 'lib/shoulda/matchers/active_record/have_db_index_matcher.rb', line 147 def Shoulda::Matchers.word_wrap( "Expected #{described_table_name} not to " + "#{negative_expectation}, but it does.", ) end |
#matches?(subject) ⇒ Boolean
126 127 128 129 |
# File 'lib/shoulda/matchers/active_record/have_db_index_matcher.rb', line 126 def matches?(subject) @subject = subject index_exists? && correct_unique? end |
#unique(unique = true) ⇒ Object
121 122 123 124 |
# File 'lib/shoulda/matchers/active_record/have_db_index_matcher.rb', line 121 def unique(unique = true) @qualifiers[:unique] = unique self end |