dm-validations 0.9.11 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. data/{History.txt → History.rdoc} +10 -3
  2. data/LICENSE +1 -0
  3. data/Manifest.txt +103 -33
  4. data/README.rdoc +172 -0
  5. data/Rakefile +4 -5
  6. data/lib/dm-validations.rb +73 -75
  7. data/lib/dm-validations/auto_validate.rb +98 -56
  8. data/lib/dm-validations/contextual_validators.rb +37 -14
  9. data/lib/dm-validations/exceptions.rb +3 -0
  10. data/lib/dm-validations/formats/url.rb +3 -1
  11. data/lib/dm-validations/support/context.rb +54 -0
  12. data/lib/dm-validations/validation_errors.rb +51 -27
  13. data/lib/dm-validations/{absent_field_validator.rb → validators/absent_field_validator.rb} +2 -8
  14. data/lib/dm-validations/{acceptance_validator.rb → validators/acceptance_validator.rb} +7 -7
  15. data/lib/dm-validations/{block_validator.rb → validators/block_validator.rb} +0 -0
  16. data/lib/dm-validations/{confirmation_validator.rb → validators/confirmation_validator.rb} +7 -7
  17. data/lib/dm-validations/{format_validator.rb → validators/format_validator.rb} +10 -16
  18. data/lib/dm-validations/{generic_validator.rb → validators/generic_validator.rb} +28 -6
  19. data/lib/dm-validations/validators/length_validator.rb +214 -0
  20. data/lib/dm-validations/validators/method_validator.rb +68 -0
  21. data/lib/dm-validations/validators/numeric_validator.rb +171 -0
  22. data/lib/dm-validations/{primitive_validator.rb → validators/primitive_validator.rb} +2 -7
  23. data/lib/dm-validations/{required_field_validator.rb → validators/required_field_validator.rb} +0 -6
  24. data/lib/dm-validations/{uniqueness_validator.rb → validators/uniqueness_validator.rb} +9 -20
  25. data/lib/dm-validations/{within_validator.rb → validators/within_validator.rb} +4 -4
  26. data/lib/dm-validations/version.rb +1 -1
  27. data/spec/fixtures/barcode.rb +32 -0
  28. data/spec/fixtures/basketball_court.rb +58 -0
  29. data/spec/fixtures/basketball_player.rb +37 -0
  30. data/spec/fixtures/beta_tester_account.rb +33 -0
  31. data/spec/fixtures/bill_of_landing.rb +42 -0
  32. data/spec/fixtures/boat_dock.rb +26 -0
  33. data/spec/fixtures/city.rb +25 -0
  34. data/spec/fixtures/company.rb +95 -0
  35. data/spec/fixtures/corporate_world.rb +47 -0
  36. data/spec/fixtures/country.rb +25 -0
  37. data/spec/fixtures/currency.rb +42 -0
  38. data/spec/fixtures/ethernet_frame.rb +56 -0
  39. data/spec/fixtures/event.rb +44 -0
  40. data/spec/fixtures/g3_concert.rb +57 -0
  41. data/spec/fixtures/jabberwock.rb +27 -0
  42. data/spec/fixtures/kayak.rb +28 -0
  43. data/spec/fixtures/lernean_hydra.rb +39 -0
  44. data/spec/fixtures/mathematical_function.rb +34 -0
  45. data/spec/fixtures/memory_object.rb +30 -0
  46. data/spec/fixtures/mittelschnauzer.rb +35 -0
  47. data/spec/fixtures/motor_launch.rb +21 -0
  48. data/spec/fixtures/page.rb +32 -0
  49. data/spec/fixtures/phone_number.rb +28 -0
  50. data/spec/fixtures/pirogue.rb +28 -0
  51. data/spec/fixtures/programming_language.rb +83 -0
  52. data/spec/fixtures/reservation.rb +38 -0
  53. data/spec/fixtures/scm_operation.rb +67 -0
  54. data/spec/fixtures/sms_message.rb +22 -0
  55. data/spec/fixtures/udp_packet.rb +49 -0
  56. data/spec/integration/absent_field_validator/absent_field_validator_spec.rb +86 -0
  57. data/spec/integration/absent_field_validator/spec_helper.rb +7 -0
  58. data/spec/integration/acceptance_validator/acceptance_validator_spec.rb +196 -0
  59. data/spec/integration/acceptance_validator/spec_helper.rb +7 -0
  60. data/spec/integration/automatic_validation/custom_messages_for_inferred_validation_spec.rb +47 -0
  61. data/spec/integration/automatic_validation/disabling_inferred_validation_spec.rb +41 -0
  62. data/spec/integration/automatic_validation/inferred_boolean_properties_validation_spec.rb +104 -0
  63. data/spec/integration/automatic_validation/inferred_float_property_validation_spec.rb +35 -0
  64. data/spec/integration/automatic_validation/inferred_format_validation_spec.rb +33 -0
  65. data/spec/integration/automatic_validation/inferred_integer_properties_validation_spec.rb +73 -0
  66. data/spec/integration/automatic_validation/inferred_length_validation_spec.rb +121 -0
  67. data/spec/integration/automatic_validation/inferred_presence_validation_spec.rb +41 -0
  68. data/spec/integration/automatic_validation/inferred_primitive_validation_spec.rb +20 -0
  69. data/spec/integration/automatic_validation/inferred_within_validation_spec.rb +33 -0
  70. data/spec/integration/automatic_validation/spec_helper.rb +74 -0
  71. data/spec/integration/block_validator/block_validator_spec.rb +32 -0
  72. data/spec/integration/block_validator/spec_helper.rb +5 -0
  73. data/spec/integration/conditional_validation/if_condition_spec.rb +61 -0
  74. data/spec/integration/conditional_validation/spec_helper.rb +5 -0
  75. data/spec/integration/confirmation_validator/confirmation_validator_spec.rb +74 -0
  76. data/spec/integration/confirmation_validator/spec_helper.rb +5 -0
  77. data/spec/integration/datamapper_models/association_validation_spec.rb +23 -0
  78. data/spec/integration/datamapper_models/inheritance_spec.rb +78 -0
  79. data/spec/integration/duplicated_validations/duplicated_validations_spec.rb +22 -0
  80. data/spec/integration/duplicated_validations/spec_helper.rb +5 -0
  81. data/spec/integration/format_validator/email_format_validator_spec.rb +113 -0
  82. data/spec/integration/format_validator/format_validator_spec.rb +60 -0
  83. data/spec/integration/format_validator/regexp_validator_spec.rb +29 -0
  84. data/spec/integration/format_validator/spec_helper.rb +5 -0
  85. data/spec/integration/format_validator/url_format_validator_spec.rb +63 -0
  86. data/spec/integration/length_validator/default_value_spec.rb +12 -0
  87. data/spec/integration/length_validator/equality_spec.rb +79 -0
  88. data/spec/integration/length_validator/error_message_spec.rb +15 -18
  89. data/spec/integration/length_validator/maximum_spec.rb +40 -24
  90. data/spec/integration/length_validator/minimum_spec.rb +32 -21
  91. data/spec/integration/length_validator/range_spec.rb +50 -60
  92. data/spec/integration/length_validator/spec_helper.rb +7 -12
  93. data/spec/integration/method_validator/method_validator_spec.rb +239 -0
  94. data/spec/integration/method_validator/spec_helper.rb +5 -0
  95. data/spec/integration/numeric_validator/equality_with_float_type_spec.rb +61 -0
  96. data/spec/integration/numeric_validator/equality_with_integer_type_spec.rb +37 -0
  97. data/spec/integration/numeric_validator/float_type_spec.rb +42 -56
  98. data/spec/integration/numeric_validator/gt_with_float_type_spec.rb +35 -0
  99. data/spec/integration/numeric_validator/gte_with_float_type_spec.rb +35 -0
  100. data/spec/integration/numeric_validator/integer_only_true_spec.rb +3 -6
  101. data/spec/integration/numeric_validator/integer_type_spec.rb +8 -24
  102. data/spec/integration/numeric_validator/lt_with_float_type_spec.rb +35 -0
  103. data/spec/integration/numeric_validator/lte_with_float_type_spec.rb +35 -0
  104. data/spec/integration/numeric_validator/spec_helper.rb +5 -77
  105. data/spec/integration/primitive_validator/primitive_validator_spec.rb +90 -0
  106. data/spec/integration/primitive_validator/spec_helper.rb +5 -0
  107. data/spec/integration/pure_ruby_objects/plain_old_ruby_object_validation_spec.rb +118 -0
  108. data/spec/integration/required_field_validator/association_spec.rb +5 -8
  109. data/spec/integration/required_field_validator/boolean_type_value_spec.rb +4 -7
  110. data/spec/integration/required_field_validator/date_type_value_spec.rb +3 -6
  111. data/spec/integration/required_field_validator/datetime_type_value_spec.rb +3 -6
  112. data/spec/integration/required_field_validator/float_type_value_spec.rb +3 -6
  113. data/spec/integration/required_field_validator/integer_type_value_spec.rb +2 -5
  114. data/spec/integration/required_field_validator/plain_old_ruby_object_spec.rb +5 -8
  115. data/spec/integration/required_field_validator/shared_examples.rb +1 -1
  116. data/spec/integration/required_field_validator/spec_helper.rb +6 -67
  117. data/spec/integration/required_field_validator/string_type_value_spec.rb +2 -5
  118. data/spec/integration/required_field_validator/text_type_value_spec.rb +2 -5
  119. data/spec/integration/shared/default_validation_context.rb +13 -0
  120. data/spec/integration/shared/valid_and_invalid_model.rb +27 -0
  121. data/spec/integration/uniqueness_validator/spec_helper.rb +5 -0
  122. data/spec/integration/uniqueness_validator/uniqueness_validator_spec.rb +114 -0
  123. data/spec/integration/within_validator/spec_helper.rb +5 -0
  124. data/spec/integration/within_validator/within_validator_spec.rb +164 -0
  125. data/spec/public/resource_spec.rb +68 -0
  126. data/spec/spec.opts +1 -0
  127. data/spec/spec_helper.rb +12 -4
  128. data/spec/unit/contextual_validators/emptiness_spec.rb +50 -0
  129. data/spec/unit/contextual_validators/execution_spec.rb +55 -0
  130. data/spec/unit/contextual_validators/spec_helper.rb +37 -0
  131. data/spec/unit/generic_validator/equality_operator_spec.rb +26 -0
  132. data/spec/unit/validation_errors/adding_spec.rb +54 -0
  133. data/spec/unit/validation_errors/emptiness_spec.rb +38 -0
  134. data/spec/unit/validation_errors/enumerable_spec.rb +32 -0
  135. data/tasks/install.rb +1 -1
  136. data/tasks/spec.rb +4 -4
  137. metadata +118 -55
  138. data/README.txt +0 -72
  139. data/lib/dm-validations/custom_validator.rb +0 -72
  140. data/lib/dm-validations/length_validator.rb +0 -113
  141. data/lib/dm-validations/method_validator.rb +0 -68
  142. data/lib/dm-validations/numeric_validator.rb +0 -83
  143. data/spec/integration/absent_field_validator_spec.rb +0 -36
  144. data/spec/integration/acceptance_validator_spec.rb +0 -87
  145. data/spec/integration/auto_validate_spec.rb +0 -342
  146. data/spec/integration/block_validator_spec.rb +0 -30
  147. data/spec/integration/confirmation_validator_spec.rb +0 -105
  148. data/spec/integration/contextual_validators_spec.rb +0 -27
  149. data/spec/integration/custom_validator_spec.rb +0 -9
  150. data/spec/integration/format_validator_spec.rb +0 -193
  151. data/spec/integration/generic_validator_spec.rb +0 -17
  152. data/spec/integration/length_validator/valid_objects_spec.rb +0 -13
  153. data/spec/integration/method_validator_spec.rb +0 -58
  154. data/spec/integration/numeric_validator_spec.rb +0 -253
  155. data/spec/integration/primitive_validator_spec.rb +0 -30
  156. data/spec/integration/uniqueness_validator_spec.rb +0 -97
  157. data/spec/integration/validation_errors_spec.rb +0 -18
  158. data/spec/integration/validation_spec.rb +0 -404
  159. data/spec/integration/within_validator_spec.rb +0 -79
