dm-validations 0.9.9 → 0.9.10

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 (57) hide show
  1. data/History.txt +15 -0
  2. data/Manifest.txt +21 -2
  3. data/lib/dm-validations.rb +14 -14
  4. data/lib/dm-validations/absent_field_validator.rb +3 -4
  5. data/lib/dm-validations/acceptance_validator.rb +6 -10
  6. data/lib/dm-validations/confirmation_validator.rb +5 -5
  7. data/lib/dm-validations/contextual_validators.rb +1 -1
  8. data/lib/dm-validations/custom_validator.rb +1 -1
  9. data/lib/dm-validations/format_validator.rb +6 -5
  10. data/lib/dm-validations/generic_validator.rb +7 -10
  11. data/lib/dm-validations/length_validator.rb +7 -7
  12. data/lib/dm-validations/method_validator.rb +2 -2
  13. data/lib/dm-validations/numeric_validator.rb +4 -4
  14. data/lib/dm-validations/primitive_validator.rb +4 -4
  15. data/lib/dm-validations/required_field_validator.rb +5 -5
  16. data/lib/dm-validations/uniqueness_validator.rb +2 -2
  17. data/lib/dm-validations/validation_errors.rb +34 -2
  18. data/lib/dm-validations/version.rb +1 -1
  19. data/lib/dm-validations/within_validator.rb +15 -13
  20. data/spec/integration/absent_field_validator_spec.rb +4 -2
  21. data/spec/integration/acceptance_validator_spec.rb +3 -3
  22. data/spec/integration/auto_validate_spec.rb +16 -9
  23. data/spec/integration/block_validator_spec.rb +2 -8
  24. data/spec/integration/confirmation_validator_spec.rb +11 -8
  25. data/spec/integration/contextual_validators_spec.rb +2 -1
  26. data/spec/integration/format_validator_spec.rb +1 -1
  27. data/spec/integration/length_validator/error_message_spec.rb +23 -0
  28. data/spec/integration/length_validator/maximum_spec.rb +31 -0
  29. data/spec/integration/length_validator/minimum_spec.rb +31 -0
  30. data/spec/integration/length_validator/range_spec.rb +95 -0
  31. data/spec/integration/length_validator/spec_helper.rb +12 -0
  32. data/spec/integration/length_validator/valid_objects_spec.rb +13 -0
  33. data/spec/integration/method_validator_spec.rb +3 -3
  34. data/spec/integration/numeric_validator/float_type_spec.rb +102 -0
  35. data/spec/integration/numeric_validator/integer_only_true_spec.rb +92 -0
  36. data/spec/integration/numeric_validator/integer_type_spec.rb +100 -0
  37. data/spec/integration/numeric_validator/spec_helper.rb +77 -0
  38. data/spec/integration/numeric_validator_spec.rb +19 -6
  39. data/spec/integration/primitive_validator_spec.rb +2 -1
  40. data/spec/integration/required_field_validator/association_spec.rb +98 -0
  41. data/spec/integration/required_field_validator/boolean_type_value_spec.rb +149 -0
  42. data/spec/integration/required_field_validator/date_type_value_spec.rb +126 -0
  43. data/spec/integration/required_field_validator/datetime_type_value_spec.rb +126 -0
  44. data/spec/integration/required_field_validator/float_type_value_spec.rb +130 -0
  45. data/spec/integration/required_field_validator/integer_type_value_spec.rb +98 -0
  46. data/spec/integration/required_field_validator/plain_old_ruby_object_spec.rb +36 -0
  47. data/spec/integration/required_field_validator/shared_examples.rb +24 -0
  48. data/spec/integration/required_field_validator/spec_helper.rb +68 -0
  49. data/spec/integration/required_field_validator/string_type_value_spec.rb +164 -0
  50. data/spec/integration/required_field_validator/text_type_value_spec.rb +46 -0
  51. data/spec/integration/uniqueness_validator_spec.rb +10 -8
  52. data/spec/integration/validation_spec.rb +25 -25
  53. data/spec/integration/within_validator_spec.rb +36 -11
  54. data/tasks/spec.rb +1 -1
  55. metadata +24 -5
  56. data/spec/integration/length_validator_spec.rb +0 -115
  57. data/spec/integration/required_field_validator_spec.rb +0 -93
@@ -3,30 +3,37 @@ require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
3
3
 
4
4
  describe DataMapper::Validate::WithinValidator do
5
5
  before(:all) do
6
- class Telephone
6
+ class ::Telephone
7
7
  include DataMapper::Resource
