Class: NoBrainer::Matchers::Validations::ValidateUniquenessOfMatcher

Inherits:
HaveValidationMatcher show all
Defined in:
lib/matchers/validations/uniqueness_of.rb

Instance Method Summary collapse

Methods inherited from HaveValidationMatcher

#failure_message_for_should, #failure_message_for_should_not, #on, #with_message

Constructor Details

#initialize(field) ⇒ ValidateUniquenessOfMatcher

Returns a new instance of ValidateUniquenessOfMatcher.



7
8
9
# File 'lib/matchers/validations/uniqueness_of.rb', line 7

def initialize(field)
  super(field, :uniqueness)
end

Instance Method Details

#descriptionObject



25
26
27
28
29
# File 'lib/matchers/validations/uniqueness_of.rb', line 25

def description
  options_desc = []
  options_desc << " scoped to #{@scope.inspect}" if @scope
  "#{super}#{options_desc.to_sentence}"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# File 'lib/matchers/validations/uniqueness_of.rb', line 17

def matches?(actual)
  return false unless @result = super(actual)

  check_scope if @scope

  @result
end

#scoped_to(*scope) ⇒ Object Also known as: scoped_on



11
12
13
14
# File 'lib/matchers/validations/uniqueness_of.rb', line 11

def scoped_to(*scope)
  @scope = [scope].flatten.map(&:to_sym)
  self
end