dm-validations 0.10.2 → 1.0.0.rc1

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 (109) hide show
  1. data/.gitignore +36 -0
  2. data/Gemfile +143 -0
  3. data/README.rdoc +52 -102
  4. data/Rakefile +3 -3
  5. data/VERSION +1 -1
  6. data/dm-validations.gemspec +126 -14
  7. data/lib/dm-validations.rb +78 -18
  8. data/lib/dm-validations/auto_validate.rb +27 -23
  9. data/lib/dm-validations/contextual_validators.rb +3 -3
  10. data/lib/dm-validations/formats/email.rb +3 -3
  11. data/lib/dm-validations/formats/url.rb +3 -3
  12. data/lib/dm-validations/support/context.rb +1 -1
  13. data/lib/dm-validations/validation_errors.rb +5 -7
  14. data/lib/dm-validations/validators/absent_field_validator.rb +13 -9
  15. data/lib/dm-validations/validators/acceptance_validator.rb +10 -7
  16. data/lib/dm-validations/validators/block_validator.rb +3 -3
  17. data/lib/dm-validations/validators/confirmation_validator.rb +10 -7
  18. data/lib/dm-validations/validators/format_validator.rb +14 -10
  19. data/lib/dm-validations/validators/generic_validator.rb +3 -3
  20. data/lib/dm-validations/validators/length_validator.rb +10 -7
  21. data/lib/dm-validations/validators/method_validator.rb +3 -3
  22. data/lib/dm-validations/validators/numeric_validator.rb +25 -14
  23. data/lib/dm-validations/validators/primitive_validator.rb +12 -8
  24. data/lib/dm-validations/validators/required_field_validator.rb +12 -9
  25. data/lib/dm-validations/validators/uniqueness_validator.rb +9 -6
  26. data/lib/dm-validations/validators/within_validator.rb +3 -3
  27. data/spec/fixtures/barcode.rb +10 -2
  28. data/spec/fixtures/basketball_court.rb +7 -7
  29. data/spec/fixtures/basketball_player.rb +3 -3
  30. data/spec/fixtures/beta_tester_account.rb +4 -4
  31. data/spec/fixtures/bill_of_landing.rb +7 -7
  32. data/spec/fixtures/boat_dock.rb +2 -2
  33. data/spec/fixtures/city.rb +1 -1
  34. data/spec/fixtures/company.rb +7 -7
  35. data/spec/fixtures/corporate_world.rb +24 -26
  36. data/spec/fixtures/country.rb +1 -1
  37. data/spec/fixtures/currency.rb +4 -4
  38. data/spec/fixtures/ethernet_frame.rb +5 -5
  39. data/spec/fixtures/event.rb +2 -2
  40. data/spec/fixtures/g3_concert.rb +3 -3
  41. data/spec/fixtures/jabberwock.rb +2 -2
  42. data/spec/fixtures/kayak.rb +2 -2
  43. data/spec/fixtures/lernean_hydra.rb +3 -3
  44. data/spec/fixtures/mathematical_function.rb +2 -2
  45. data/spec/fixtures/memory_object.rb +3 -3
  46. data/spec/fixtures/mittelschnauzer.rb +3 -3
  47. data/spec/fixtures/motor_launch.rb +1 -1
  48. data/spec/fixtures/page.rb +3 -3
  49. data/spec/fixtures/phone_number.rb +2 -2
  50. data/spec/fixtures/pirogue.rb +2 -2
  51. data/spec/fixtures/programming_language.rb +3 -3
  52. data/spec/fixtures/reservation.rb +5 -5
  53. data/spec/fixtures/scm_operation.rb +42 -45
  54. data/spec/fixtures/sms_message.rb +1 -1
  55. data/spec/fixtures/udp_packet.rb +3 -3
  56. data/spec/integration/absent_field_validator/absent_field_validator_spec.rb +6 -6
  57. data/spec/integration/acceptance_validator/acceptance_validator_spec.rb +3 -3
  58. data/spec/integration/automatic_validation/inferred_length_validation_spec.rb +5 -5
  59. data/spec/integration/automatic_validation/spec_helper.rb +1 -1
  60. data/spec/integration/block_validator/block_validator_spec.rb +2 -2
  61. data/spec/integration/conditional_validation/if_condition_spec.rb +3 -3
  62. data/spec/integration/confirmation_validator/confirmation_validator_spec.rb +3 -3
  63. data/spec/integration/datamapper_models/association_validation_spec.rb +5 -5
  64. data/spec/integration/datamapper_models/inheritance_spec.rb +6 -6
  65. data/spec/integration/duplicated_validations/duplicated_validations_spec.rb +3 -3
  66. data/spec/integration/format_validator/email_format_validator_spec.rb +6 -6
  67. data/spec/integration/format_validator/format_validator_spec.rb +8 -8
  68. data/spec/integration/format_validator/regexp_validator_spec.rb +4 -4
  69. data/spec/integration/format_validator/url_format_validator_spec.rb +4 -4
  70. data/spec/integration/length_validator/default_value_spec.rb +3 -3
  71. data/spec/integration/length_validator/equality_spec.rb +4 -4
  72. data/spec/integration/length_validator/error_message_spec.rb +3 -3
  73. data/spec/integration/length_validator/maximum_spec.rb +3 -3
  74. data/spec/integration/length_validator/minimum_spec.rb +3 -3
  75. data/spec/integration/length_validator/range_spec.rb +3 -3
  76. data/spec/integration/method_validator/method_validator_spec.rb +8 -8
  77. data/spec/integration/numeric_validator/equality_with_float_type_spec.rb +7 -7
  78. data/spec/integration/numeric_validator/equality_with_integer_type_spec.rb +5 -5
  79. data/spec/integration/numeric_validator/float_type_spec.rb +3 -3
  80. data/spec/integration/numeric_validator/gt_with_float_type_spec.rb +3 -3
  81. data/spec/integration/numeric_validator/gte_with_float_type_spec.rb +3 -3
  82. data/spec/integration/numeric_validator/lt_with_float_type_spec.rb +3 -3
  83. data/spec/integration/numeric_validator/lte_with_float_type_spec.rb +3 -3
  84. data/spec/integration/primitive_validator/primitive_validator_spec.rb +4 -4
  85. data/spec/integration/pure_ruby_objects/plain_old_ruby_object_validation_spec.rb +4 -4
  86. data/spec/integration/required_field_validator/association_spec.rb +19 -51
  87. data/spec/integration/required_field_validator/boolean_type_value_spec.rb +4 -1
  88. data/spec/integration/required_field_validator/date_type_value_spec.rb +4 -2
  89. data/spec/integration/required_field_validator/datetime_type_value_spec.rb +4 -2
  90. data/spec/integration/required_field_validator/float_type_value_spec.rb +4 -2
  91. data/spec/integration/required_field_validator/integer_type_value_spec.rb +4 -2
  92. data/spec/integration/required_field_validator/plain_old_ruby_object_spec.rb +6 -4
  93. data/spec/integration/required_field_validator/string_type_value_spec.rb +3 -1
  94. data/spec/integration/required_field_validator/text_type_value_spec.rb +3 -1
  95. data/spec/integration/shared/valid_and_invalid_model.rb +8 -0
  96. data/spec/integration/uniqueness_validator/uniqueness_validator_spec.rb +29 -25
  97. data/spec/integration/within_validator/within_validator_spec.rb +6 -6
  98. data/spec/public/resource_spec.rb +47 -9
  99. data/spec/spec_helper.rb +13 -27
  100. data/spec/unit/contextual_validators/emptiness_spec.rb +4 -4
  101. data/spec/unit/contextual_validators/execution_spec.rb +6 -6
  102. data/spec/unit/contextual_validators/spec_helper.rb +3 -3
  103. data/spec/unit/generic_validator/equality_operator_spec.rb +7 -7
  104. data/spec/unit/validation_errors/adding_spec.rb +2 -2
  105. data/spec/unit/validation_errors/emptiness_spec.rb +2 -2
  106. data/spec/unit/validation_errors/enumerable_spec.rb +2 -2
  107. data/tasks/local_gemfile.rake +18 -0
  108. data/tasks/spec.rake +0 -3
  109. metadata +157 -25
