lgustafson-validatable 1.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. data/README.rdoc +116 -0
  2. data/Rakefile +34 -0
  3. data/VERSION.yml +5 -0
  4. data/lib/validatable/child_validation.rb +15 -0
  5. data/lib/validatable/errors.rb +106 -0
  6. data/lib/validatable/included_validation.rb +9 -0
  7. data/lib/validatable/macros.rb +314 -0
  8. data/lib/validatable/object_extension.rb +40 -0
  9. data/lib/validatable/requireable.rb +26 -0
  10. data/lib/validatable/understandable.rb +31 -0
  11. data/lib/validatable/validatable_class_methods.rb +87 -0
  12. data/lib/validatable/validatable_instance_methods.rb +106 -0
  13. data/lib/validatable/validations/validates_acceptance_of.rb +14 -0
  14. data/lib/validatable/validations/validates_associated.rb +13 -0
  15. data/lib/validatable/validations/validates_confirmation_of.rb +23 -0
  16. data/lib/validatable/validations/validates_each.rb +14 -0
  17. data/lib/validatable/validations/validates_exclusion_of.rb +17 -0
  18. data/lib/validatable/validations/validates_format_of.rb +16 -0
  19. data/lib/validatable/validations/validates_inclusion_of.rb +17 -0
  20. data/lib/validatable/validations/validates_length_of.rb +30 -0
  21. data/lib/validatable/validations/validates_numericality_of.rb +27 -0
  22. data/lib/validatable/validations/validates_presence_of.rb +17 -0
  23. data/lib/validatable/validations/validates_true_for.rb +13 -0
  24. data/lib/validatable/validations/validation_base.rb +91 -0
  25. data/lib/validatable.rb +36 -0
  26. data/test/functional/test_validatable.rb +519 -0
  27. data/test/functional/test_validates_acceptance_of.rb +16 -0
  28. data/test/functional/test_validates_associated.rb +41 -0
  29. data/test/functional/test_validates_confirmation_of.rb +56 -0
  30. data/test/functional/test_validates_each.rb +14 -0
  31. data/test/functional/test_validates_exclusion_of.rb +29 -0
  32. data/test/functional/test_validates_format_of.rb +34 -0
  33. data/test/functional/test_validates_inclusion_of.rb +29 -0
  34. data/test/functional/test_validates_length_of.rb +64 -0
  35. data/test/functional/test_validates_numericality_of.rb +57 -0
  36. data/test/functional/test_validates_presence_of.rb +16 -0
  37. data/test/functional/test_validates_true_for.rb +27 -0
  38. data/test/test_helper.rb +26 -0
  39. data/test/unit/test_errors.rb +88 -0
  40. data/test/unit/test_understandable.rb +19 -0
  41. data/test/unit/test_validatable.rb +38 -0
  42. data/test/unit/test_validates_acceptance_of.rb +45 -0
  43. data/test/unit/test_validates_associated.rb +29 -0
  44. data/test/unit/test_validates_confirmation_of.rb +76 -0
  45. data/test/unit/test_validates_exclusion_of.rb +23 -0
  46. data/test/unit/test_validates_format_of.rb +44 -0
  47. data/test/unit/test_validates_inclusion_of.rb +23 -0
  48. data/test/unit/test_validates_length_of.rb +80 -0
  49. data/test/unit/test_validates_numericality_of.rb +82 -0
  50. data/test/unit/test_validates_presence_of.rb +35 -0
  51. data/test/unit/test_validates_true_for.rb +29 -0
  52. data/test/unit/test_validation_base.rb +52 -0
  53. metadata +164 -0
