Class: Shoulda::ActiveRecord::Matchers::EnsureInclusionOfMatcher

Inherits:
ValidationMatcher show all
Defined in:
lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from ValidationMatcher

#failure_message

Instance Method Summary collapse

Methods inherited from ValidationMatcher

#initialize, #negative_failure_message

Constructor Details

This class inherits a constructor from Shoulda::ActiveRecord::Matchers::ValidationMatcher

Instance Method Details

#descriptionObject



50
51
52
# File 'lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb', line 50

def description
  "ensure inclusion of #{@attribute} in #{@range.inspect}"
end

#in_range(range) ⇒ Object



25
26
27
28
29
30
# File 'lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb', line 25

def in_range(range)
  @range = range
  @minimum = range.first
  @maximum = range.last
  self
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
57
58
59
60
61
62
63
64
# File 'lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb', line 54

def matches?(subject)
  super(subject)

  @low_message  ||= :inclusion
  @high_message ||= :inclusion

  disallows_lower_value &&
    allows_minimum_value &&
    disallows_higher_value &&
    allows_maximum_value
end

#with_high_message(message) ⇒ Object



45
46
47
48
# File 'lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb', line 45

def with_high_message(message)
  @high_message = message if message
  self
end

#with_low_message(message) ⇒ Object



40
41
42
43
# File 'lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb', line 40

def with_low_message(message)
  @low_message = message if message
  self
end

#with_message(message) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb', line 32

def with_message(message)
  if message
    @low_message = message
    @high_message = message
  end
  self
end