@@ -1,5 +1,5 @@
1
1
  module DataMapper
2
- module Validate
2
+ module Validations
3
3
 
4
4
  ##
5
5
  #
@@ -52,9 +52,9 @@ module DataMapper
52
52
  define_method(method_name, block)
53
53
  opts = opts_from_validator_args(fields)
54
54
  opts[:method] = method_name
55
- add_validator_to_context(opts, fields.empty? ? [method_name] : fields, DataMapper::Validate::MethodValidator)
55
+ add_validator_to_context(opts, fields.empty? ? [method_name] : fields, DataMapper::Validations::MethodValidator)
56
56
  end
57
57
 
58
58
  end # module ValidatesWithMethod
59
- end # module Validate
59
+ end # module Validations
60
60
  end # module DataMapper
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  module DataMapper
3
- module Validate
3
+ module Validations
4
4
 
5
5
  ##
6
6
  #
@@ -40,7 +40,8 @@ module DataMapper
40
40
  end
41
41
  end # class ConfirmationValidator
42
42
 
43
- module ValidatesIsConfirmed
43
+ module ValidatesConfirmation
44
+ extend Deprecate
44
45
 
45
46
  ##
46
47
  # Validates that the given attribute is confirmed by another attribute.
@@ -64,19 +65,21 @@ module DataMapper
64
65
  # attr_accessor :password_confirmation