@@ -0,0 +1,171 @@
1
+ module DataMapper
2
+ module Validate
3
+
4
+ ##
5
+ #
6
+ # @author Guy van den Berg
7
+ # @since 0.9
8
+ class NumericValidator < GenericValidator
9
+
10
+ def call(target)
11
+ value = target.send(field_name)
12
+ return true if allow_nil? && value.blank?
13
+
14
+ errors = []
15
+
16
+ validate_with(integer_only? ? :integer : :numeric, value, errors)
17
+
18
+ add_errors(target, errors)
19
+
20
+ # if the number is invalid, skip further tests
21
+ return false if errors.any?
22
+
23
+ [ :gt, :lt, :gte, :lte, :eq, :ne ].each do |validation_type|
24
+ validate_with(validation_type, value, errors)
25
+ end
26
+
27
+ add_errors(target, errors)
28
+
29
+ errors.empty?
30
+ end
31
+
32
+ private
33
+
34
+ def allow_nil?
35
+ options.fetch(:allow_nil, false)
36
+ end
37
+
38
+ def integer_only?
39
+ options.fetch(:integer_only, false)
40
+ end
41
+
42
+ def value_as_string(value)
43
+ case value
44
+ when Float then value.to_d.to_s('F') # Avoid Scientific Notation in Float to_s
45
+ when BigDecimal then value.to_s('F')
46
+ else value.to_s
47
+ end
48
+ end
49
+
50
+ def add_errors(target, errors)
51
+ return if errors.empty?
52
+
53
+ if options.key?(:message)
54
+ add_error(target, options[:message], field_name)
55
+ else
56
+ errors.each do |error_message|
57
+ add_error(target, error_message, field_name)
58
+ end
59
+ end
60
+ end
61
+
62
+ def validate_with(validation_type, value, errors)
63
+ send("validate_#{validation_type}", value, errors)
64
+ end
65
+
66
+ def validate_with_comparison(value, cmp, expected, error_message_name, errors, negated = false)
67
+ return if expected.nil?
68
+
69
+ comparison = value.send(cmp, expected)
70
+ return if negated ? !comparison : comparison
71
+
72
+ errors << ValidationErrors.default_error_message(error_message_name, field_name, expected)
73
+ end
74
+
75
+ def validate_integer(value, errors)
76
+ validate_with_comparison(value_as_string(value), :=~, /\A[+-]?\d+\z/, :not_an_integer, errors)
77
+ end
78
+
79
+ def validate_numeric(value, errors)
80
+ precision = options[:precision]
81
+ scale = options[:scale]
82
+
83
+ regexp = if precision && scale
84
+ if precision > scale && scale == 0
85
+ /\A[+-]?(?:\d{1,#{precision}}(?:\.0)?)\z/
86
+ elsif precision > scale
87
+ /\A[+-]?(?:\d{1,#{precision - scale}}|\d{0,#{precision - scale}}\.\d{1,#{scale}})\z/
88
+ elsif precision == scale
89
+ /\A[+-]?(?:0(?:\.\d{1,#{scale}})?)\z/
90
+ else
91
+ raise ArgumentError, "Invalid precision #{precision.inspect} and scale #{scale.inspect} for #{field_name} (value: #{value.inspect} #{value.class})"
92
+ end
93
+ else
94
+ /\A[+-]?(?:\d+|\d*\.\d+)\z/
95
+ end
96
+
97
+ validate_with_comparison(value_as_string(value), :=~, regexp, :not_a_number, errors)
98
+ end
99
+
100
+ def validate_gt(value, errors)
101
+ validate_with_comparison(value, :>, options[:gt], :greater_than, errors)
102
+ end
103
+
104
+ def validate_lt(value, errors)
105
+ validate_with_comparison(value, :<, options[:lt], :less_than, errors)
106
+ end
107
+
108
+ def validate_gte(value, errors)
109
+ validate_with_comparison(value, :>=, options[:gte], :greater_than_or_equal_to, errors)
110
+ end
111
+
112
+ def validate_lte(value, errors)
113
+ validate_with_comparison(value, :<=, options[:lte], :less_than_or_equal_to, errors)
114
+ end
115
+
116
+ def validate_eq(value, errors)
117
+ eq = options[:eq] || options[:equal] || options[:equals] || options[:exactly]
118
+ validate_with_comparison(value, :==, eq, :equal_to, errors)
119
+ end
120
+
121
+ def validate_ne(value, errors)
122
+ validate_with_comparison(value, :==, options[:ne], :not_equal_to, errors, true)
123
+ end
124
+ end # class NumericValidator
125
+
126
+ module ValidatesIsNumber
127
+
128
+ # Validate whether a field is numeric
129
+ #
130
+ # @details
131
+ #
132
+ # Options are:
133
+ #
134
+ # :message => "Error message for %s"
135
+ # Custom error message, also can be a callable object that takes
136
+ # an object (for pure Ruby objects) or object and property (for DM resources)
137
+ #
138
+ # :precision => 2
139
+ # Required precision of a value
140
+ #
141
+ # :scale => 2
142
+ # Required scale of a value
143
+ #
144
+ # :gte => 5.75
145
+ # 'Greater than or greater' requirement
146
+ #
147
+ # :lte => 5.75
148
+ # 'Less than or greater' requirement
149
+ #
150
+ # :lt => 5.75
151
+ # 'Less than' requirement
152
+ #
153
+ # :gt => 5.75
154
+ # 'Greater than' requirement
155
+ #
156
+ # :eq => 5.75
157
+ # 'Equal' requirement
158
+ #
159
+ # :ne => 5.75
160
+ # 'Not equal' requirement
161
+ #
162
+ # :integer_only => true
163
+ # Use to restrict allowed values to integers
164
+ def validates_is_number(*fields)
165
+ opts = opts_from_validator_args(fields)
166
+ add_validator_to_context(opts, fields, DataMapper::Validate::NumericValidator)
167
+ end
168
+
169
+ end # module ValidatesIsNumber
170
+ end # module Validate
171
+ end # module DataMapper
@@ -6,15 +6,10 @@ module DataMapper
6
6
  # @author Dirkjan Bussink
7
7
  # @since 0.9
8
8
  class PrimitiveValidator < GenericValidator
9
-
10
- def initialize(field_name, options={})
11
- super
12
- @field_name, @options = field_name, options
13
- end
14
-
15
9
  def call(target)
16
- value = target.validation_property_value(field_name)
10
+ value = target.validation_property_value(field_name)
17
11
  property = target.validation_property(field_name)
12
+
18
13
  return true if value.nil? || value.kind_of?(property.primitive) || property.primitive == TrueClass && value.kind_of?(FalseClass)
19
14
 
20
15
  error_message = @options[:message] || default_error(property)
@@ -6,12 +6,6 @@ module DataMapper
6
6
  # @author Guy van den Berg
7
7
  # @since 0.9
8
8
  class RequiredFieldValidator < GenericValidator
9
-
10
- def initialize(field_name, options={})
11
- super
12
- @field_name, @options = field_name, options
13
- end
14
-
15
9
  def call(target)
16
10
  value = target.validation_property_value(field_name)
17
11
  property = target.validation_property(field_name)
@@ -11,42 +11,31 @@ module DataMapper
11
11
  def initialize(field_name, options = {})
12
12
  assert_kind_of 'scope', options[:scope], Array, Symbol if options.has_key?(:scope)
13
13
  super
14
- @field_name, @options = field_name, options
14
+
15
+ @options[:allow_nil] = true unless @options.include?(:allow_nil)
15
16
  end
16
17
 
17
18
  def call(target)
18
- scope = Array(@options[:scope])
19
-
20
- return true if @options[:allow_nil] && target.send(field_name).nil?
19
+ value = target.send(field_name)
21
20
 
22
- repository_name = target.repository.name
21
+ return true if @options[:allow_nil] && value.blank?
23
22
 
24
23
  opts = {
25
24
  :fields => target.model.key,
26
- field_name => target.validation_property_value(field_name)
25
+ field_name => value,
27
26
  }
28
27
 
29
- scope.each do |item|
30
- if target.model.properties(repository_name).has_property?(item)
31
- opts[item] = target.validation_property_value(item)
32
- elsif target.model.relationships(repository_name).has_key?(item)
33
- target.validation_association_keys(item).each do |key|
34
- opts[key] = target.validation_property_value(key)
35
- end
36
- end
37
- end
28
+ Array(@options[:scope]).each { |subject| opts[subject] = target.send(subject) }
38
29
 
39
- resource = repository(repository_name) { target.model.first(opts) }
30
+ resource = DataMapper.repository(target.repository.name) { target.model.first(opts) }
40
31
 
41
32
  return true if resource.nil?
42
-
43
- # is target and found resource identic? same instance... but not ==
44
- return true if !target.new_record? && resource.repository.name == repository_name && resource.model == target.model && resource.key == target.key
33
+ return true if target.saved? && resource.key == target.key
45
34
 
46
35
  error_message = @options[:message] || ValidationErrors.default_error_message(:taken, field_name)
47
36
  add_error(target, error_message, field_name)
48
37
 
49
- return false
38
+ false
50
39
  end
51
40
  end # class UniquenessValidator
52
41
 
@@ -9,13 +9,13 @@ module DataMapper
9
9
 
10
10
  def initialize(field_name, options={})
11
11
  super
12
- @field_name, @options = field_name, options
12
+
13
13
  @options[:set] = [] unless @options.has_key?(:set)
14
14
  end
15
15
 
16
16
  def call(target)
17
17
  value = target.send(field_name)
18
- return true if @options[:allow_nil] && value.nil?
18
+ return true if @options[:allow_nil] && value.blank?
19
19
  return true if @options[:set].include?(value)
20
20
 
21
21
  set = @options[:set]
@@ -29,7 +29,7 @@ module DataMapper
29
29
  error_message = msg || ValidationErrors.default_error_message(:greater_than_or_equal_to, field_name, set.first)
30
30
  end
31
31
  else
32
- error_message = ValidationErrors.default_error_message(:inclusion, field_name, set.join(', '))
32
+ error_message = msg || ValidationErrors.default_error_message(:inclusion, field_name, set.join(', '))
33
33
  end
34
34
 
35
35
  add_error(target, error_message, field_name)
@@ -43,7 +43,7 @@ module DataMapper
43
43
 
44
44
  module ValidatesWithin
45
45
 
46
- # Validate the absence of a field
46
+ # Validate that value of a field if within a range/set
47
47
  #
48
48
  def validates_within(*fields)
49
49
  opts = opts_from_validator_args(fields)
@@ -1,5 +1,5 @@
1
1
  module DataMapper
2
2
  module Validations
3
- VERSION = '0.9.11'
3
+ VERSION = '0.10.0'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,32 @@
1
+ module DataMapper
2
+ module Validate
3
+ module Fixtures
4
+ class Barcode
5
+
6
+ #
7
+ # Behaviors
8
+ #
9
+
10
+ include DataMapper::Resource
11
+
12
+ #
13
+ # Properties
14
+ #
15
+
16
+ without_auto_validations do
17
+ property :code, String, :key => true
18
+ end
19
+
20
+ #
21
+ # Validations
22
+ #
23
+
24
+ validates_length :code, :max => 10
25
+
26
+ def self.valid_instance
27
+ new(:code => "3600029145")
28
+ end
29
+ end # Barcode
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,58 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module DataMapper
4
+ module Validate
5
+ module Fixtures
6
+ class BasketballCourt
7
+ #
8
+ # Behaviors
9
+ #
10
+
11
+ include DataMapper::Resource
12
+
13
+ #
14
+ # Properties
15
+ #
16
+
17
+ property :id, Serial
18
+
19
+ without_auto_validations do
20
+ property :name, String
21
+
22
+ property :length, Float
23
+ property :width, Float
24
+
25
+ property :three_point_line_distance, Float
26
+ property :free_throw_line_distance, Float
27
+ property :rim_height, Float
28
+ end
29
+
30
+ #
31
+ # Validations
32
+ #
33
+
34
+ # obviously these are all metrics
35
+ validates_is_number :length, :gte => 15.0, :lte => 15.24
36
+ validates_is_number :width, :gte => 25.28, :lte => 28.65
37
+
38
+ # 3 pt line distance may use :gte and :lte, but for
39
+ # sake of spec example we make it up a little
40
+ validates_is_number :three_point_line_distance, :gt => 6.7, :lt => 7.24
41
+ validates_is_number :free_throw_line_distance, :equals => 4.57
42
+ validates_is_number :rim_height, :eq => 3.05
43
+
44
+ def self.valid_instance(overrides = {})
45
+ defaults = {
46
+ :length => 15.24,
47
+ :width => 28.65,
48
+ :free_throw_line_distance => 4.57,
49
+ :rim_height => 3.05,
50
+ :three_point_line_distance => 6.9
51
+ }
52
+
53
+ new(defaults.merge(overrides))
54
+ end
55
+ end
56
+ end # Fixtures
57
+ end # Validate
58
+ end # DataMapper
@@ -0,0 +1,37 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module DataMapper
4
+ module Validate
5
+ module Fixtures
6
+ class BasketballPlayer
7
+ #
8
+ # Behaviors
9
+ #
10
+
11
+ include DataMapper::Resource
12
+
13
+ #
14
+ # Properties
15
+ #
16
+
17
+ property :id, Serial
18
+
19
+ without_auto_validations do
20
+ property :name, String
21
+ property :height, Float
22
+ property :weight, Float
23
+ end
24
+
25
+ #
26
+ # Validations
27
+ #
28
+
29
+ # precision and scale need to be defined for length to be validated
30
+ validates_is_number :height, :weight, :precision => 10
31
+ end
32
+ BasketballPlayer.auto_migrate!
33
+
34
+
35
+ end # Fixtures
36
+ end # Validate
37
+ end # DataMapper
@@ -0,0 +1,33 @@
1
+ module DataMapper
2
+ module Validate
3
+ module Fixtures
4
+ class BetaTesterAccount
5
+ #
6
+ # Behaviors
7
+ #
8
+
9
+ include ::DataMapper::Resource
10
+
11
+ #
12
+ # Properties
13
+ #
14
+
15
+ property :id, Serial
16
+ property :full_name, String, :auto_validation => false
17
+ property :email, String, :auto_validation => false
18
+
19
+ property :user_agreement, Boolean, :auto_validation => false
20
+ property :newsletter_signup, String, :auto_validation => false
21
+ property :privacy_agreement, String, :auto_validation => false
22
+
23
+ #
24
+ # Validations
25
+ #
26
+
27
+ validates_is_accepted :user_agreement, :allow_nil => false
28
+ validates_is_accepted :newsletter_signup
29
+ validates_is_accepted :privacy_agreement, :accept => %w(agreed accept), :message => "You must accept this agreement in order to proceed"
30
+ end # BetaTesterAccount
31
+ end
32
+ end
33
+ end