dm-validations 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/LICENSE +20 -0
  2. data/README +72 -0
  3. data/Rakefile +74 -0
  4. data/TODO +16 -0
  5. data/lib/dm-validations.rb +208 -0
  6. data/lib/dm-validations/absent_field_validator.rb +60 -0
  7. data/lib/dm-validations/acceptance_validator.rb +76 -0
  8. data/lib/dm-validations/auto_validate.rb +98 -0
  9. data/lib/dm-validations/confirmation_validator.rb +76 -0
  10. data/lib/dm-validations/contextual_validators.rb +56 -0
  11. data/lib/dm-validations/custom_validator.rb +72 -0
  12. data/lib/dm-validations/format_validator.rb +94 -0
  13. data/lib/dm-validations/formats/email.rb +40 -0
  14. data/lib/dm-validations/generic_validator.rb +92 -0
  15. data/lib/dm-validations/length_validator.rb +113 -0
  16. data/lib/dm-validations/method_validator.rb +58 -0
  17. data/lib/dm-validations/numeric_validator.rb +66 -0
  18. data/lib/dm-validations/primitive_validator.rb +60 -0
  19. data/lib/dm-validations/required_field_validator.rb +88 -0
  20. data/lib/dm-validations/support/object.rb +5 -0
  21. data/lib/dm-validations/uniqueness_validator.rb +61 -0
  22. data/lib/dm-validations/validation_errors.rb +63 -0
  23. data/lib/dm-validations/within_validator.rb +41 -0
  24. data/spec/integration/absent_field_validator_spec.rb +34 -0
  25. data/spec/integration/acceptance_validator_spec.rb +87 -0
  26. data/spec/integration/auto_validate_spec.rb +262 -0
  27. data/spec/integration/confirmation_validator_spec.rb +66 -0
  28. data/spec/integration/contextual_validators_spec.rb +28 -0
  29. data/spec/integration/custom_validator_spec.rb +9 -0
  30. data/spec/integration/format_validator_spec.rb +118 -0
  31. data/spec/integration/generic_validator_spec.rb +9 -0
  32. data/spec/integration/length_validator_spec.rb +113 -0
  33. data/spec/integration/method_validator_spec.rb +31 -0
  34. data/spec/integration/numeric_validator_spec.rb +192 -0
  35. data/spec/integration/primitive_validator_spec.rb +25 -0
  36. data/spec/integration/required_field_validator_spec.rb +93 -0
  37. data/spec/integration/uniqueness_validator_spec.rb +81 -0
  38. data/spec/integration/validation_errors_spec.rb +18 -0
  39. data/spec/integration/validation_spec.rb +339 -0
  40. data/spec/integration/within_validator_spec.rb +35 -0
  41. data/spec/spec.opts +2 -0
  42. data/spec/spec_helper.rb +26 -0
  43. metadata +104 -0