65
66
  # attr_accessor :email_repeated
66
67
  #
67
- # validates_is_confirmed :password
68
- # validates_is_confirmed :email, :confirm => :email_repeated
68
+ # validates_confirmation_of :password
69
+ # validates_confirmation_of :email, :confirm => :email_repeated
69
70
  #
70
71
  # # a call to valid? will return false unless:
71
72
  # # password == password_confirmation
72
73
  # # and
73
74
  # # email == email_repeated
74
75
  #
75
- def validates_is_confirmed(*fields)
76
+ def validates_confirmation_of(*fields)
76
77
  opts = opts_from_validator_args(fields)
77
- add_validator_to_context(opts, fields, DataMapper::Validate::ConfirmationValidator)
78
+ add_validator_to_context(opts, fields, DataMapper::Validations::ConfirmationValidator)
78
79
  end
79
80
 
81
+ deprecate :validates_is_confirmed, :validates_confirmation_of
82
+
80
83
  end # module ValidatesIsConfirmed
81
- end # module Validate
84
+ end # module Validations
82
85
  end # module DataMapper
@@ -5,7 +5,8 @@ require Pathname(__FILE__).dirname.expand_path + ".." + 'formats/email'
5
5
  require Pathname(__FILE__).dirname.expand_path + ".." + 'formats/url'
6
6
 
7
7
  module DataMapper
8
- module Validate
8
+ module Validations
9
+ class UnknownValidationFormat < ::ArgumentError; end
9
10
 
10
11
  ##
11
12
  #
@@ -14,8 +15,8 @@ module DataMapper
14
15
  class FormatValidator < GenericValidator
15
16
 
16
17
  FORMATS = {}
17
- include DataMapper::Validate::Format::Email
18
- include DataMapper::Validate::Format::Url
18
+ include DataMapper::Validations::Format::Email
19
+ include DataMapper::Validations::Format::Url
19
20
 
20
21
  def initialize(field_name, options = {})
21
22
  super
@@ -56,6 +57,7 @@ module DataMapper
56
57
 
57
58
 
58
59
  module ValidatesFormat
60
+ extend Deprecate
59
61
 
60
62
  ##
61
63
  # Validates that the attribute is in the specified format. You may use the
@@ -69,8 +71,8 @@ module DataMapper
69
71
  # @option :with<Format, Proc, Regexp> an alias for :as
70
72
  #
71
73
  # @details [Pre-defined Formats]
72
- # :email_address (format is specified in DataMapper::Validate::Format::Email)
73
- # :url (format is specified in DataMapper::Validate::Format::Url)
74
+ # :email_address (format is specified in DataMapper::Validations::Format::Email)
75
+ # :url (format is specified in DataMapper::Validations::Format::Url)
74
76
  #
75
77
  # @example [Usage]
76
78
  # require 'dm-validations'
@@ -81,19 +83,21 @@ module DataMapper
81
83
  # property :email, String
82
84
  # property :zip_code, String
83
85
  #
84
- # validates_format :email, :as => :email_address
85
- # validates_format :zip_code, :with => /^\d{5}$/
86
+ # validates_format_of :email, :as => :email_address
87
+ # validates_format_of :zip_code, :with => /^\d{5}$/
86
88
  #
87
89
  # # a call to valid? will return false unless:
88
90
  # # email is formatted like an email address
89
91
  # # and
90
92
  # # zip_code is a string of 5 digits
91
93
  #
92
- def validates_format(*fields)
94
+ def validates_format_of(*fields)
93
95
  opts = opts_from_validator_args(fields)
94
- add_validator_to_context(opts, fields, DataMapper::Validate::FormatValidator)
96
+ add_validator_to_context(opts, fields, DataMapper::Validations::FormatValidator)
95
97
  end
