Class: Shoulda::Lotus::Matchers::ValidateInclusionOfMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda/lotus/matchers/validate_inclusion_of_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(attribute) ⇒ ValidateInclusionOfMatcher



9
10
11
# File 'lib/shoulda/lotus/matchers/validate_inclusion_of_matcher.rb', line 9

def initialize(attribute)
  @attribute = attribute
end

Instance Method Details

#descriptionObject



25
26
27
# File 'lib/shoulda/lotus/matchers/validate_inclusion_of_matcher.rb', line 25

def description
  "inclusion only '#{@values.inspect}' values on '#{@attribute}'"
end

#failure_messageObject



29
30
31
# File 'lib/shoulda/lotus/matchers/validate_inclusion_of_matcher.rb', line 29

def failure_message
  "'#{@attribute}' is include only '#{@values.inspect}'"
end

#failure_message_when_negatedObject



33
34
35
# File 'lib/shoulda/lotus/matchers/validate_inclusion_of_matcher.rb', line 33

def failure_message_when_negated
  "'#{@attribute}' is not include only '#{@values.inspect}'"
end

#in_array(values) ⇒ Object



37
38
39
40
# File 'lib/shoulda/lotus/matchers/validate_inclusion_of_matcher.rb', line 37

def in_array(values)
  @values = values
  self
end

#matches?(target) ⇒ Boolean



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/shoulda/lotus/matchers/validate_inclusion_of_matcher.rb', line 13

def matches?(target)
  value = nil

  loop do
    value = SecureRandom.hex
    break unless @values.include? value
  end

  target.send("#{@attribute}=", value)
  Matcher.new(target, @attribute, :inclusion).matches?
end