Class: Mongoid::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

Constructor Details

#initialize(field) ⇒ ValidateUniquenessOfMatcher

Returns a new instance of ValidateUniquenessOfMatcher.



5
6
7
# File 'lib/matchers/validations/uniqueness_of.rb', line 5

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

Instance Method Details

#allow_blank?(allow_blank) ⇒ Boolean

Returns:

  • (Boolean)


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

def allow_blank?(allow_blank)
  @allow_blank = allow_blank
  self
end

#case_insensitiveObject



15
16
17
18
# File 'lib/matchers/validations/uniqueness_of.rb', line 15

def case_insensitive
  @case_insensitive = true
  self
end

#descriptionObject



41
42
43
44
45
46
47
48
# File 'lib/matchers/validations/uniqueness_of.rb', line 41

def description
  options_desc = []
  options_desc << " scoped to #{@scope.inspect}" if @scope
  options_desc << " allowing blank values" if @allow_blank
  options_desc << " allowing case insensitive values" if @case_insensitive
  options_desc << " with message '#{@expected_message}'" if @case_insensitive
  super << options_desc.to_sentence
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
38
39
# File 'lib/matchers/validations/uniqueness_of.rb', line 30

def matches?(actual)
  return false unless @result = super(actual)
  
  check_scope if @scope
  check_allow_blank if @allow_blank
  check_case_sensitivity if @case_insensitive
  check_expected_message if @expected_message
  
  @result
end

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



9
10
11
12
# File 'lib/matchers/validations/uniqueness_of.rb', line 9

def scoped_to(*scope)
  @scope = [scope].flatten
  self
end

#with_message(message) ⇒ Object



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

def with_message(message)
  @expected_message = message
  self
end