Module: Spec::Rails::Matchers
- Defined in:
- lib/spec/rails/matchers/couch_document_validations.rb
Instance Method Summary collapse
- #validate_couchdb_document_format_of(attribute, options) ⇒ Object
- #validate_couchdb_document_length_of(attribute, options) ⇒ Object
- #validate_couchdb_document_numericality_of(attribute) ⇒ Object
- #validate_couchdb_document_presence_of(attribute) ⇒ Object
Instance Method Details
#validate_couchdb_document_format_of(attribute, options) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/spec/rails/matchers/couch_document_validations.rb', line 5 def validate_couchdb_document_format_of(attribute, ) return simple_matcher("document model to validate format of :#{attribute} with #{[:with]}") do |model| model.send("#{attribute}=", nil) !model.valid? && model.errors.on(attribute) end end |
#validate_couchdb_document_length_of(attribute, options) ⇒ Object
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, ) return simple_matcher("document model to validate length of :#{attribute} within #{[:maximum] || 0} to #{[:minimum] || 'infinity'}") do |model| if [:within] model.send("#{attribute}=", 'x' * ([:within].last + 1)) else if [:maximum] model.send("#{attribute}=", 'x' * ([:maximum] + 1)) else model.send("#{attribute}=", 'x' * ([:minimum] - 1)) end end !model.valid? && model.errors.on(attribute) end end |
#validate_couchdb_document_numericality_of(attribute) ⇒ Object
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 |
#validate_couchdb_document_presence_of(attribute) ⇒ Object
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 |