File: validatable_test.rb

package info (click to toggle)
ruby-validatable 1.6.7-11
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 284 kB
  • sloc: ruby: 1,636; makefile: 10
file content (38 lines) | stat: -rw-r--r-- 885 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')

Expectations do
  expect false do
    validation = stub_everything(:should_validate? => true, :attribute => "attribute", :level => 1, :groups => [])
    klass = Class.new do
      include Validatable
      validations << validation
    end
    klass.new.valid?
  end
  
  expect true do
    klass = Class.new do
      include Validatable
    end
    instance = klass.new
    instance.errors.add(:attribute, "message")
    instance.valid?
    instance.errors.empty?
  end
  
  expect false do
    klass = Class.new do
      include Validatable
    end
    klass.validation_keys_include?("anything")
  end
  
  expect true do
    validation = stub_everything(:key => "key")
    klass = Class.new do
      include Validatable
      validations << validation
    end
    klass.validation_keys_include?("key")
  end
end