8
8
  property :id, Integer, :serial => true
9
9
  property :type_of_number, String, :auto_validation => false
10
- validates_within :type_of_number, :set => ['Home','Work','Cell']
10
+ validates_within :type_of_number, :set => ['Home', 'Work', 'Cell']
11
11
  end
12
12
 
13
- class Inf
13
+ class ::Inf
14
14
  include DataMapper::Resource
15
15
  property :id, Integer, :serial => true
16
- property :greater_than, String, :auto_validation => false
17
- property :less_than, String, :auto_validation => false
18
- property :between, String, :auto_validation => false
19
- validates_within :greater_than, :set => (10..n)
20
- validates_within :less_than, :set => (-n..10)
16
+ property :gte, Integer, :auto_validation => false
17
+ property :lte, Integer, :auto_validation => false
18
+ property :between, Integer, :auto_validation => false
19
+ validates_within :gte, :set => (10..n)
20
+ validates_within :lte, :set => (-n..10)
21
21
  validates_within :between, :set => (10..20)
22
22
  end
23
23
 
24
- class Receiver
24
+ class ::Receiver
25
25
  include DataMapper::Resource
26
26
  property :id, Integer, :serial => true
27
27
  property :holder, String, :auto_validation => false, :default => 'foo'
28
28
  validates_within :holder, :set => ['foo', 'bar', 'bang']
29
29
  end
30
+
31
+ class ::Nullable
32
+ include DataMapper::Resource
33
+ property :id, Integer, :serial => true
34
+ property :nullable, Integer, :auto_validation => false
35
+ validates_within :nullable, :set => (1..5), :allow_nil => true
36
+ end
30
37
  end
31
38
 
32
39
  it "should validate a value on an instance of a resource within a predefined
@@ -42,13 +49,31 @@ describe DataMapper::Validate::WithinValidator do
42
49
  it "should validate a value within range with infinity" do
43
50
  inf = Inf.new
44
51
  inf.should_not be_valid
45
- inf.errors.on(:greater_than).first.should == 'Greater than must be greater than 10'
46
- inf.errors.on(:less_than).first.should == 'Less than must be less than 10'
52
+ inf.errors.on(:gte).first.should == 'Gte must be greater than or equal to 10'
53
+ inf.errors.on(:lte).first.should == 'Lte must be less than or equal to 10'
47
54
  inf.errors.on(:between).first.should == 'Between must be between 10 and 20'
55
+
56
+ inf.gte = 10
57
+ inf.lte = 10
58
+ inf.between = 10
59
+ inf.valid?.should == true
48
60
  end
49
61
 
50
62
  it "should validate a value by its default" do
51
63
  tel = Receiver.new
52
64
  tel.should be_valid
53
65
  end
66
+
67
+ it "should allow a nil value if :allow_nil is true" do
68
+ nullable = Nullable.new
69
+
70
+ nullable.nullable = nil
71
+ nullable.should be_valid
72
+
73
+ nullable.nullable = 11
74
+ nullable.should_not be_valid
75
+
76
+ nullable.nullable = 3
77
+ nullable.should be_valid
78
+ end
54
79
  end
data/tasks/spec.rb CHANGED
@@ -8,7 +8,7 @@ begin
8
8
  desc 'Run specifications'
9
9
  Spec::Rake::SpecTask.new(:spec) do |t|
10
10
  t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
11
- t.spec_files = Pathname.glob((ROOT + 'spec/**/*_spec.rb').to_s)
11
+ t.spec_files = Pathname.glob((ROOT + 'spec/**/*_spec.rb').to_s).map { |f| f.to_s }
12
12
 
13
13
  begin
14
14
  gem 'rcov', '~>0.8'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.9
4
+ version: 0.9.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guy van den Berg
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-04 00:00:00 -08:00
12
+ date: 2009-01-19 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ~>
22
22
  - !ruby/object:Gem::Version
23
- version: 0.9.9
23
+ version: 0.9.10
24
24
  version:
25
25
  description: DataMapper plugin for performing validations on data models
26
26
  email:
@@ -72,11 +72,30 @@ files:
72
72
  - spec/integration/custom_validator_spec.rb
73
73
  - spec/integration/format_validator_spec.rb
74
74
  - spec/integration/generic_validator_spec.rb