96
98
 
99
+ deprecate :validates_format, :validates_format_of
100
+
97
101
  end # module ValidatesFormat
98
- end # module Validate
102
+ end # module Validations
99
103
  end # module DataMapper
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  module DataMapper
3
- module Validate
3
+ module Validations
4
4
 
5
5
  # All validators extend this base class. Validators must:
6
6
  #
@@ -33,7 +33,7 @@ module DataMapper
33
33
  @options = options.except(:if, :unless)
34
34
  @if_clause = options[:if]
35
35
  @unless_clause = options[:unless]
36
- @humanized_field_name = Extlib::Inflection.humanize(@field_name)
36
+ @humanized_field_name = ActiveSupport::Inflector.humanize(@field_name)
37
37
  end
38
38
 
39
39
  # Add an error message to a target resource. If the error corresponds to a
@@ -145,5 +145,5 @@ module DataMapper
145
145
 
146
146
  alias to_s inspect
147
147
  end # class GenericValidator
148
- end # module Validate
148
+ end # module Validations
149
149
  end # module DataMapper
@@ -1,5 +1,5 @@
1
1
  module DataMapper
2
- module Validate
2
+ module Validations
3
3
  class LengthValidator < GenericValidator
4
4
 
5
5
  # Initialize a length validator
@@ -156,6 +156,7 @@ module DataMapper
156
156
  end # class LengthValidator
157
157
 
158
158
  module ValidatesLength
159
+ extend Deprecate
159
160
 
160
161
  # Validates that the length of the attribute is equal to, less than,
161
162
  # greater than or within a certain range (depending upon the options
@@ -186,20 +187,22 @@ module DataMapper
186
187
  # property low, Integer
187
188
  # property just_right, Integer
188
189
  #
189
- # validates_length :high, :min => 100000000000
190
- # validates_length :low, :equals => 0
191
- # validates_length :just_right, :within => 1..10
190
+ # validates_length_of :high, :min => 100000000000
191
+ # validates_length_of :low, :equals => 0
192
+ # validates_length_of :just_right, :within => 1..10
192
193
  #
193
194
  # # a call to valid? will return false unless:
194
195
  # # high is greater than or equal to 100000000000
195
196
  # # low is equal to 0
196
197
  # # just_right is between 1 and 10 (inclusive of both 1 and 10)
197
198
  #
198
- def validates_length(*fields)
199
+ def validates_length_of(*fields)
199
200
  opts = opts_from_validator_args(fields)
200
- add_validator_to_context(opts, fields, DataMapper::Validate::LengthValidator)
201
+ add_validator_to_context(opts, fields, DataMapper::Validations::LengthValidator)
201
202
  end
202
203
 
204
+ deprecate :validates_length, :validates_length_of
205
+
203
206
  end # module ValidatesLength
204
- end # module Validate
207
+ end # module Validations
205
208
  end # module DataMapper
@@ -1,5 +1,5 @@
1
1
  module DataMapper
2
- module Validate
2
+ module Validations
3
3
 
4
4
  ##
5
5
  #
@@ -60,9 +60,9 @@ module DataMapper
60
60
  # end
61
61
  def validates_with_method(*fields)
62
62
  opts = opts_from_validator_args(fields)
63
- add_validator_to_context(opts, fields, DataMapper::Validate::MethodValidator)
63
+ add_validator_to_context(opts, fields, DataMapper::Validations::MethodValidator)
64
64
  end
65
65
 
66
66
  end # module ValidatesWithMethod
67
- end # module Validate
67
+ end # module Validations
68
68
  end # module DataMapper
@@ -1,11 +1,11 @@
1
1
  module DataMapper
2
- module Validate
2
+ module Validations
3
3
 
4
4
  ##
5
5
  #
6
6
  # @author Guy van den Berg
7
7
  # @since 0.9
8
- class NumericValidator < GenericValidator
8
+ class NumericalityValidator < GenericValidator
9
9
 
10
10
  def call(target)
11
11
  value = target.validation_property_value(field_name)
@@ -32,7 +32,7 @@ module DataMapper
32
32
  private
33
33
 
34
34
  def integer_only?
35
- options.fetch(:integer_only, false)
35
+ options[:only_integer] || options.fetch(:integer_only, false)
36
36
  end
37
37
 
38
38
  def value_as_string(value)
@@ -62,6 +62,13 @@ module DataMapper
62
62
  def validate_with_comparison(value, cmp, expected, error_message_name, errors, negated = false)
