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
- #validating(value = true, allowing_nil: false) ⇒ Object
- #with_default(default_value) ⇒ Object
- #with_prefix(expected_prefix = true) ⇒ Object
- #with_suffix(expected_suffix = true) ⇒ Object
- #with_values(expected_enum_values) ⇒ Object
- #without_instance_methods ⇒ Object
- #without_scopes ⇒ Object
Constructor Details
#initialize(attribute_name) ⇒ DefineEnumForMatcher
Returns a new instance of DefineEnumForMatcher.
285 286 287 288 |
# File 'lib/shoulda/matchers/active_record/define_enum_for_matcher.rb', line 285 def initialize(attribute_name) @attribute_name = attribute_name @options = { expected_enum_values: [], scopes: true, instance_methods: true } end |
Instance Method Details
#backed_by_column_of_type(expected_column_type) ⇒ Object
333 334 335 336 |
# File 'lib/shoulda/matchers/active_record/define_enum_for_matcher.rb', line 333 def backed_by_column_of_type(expected_column_type) [:expected_column_type] = expected_column_type self end |
#description ⇒ Object
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/shoulda/matchers/active_record/define_enum_for_matcher.rb', line 290 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
365 366 367 368 369 370 371 372 373 374 375 376 |
# File 'lib/shoulda/matchers/active_record/define_enum_for_matcher.rb', line 365 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
378 379 380 381 |
# File 'lib/shoulda/matchers/active_record/define_enum_for_matcher.rb', line 378 def = "Expected #{model} not to #{expectation}, but it did." Shoulda::Matchers.word_wrap() end |
#matches?(subject) ⇒ Boolean
353 354 355 356 357 358 359 360 361 362 363 |
# File 'lib/shoulda/matchers/active_record/define_enum_for_matcher.rb', line 353 def matches?(subject) @record = subject enum_defined? && enum_values_match? && column_type_matches? && enum_value_methods_exist? && scope_presence_matches? && default_value_matches? && validating_matches? end |
#validating(value = true, allowing_nil: false) ⇒ Object
312 313 314 315 316 |
# File 'lib/shoulda/matchers/active_record/define_enum_for_matcher.rb', line 312 def validating(value = true, allowing_nil: false) [:validating] = value [:allowing_nil] = allowing_nil self end |
#with_default(default_value) ⇒ Object
348 349 350 351 |
# File 'lib/shoulda/matchers/active_record/define_enum_for_matcher.rb', line 348 def with_default(default_value) [:default] = default_value self end |
#with_prefix(expected_prefix = true) ⇒ Object
323 324 325 326 |
# File 'lib/shoulda/matchers/active_record/define_enum_for_matcher.rb', line 323 def with_prefix(expected_prefix = true) [:prefix] = expected_prefix self end |
#with_suffix(expected_suffix = true) ⇒ Object
328 329 330 331 |
# File 'lib/shoulda/matchers/active_record/define_enum_for_matcher.rb', line 328 def with_suffix(expected_suffix = true) [:suffix] = expected_suffix self end |
#with_values(expected_enum_values) ⇒ Object
318 319 320 321 |
# File 'lib/shoulda/matchers/active_record/define_enum_for_matcher.rb', line 318 def with_values(expected_enum_values) [:expected_enum_values] = expected_enum_values self end |
#without_instance_methods ⇒ Object
343 344 345 346 |
# File 'lib/shoulda/matchers/active_record/define_enum_for_matcher.rb', line 343 def without_instance_methods [:instance_methods] = false self end |
#without_scopes ⇒ Object
338 339 340 341 |
# File 'lib/shoulda/matchers/active_record/define_enum_for_matcher.rb', line 338 def without_scopes [:scopes] = false self end |