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.
- data/{History.txt → History.rdoc} +10 -3
- data/LICENSE +1 -0
- data/Manifest.txt +103 -33
- data/README.rdoc +172 -0
- data/Rakefile +4 -5
- data/lib/dm-validations.rb +73 -75
- data/lib/dm-validations/auto_validate.rb +98 -56
- data/lib/dm-validations/contextual_validators.rb +37 -14
- data/lib/dm-validations/exceptions.rb +3 -0
- data/lib/dm-validations/formats/url.rb +3 -1
- data/lib/dm-validations/support/context.rb +54 -0
- data/lib/dm-validations/validation_errors.rb +51 -27
- data/lib/dm-validations/{absent_field_validator.rb → validators/absent_field_validator.rb} +2 -8
- data/lib/dm-validations/{acceptance_validator.rb → validators/acceptance_validator.rb} +7 -7
- data/lib/dm-validations/{block_validator.rb → validators/block_validator.rb} +0 -0
- data/lib/dm-validations/{confirmation_validator.rb → validators/confirmation_validator.rb} +7 -7
- data/lib/dm-validations/{format_validator.rb → validators/format_validator.rb} +10 -16
- data/lib/dm-validations/{generic_validator.rb → validators/generic_validator.rb} +28 -6
- data/lib/dm-validations/validators/length_validator.rb +214 -0
- data/lib/dm-validations/validators/method_validator.rb +68 -0
- data/lib/dm-validations/validators/numeric_validator.rb +171 -0
- data/lib/dm-validations/{primitive_validator.rb → validators/primitive_validator.rb} +2 -7
- data/lib/dm-validations/{required_field_validator.rb → validators/required_field_validator.rb} +0 -6
- data/lib/dm-validations/{uniqueness_validator.rb → validators/uniqueness_validator.rb} +9 -20
- data/lib/dm-validations/{within_validator.rb → validators/within_validator.rb} +4 -4
- data/lib/dm-validations/version.rb +1 -1
- data/spec/fixtures/barcode.rb +32 -0
- data/spec/fixtures/basketball_court.rb +58 -0
- data/spec/fixtures/basketball_player.rb +37 -0
- data/spec/fixtures/beta_tester_account.rb +33 -0
- data/spec/fixtures/bill_of_landing.rb +42 -0
- data/spec/fixtures/boat_dock.rb +26 -0
- data/spec/fixtures/city.rb +25 -0
- data/spec/fixtures/company.rb +95 -0
- data/spec/fixtures/corporate_world.rb +47 -0
- data/spec/fixtures/country.rb +25 -0
- data/spec/fixtures/currency.rb +42 -0
- data/spec/fixtures/ethernet_frame.rb +56 -0
- data/spec/fixtures/event.rb +44 -0
- data/spec/fixtures/g3_concert.rb +57 -0
- data/spec/fixtures/jabberwock.rb +27 -0
- data/spec/fixtures/kayak.rb +28 -0
- data/spec/fixtures/lernean_hydra.rb +39 -0
- data/spec/fixtures/mathematical_function.rb +34 -0
- data/spec/fixtures/memory_object.rb +30 -0
- data/spec/fixtures/mittelschnauzer.rb +35 -0
- data/spec/fixtures/motor_launch.rb +21 -0
- data/spec/fixtures/page.rb +32 -0
- data/spec/fixtures/phone_number.rb +28 -0
- data/spec/fixtures/pirogue.rb +28 -0
- data/spec/fixtures/programming_language.rb +83 -0
- data/spec/fixtures/reservation.rb +38 -0
- data/spec/fixtures/scm_operation.rb +67 -0
- data/spec/fixtures/sms_message.rb +22 -0
- data/spec/fixtures/udp_packet.rb +49 -0
- data/spec/integration/absent_field_validator/absent_field_validator_spec.rb +86 -0
- data/spec/integration/absent_field_validator/spec_helper.rb +7 -0
- data/spec/integration/acceptance_validator/acceptance_validator_spec.rb +196 -0
- data/spec/integration/acceptance_validator/spec_helper.rb +7 -0
- data/spec/integration/automatic_validation/custom_messages_for_inferred_validation_spec.rb +47 -0
- data/spec/integration/automatic_validation/disabling_inferred_validation_spec.rb +41 -0
- data/spec/integration/automatic_validation/inferred_boolean_properties_validation_spec.rb +104 -0
- data/spec/integration/automatic_validation/inferred_float_property_validation_spec.rb +35 -0
- data/spec/integration/automatic_validation/inferred_format_validation_spec.rb +33 -0
- data/spec/integration/automatic_validation/inferred_integer_properties_validation_spec.rb +73 -0
- data/spec/integration/automatic_validation/inferred_length_validation_spec.rb +121 -0
- data/spec/integration/automatic_validation/inferred_presence_validation_spec.rb +41 -0
- data/spec/integration/automatic_validation/inferred_primitive_validation_spec.rb +20 -0
- data/spec/integration/automatic_validation/inferred_within_validation_spec.rb +33 -0
- data/spec/integration/automatic_validation/spec_helper.rb +74 -0
- data/spec/integration/block_validator/block_validator_spec.rb +32 -0
- data/spec/integration/block_validator/spec_helper.rb +5 -0
- data/spec/integration/conditional_validation/if_condition_spec.rb +61 -0
- data/spec/integration/conditional_validation/spec_helper.rb +5 -0
- data/spec/integration/confirmation_validator/confirmation_validator_spec.rb +74 -0
- data/spec/integration/confirmation_validator/spec_helper.rb +5 -0
- data/spec/integration/datamapper_models/association_validation_spec.rb +23 -0
- data/spec/integration/datamapper_models/inheritance_spec.rb +78 -0
- data/spec/integration/duplicated_validations/duplicated_validations_spec.rb +22 -0
- data/spec/integration/duplicated_validations/spec_helper.rb +5 -0
- data/spec/integration/format_validator/email_format_validator_spec.rb +113 -0
- data/spec/integration/format_validator/format_validator_spec.rb +60 -0
- data/spec/integration/format_validator/regexp_validator_spec.rb +29 -0
- data/spec/integration/format_validator/spec_helper.rb +5 -0
- data/spec/integration/format_validator/url_format_validator_spec.rb +63 -0
- data/spec/integration/length_validator/default_value_spec.rb +12 -0
- data/spec/integration/length_validator/equality_spec.rb +79 -0
- data/spec/integration/length_validator/error_message_spec.rb +15 -18
- data/spec/integration/length_validator/maximum_spec.rb +40 -24
- data/spec/integration/length_validator/minimum_spec.rb +32 -21
- data/spec/integration/length_validator/range_spec.rb +50 -60
- data/spec/integration/length_validator/spec_helper.rb +7 -12
- data/spec/integration/method_validator/method_validator_spec.rb +239 -0
- data/spec/integration/method_validator/spec_helper.rb +5 -0
- data/spec/integration/numeric_validator/equality_with_float_type_spec.rb +61 -0
- data/spec/integration/numeric_validator/equality_with_integer_type_spec.rb +37 -0
- data/spec/integration/numeric_validator/float_type_spec.rb +42 -56
- data/spec/integration/numeric_validator/gt_with_float_type_spec.rb +35 -0
- data/spec/integration/numeric_validator/gte_with_float_type_spec.rb +35 -0
- data/spec/integration/numeric_validator/integer_only_true_spec.rb +3 -6
- data/spec/integration/numeric_validator/integer_type_spec.rb +8 -24
- data/spec/integration/numeric_validator/lt_with_float_type_spec.rb +35 -0
- data/spec/integration/numeric_validator/lte_with_float_type_spec.rb +35 -0
- data/spec/integration/numeric_validator/spec_helper.rb +5 -77
- data/spec/integration/primitive_validator/primitive_validator_spec.rb +90 -0
- data/spec/integration/primitive_validator/spec_helper.rb +5 -0
- data/spec/integration/pure_ruby_objects/plain_old_ruby_object_validation_spec.rb +118 -0
- data/spec/integration/required_field_validator/association_spec.rb +5 -8
- data/spec/integration/required_field_validator/boolean_type_value_spec.rb +4 -7
- data/spec/integration/required_field_validator/date_type_value_spec.rb +3 -6
- data/spec/integration/required_field_validator/datetime_type_value_spec.rb +3 -6
- data/spec/integration/required_field_validator/float_type_value_spec.rb +3 -6
- data/spec/integration/required_field_validator/integer_type_value_spec.rb +2 -5
- data/spec/integration/required_field_validator/plain_old_ruby_object_spec.rb +5 -8
- data/spec/integration/required_field_validator/shared_examples.rb +1 -1
- data/spec/integration/required_field_validator/spec_helper.rb +6 -67
- data/spec/integration/required_field_validator/string_type_value_spec.rb +2 -5
- data/spec/integration/required_field_validator/text_type_value_spec.rb +2 -5
- data/spec/integration/shared/default_validation_context.rb +13 -0
- data/spec/integration/shared/valid_and_invalid_model.rb +27 -0
- data/spec/integration/uniqueness_validator/spec_helper.rb +5 -0
- data/spec/integration/uniqueness_validator/uniqueness_validator_spec.rb +114 -0
- data/spec/integration/within_validator/spec_helper.rb +5 -0
- data/spec/integration/within_validator/within_validator_spec.rb +164 -0
- data/spec/public/resource_spec.rb +68 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +12 -4
- data/spec/unit/contextual_validators/emptiness_spec.rb +50 -0
- data/spec/unit/contextual_validators/execution_spec.rb +55 -0
- data/spec/unit/contextual_validators/spec_helper.rb +37 -0
- data/spec/unit/generic_validator/equality_operator_spec.rb +26 -0
- data/spec/unit/validation_errors/adding_spec.rb +54 -0
- data/spec/unit/validation_errors/emptiness_spec.rb +38 -0
- data/spec/unit/validation_errors/enumerable_spec.rb +32 -0
- data/tasks/install.rb +1 -1
- data/tasks/spec.rb +4 -4
- metadata +118 -55
- data/README.txt +0 -72
- data/lib/dm-validations/custom_validator.rb +0 -72
- data/lib/dm-validations/length_validator.rb +0 -113
- data/lib/dm-validations/method_validator.rb +0 -68
- data/lib/dm-validations/numeric_validator.rb +0 -83
- data/spec/integration/absent_field_validator_spec.rb +0 -36
- data/spec/integration/acceptance_validator_spec.rb +0 -87
- data/spec/integration/auto_validate_spec.rb +0 -342
- data/spec/integration/block_validator_spec.rb +0 -30
- data/spec/integration/confirmation_validator_spec.rb +0 -105
- data/spec/integration/contextual_validators_spec.rb +0 -27
- data/spec/integration/custom_validator_spec.rb +0 -9
- data/spec/integration/format_validator_spec.rb +0 -193
- data/spec/integration/generic_validator_spec.rb +0 -17
- data/spec/integration/length_validator/valid_objects_spec.rb +0 -13
- data/spec/integration/method_validator_spec.rb +0 -58
- data/spec/integration/numeric_validator_spec.rb +0 -253
- data/spec/integration/primitive_validator_spec.rb +0 -30
- data/spec/integration/uniqueness_validator_spec.rb +0 -97
- data/spec/integration/validation_errors_spec.rb +0 -18
- data/spec/integration/validation_spec.rb +0 -404
- data/spec/integration/within_validator_spec.rb +0 -79
@@ -0,0 +1,22 @@
|
|
1
|
+
module DataMapper
|
2
|
+
module Validate
|
3
|
+
module Fixtures
|
4
|
+
|
5
|
+
class SmsMessage
|
6
|
+
#
|
7
|
+
# Behaviors
|
8
|
+
#
|
9
|
+
|
10
|
+
include DataMapper::Resource
|
11
|
+
|
12
|
+
#
|
13
|
+
# Properties
|
14
|
+
#
|
15
|
+
|
16
|
+
property :id, Serial
|
17
|
+
property :body, Text, :length => (1..500)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module DataMapper
|
4
|
+
module Validate
|
5
|
+
module Fixtures
|
6
|
+
|
7
|
+
class UDPPacket
|
8
|
+
#
|
9
|
+
# Behaviors
|
10
|
+
#
|
11
|
+
|
12
|
+
include DataMapper::Resource
|
13
|
+
|
14
|
+
#
|
15
|
+
# Properties
|
16
|
+
#
|
17
|
+
|
18
|
+
property :id, Serial
|
19
|
+
|
20
|
+
property :source_port, Integer, :auto_validation => false
|
21
|
+
property :destination_port, Integer, :auto_validation => false
|
22
|
+
|
23
|
+
property :length, Integer, :auto_validation => false
|
24
|
+
property :checksum, String, :auto_validation => false
|
25
|
+
# consider that there are multiple algorithms
|
26
|
+
# available to the app, and it is allowed
|
27
|
+
# to be chosed
|
28
|
+
#
|
29
|
+
# yes, to some degree, this is a made up
|
30
|
+
# property ;)
|
31
|
+
property :checksum_algorithm, String, :auto_validation => false
|
32
|
+
property :data, Text, :auto_validation => false
|
33
|
+
|
34
|
+
#
|
35
|
+
# Volatile attributes
|
36
|
+
#
|
37
|
+
|
38
|
+
attr_accessor :underlying_ip_version
|
39
|
+
|
40
|
+
#
|
41
|
+
# Validations
|
42
|
+
#
|
43
|
+
|
44
|
+
validates_present :checksum_algorithm, :checksum, :if => Proc.new { |packet| packet.underlying_ip_version == 6 }, :message => "Checksum is mandatory when used with IPv6"
|
45
|
+
end
|
46
|
+
|
47
|
+
end # Fixtures
|
48
|
+
end # Validate
|
49
|
+
end # DataMapper
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/absent_field_validator/spec_helper'
|
3
|
+
|
4
|
+
describe DataMapper::Validate::Fixtures::Kayak do
|
5
|
+
before :all do
|
6
|
+
@kayak = DataMapper::Validate::Fixtures::Kayak.new
|
7
|
+
@kayak.should be_valid_for_sale
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "with salesman being non blank" do
|
11
|
+
before :all do
|
12
|
+
@kayak.salesman = 'Joe'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "is invalid" do
|
16
|
+
@kayak.should_not be_valid_for_sale
|
17
|
+
end
|
18
|
+
|
19
|
+
it "has meaningful error message" do
|
20
|
+
@kayak.errors.on(:salesman).should == [ 'Salesman must be absent' ]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
describe "with salesman being nil" do
|
26
|
+
before :all do
|
27
|
+
@kayak.salesman = nil
|
28
|
+
end
|
29
|
+
|
30
|
+
it "is valid" do
|
31
|
+
@kayak.should be_valid_for_sale
|
32
|
+
end
|
33
|
+
|
34
|
+
it "has no error messages" do
|
35
|
+
@kayak.errors.on(:salesman).should be_blank
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
describe "with salesman being an empty string" do
|
41
|
+
before :all do
|
42
|
+
@kayak.salesman = ''
|
43
|
+
end
|
44
|
+
|
45
|
+
it "is valid" do
|
46
|
+
@kayak.should be_valid_for_sale
|
47
|
+
end
|
48
|
+
|
49
|
+
it "has no error messages" do
|
50
|
+
@kayak.errors.on(:salesman).should be_blank
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
describe "with salesman being a string of white spaces" do
|
56
|
+
before :all do
|
57
|
+
@kayak.salesman = ' '
|
58
|
+
end
|
59
|
+
|
60
|
+
it "is valid" do
|
61
|
+
@kayak.should be_valid_for_sale
|
62
|
+
end
|
63
|
+
|
64
|
+
it "has no error messages" do
|
65
|
+
@kayak.errors.on(:salesman).should be_blank
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
describe DataMapper::Validate::Fixtures::Pirogue do
|
72
|
+
before :all do
|
73
|
+
@kayak = DataMapper::Validate::Fixtures::Pirogue.new
|
74
|
+
@kayak.should_not be_valid_for_sale
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "by default" do
|
78
|
+
it "is invalid" do
|
79
|
+
@kayak.should_not be_valid_for_sale
|
80
|
+
end
|
81
|
+
|
82
|
+
it "has meaningful error message" do
|
83
|
+
@kayak.errors.on(:salesman).should == [ 'Salesman must be absent' ]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,196 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/acceptance_validator/spec_helper'
|
3
|
+
|
4
|
+
describe DataMapper::Validate::Fixtures::BetaTesterAccount do
|
5
|
+
before :each do
|
6
|
+
@model = DataMapper::Validate::Fixtures::BetaTesterAccount.new(:user_agreement => true,
|
7
|
+
:newsletter_signup => "",
|
8
|
+
:privacy_agreement => "accept")
|
9
|
+
@model.should be_valid
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "with a missing newsletter signup field" do
|
13
|
+
before :each do
|
14
|
+
@model.newsletter_signup = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "is perfectly valid" do
|
18
|
+
@model.should be_valid
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "with a blank newsletter signup field" do
|
23
|
+
before :each do
|
24
|
+
@model.newsletter_signup = ""
|
25
|
+
end
|
26
|
+
|
27
|
+
it "is perfectly valid" do
|
28
|
+
@model.should be_valid
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
describe "with a blank user agreement field" do
|
34
|
+
before :each do
|
35
|
+
@model.user_agreement = ""
|
36
|
+
end
|
37
|
+
|
38
|
+
it "is NOT valid" do
|
39
|
+
@model.should_not be_valid
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
describe "with a nil user agreement field" do
|
45
|
+
before :each do
|
46
|
+
@model.user_agreement = nil
|
47
|
+
end
|
48
|
+
|
49
|
+
it "is NOT valid" do
|
50
|
+
@model.should_not be_valid
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
describe "with user agreement field having value of 1 (as integer)" do
|
56
|
+
before :each do
|
57
|
+
@model.user_agreement = 1
|
58
|
+
end
|
59
|
+
|
60
|
+
it "is valid" do
|
61
|
+
@model.should be_valid
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
describe "with user agreement field having value of 1 (as a string)" do
|
67
|
+
before :each do
|
68
|
+
@model.user_agreement = "1"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "is valid" do
|
72
|
+
@model.should be_valid
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
describe "with user agreement field having value of 'true' (as a string)" do
|
78
|
+
before :each do
|
79
|
+
@model.user_agreement = 'true'
|
80
|
+
end
|
81
|
+
|
82
|
+
it "is valid" do
|
83
|
+
@model.should be_valid
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
describe "with user agreement field having value of true (TrueClass instance)" do
|
89
|
+
before :each do
|
90
|
+
@model.user_agreement = true
|
91
|
+
end
|
92
|
+
|
93
|
+
it "is valid" do
|
94
|
+
@model.should be_valid
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
describe "with user agreement field having value of 't' (The Lisp Way)" do
|
100
|
+
before :each do
|
101
|
+
@model.user_agreement = 't'
|
102
|
+
end
|
103
|
+
|
104
|
+
it "is valid" do
|
105
|
+
@model.should be_valid
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
describe "with user agreement field having value of 'f'" do
|
111
|
+
before :each do
|
112
|
+
@model.user_agreement = 'f'
|
113
|
+
end
|
114
|
+
|
115
|
+
it "is NOT valid" do
|
116
|
+
@model.should_not be_valid
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
describe "with privacy agreement field having value of 1" do
|
122
|
+
before :each do
|
123
|
+
@model.privacy_agreement = 1
|
124
|
+
end
|
125
|
+
|
126
|
+
it "is NOT valid" do
|
127
|
+
@model.should_not be_valid
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "with privacy agreement field having value of true" do
|
132
|
+
before :each do
|
133
|
+
@model.privacy_agreement = true
|
134
|
+
end
|
135
|
+
|
136
|
+
it "is NOT valid" do
|
137
|
+
@model.should_not be_valid
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
describe "with privacy agreement field having value of '1'" do
|
143
|
+
before :each do
|
144
|
+
@model.privacy_agreement = '1'
|
145
|
+
end
|
146
|
+
|
147
|
+
it "is NOT valid" do
|
148
|
+
@model.should_not be_valid
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
|
153
|
+
describe "with privacy agreement field having value of 't'" do
|
154
|
+
before :each do
|
155
|
+
@model.privacy_agreement = 't'
|
156
|
+
end
|
157
|
+
|
158
|
+
it "is NOT valid" do
|
159
|
+
@model.should_not be_valid
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
|
164
|
+
describe "with privacy agreement field having value of 'accept'" do
|
165
|
+
before :each do
|
166
|
+
@model.privacy_agreement = 'accept'
|
167
|
+
end
|
168
|
+
|
169
|
+
it "is valid" do
|
170
|
+
@model.should be_valid
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
|
175
|
+
describe "with privacy agreement field having value of 'agreed'" do
|
176
|
+
before :each do
|
177
|
+
@model.privacy_agreement = 'agreed'
|
178
|
+
end
|
179
|
+
|
180
|
+
it "is valid" do
|
181
|
+
@model.should be_valid
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
describe "with privacy agreement field having value of 'ah, greed'" do
|
187
|
+
before :each do
|
188
|
+
@model.privacy_agreement = 'ah, greed'
|
189
|
+
end
|
190
|
+
|
191
|
+
it "is NOT valid" do
|
192
|
+
# greed is invalid? can't be
|
193
|
+
@model.should_not be_valid
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end # describe DataMapper::Validate::Fixtures::BetaTesterAccount do
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/automatic_validation/spec_helper'
|
3
|
+
|
4
|
+
describe 'Inferred validations' do
|
5
|
+
it "allow overriding a single error message" do
|
6
|
+
custom_boat = Class.new do
|
7
|
+
include DataMapper::Resource
|
8
|
+
property :id, DataMapper::Types::Serial
|
9
|
+
property :name, String, :nullable => false, :message => "This boat must have name"
|
10
|
+
end
|
11
|
+
boat = custom_boat.new
|
12
|
+
boat.should_not be_valid
|
13
|
+
boat.errors.on(:name).should == [ 'This boat must have name' ]
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have correct error messages" do
|
17
|
+
custom_boat = Class.new do
|
18
|
+
include DataMapper::Resource
|
19
|
+
property :id, DataMapper::Types::Serial
|
20
|
+
property :name, String, :nullable => false, :length => 5..20, :format => /^[a-z]+$/,
|
21
|
+
:messages => {
|
22
|
+
:presence => "This boat must have name",
|
23
|
+
:length => "Name must have at least 4 and at most 20 chars",
|
24
|
+
:format => "Please use only small letters"
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
boat = custom_boat.new
|
29
|
+
boat.should_not be_valid
|
30
|
+
boat.errors.on(:name).should == [ 'This boat must have name' ]
|
31
|
+
|
32
|
+
boat.name = "%%"
|
33
|
+
boat.should_not be_valid
|
34
|
+
boat.errors.on(:name).should == [
|
35
|
+
'Name must have at least 4 and at most 20 chars',
|
36
|
+
'Please use only small letters',
|
37
|
+
]
|
38
|
+
|
39
|
+
boat.name = "%%asd"
|
40
|
+
boat.should_not be_valid
|
41
|
+
boat.errors.on(:name).should == [ 'Please use only small letters' ]
|
42
|
+
|
43
|
+
boat.name = "superboat"
|
44
|
+
boat.should be_valid
|
45
|
+
boat.errors.on(:name).should be_nil
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/automatic_validation/spec_helper'
|
3
|
+
|
4
|
+
describe "A class with inferred validations disabled for all properties with an option" do
|
5
|
+
before :all do
|
6
|
+
@klass = Class.new do
|
7
|
+
include DataMapper::Resource
|
8
|
+
|
9
|
+
property :id, DataMapper::Types::Serial, :auto_validation => false
|
10
|
+
property :name, String, :nullable => false, :auto_validation => false
|
11
|
+
property :bool, DataMapper::Types::Boolean, :nullable => false, :auto_validation => false
|
12
|
+
end
|
13
|
+
|
14
|
+
@model = @klass.new
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "when instantiated w/o any attributes" do
|
18
|
+
it_should_behave_like "valid model"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
describe "A class with inferred validations disabled for all properties with a block" do
|
24
|
+
before :all do
|
25
|
+
@klass = Class.new do
|
26
|
+
include DataMapper::Resource
|
27
|
+
|
28
|
+
without_auto_validations do
|
29
|
+
property :id, DataMapper::Types::Serial
|
30
|
+
property :name, String, :nullable => false
|
31
|
+
property :bool, DataMapper::Types::Boolean, :nullable => false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
@model = @klass.new
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "when instantiated w/o any attributes" do
|
39
|
+
it_should_behave_like "valid model"
|
40
|
+
end
|
41
|
+
end
|