Class: Shoulda::Matchers::ActiveRecord::DefineEnumForMatcher
- Inherits:
-
Object
- Object
- Shoulda::Matchers::ActiveRecord::DefineEnumForMatcher
- Defined in:
- lib/shoulda/matchers/active_record/define_enum_for_matcher.rb
Instance Method Summary collapse
- #backed_by_column_of_type(expected_column_type) ⇒ Object
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(attribute_name) ⇒ DefineEnumForMatcher
constructor
A new instance of DefineEnumForMatcher.
- #matches?(subject) ⇒ Boolean
- #with(expected_enum_values) ⇒ Object
- #with_prefix(expected_prefix = true) ⇒ Object
- #with_suffix(expected_suffix = true) ⇒ Object
- #with_values(expected_enum_values) ⇒ Object
Constructor Details
#initialize(attribute_name) ⇒ DefineEnumForMatcher
Returns a new instance of DefineEnumForMatcher.
174 175 176 177 |
# File 'lib/shoulda/matchers/active_record/define_enum_for_matcher.rb', line 174 def initialize(attribute_name) @attribute_name = attribute_name @options = { expected_enum_values: [] } end |
Instance Method Details
#backed_by_column_of_type(expected_column_type) ⇒ Object
224 225 226 227 |
# File 'lib/shoulda/matchers/active_record/define_enum_for_matcher.rb', line 224 def backed_by_column_of_type(expected_column_type) [:expected_column_type] = expected_column_type self end |
#description ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/shoulda/matchers/active_record/define_enum_for_matcher.rb', line 179 def description description = "#{simple_description} backed by " description << Shoulda::Matchers::Util.a_or_an(expected_column_type) if expected_enum_values.any? description << ' with values ' description << Shoulda::Matchers::Util.inspect_value( expected_enum_values, ) end if [:prefix] description << ", prefix: #{[:prefix].inspect}" end if [:suffix] description << ", suffix: #{[:suffix].inspect}" end description end |
#failure_message ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/shoulda/matchers/active_record/define_enum_for_matcher.rb', line 238 def = if enum_defined? "Expected #{model} to #{expectation}. " else "Expected #{model} to #{expectation}, but " end << "#{}." Shoulda::Matchers.word_wrap() end |
#failure_message_when_negated ⇒ Object
251 252 253 254 |
# File 'lib/shoulda/matchers/active_record/define_enum_for_matcher.rb', line 251 def = "Expected #{model} not to #{expectation}, but it did." Shoulda::Matchers.word_wrap() end |
#matches?(subject) ⇒ Boolean
229 230 231 232 233 234 235 236 |
# File 'lib/shoulda/matchers/active_record/define_enum_for_matcher.rb', line 229 def matches?(subject) @record = subject enum_defined? && enum_values_match? && column_type_matches? && enum_value_methods_exist? end |
#with(expected_enum_values) ⇒ Object
206 207 208 209 210 211 212 |
# File 'lib/shoulda/matchers/active_record/define_enum_for_matcher.rb', line 206 def with(expected_enum_values) Shoulda::Matchers.warn_about_deprecated_method( 'The `with` qualifier on `define_enum_for`', '`with_values`', ) with_values(expected_enum_values) end |
#with_prefix(expected_prefix = true) ⇒ Object
214 215 216 217 |
# File 'lib/shoulda/matchers/active_record/define_enum_for_matcher.rb', line 214 def with_prefix(expected_prefix = true) [:prefix] = expected_prefix self end |
#with_suffix(expected_suffix = true) ⇒ Object
219 220 221 222 |
# File 'lib/shoulda/matchers/active_record/define_enum_for_matcher.rb', line 219 def with_suffix(expected_suffix = true) [:suffix] = expected_suffix self end |
#with_values(expected_enum_values) ⇒ Object
201 202 203 204 |
# File 'lib/shoulda/matchers/active_record/define_enum_for_matcher.rb', line 201 def with_values(expected_enum_values) [:expected_enum_values] = expected_enum_values self end |