63
63
  return if expected.nil?
64
64
 
65
+ # XXX: workaround for jruby. This is needed because the jruby
66
+ # compiler optimizes a bit too far with magic variables like $~.
67
+ # the value.send line sends $~. Inserting this line makes sure the
68
+ # jruby compiler does not optimise here.
69
+ # see http://jira.codehaus.org/browse/JRUBY-3765
70
+ $~ = nil if RUBY_PLATFORM[/java/]
71
+
65
72
  comparison = value.send(cmp, expected)
66
73
  return if negated ? !comparison : comparison
67
74
 
@@ -94,32 +101,33 @@ module DataMapper
94
101
  end
95
102
 
96
103
  def validate_gt(value, errors)
97
- validate_with_comparison(value, :>, options[:gt], :greater_than, errors)
104
+ validate_with_comparison(value, :>, options[:gt] || options[:greater_than], :greater_than, errors)
98
105
  end
99
106
 
100
107
  def validate_lt(value, errors)
101
- validate_with_comparison(value, :<, options[:lt], :less_than, errors)
108
+ validate_with_comparison(value, :<, options[:lt] || options[:less_than], :less_than, errors)
102
109
  end
103
110
 
104
111
  def validate_gte(value, errors)
105
- validate_with_comparison(value, :>=, options[:gte], :greater_than_or_equal_to, errors)
112
+ validate_with_comparison(value, :>=, options[:gte] || options[:greater_than_or_equal_to], :greater_than_or_equal_to, errors)
106
113
  end
107
114
 
108
115
  def validate_lte(value, errors)
109
- validate_with_comparison(value, :<=, options[:lte], :less_than_or_equal_to, errors)
116
+ validate_with_comparison(value, :<=, options[:lte] || options[:less_than_or_equal_to], :less_than_or_equal_to, errors)
110
117
  end
111
118
 
112
119
  def validate_eq(value, errors)
113
- eq = options[:eq] || options[:equal] || options[:equals] || options[:exactly]
120
+ eq = options[:eq] || options[:equal] || options[:equals] || options[:exactly] || options[:equal_to]
114
121
  validate_with_comparison(value, :==, eq, :equal_to, errors)
115
122
  end
116
123
 
117
124
  def validate_ne(value, errors)
118
- validate_with_comparison(value, :==, options[:ne], :not_equal_to, errors, true)
125
+ validate_with_comparison(value, :==, options[:ne] || options[:not_equal_to], :not_equal_to, errors, true)
119
126
  end
120
- end # class NumericValidator
127
+ end # class NumericalityValidator
121
128
 
122
- module ValidatesIsNumber
129
+ module ValidatesNumericality
130
+ extend Deprecate
123
131
 
124
132
  # Validate whether a field is numeric
125
133
  #
@@ -163,11 +171,14 @@ module DataMapper
163
171
  #
164
172
  # :integer_only => true
165
173
  # Use to restrict allowed values to integers
166
- def validates_is_number(*fields)
174
+ #
175
+ def validates_numericality_of(*fields)
167
176
  opts = opts_from_validator_args(fields)
168
- add_validator_to_context(opts, fields, DataMapper::Validate::NumericValidator)
177
+ add_validator_to_context(opts, fields, DataMapper::Validations::NumericalityValidator)
169
178
  end
170
179
 
180
+ deprecate :validates_is_number, :validates_numericality_of
181
+
171
182
  end # module ValidatesIsNumber
172
- end # module Validate
183
+ end # module Validations
173
184
  end # module DataMapper
@@ -1,11 +1,11 @@
1
1
  module DataMapper
2
- module Validate
2
+ module Validations
3
3
 
4
4
  ##
5
5
  #
6
6
  # @author Dirkjan Bussink
7
7
  # @since 0.9
8
- class PrimitiveValidator < GenericValidator
8
+ class PrimitiveTypeValidator < GenericValidator
9
9
  def call(target)
10
10
  value = target.validation_property_value(field_name)
11
11
  property = target.validation_property(field_name)
@@ -24,9 +24,11 @@ module DataMapper
24
24
  ValidationErrors.default_error_message(:primitive, field_name, property.primitive)
25
25
  end
26
26
 
27
- end # class PrimitiveValidator
27
+ end # class PrimitiveTypeValidator
28
28
 
29
- module ValidatesIsPrimitive
29
+ module ValidatesPrimitiveType
30
+
31
+ extend Deprecate
30
32
 
31
33
  ##