@@ -0,0 +1,29 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ module Functional
4
+ class ValidatesInclusionOfTest < Test::Unit::TestCase
5
+ test "given state not in list, when validated, then error is in the objects error collection" do
6
+ klass = Class.new do
7
+ include Validatable
8
+ attr_accessor :state
9
+ validates_inclusion_of :state, :within => %w(in out)
10
+ end
11
+ instance = klass.new
12
+ instance.state = 'foo'
13
+ instance.valid?
14
+ assert_equal "is not in the list", instance.errors.on(:state)
15
+ end
16
+
17
+ test "given state in list, when validated, then no error is in the objects error collection" do
18
+ klass = Class.new do
19
+ include Validatable
20
+ attr_accessor :state
21
+ validates_inclusion_of :state, :within => %w(in out)
22
+ end
23
+ instance = klass.new
24
+ instance.state = 'in'
25
+ instance.valid?
26
+ assert_nil instance.errors.on(:state)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,64 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ module Functional
4
+ class ValidatesLengthOfTest < Test::Unit::TestCase
5
+ test "given short value, when validated, then error is in the objects error collection" do
6
+ klass = Class.new do
7
+ include Validatable
8
+ attr_accessor :name
9
+ validates_length_of :name, :minimum => 2
10
+ end
11
+ instance = klass.new
12
+ instance.valid?
13
+ assert_equal "is invalid", instance.errors.on(:name)
14
+ end
15
+
16
+ test "given is constraint, when validated, then error is in the objects error collection" do
17
+ klass = Class.new do
18
+ include Validatable
19
+ attr_accessor :name
20
+ validates_length_of :name, :is => 2
21
+ end
22
+
23
+ instance = klass.new
24
+ instance.valid?
25
+ assert_equal "is invalid", instance.errors.on(:name)
26
+ end
27
+
28
+ test "given is constraint is met, when validated, then valid is true" do
29
+ klass = Class.new do
30
+ include Validatable
31
+ attr_accessor :name
32
+ validates_length_of :name, :is => 2
33
+ end
34
+
35
+ instance = klass.new
36
+ instance.name = "bk"
37
+ assert_equal true, instance.valid?
38
+ end
39
+
40
+ test "given within constraint, when validated, then error is in the objects error collection" do
41
+ klass = Class.new do
42
+ include Validatable
43
+ attr_accessor :name
44
+ validates_length_of :name, :within => 2..4
45
+ end
46
+
47
+ instance = klass.new
48
+ instance.valid?
49
+ assert_equal "is invalid", instance.errors.on(:name)
50
+ end
51
+
52
+ test "given within constraint, when validated, then valid is true" do
53
+ klass = Class.new do
54
+ include Validatable
55
+ attr_accessor :name
56
+ validates_length_of :name, :within => 2..4
57
+ end
58
+
59
+ instance = klass.new
60
+ instance.name = "bk"
61
+ assert_equal true, instance.valid?
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,57 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ module Functional
4
+ class ValidatesNumericalityOfTest < Test::Unit::TestCase
5
+ test "when validating numericality and the value is nil an error should exist on the instance" do
6
+ klass = Class.new do
7
+ include Validatable
8
+ attr_accessor :nothing
9
+ validates_numericality_of :nothing
10
+ end
11
+ instance = klass.new
12
+ instance.valid?
13
+ assert_equal "must be a number", instance.errors.on(:nothing)
14
+ end
15
+
16
+ test "when validating numericality and the value has a non numeric character an error should exist on the instance" do
17
+ klass = Class.new do
18
+ include Validatable
19
+ validates_numericality_of :some_string
20
+
21
+ def some_string
22
+ "some_string"
23
+ end
24
+ end
25
+ instance = klass.new
26
+ instance.valid?
27
+ assert_equal "must be a number", instance.errors.on(:some_string)
28
+ end
29
+
30
+ test "when validating a number no error will be in the instance" do
31
+ klass = Class.new do
32
+ include Validatable
33
+ validates_numericality_of :valid_number
34
+
35
+ def valid_number
36
+ 1.23
37
+ end
38
+ end
39
+ instance = klass.new
40
+ instance.valid?
41
+ assert_equal nil, instance.errors.on(:valid_number)
42
+ end
43
+
44
+ test "when validating an integer and the value is a decimal an error should exist on the instance" do
45
+ klass = Class.new do
46
+ include Validatable
47
+ validates_numericality_of :valid_number, :only_integer => true
48
+ attr_accessor :valid_number
49
+ end
50
+
51
+ instance = klass.new
52
+ instance.valid_number = 1.23
53
+ instance.valid?
54
+ assert_equal "must be a number", instance.errors.on(:valid_number)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ module Functional
4
+ class ValidatesPresenceOfTest < Test::Unit::TestCase
5
+ test "given no name, when validated, then error is in the objects error collection" do
6
+ klass = Class.new do
7
+ include Validatable
8
+ attr_accessor :name
9
+ validates_presence_of :name
10
+ end
11
+ instance = klass.new
12
+ instance.valid?
13
+ assert_equal "can't be empty", instance.errors.on(:name)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ module Functional
4
+ class ValidatesFormatOfTest < Test::Unit::TestCase
5
+ test "given invalid name, when validated, then error is in the objects error collection" do
6
+ klass = Class.new do
7
+ include Validatable
8
+ attr_accessor :name
9
+ validates_true_for :name, :logic => lambda {|*x| name == "nombre" }
10
+ end
11
+ instance = klass.new
12
+ instance.valid?
13
+ assert_equal "is invalid", instance.errors.on(:name)
14
+ end
15
+
16
+ test "given valid name, when validated, then no error is in the objects error collection" do
17
+ klass = Class.new do
18
+ include Validatable
19
+ attr_accessor :name
20
+ validates_true_for :name, :logic => lambda {|*x| name == "nombre" }
21
+ end
22
+ instance = klass.new
23
+ instance.name = "nombre"
24
+ assert_equal true, instance.valid?
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ require 'set'
2
+ require 'test/unit'
3
+ require 'mocha'
4
+ require 'dust'
5
+ require 'expectations'
6
+
7
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/validatable')
8
+
9
+ class << Test::Unit::TestCase
10
+ def expect(expected_value, &block)
11
+ define_method :"test_#{caller.first.split("/").last}" do
12
+ begin
13
+ assert_equal expected_value, instance_eval(&block)
14
+ rescue Exception => ex
15
+ raise ex unless expected_value.is_a?(Class) && ex.is_a?(expected_value)
16
+ assert_equal expected_value, ex.class
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ class Array
23
+ def to_blank_options_hash
24
+ self.inject({}) {|hash, value| hash[value] = nil; hash }
25
+ end
26
+ end
@@ -0,0 +1,88 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ Expectations do
4
+ expect "message" do
5
+ errors = Validatable::Errors.new
6
+ errors.add(:attribute, "message")
7
+ errors.on(:attribute)
8
+ end
9
+
10
+ expect "message" do
11
+ errors = Validatable::Errors.new
12
+ errors.add_to_base("message")
13
+ errors.on_base
14
+ end
15
+
16
+ expect ["message"] do
17
+ errors = Validatable::Errors.new
18
+ errors.add(:attribute, "message")
19
+ errors.raw(:attribute)
20
+ end
21
+
22
+ expect "something new" do
23
+ errors = Validatable::Errors.new
24
+ errors.add(:attribute, "something old")
25
+ errors.replace(:attribute, ["something new"])
26
+ errors.on(:attribute)
27
+ end
28
+
29
+ expect "Capitalized word" do
30
+ errors = Validatable::Errors.new
31
+ errors.humanize("capitalized_word")
32
+ end
33
+
34
+ expect "Capitalized word without" do
35
+ errors = Validatable::Errors.new
36
+ errors.humanize("capitalized_word_without_id")
37
+ end
38
+
39
+ expect ["A humanized message", "a base message"] do
40
+ errors = Validatable::Errors.new
41
+ errors.add(:base, "a base message")
42
+ errors.add(:a_humanized, "message")
43
+ errors.full_messages.sort
44
+ end
45
+
46
+ expect true do
47
+ Validatable::Errors.included_modules.include?(Enumerable)
48
+ end
49
+
50
+ expect ["message1", "message2"] do
51
+ errors = Validatable::Errors.new
52
+ errors.add(:attribute, "message1")
53
+ errors.add(:attribute, "message2")
54
+ errors.on(:attribute)
55
+ end
56
+
57
+ expect 2 do
58
+ errors = Validatable::Errors.new
59
+ errors.add(:attribute, "message1")
60
+ errors.add(:attribute, "message2")
61
+ errors.count
62
+ end
63
+
64
+ expect 2 do
65
+ errors = Validatable::Errors.new
66
+ errors.add(:attribute1, "message1")
67
+ errors.add(:attribute2, "message2")
68
+ errors.count
69
+ end
70
+
71
+ expect [] do
72
+ errors = Validatable::Errors.new
73
+ errors[:attribute]
74
+ end
75
+
76
+ expect ["message"] do
77
+ errors = Validatable::Errors.new
78
+ errors.add(:attribute, "message")
79
+ errors[:attribute]
80
+ end
81
+
82
+ expect ["message1", "message2"] do
83
+ errors = Validatable::Errors.new
84
+ errors.add(:attribute, "message1")
85
+ errors.add(:attribute, "message2")
86
+ errors[:attribute]
87
+ end
88
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ Expectations do
4
+ expect [:c, :b, :a] do
5
+ a = Class.new do
6
+ include Validatable::Understandable
7
+ understands :a
8
+ end
9
+ b = Class.new(a) do
10
+ include Validatable::Understandable
11
+ understands :b
12
+ end
13
+ c = Class.new(b) do
14
+ include Validatable::Understandable
15
+ understands :c
16
+ end
17
+ c.all_understandings
18
+ end
19
+ end
@@ -0,0 +1,38 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ Expectations do
4
+ expect false do
5
+ validation = stub_everything(:should_validate? => true, :attribute => "attribute", :level => 1, :groups => [])
6
+ klass = Class.new do
7
+ include Validatable
8
+ validations << validation
9
+ end
10
+ klass.new.valid?
11
+ end
12
+
13
+ expect true do
14
+ klass = Class.new do
15
+ include Validatable
16
+ end
17
+ instance = klass.new
18
+ instance.errors.add(:attribute, "message")
19
+ instance.valid?
20
+ instance.errors.empty?
21
+ end
22
+
23
+ expect false do
24
+ klass = Class.new do
25
+ include Validatable
26
+ end
27
+ klass.validation_keys_include?("anything")
28
+ end
29
+
30
+ expect true do
31
+ validation = stub_everything(:key => "key")
32
+ klass = Class.new do
33
+ include Validatable
34
+ validations << validation
35
+ end
36
+ klass.validation_keys_include?("key")
37
+ end
38
+ end
@@ -0,0 +1,45 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ Expectations do
4
+ expect true do
5
+ validation = Validatable::ValidatesAcceptanceOf.new stub_everything, :acceptance
6
+ instance = stub(:acceptance=>'1')
7
+ validation.valid?(instance)
8
+ end
9
+
10
+ expect true do
11
+ validation = Validatable::ValidatesAcceptanceOf.new stub_everything, :acceptance
12
+ instance = stub(:acceptance=>'t')
13
+ validation.valid?(instance)
14
+ end
15
+
16
+ expect true do
17
+ validation = Validatable::ValidatesAcceptanceOf.new stub_everything, :acceptance
18
+ instance = stub(:acceptance=>'true')
19
+ validation.valid?(instance)
20
+ end
21
+
22
+ expect true do
23
+ validation = Validatable::ValidatesAcceptanceOf.new stub_everything, :acceptance, :allow_nil => true
24
+ instance = stub(:acceptance=>nil)
25
+ validation.valid?(instance)
26
+ end
27
+
28
+ expect true do
29
+ validation = Validatable::ValidatesAcceptanceOf.new stub_everything, :acceptance, :allow_blank => true
30
+ instance = stub(:acceptance=>'')
31
+ validation.valid?(instance)
32
+ end
33
+
34
+ expect false do
35
+ validation = Validatable::ValidatesAcceptanceOf.new stub_everything, :acceptance
36
+ instance = stub(:acceptance=>'0')
37
+ validation.valid?(instance)
38
+ end
39
+
40
+ expect true do
41
+ options = {:message => nil, :if => nil, :times => nil, :level => nil, :groups => nil}
42
+ Validatable::ValidatesAcceptanceOf.new(stub_everything, :test).must_understand(options)
43
+ end
44
+
45
+ end
@@ -0,0 +1,29 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ Expectations do
4
+
5
+ expect false do
6
+ parent = stub('parent', :child => stub(:valid? => false))
7
+ validation = Validatable::ValidatesAssociated.new stub_everything, :child
8
+ validation.valid?(parent)
9
+ end
10
+
11
+ expect true do
12
+ parent = stub('parent', :child => stub(:valid? => true))
13
+ validation = Validatable::ValidatesAssociated.new stub_everything, :child
14
+ validation.valid?(parent)
15
+ end
16
+
17
+ expect false do
18
+ parent = stub('parent', :children => [stub(:valid? => false)])
19
+ validation = Validatable::ValidatesAssociated.new stub_everything, :children
20
+ validation.valid?(parent)
21
+ end
22
+
23
+ expect true do
24
+ parent = stub('parent', :children => [stub(:valid? => true)])
25
+ validation = Validatable::ValidatesAssociated.new stub_everything, :children
26
+ validation.valid?(parent)
27
+ end
28
+
29
+ end
@@ -0,0 +1,76 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ Expectations do
4
+
5
+ expect true do
6
+ validation = Validatable::ValidatesConfirmationOf.new stub_everything, :username
7
+ instance = stub(:username=>"username", :username_confirmation=>"username")
8
+ validation.valid?(instance)
9
+ end
10
+
11
+ expect false do
12
+ validation = Validatable::ValidatesConfirmationOf.new stub_everything, :username
13
+ instance = stub(:username=>"username", :username_confirmation=>"usessrname")
14
+ validation.valid?(instance)
15
+ end
16
+
17
+ expect true do
18
+ validation = Validatable::ValidatesConfirmationOf.new stub_everything, :username, :allow_nil => true
19
+ instance = stub(:username=>"username", :username_confirmation=>nil)
20
+ validation.valid?(instance)
21
+ end
22
+
23
+ expect true do
24
+ validation = Validatable::ValidatesConfirmationOf.new stub_everything, :username, :allow_blank => true
25
+ instance = stub(:username=>"username", :username_confirmation=>'')
26
+ validation.valid?(instance)
27
+ end
28
+
29
+ expect true do
30
+ validation = Validatable::ValidatesConfirmationOf.new stub_everything, :username, :case_sensitive => false
31
+ instance = stub(:username=>"username", :username_confirmation=>"USERNAME")
32
+ validation.valid?(instance)
33
+ end
34
+
35
+ expect false do
36
+ validation = Validatable::ValidatesConfirmationOf.new stub_everything, :username, :case_sensitive => true
37
+ instance = stub(:username=>"username", :username_confirmation=>"USERNAME")
38
+ validation.valid?(instance)
39
+ end
40
+
41
+ expect false do
42
+ validation = Validatable::ValidatesConfirmationOf.new stub_everything, :username, :case_sensitive => true
43
+ validation.valid?(stub(:username => nil, :username_confirmation => 'something'))
44
+ end
45
+
46
+ expect false do
47
+ validation = Validatable::ValidatesConfirmationOf.new stub_everything, :username, :case_sensitive => true
48
+ validation.valid?(stub(:username => 'something', :username_confirmation => nil))
49
+ end
50
+
51
+ expect true do
52
+ validation = Validatable::ValidatesConfirmationOf.new stub_everything, :username, :case_sensitive => true
53
+ validation.valid?(stub(:username => nil, :username_confirmation => nil))
54
+ end
55
+
56
+ expect false do
57
+ validation = Validatable::ValidatesConfirmationOf.new stub_everything, :username, :case_sensitive => false
58
+ validation.valid?(stub(:username => nil, :username_confirmation => 'something'))
59
+ end
60
+
61
+ expect false do
62
+ validation = Validatable::ValidatesConfirmationOf.new stub_everything, :username, :case_sensitive => false
63
+ validation.valid?(stub(:username => 'something', :username_confirmation => nil))
64
+ end
65
+
66
+ expect true do
67
+ validation = Validatable::ValidatesConfirmationOf.new stub_everything, :username, :case_sensitive => false
68
+ validation.valid?(stub(:username => nil, :username_confirmation => nil))
69
+ end
70
+
71
+ expect true do
72
+ options = { :message => nil, :if => nil, :times => nil, :level => nil, :groups => nil, :case_sensitive => nil }
73
+ Validatable::ValidatesConfirmationOf.new(stub_everything, :test).must_understand(options)
74
+ end
75
+
76
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ Expectations do
4
+ expect false do
5
+ validation = Validatable::ValidatesExclusionOf.new stub_everything, :state, :within => %w(in out)
6
+ validation.valid?(stub(:state => 'in'))
7
+ end
8
+
9
+ expect true do
10
+ validation = Validatable::ValidatesExclusionOf.new stub_everything, :state, :within => %w(in out)
11
+ validation.valid?(stub(:state => 'foo'))
12
+ end
13
+
14
+ expect true do
15
+ validation = Validatable::ValidatesExclusionOf.new stub_everything, :state, :within => %w(in out), :allow_blank => true
16
+ validation.valid?(stub(:state => ''))
17
+ end
18
+
19
+ expect true do
20
+ validation = Validatable::ValidatesExclusionOf.new stub_everything, :state, :within => %w(in out), :allow_nil => true
21
+ validation.valid?(stub(:state => nil))
22
+ end
23
+ end
@@ -0,0 +1,44 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ Expectations do
4
+
5
+ expect false do
6
+ validation = Validatable::ValidatesFormatOf.new stub_everything, :name, :with => /book/
7
+ validation.valid?(stub_everything)
8
+ end
9
+
10
+ expect true do
11
+ validation = Validatable::ValidatesFormatOf.new stub_everything, :name, :with => /book/
12
+ validation.valid?(stub(:name=>"book"))
13
+ end
14
+
15
+ expect true do
16
+ validation = Validatable::ValidatesFormatOf.new stub_everything, :name, :with => /book/, :allow_nil => true
17
+ validation.valid?(stub(:name=>nil))
18
+ end
19
+
20
+ expect true do
21
+ validation = Validatable::ValidatesFormatOf.new stub_everything, :name, :with => /book/, :allow_blank => true
22
+ validation.valid?(stub(:name=>''))
23
+ end
24
+
25
+ expect true do
26
+ validation = Validatable::ValidatesFormatOf.new stub_everything, :age, :with => /14/
27
+ validation.valid?(stub(:age=>14))
28
+ end
29
+
30
+ expect ArgumentError do
31
+ validation = Validatable::ValidatesFormatOf.new stub_everything, :age
32
+ end
33
+
34
+ expect true do
35
+ options = [:message, :if, :times, :level, :groups, :with, :key]
36
+ Validatable::ValidatesFormatOf.new(stub_everything, :test, options.to_blank_options_hash).must_understand(options.to_blank_options_hash)
37
+ end
38
+
39
+ expect true do
40
+ options = [:with]
41
+ Validatable::ValidatesFormatOf.new(stub_everything, :name, options.to_blank_options_hash).requires(options.to_blank_options_hash)
42
+ end
43
+
44
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ Expectations do
4
+ expect true do
5
+ validation = Validatable::ValidatesInclusionOf.new stub_everything, :state, :within => %w(in out)
6
+ validation.valid?(stub(:state => 'in'))
7
+ end
8
+
9
+ expect false do
10
+ validation = Validatable::ValidatesInclusionOf.new stub_everything, :state, :within => %w(in out)
11
+ validation.valid?(stub(:state => 'foo'))
12
+ end
13
+
14
+ expect true do
15
+ validation = Validatable::ValidatesInclusionOf.new stub_everything, :state, :within => %w(in out), :allow_blank => true
16
+ validation.valid?(stub(:state => ''))
17
+ end
18
+
19
+ expect true do
20
+ validation = Validatable::ValidatesInclusionOf.new stub_everything, :state, :within => %w(in out), :allow_nil => true
21
+ validation.valid?(stub(:state => nil))
22
+ end
23
+ end