@@ -0,0 +1,35 @@
1
+ require 'pathname'
2
+ require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
3
+
4
+ describe DataMapper::Validate::WithinValidator do
5
+ before(:all) do
6
+ class Telephone
7
+ include DataMapper::Resource
8
+ property :id, Integer, :serial => true
9
+ property :type_of_number, String, :auto_validation => false
10
+ validates_within :type_of_number, :set => ['Home','Work','Cell']
11
+ end
12
+
13
+ class Reciever
14
+ include DataMapper::Resource
15
+ property :id, Integer, :serial => true
16
+ property :holder, String, :auto_validation => false, :default => 'foo'
17
+ validates_within :holder, :set => ['foo', 'bar', 'bang']
18
+ end
19
+ end
20
+
21
+ it "should validate a value on an instance of a resource within a predefined
22
+ set of values" do
23
+ tel = Telephone.new
24
+ tel.valid?.should_not == true
25
+ tel.errors.full_messages.first.should == 'Type of number must be one of [Home, Work, Cell]'
26
+
27
+ tel.type_of_number = 'Cell'
28
+ tel.valid?.should == true
29
+ end
30
+
31
+ it "should validate a value by its default" do
32
+ tel = Reciever.new
33
+ tel.should be_valid
34
+ end
35
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --format specdoc
2
+ --colour
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ require 'pathname'
3
+ require Pathname(__FILE__).dirname.expand_path.parent + 'lib/dm-validations'
4
+
5
+ def load_driver(name, default_uri)
6
+ return false if ENV['ADAPTER'] != name.to_s
7
+
8
+ lib = "do_#{name}"
9
+
10
+ begin
11
+ gem lib, '=0.9.2'
12
+ require lib
13
+ DataMapper.setup(name, ENV["#{name.to_s.upcase}_SPEC_URI"] || default_uri)
14
+ DataMapper::Repository.adapters[:default] = DataMapper::Repository.adapters[name]
15
+ true
16
+ rescue Gem::LoadError => e
17
+ warn "Could not load #{lib}: #{e}"
18
+ false
19
+ end
20
+ end
21
+
22
+ ENV['ADAPTER'] ||= 'sqlite3'
23
+
24
+ HAS_SQLITE3 = load_driver(:sqlite3, 'sqlite3::memory:')
25
+ HAS_MYSQL = load_driver(:mysql, 'mysql://localhost/dm_core_test')
26
+ HAS_POSTGRES = load_driver(:postgres, 'postgres://postgres@localhost/dm_core_test')
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dm-validations
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.2
5
+ platform: ruby
6
+ authors:
7
+ - Guy van den Berg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-06-25 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: dm-core
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - "="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.9.2
23
+ version:
24
+ description: DataMapper plugin for performing validations on data models
25
+ email: vandenberg.guy@gmail.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README
32
+ - LICENSE
33
+ - TODO
34
+ files:
35
+ - lib/dm-validations/absent_field_validator.rb
36
+ - lib/dm-validations/acceptance_validator.rb
37
+ - lib/dm-validations/auto_validate.rb
38
+ - lib/dm-validations/confirmation_validator.rb
39
+ - lib/dm-validations/contextual_validators.rb
40
+ - lib/dm-validations/custom_validator.rb
41
+ - lib/dm-validations/format_validator.rb
42
+ - lib/dm-validations/formats/email.rb
43
+ - lib/dm-validations/generic_validator.rb
44
+ - lib/dm-validations/length_validator.rb
45
+ - lib/dm-validations/method_validator.rb
46
+ - lib/dm-validations/numeric_validator.rb
47
+ - lib/dm-validations/primitive_validator.rb
48
+ - lib/dm-validations/required_field_validator.rb
49
+ - lib/dm-validations/support/object.rb
50
+ - lib/dm-validations/uniqueness_validator.rb
51
+ - lib/dm-validations/validation_errors.rb
52
+ - lib/dm-validations/within_validator.rb
53
+ - lib/dm-validations.rb
54
+ - spec/integration/absent_field_validator_spec.rb
55
+ - spec/integration/acceptance_validator_spec.rb
56
+ - spec/integration/auto_validate_spec.rb
57
+ - spec/integration/confirmation_validator_spec.rb
58
+ - spec/integration/contextual_validators_spec.rb
59
+ - spec/integration/custom_validator_spec.rb
60
+ - spec/integration/format_validator_spec.rb
61
+ - spec/integration/generic_validator_spec.rb
62
+ - spec/integration/length_validator_spec.rb
63
+ - spec/integration/method_validator_spec.rb
64
+ - spec/integration/numeric_validator_spec.rb
65
+ - spec/integration/primitive_validator_spec.rb
66
+ - spec/integration/required_field_validator_spec.rb
67
+ - spec/integration/uniqueness_validator_spec.rb
68
+ - spec/integration/validation_errors_spec.rb
69
+ - spec/integration/validation_spec.rb
70
+ - spec/integration/within_validator_spec.rb
71
+ - spec/spec_helper.rb
72
+ - spec/spec.opts
73
+ - Rakefile
74
+ - README
75
+ - LICENSE
76
+ - TODO
77
+ has_rdoc: true
78
+ homepage: http://github.com/sam/dm-more/tree/master/dm-validations
79
+ post_install_message:
80
+ rdoc_options: []
81
+
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ version:
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ version:
96
+ requirements: []
97
+
98
+ rubyforge_project:
99
+ rubygems_version: 1.0.1
100
+ signing_key:
101
+ specification_version: 2
102
+ summary: DataMapper plugin for performing validations on data models
103
+ test_files: []
104
+