75
- - spec/integration/length_validator_spec.rb
75
+ - spec/integration/length_validator/error_message_spec.rb
76
+ - spec/integration/length_validator/maximum_spec.rb
77
+ - spec/integration/length_validator/minimum_spec.rb
78
+ - spec/integration/length_validator/range_spec.rb
79
+ - spec/integration/length_validator/spec_helper.rb
80
+ - spec/integration/length_validator/valid_objects_spec.rb
76
81
  - spec/integration/method_validator_spec.rb
82
+ - spec/integration/numeric_validator/float_type_spec.rb
83
+ - spec/integration/numeric_validator/integer_only_true_spec.rb
84
+ - spec/integration/numeric_validator/integer_type_spec.rb
85
+ - spec/integration/numeric_validator/spec_helper.rb
77
86
  - spec/integration/numeric_validator_spec.rb
78
87
  - spec/integration/primitive_validator_spec.rb
79
- - spec/integration/required_field_validator_spec.rb
88
+ - spec/integration/required_field_validator/association_spec.rb
89
+ - spec/integration/required_field_validator/boolean_type_value_spec.rb
90
+ - spec/integration/required_field_validator/date_type_value_spec.rb
91
+ - spec/integration/required_field_validator/datetime_type_value_spec.rb
92
+ - spec/integration/required_field_validator/float_type_value_spec.rb
93
+ - spec/integration/required_field_validator/integer_type_value_spec.rb
94
+ - spec/integration/required_field_validator/plain_old_ruby_object_spec.rb
95
+ - spec/integration/required_field_validator/shared_examples.rb
96
+ - spec/integration/required_field_validator/spec_helper.rb
97
+ - spec/integration/required_field_validator/string_type_value_spec.rb
98
+ - spec/integration/required_field_validator/text_type_value_spec.rb
80
99
  - spec/integration/uniqueness_validator_spec.rb
81
100
  - spec/integration/validation_errors_spec.rb
82
101
  - spec/integration/validation_spec.rb
