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
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/automatic_validation/spec_helper'
|
3
|
+
|
4
|
+
describe "A model with a Boolean property" do
|
5
|
+
before :all do
|
6
|
+
@model = HasNullableBoolean.new(:id => 1)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "assigned to true" do
|
10
|
+
before :all do
|
11
|
+
@model.set(:bool => true)
|
12
|
+
end
|
13
|
+
|
14
|
+
it_should_behave_like "valid model"
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "assigned to false" do
|
18
|
+
before :all do
|
19
|
+
@model.set(:bool => false)
|
20
|
+
end
|
21
|
+
|
22
|
+
it_should_behave_like "valid model"
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "assigned to a nil" do
|
26
|
+
before :all do
|
27
|
+
@model.set(:bool => nil)
|
28
|
+
end
|
29
|
+
|
30
|
+
it_should_behave_like "valid model"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
describe "A model with a non-nullable Boolean property" do
|
37
|
+
before :all do
|
38
|
+
@model = HasNotNullableBoolean.new(:id => 1)
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "assigned to true" do
|
42
|
+
before :all do
|
43
|
+
@model.set(:bool => true)
|
44
|
+
end
|
45
|
+
|
46
|
+
it_should_behave_like "valid model"
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "assigned to false" do
|
50
|
+
before :all do
|
51
|
+
@model.set(:bool => false)
|
52
|
+
end
|
53
|
+
|
54
|
+
it_should_behave_like "valid model"
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "assigned to a nil" do
|
58
|
+
before :all do
|
59
|
+
@model.set(:bool => nil)
|
60
|
+
end
|
61
|
+
|
62
|
+
it_should_behave_like "invalid model"
|
63
|
+
|
64
|
+
it "has a meaningful error message" do
|
65
|
+
@model.errors.on(:bool).should == [ 'Bool must not be nil' ]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
describe "A model with a non-nullable paranoid Boolean property" do
|
73
|
+
before :all do
|
74
|
+
@model = HasNotNullableParanoidBoolean.new(:id => 1)
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "assigned to true" do
|
78
|
+
before :all do
|
79
|
+
@model.set(:bool => true)
|
80
|
+
end
|
81
|
+
|
82
|
+
it_should_behave_like "valid model"
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "assigned to false" do
|
86
|
+
before :all do
|
87
|
+
@model.set(:bool => false)
|
88
|
+
end
|
89
|
+
|
90
|
+
it_should_behave_like "valid model"
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "assigned to a nil" do
|
94
|
+
before :all do
|
95
|
+
@model.set(:bool => nil)
|
96
|
+
end
|
97
|
+
|
98
|
+
it_should_behave_like "invalid model"
|
99
|
+
|
100
|
+
it "has a meaningful error message" do
|
101
|
+
@model.errors.on(:bool).should == [ 'Bool must not be nil' ]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/automatic_validation/spec_helper'
|
3
|
+
|
4
|
+
|
5
|
+
{ :float => Float, :big_decimal => BigDecimal }.each do |column, type|
|
6
|
+
describe "#{type} property" do
|
7
|
+
before :all do
|
8
|
+
@model = SailBoat.new(:id => 1)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "with an integer value" do
|
12
|
+
before :all do
|
13
|
+
@model.set(column => 1)
|
14
|
+
end
|
15
|
+
|
16
|
+
it_should_behave_like "valid model"
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "with a float value" do
|
20
|
+
before :all do
|
21
|
+
@model.set(column => 1.0)
|
22
|
+
end
|
23
|
+
|
24
|
+
it_should_behave_like "valid model"
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "with a BigDecimal value" do
|
28
|
+
before :all do
|
29
|
+
@model.set(column => BigDecimal('1'))
|
30
|
+
end
|
31
|
+
|
32
|
+
it_should_behave_like "valid model"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/automatic_validation/spec_helper'
|
3
|
+
|
4
|
+
describe SailBoat, "with a :format option on a property" do
|
5
|
+
before :all do
|
6
|
+
@model = SailBoat.new
|
7
|
+
@model.should be_valid_for_format_test
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "and value that matches the format" do
|
11
|
+
before :all do
|
12
|
+
@model.code = 'A1234'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "passes inferred format validation" do
|
16
|
+
@model.should be_valid_for_format_test
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "and value that DOES NOT match the format" do
|
21
|
+
before :all do
|
22
|
+
@model.code = 'BAD CODE'
|
23
|
+
end
|
24
|
+
|
25
|
+
it "does not pass inferred format validation" do
|
26
|
+
@model.should_not be_valid_for_format_test
|
27
|
+
end
|
28
|
+
|
29
|
+
it "has a meaningful error message" do
|
30
|
+
@model.errors.on(:code).should == [ 'Code has an invalid format' ]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/automatic_validation/spec_helper'
|
3
|
+
|
4
|
+
describe "A model with an Integer property" do
|
5
|
+
before :all do
|
6
|
+
@model = SailBoat.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "assigned to an integer" do
|
10
|
+
before :all do
|
11
|
+
@model.set(:id => 1)
|
12
|
+
end
|
13
|
+
|
14
|
+
it_should_behave_like "valid model"
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "assigned to a float" do
|
18
|
+
before :all do
|
19
|
+
@model.set(:id => 1.0)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "is invalid" do
|
23
|
+
@model.should_not be_valid
|
24
|
+
end
|
25
|
+
|
26
|
+
it "has a meaningful default error message" do
|
27
|
+
@model.errors.on(:id).should == [ 'Id must be an integer' ]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "assigned to a BigDecimal" do
|
32
|
+
before :all do
|
33
|
+
@model.set(:id => BigDecimal('1'))
|
34
|
+
end
|
35
|
+
|
36
|
+
it "is invalid" do
|
37
|
+
@model.should_not be_valid
|
38
|
+
end
|
39
|
+
|
40
|
+
it "has a meaningful default error message" do
|
41
|
+
@model.errors.on(:id).should == [ 'Id must be an integer' ]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "assigned to a too-small integer" do
|
46
|
+
before :all do
|
47
|
+
@model.set(:id => 0)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "is invalid" do
|
51
|
+
@model.should_not be_valid
|
52
|
+
end
|
53
|
+
|
54
|
+
it "has a meaningful default error message" do
|
55
|
+
@model.errors.on(:id).should == [ 'Id must be greater than or equal to 1' ]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "assigned to a too-large integer" do
|
60
|
+
before :all do
|
61
|
+
@model.set(:id => 11)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "is invalid" do
|
65
|
+
@model.should_not be_valid
|
66
|
+
end
|
67
|
+
|
68
|
+
it "has a meaningful default error message" do
|
69
|
+
@model.errors.on(:id).should == [ 'Id must be less than or equal to 10' ]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/automatic_validation/spec_helper'
|
3
|
+
|
4
|
+
describe SailBoat do
|
5
|
+
before :all do
|
6
|
+
@model = SailBoat.new(:id => 1)
|
7
|
+
@model.should be_valid_for_length_test_1
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
describe "with a nil value on property that allows nil" do
|
12
|
+
before :all do
|
13
|
+
@model.allow_nil = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
it "is valid" do
|
17
|
+
@model.should be_valid_for_nil_test
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
describe "with 11 characters long description" do
|
23
|
+
before :all do
|
24
|
+
@model.description = 'ABCDEFGHIJK' #11
|
25
|
+
end
|
26
|
+
|
27
|
+
# validates_length is inferred from property's :length option
|
28
|
+
it "is invalid" do
|
29
|
+
@model.should_not be_valid_for_length_test_1
|
30
|
+
@model.errors.on(:description).should == [ 'Description must be at most 10 characters long' ]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
describe "with 9 characters long description" do
|
36
|
+
before :all do
|
37
|
+
@model.description = 'ABCDEFGHI' # 9
|
38
|
+
end
|
39
|
+
|
40
|
+
# validates_length is inferred from property's :length option
|
41
|
+
it_should_behave_like "valid model"
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "with 2 character long note" do
|
45
|
+
before :all do
|
46
|
+
@model = SailBoat.new(:notes => "AB")
|
47
|
+
end
|
48
|
+
|
49
|
+
it "is valid" do
|
50
|
+
@model.should be_valid_for_length_test_2
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "with 10 character long note" do
|
55
|
+
before :all do
|
56
|
+
@model = SailBoat.new(:notes => "ABCDEFGHIJ")
|
57
|
+
end
|
58
|
+
|
59
|
+
it "is valid" do
|
60
|
+
@model.should be_valid_for_length_test_2
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "with 11 character long note" do
|
65
|
+
before :all do
|
66
|
+
@model = SailBoat.new(:notes => "ABCDEFGHIJK")
|
67
|
+
end
|
68
|
+
|
69
|
+
it "is invalid" do
|
70
|
+
@model.should_not be_valid_for_length_test_2
|
71
|
+
end
|
72
|
+
|
73
|
+
it "has a meaningful error message" do
|
74
|
+
@model.errors.on(:notes).should == [ 'Notes must be between 2 and 10 characters long' ]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
describe DataMapper::Validate::Fixtures::SmsMessage do
|
82
|
+
before :all do
|
83
|
+
@model = DataMapper::Validate::Fixtures::SmsMessage.new(:id => 10)
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "with 2 character long note" do
|
87
|
+
before :all do
|
88
|
+
@model.body = "ab"
|
89
|
+
end
|
90
|
+
|
91
|
+
it_should_behave_like "valid model"
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "with 10 character long note" do
|
95
|
+
before :all do
|
96
|
+
@model.body = "ABCDEFGHIJ"
|
97
|
+
end
|
98
|
+
|
99
|
+
it_should_behave_like "valid model"
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "with 499 character long note" do
|
103
|
+
before :all do
|
104
|
+
@model.body = "a" * 499
|
105
|
+
end
|
106
|
+
|
107
|
+
it_should_behave_like "valid model"
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "with 503 character long note" do
|
111
|
+
before :all do
|
112
|
+
@model.body = "a" * 503
|
113
|
+
end
|
114
|
+
|
115
|
+
it_should_behave_like "invalid model"
|
116
|
+
|
117
|
+
it "has a meaningful error message" do
|
118
|
+
@model.errors.on(:body).should == [ 'Body must be between 1 and 500 characters long' ]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/automatic_validation/spec_helper'
|
3
|
+
|
4
|
+
describe SailBoat do
|
5
|
+
before :all do
|
6
|
+
@model = SailBoat.new(:id => 1)
|
7
|
+
@model.name = 'Float'
|
8
|
+
@model.should be_valid_for_presence_test
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "without name" do
|
12
|
+
before :all do
|
13
|
+
@model.name = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
# has validates_is_present for name thanks to :nullable => false
|
17
|
+
it "is invalid" do
|
18
|
+
@model.should_not be_valid_for_presence_test
|
19
|
+
@model.errors.on(:name).should == [ 'Name must not be blank' ]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
describe SailBoat do
|
27
|
+
before :all do
|
28
|
+
@model = SailBoat.new(:id => 1)
|
29
|
+
@model.name = 'Float'
|
30
|
+
@model.should be_valid_for_presence_test
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "with a name" do
|
34
|
+
before :all do
|
35
|
+
# no op
|
36
|
+
end
|
37
|
+
|
38
|
+
# has validates_is_present for name thanks to :nullable => false
|
39
|
+
it_should_behave_like "valid model"
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/automatic_validation/spec_helper'
|
3
|
+
|
4
|
+
describe SailBoat do
|
5
|
+
before :all do
|
6
|
+
@model = SailBoat.new(:id => 1)
|
7
|
+
@model.should be_valid_for_primitive_test
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "with invlid value assigned to primitive column" do
|
11
|
+
before :all do
|
12
|
+
@model.build_date = 'ABC'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "is invalid" do
|
16
|
+
@model.should_not be_valid_for_primitive_test
|
17
|
+
@model.errors.on(:build_date).should == [ 'Build date must be of type Date' ]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/automatic_validation/spec_helper'
|
3
|
+
|
4
|
+
describe 'A model with a :set & :default options on a property' do
|
5
|
+
before :all do
|
6
|
+
class ::LimitedBoat
|
7
|
+
include DataMapper::Resource
|
8
|
+
property :id, DataMapper::Types::Serial
|
9
|
+
property :limited, String, :set => %w[ foo bar bang ], :default => 'foo'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "without value on that property" do
|
14
|
+
before :all do
|
15
|
+
@model = LimitedBoat.new
|
16
|
+
end
|
17
|
+
|
18
|
+
# default value is respected
|
19
|
+
it_should_behave_like "valid model"
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "without value on that property that is not in allowed range/set" do
|
23
|
+
before :all do
|
24
|
+
@model = LimitedBoat.new(:limited => "blah")
|
25
|
+
end
|
26
|
+
|
27
|
+
it_should_behave_like "invalid model"
|
28
|
+
|
29
|
+
it "has a meaningful error message" do
|
30
|
+
@model.errors.on(:limited).should == [ 'Limited must be one of foo, bar, bang' ]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|