dm-validations 0.9.11 → 0.10.0
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.
- 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
@@ -1,12 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
include DataMapper::Resource
|
9
|
-
property :id, Integer, :serial => true
|
10
|
-
property :name, String, :auto_validation => false, :default => "I'm a long string"
|
11
|
-
validates_length :name, :min => 3
|
12
|
-
end
|
1
|
+
# put validator specific fixture models and helpers here
|
2
|
+
#
|
3
|
+
# make sure you check out spec/fixtures to see fixture models
|
4
|
+
# already written
|
5
|
+
#
|
6
|
+
# DataMapper developers feels strongly against foobars in the spec
|
7
|
+
# suite
|
@@ -0,0 +1,239 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/method_validator/spec_helper'
|
3
|
+
|
4
|
+
describe "a good fit for DSLs", :shared => true do
|
5
|
+
it "is a good fit for DSLs" do
|
6
|
+
@model.should be_valid_for_implementing_a_dsl
|
7
|
+
end
|
8
|
+
|
9
|
+
it "is totally fine for DSLs" do
|
10
|
+
@model.ensure_appropriate_for_dsls.should be_true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "a poor candidate for DSLs", :shared => true do
|
15
|
+
it "is a poor candidate for DSLs" do
|
16
|
+
@model.should_not be_valid_for_implementing_a_dsl
|
17
|
+
end
|
18
|
+
|
19
|
+
it "is unappropriate for DSLs" do
|
20
|
+
@model.ensure_appropriate_for_dsls.first.should be_false
|
21
|
+
end
|
22
|
+
|
23
|
+
it "has a (more or less) meaningful error message" do
|
24
|
+
@model.errors.on(:ensure_appropriate_for_dsls).should == [ 'may not be so good for domain specific languages' ]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
describe "a good fit for game engine core", :shared => true do
|
30
|
+
it "is a good fit for game engine core" do
|
31
|
+
@model.should be_valid_for_implementing_a_game_engine_core
|
32
|
+
end
|
33
|
+
|
34
|
+
it "is appropriate for system programming" do
|
35
|
+
@model.ensure_appropriate_for_system_programming.should be_true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "a poor candidate for game engine core", :shared => true do
|
40
|
+
it "is a poor candidate for game engine core" do
|
41
|
+
@model.should_not be_valid_for_implementing_a_game_engine_core
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
describe "a good fit for kernel hacking", :shared => true do
|
48
|
+
it "is a good fit for kernel hacking" do
|
49
|
+
@model.should be_valid_for_hacking_on_the_kernel
|
50
|
+
end
|
51
|
+
|
52
|
+
it "is appropriate for system programming" do
|
53
|
+
@model.ensure_appropriate_for_system_programming.should be_true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
describe "a poor candidate for kernel hacking", :shared => true do
|
59
|
+
it "is not a good fit for kernel hacking" do
|
60
|
+
@model.should_not be_valid_for_hacking_on_the_kernel
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# Note that ProgrammingLanguage is not a DM resource,
|
66
|
+
# it is a plain old Ruby object (PORO), or simply put,
|
67
|
+
# just a "regular" Ruby class with a bunch of accessors.
|
68
|
+
#
|
69
|
+
# And yes, assumptions below are full of bullshit and
|
70
|
+
# author is a moron, and your favourite programming
|
71
|
+
# language is good for EVARYTHIN'!
|
72
|
+
#
|
73
|
+
#Please see spec_helper.rb next to this file
|
74
|
+
#
|
75
|
+
|
76
|
+
describe "C" do
|
77
|
+
before :all do
|
78
|
+
@model = ::DataMapper::Validate::Fixtures::ProgrammingLanguage.new(:name => "C",
|
79
|
+
:allows_system_calls => true,
|
80
|
+
:allows_manual_memory_management => true,
|
81
|
+
:approved_by_linus => true,
|
82
|
+
:compiler_excels_at_utilizing_cpu_cache => true,
|
83
|
+
:is_very_high_level => false,
|
84
|
+
:does_not_require_explicit_return_keyword => false,
|
85
|
+
:allows_operator_overload => false,
|
86
|
+
:allows_optional_parentheses => false
|
87
|
+
)
|
88
|
+
end
|
89
|
+
|
90
|
+
it_should_behave_like "a good fit for kernel hacking"
|
91
|
+
|
92
|
+
it_should_behave_like "a good fit for game engine core"
|
93
|
+
|
94
|
+
it_should_behave_like "a poor candidate for DSLs"
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
describe "C++" do
|
100
|
+
before :all do
|
101
|
+
@model = ::DataMapper::Validate::Fixtures::ProgrammingLanguage.new(:name => "C++",
|
102
|
+
:allows_system_calls => true,
|
103
|
+
:allows_manual_memory_management => true,
|
104
|
+
:approved_by_linus => false,
|
105
|
+
:compiler_excels_at_utilizing_cpu_cache => true,
|
106
|
+
:is_very_high_level => false,
|
107
|
+
:does_not_require_explicit_return_keyword => false,
|
108
|
+
:allows_operator_overload => true,
|
109
|
+
:allows_optional_parentheses => false
|
110
|
+
)
|
111
|
+
end
|
112
|
+
|
113
|
+
it_should_behave_like "a poor candidate for kernel hacking"
|
114
|
+
|
115
|
+
it_should_behave_like "a good fit for game engine core"
|
116
|
+
|
117
|
+
it_should_behave_like "a poor candidate for DSLs"
|
118
|
+
|
119
|
+
it "is not approved by Linus" do
|
120
|
+
@model.valid?(:hacking_on_the_kernel)
|
121
|
+
@model.errors.on(:ensure_approved_by_linus_himself).should_not be_blank
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
describe "Ruby" do
|
127
|
+
before :all do
|
128
|
+
@model = ::DataMapper::Validate::Fixtures::ProgrammingLanguage.new(:name => "Ruby",
|
129
|
+
# well, C extensions do not really count
|
130
|
+
:allows_system_calls => false,
|
131
|
+
:allows_manual_memory_management => false,
|
132
|
+
:approved_by_linus => false,
|
133
|
+
:compiler_excels_at_utilizing_cpu_cache => false,
|
134
|
+
:is_very_high_level => true,
|
135
|
+
:does_not_require_explicit_return_keyword => true,
|
136
|
+
:allows_operator_overload => true,
|
137
|
+
:allows_optional_parentheses => true
|
138
|
+
)
|
139
|
+
end
|
140
|
+
|
141
|
+
it_should_behave_like "a good fit for DSLs"
|
142
|
+
|
143
|
+
it_should_behave_like "a poor candidate for kernel hacking"
|
144
|
+
|
145
|
+
it_should_behave_like "a poor candidate for game engine core"
|
146
|
+
|
147
|
+
it "has a (more or less) meaningful error message" do
|
148
|
+
@model.valid?(:doing_system_programming)
|
149
|
+
@model.errors.on(:ensure_appropriate_for_system_programming).should == [ 'try something that is closer to the metal' ]
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
|
154
|
+
describe "Scala" do
|
155
|
+
before :all do
|
156
|
+
@model = ::DataMapper::Validate::Fixtures::ProgrammingLanguage.new(:name => "Scala",
|
157
|
+
:allows_system_calls => false,
|
158
|
+
:allows_manual_memory_management => false,
|
159
|
+
:approved_by_linus => false,
|
160
|
+
:compiler_excels_at_utilizing_cpu_cache => false,
|
161
|
+
:is_very_high_level => true,
|
162
|
+
:does_not_require_explicit_return_keyword => true,
|
163
|
+
:allows_operator_overload => true,
|
164
|
+
:allows_optional_parentheses => true
|
165
|
+
)
|
166
|
+
end
|
167
|
+
|
168
|
+
it_should_behave_like "a good fit for DSLs"
|
169
|
+
|
170
|
+
it_should_behave_like "a poor candidate for kernel hacking"
|
171
|
+
|
172
|
+
it_should_behave_like "a poor candidate for game engine core"
|
173
|
+
|
174
|
+
it "has a (more or less) meaningful error message" do
|
175
|
+
@model.valid?(:doing_system_programming)
|
176
|
+
@model.errors.on(:ensure_appropriate_for_system_programming).should == [ 'try something that is closer to the metal' ]
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
describe "Haskell" do
|
183
|
+
before :all do
|
184
|
+
@model = ::DataMapper::Validate::Fixtures::ProgrammingLanguage.new(:name => "Haskell",
|
185
|
+
:allows_system_calls => false,
|
186
|
+
:allows_manual_memory_management => false,
|
187
|
+
:approved_by_linus => false,
|
188
|
+
:compiler_excels_at_utilizing_cpu_cache => true,
|
189
|
+
:is_very_high_level => true,
|
190
|
+
:does_not_require_explicit_return_keyword => true,
|
191
|
+
# operators are not different from any other function
|
192
|
+
:allows_operator_overload => true,
|
193
|
+
# or, allows explicit parentheses? who cares, we
|
194
|
+
# are just trying to come up with a relatively
|
195
|
+
# non-stupid spec example
|
196
|
+
:allows_optional_parentheses => true
|
197
|
+
)
|
198
|
+
end
|
199
|
+
|
200
|
+
it_should_behave_like "a good fit for DSLs"
|
201
|
+
|
202
|
+
it_should_behave_like "a poor candidate for kernel hacking"
|
203
|
+
|
204
|
+
it_should_behave_like "a poor candidate for game engine core"
|
205
|
+
|
206
|
+
it "has a (more or less) meaningful error message" do
|
207
|
+
@model.valid?(:doing_system_programming)
|
208
|
+
@model.errors.on(:ensure_appropriate_for_system_programming).should == [ 'try something that is closer to the metal' ]
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
|
213
|
+
describe DataMapper::Validate::Fixtures::Event do
|
214
|
+
before :all do
|
215
|
+
@model = DataMapper::Validate::Fixtures::Event.new(:name => "Fools day 2009")
|
216
|
+
end
|
217
|
+
|
218
|
+
describe "with start time before end time" do
|
219
|
+
before :all do
|
220
|
+
@model.starts_at = DateTime.new(2009, 4, 1, 00, 00, 01)
|
221
|
+
@model.ends_at = DateTime.new(2009, 4, 1, 23, 59, 59)
|
222
|
+
end
|
223
|
+
|
224
|
+
it_should_behave_like "valid model"
|
225
|
+
end
|
226
|
+
|
227
|
+
describe "with start time after end time" do
|
228
|
+
before :all do
|
229
|
+
@model.starts_at = DateTime.new(2009, 4, 1, 23, 59, 59)
|
230
|
+
@model.ends_at = DateTime.new(2009, 4, 1, 00, 00, 01)
|
231
|
+
end
|
232
|
+
|
233
|
+
it_should_behave_like "invalid model"
|
234
|
+
|
235
|
+
it "uses custom error message for property starts_at" do
|
236
|
+
@model.errors.on(:starts_at).should == [ 'Start time cannot be after end time' ]
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/numeric_validator/spec_helper'
|
3
|
+
|
4
|
+
describe DataMapper::Validate::Fixtures::BasketballCourt do
|
5
|
+
describe "with valid set of attributes" do
|
6
|
+
before :all do
|
7
|
+
@model = DataMapper::Validate::Fixtures::BasketballCourt.valid_instance
|
8
|
+
@model.valid?
|
9
|
+
end
|
10
|
+
|
11
|
+
it_should_behave_like "valid model"
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
describe "with rim height of 3.05" do
|
16
|
+
before :all do
|
17
|
+
@model = DataMapper::Validate::Fixtures::BasketballCourt.valid_instance(:rim_height => 3.05)
|
18
|
+
@model.valid?
|
19
|
+
end
|
20
|
+
|
21
|
+
it_should_behave_like "valid model"
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
describe "with rim height of 3.30" do
|
26
|
+
before :all do
|
27
|
+
@model = DataMapper::Validate::Fixtures::BasketballCourt.valid_instance(:rim_height => 3.30)
|
28
|
+
@model.valid?
|
29
|
+
end
|
30
|
+
|
31
|
+
it_should_behave_like "invalid model"
|
32
|
+
|
33
|
+
it "has a meaningful error message" do
|
34
|
+
@model.errors.on(:rim_height).should == [ 'Rim height must be equal to 3.05' ]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
describe "with free throw line distance of 4.57" do
|
40
|
+
before :all do
|
41
|
+
@model = DataMapper::Validate::Fixtures::BasketballCourt.valid_instance(:free_throw_line_distance => 4.57)
|
42
|
+
@model.valid?
|
43
|
+
end
|
44
|
+
|
45
|
+
it_should_behave_like "valid model"
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
describe "with free throw line distance of 3.10" do
|
50
|
+
before :all do
|
51
|
+
@model = DataMapper::Validate::Fixtures::BasketballCourt.valid_instance(:free_throw_line_distance => 3.10)
|
52
|
+
@model.valid?
|
53
|
+
end
|
54
|
+
|
55
|
+
it_should_behave_like "invalid model"
|
56
|
+
|
57
|
+
it "has a meaningful error message" do
|
58
|
+
@model.errors.on(:free_throw_line_distance).should == [ 'Free throw line distance must be equal to 4.57' ]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/numeric_validator/spec_helper'
|
3
|
+
|
4
|
+
describe DataMapper::Validate::Fixtures::LerneanHydra do
|
5
|
+
describe "with valid set of attributes" do
|
6
|
+
before :all do
|
7
|
+
@model = DataMapper::Validate::Fixtures::LerneanHydra.valid_instance
|
8
|
+
@model.valid?
|
9
|
+
end
|
10
|
+
|
11
|
+
it_should_behave_like "valid model"
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
describe "with 9 heads" do
|
16
|
+
before :all do
|
17
|
+
@model = DataMapper::Validate::Fixtures::LerneanHydra.valid_instance(:head_count => 9)
|
18
|
+
@model.valid?
|
19
|
+
end
|
20
|
+
|
21
|
+
it_should_behave_like "valid model"
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
describe "with only 3 heads" do
|
26
|
+
before :all do
|
27
|
+
@model = DataMapper::Validate::Fixtures::LerneanHydra.valid_instance(:head_count => 3)
|
28
|
+
@model.valid?
|
29
|
+
end
|
30
|
+
|
31
|
+
it_should_behave_like "invalid model"
|
32
|
+
|
33
|
+
it "has a meaningful error message" do
|
34
|
+
@model.errors.on(:head_count).should == [ 'Lernean hydra is said to have exactly 9 heads' ]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,102 +1,88 @@
|
|
1
|
-
require '
|
2
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/numeric_validator/spec_helper'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
describe BasketballPlayer do
|
8
|
-
before(:each) do
|
9
|
-
@mj = BasketballPlayer.new(:name => "Michael Jordan", :height => 198.1, :weight => 97.2)
|
4
|
+
describe DataMapper::Validate::Fixtures::BasketballPlayer do
|
5
|
+
before :all do
|
6
|
+
@model = DataMapper::Validate::Fixtures::BasketballPlayer.new(:name => "Michael Jordan", :height => 198.1, :weight => 97.2)
|
10
7
|
end
|
11
8
|
|
12
9
|
describe "with height as float" do
|
13
|
-
before
|
10
|
+
before :all do
|
14
11
|
# no op in this case
|
15
12
|
end
|
16
13
|
|
17
|
-
|
18
|
-
@mj.should be_valid
|
19
|
-
end
|
14
|
+
it_should_behave_like "valid model"
|
20
15
|
end
|
21
16
|
|
22
|
-
|
23
17
|
describe "with height as integer" do
|
24
|
-
before
|
25
|
-
@
|
18
|
+
before :all do
|
19
|
+
@model.height = 198
|
26
20
|
end
|
27
21
|
|
28
|
-
|
29
|
-
@mj.should be_valid
|
30
|
-
end
|
22
|
+
it_should_behave_like "valid model"
|
31
23
|
end
|
32
24
|
|
33
|
-
|
34
25
|
describe "with height as string containing only integers" do
|
35
|
-
before
|
36
|
-
@
|
26
|
+
before :all do
|
27
|
+
@model.height = "198"
|
37
28
|
end
|
38
29
|
|
39
|
-
|
40
|
-
@mj.should be_valid
|
41
|
-
end
|
30
|
+
it_should_behave_like "valid model"
|
42
31
|
end
|
43
32
|
|
44
|
-
|
45
33
|
describe "with height as string containing a float" do
|
46
|
-
before
|
47
|
-
@
|
34
|
+
before :all do
|
35
|
+
@model.height = "198.1"
|
48
36
|
end
|
49
37
|
|
50
|
-
|
51
|
-
@mj.should be_valid
|
52
|
-
end
|
38
|
+
it_should_behave_like "valid model"
|
53
39
|
end
|
54
40
|
|
41
|
+
describe "with height as string containing a float that will be represented in scientific notation" do
|
42
|
+
before :all do
|
43
|
+
@model.height = '0.00004'
|
44
|
+
end
|
45
|
+
|
46
|
+
it_should_behave_like "valid model"
|
47
|
+
end
|
55
48
|
|
56
49
|
describe "with height as string containing random alphanumeric characters" do
|
57
|
-
before
|
58
|
-
@
|
50
|
+
before :all do
|
51
|
+
@height = 'height=198.1'
|
52
|
+
@model.height = "height=198.1"
|
59
53
|
end
|
60
54
|
|
61
|
-
it "is
|
62
|
-
@
|
55
|
+
it "is should not change the value" do
|
56
|
+
@model.height.should == @height
|
63
57
|
end
|
64
58
|
|
65
|
-
|
66
|
-
# float property is set to 0.0 here
|
67
|
-
@mj.should be_valid
|
68
|
-
end
|
59
|
+
it_should_behave_like "invalid model"
|
69
60
|
end
|
70
61
|
|
71
|
-
|
72
62
|
describe "with height as string containing random punctuation characters" do
|
73
|
-
before
|
74
|
-
@
|
63
|
+
before :all do
|
64
|
+
@height = '$$ * $?'
|
65
|
+
@model.height = @height
|
75
66
|
end
|
76
67
|
|
77
|
-
it "is
|
78
|
-
@
|
68
|
+
it "is should not change the value" do
|
69
|
+
@model.height.should == @height
|
79
70
|
end
|
80
71
|
|
81
|
-
|
82
|
-
# float property is set to 0.0 here
|
83
|
-
@mj.should be_valid
|
84
|
-
end
|
72
|
+
it_should_behave_like "invalid model"
|
85
73
|
end
|
86
74
|
|
87
|
-
|
88
75
|
describe "with nil height" do
|
89
|
-
before
|
90
|
-
@
|
76
|
+
before :all do
|
77
|
+
@model.height = nil
|
78
|
+
@model.valid?
|
91
79
|
end
|
92
80
|
|
93
|
-
|
94
|
-
|
95
|
-
end
|
81
|
+
# typecasting kicks in
|
82
|
+
it_should_behave_like "invalid model"
|
96
83
|
|
97
|
-
it "has a meaningful error message
|
98
|
-
@
|
99
|
-
@mj.errors.on(:height).should include("Height must be a number")
|
84
|
+
it "has a meaningful error message" do
|
85
|
+
@model.errors.on(:height).should == [ 'Height must be a number' ]
|
100
86
|
end
|
101
87
|
end
|
102
88
|
end
|