@@ -1,115 +0,0 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
3
-
4
- describe DataMapper::Validate::LengthValidator do
5
- before(:all) do
6
- class MotorLaunch
7
- include DataMapper::Resource
8
- property :id, Integer, :serial => true
9
- property :name, String, :auto_validation => false
10
- end
11
-
12
- class BoatDock
13
- include DataMapper::Resource
14
- property :id, Integer, :serial => true
15
- property :name, String, :auto_validation => false, :default => "I'm a long string"
16
- validates_length :name, :min => 3
17
- end
18
- end
19
-
20
- it "should be able to consider things valid even if we have a custom error message" do
21
- class Jabberwock
22
- include DataMapper::Resource
23
- property :id, Integer, :key => true
24
- property :snickersnack, String
25
- validates_length :snickersnack, :within => 3..40, :message => "worble warble"
26
- end
27
- wock = Jabberwock.new
28
- wock.valid?.should == false
29
- wock.errors.full_messages.sort.last.should == 'worble warble'
30
- wock.snickersnack = "hello"
31
- wock.id = 1
32
- wock.valid?.should == true
33
- end
34
-
35
- it "should be able to set a minimum length of a string field" do
36
- class MotorLaunch
37
- validates_length :name, :min => 3
38
- end
39
-
40
- launch = MotorLaunch.new
41
- launch.name = 'Ab'
42
- launch.valid?.should == false
43
- launch.errors.full_messages.first.should == 'Name must be more than 3 characters long'
44
- end
45
-
46
- it "should be able to alias :minimum for :min " do
47
- class MotorLaunch
48
- validators.clear!
49
- validates_length :name, :minimum => 3
50
- end
51
-
52
- launch = MotorLaunch.new
53
- launch.name = 'Ab'
54
- launch.valid?.should == false
55
- launch.errors.full_messages.first.should == 'Name must be more than 3 characters long'
56
- end
57
-
58
- it "should be able to set a maximum length of a string field" do
59
- class MotorLaunch
60
- validators.clear!
61
- validates_length :name, :max => 5
62
- end
63
-
64
- launch = MotorLaunch.new
65
- launch.name = 'Lip­smackin­thirst­quenchin­acetastin­motivatin­good­buzzin­cool­talkin­high­walkin­fast­livin­ever­givin­cool­fizzin'
66
- launch.valid?.should == false
67
- launch.errors.full_messages.first.should == 'Name must be less than 5 characters long'
68
- end
69
-
70
- it "should be able to alias :maximum for :max" do
71
- class MotorLaunch
72
- validators.clear!
73
- validates_length :name, :maximum => 5
74
- end
75
- launch = MotorLaunch.new
76
- launch.name = 'Lip­smackin­thirst­quenchin­acetastin­motivatin­good­buzzin­cool­talkin­high­walkin­fast­livin­ever­givin­cool­fizzin'
77
- launch.valid?.should == false
78
- launch.errors.full_messages.first.should == 'Name must be less than 5 characters long'
79
- end
80
-
81
- it "should be able to specify a length range of a string field" do
82
- class MotorLaunch
83
- validators.clear!
84
- validates_length :name, :in => (3..5)
85
- end
86
-
87
- launch = MotorLaunch.new
88
- launch.name = 'Lip­smackin­thirst­quenchin­acetastin­motivatin­good­buzzin­cool­talkin­high­walkin­fast­livin­ever­givin­cool­fizzin'
89
- launch.valid?.should == false
90
- launch.errors.full_messages.first.should == 'Name must be between 3 and 5 characters long'
91
-
92
- launch.name = 'A'
93
- launch.valid?.should == false
94
- launch.errors.full_messages.first.should == 'Name must be between 3 and 5 characters long'
95
-
96
- launch.name = 'Ride'
97
- launch.valid?.should == true
98
- end
99
-
100
- it "should be able to alias :within for :in" do
101
- class MotorLaunch
102
- validators.clear!
103
- validates_length :name, :within => (3..5)
104
- end
105
-
106
- launch = MotorLaunch.new
107
- launch.name = 'Ride'
108
- launch.valid?.should == true
109
- end
110
-
111
- it "should pass if a default fulfills the requirements" do
112
- doc = BoatDock.new
113
- doc.should be_valid
114
- end
115
- end
@@ -1,93 +0,0 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
3
-
4
- if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
5
- describe DataMapper::Validate::RequiredFieldValidator do
6
-
7
- describe "Resources" do
8
- before do
9
- class Landscaper
10
- include DataMapper::Resource
11
- property :id, Integer, :key => true
12
- property :name, String
13
- end
14
-
15
- class Garden
16
- include DataMapper::Resource
17
- property :id, Integer, :key => true
18
- property :landscaper_id, Integer
19
- property :name, String, :auto_validation => false
20
-
21
- belongs_to :landscaper #has :landscaper, 1..n
22
-
23
- validates_present :name, :when => :property_test
24
- validates_present :landscaper, :when => :association_test
25
- end
26
-
27
- class Fertilizer
28
- include DataMapper::Resource
29
- property :id, Integer, :serial => true
30
- property :brand, String, :auto_validation => false, :default => 'Scotts'
31
- validates_present :brand, :when => :property_test
32
- end
33
-
34
- Landscaper.auto_migrate!
35
- Garden.auto_migrate!
36
- Fertilizer.auto_migrate!
37
- end
38
-
39
- it "should validate the presence of a property value on an instance of a resource" do
40
- garden = Garden.new
41
- garden.should_not be_valid_for_property_test
42
- garden.errors.on(:name).should include('Name must not be blank')
43
-
44
- garden.name = 'The Wilds'
45
- garden.should be_valid_for_property_test
46
- end
47
-
48
- it "should validate the presence of an association value on an instance of a resource when dirty"
49
- #do
50
- # garden = Garden.new
51
- # landscaper = garden.landscaper
52
- # puts landscaper.children.length
53
- # #puts "Gardens landscaper is #{garden.landscaper.child_key}"
54
- #end
55
-
56
- it "should pass when a default is available" do
57
- fert = Fertilizer.new
58
- fert.should be_valid_for_property_test
59
- end
60
- end
61
-
62
- describe "A plain class (not a DM resource)" do
63
-
64
- before do
65
- class PlainClass
66
- extend DataMapper::Validate::ClassMethods
67
- include DataMapper::Validate
68
- attr_accessor :accessor
69
- validates_present :here, :empty, :nil, :accessor
70
- def here; "here" end
71
- def empty; "" end
72
- def nil; nil end
73
- end
74
-
75
- @pc = PlainClass.new
76
- end
77
-
78
- it "should fail validation with empty, nil, or blank fields" do
79
- @pc.should_not be_valid
80
- @pc.errors.on(:empty).should include("Empty must not be blank")
81
- @pc.errors.on(:nil).should include("Nil must not be blank")
82
- @pc.errors.on(:accessor).should include("Accessor must not be blank")
83
- end
84
-
85
- it "giving accessor a value should remove validation error" do
86
- @pc.accessor = "full"
87
- @pc.valid?
88
- @pc.errors.on(:accessor).should be_nil
89
- end
90
- end
91
-
92
- end
93
- end