32
34
  # Validates that the specified attribute is of the correct primitive type.
@@ -39,17 +41,19 @@ module DataMapper
39
41
  #
40
42
  # property :birth_date, Date
41
43
  #
42
- # validates_is_primitive :birth_date
44
+ # validates_primitive_type_of :birth_date
43
45
  #
44
46
  # # a call to valid? will return false unless
45
47
  # # the birth_date is something that can be properly
46
48
  # # casted into a Date object.
47
49
  # end
48
- def validates_is_primitive(*fields)
50
+ def validates_primitive_type_of(*fields)
49
51
  opts = opts_from_validator_args(fields)
50
- add_validator_to_context(opts, fields, DataMapper::Validate::PrimitiveValidator)
52
+ add_validator_to_context(opts, fields, DataMapper::Validations::PrimitiveTypeValidator)
51
53
  end
52
54
 
55
+ deprecate :validates_is_primitive, :validates_primitive_type_of
56
+
53
57
  end # module ValidatesPresent
54
- end # module Validate
58
+ end # module Validations
55
59
  end # module DataMapper
@@ -1,11 +1,11 @@
1
1
  module DataMapper
2
- module Validate
2
+ module Validations
3
3
 
4
4
  ##
5
5
  #
6
6
  # @author Guy van den Berg
7
7
  # @since 0.9
8
- class RequiredFieldValidator < GenericValidator
8
+ class PresenceValidator < GenericValidator
9
9
  def call(target)
10
10
  value = target.validation_property_value(field_name)
11
11
  property = target.validation_property(field_name)
@@ -40,9 +40,10 @@ module DataMapper
40
40
  property ? property.primitive == TrueClass : false
41
41
  end
42
42
 
43
- end # class RequiredFieldValidator
43
+ end # class PresenceValidator
44
44
 
45
- module ValidatesPresent
45
+ module ValidatesPresence
46
+ extend Deprecate
46
47
 
47
48
  ##
48
49
  # Validates that the specified attribute is present.
@@ -66,17 +67,19 @@ module DataMapper
66
67
  # property :another_required, String
67
68
  # property :yet_again, String
68
69
  #
69
- # validates_present :required_attribute
70
- # validates_present :another_required, :yet_again
70
+ # validates_presence_of :required_attribute
71
+ # validates_presence_of :another_required, :yet_again
71
72
  #
72
73
  # # a call to valid? will return false unless
73
74
  # # all three attributes are !blank?
74
75
  # end
75
- def validates_present(*fields)
76
+ def validates_presence_of(*fields)
76
77
  opts = opts_from_validator_args(fields)
77
- add_validator_to_context(opts, fields, DataMapper::Validate::RequiredFieldValidator)
78
+ add_validator_to_context(opts, fields, DataMapper::Validations::PresenceValidator)
78
79
  end
79
80
 
81
+ deprecate :validates_present, :validates_presence_of
82
+
80
83
  end # module ValidatesPresent
81
- end # module Validate
84
+ end # module Validations
82
85
  end # module DataMapper
@@ -1,12 +1,12 @@
1
1
  module DataMapper
2
- module Validate
2
+ module Validations
3
3
 
4
4
  ##
5
5
  #
6
6
  # @author Guy van den Berg
7
7
  # @since 0.9
8
8
  class UniquenessValidator < GenericValidator
9
- include Extlib::Assertions
9
+ include DataMapper::Assertions
10
10
 
11
11
  def initialize(field_name, options = {})
12
12
  assert_kind_of 'scope', options[:scope], Array, Symbol if options.has_key?(:scope)
@@ -43,15 +43,18 @@ module DataMapper
43
43
  end
44
44
  end # class UniquenessValidator
45
45
 
46
- module ValidatesIsUnique
46
+ module ValidatesUniqueness
47
+ extend Deprecate
47
48
 
48
49
  # Validate the uniqueness of a field
49
50
  #
50
- def validates_is_unique(*fields)
51
+ def validates_uniqueness_of(*fields)
51
52
  opts = opts_from_validator_args(fields)
52
- add_validator_to_context(opts, fields, DataMapper::Validate::UniquenessValidator)
53
+ add_validator_to_context(opts, fields, DataMapper::Validations::UniquenessValidator)
53
54
  end
54
55
 
56
+ deprecate :validates_is_unique, :validates_uniqueness_of
57
+
55
58
  end # module ValidatesIsUnique
56
- end # module Validate
59
+ end # module Validations
57
60
  end # module DataMapper