Module: Spec::Rails::Matchers

Defined in:
lib/spec/rails/matchers/couch_document_validations.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) validate_couchdb_document_format_of(attribute, options)



5
6
7
8
9
10
# File 'lib/spec/rails/matchers/couch_document_validations.rb', line 5

def validate_couchdb_document_format_of(attribute, options)
  return simple_matcher("document model to validate format of :#{attribute} with #{options[:with]}") do |model|
    model.send("#{attribute}=", nil)
    !model.valid? && model.errors.on(attribute)
  end
end

- (Object) validate_couchdb_document_length_of(attribute, options)



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/spec/rails/matchers/couch_document_validations.rb', line 12

def validate_couchdb_document_length_of(attribute, options)
  return simple_matcher("document model to validate length of :#{attribute} within
    #{options[:maximum] || 0} to #{options[:minimum] || 'infinity'}") do |model|
    if options[:within]
       model.send("#{attribute}=", 'x' * (options[:within].last + 1))
    else
      if options[:maximum]
        model.send("#{attribute}=", 'x' * (options[:maximum] + 1))
      else
        model.send("#{attribute}=", 'x' * (options[:minimum] - 1))
      end
    end
    !model.valid? && model.errors.on(attribute)
  end
end

- (Object) validate_couchdb_document_numericality_of(attribute)



35
36
37
38
39
40
# File 'lib/spec/rails/matchers/couch_document_validations.rb', line 35

def validate_couchdb_document_numericality_of(attribute)
  return simple_matcher("document model to validate numericality of :#{attribute}") do |model|
    model.send("#{attribute}=", 'x')
    !model.valid? && model.errors.on(attribute)
  end
end

- (Object) validate_couchdb_document_presence_of(attribute)



28
29
30
31
32
33
# File 'lib/spec/rails/matchers/couch_document_validations.rb', line 28

def validate_couchdb_document_presence_of(attribute)
  return simple_matcher("document model to validate presence of :#{attribute}") do |model|
    model.send("#{attribute}=", nil)
    !model.valid? && model.errors.on(attribute)
  end
end