dm-validations 0.9.11 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. data/{History.txt → History.rdoc} +10 -3
  2. data/LICENSE +1 -0
  3. data/Manifest.txt +103 -33
  4. data/README.rdoc +172 -0
  5. data/Rakefile +4 -5
  6. data/lib/dm-validations.rb +73 -75
  7. data/lib/dm-validations/auto_validate.rb +98 -56
  8. data/lib/dm-validations/contextual_validators.rb +37 -14
  9. data/lib/dm-validations/exceptions.rb +3 -0
  10. data/lib/dm-validations/formats/url.rb +3 -1
  11. data/lib/dm-validations/support/context.rb +54 -0
  12. data/lib/dm-validations/validation_errors.rb +51 -27
  13. data/lib/dm-validations/{absent_field_validator.rb → validators/absent_field_validator.rb} +2 -8
  14. data/lib/dm-validations/{acceptance_validator.rb → validators/acceptance_validator.rb} +7 -7
  15. data/lib/dm-validations/{block_validator.rb → validators/block_validator.rb} +0 -0
  16. data/lib/dm-validations/{confirmation_validator.rb → validators/confirmation_validator.rb} +7 -7
  17. data/lib/dm-validations/{format_validator.rb → validators/format_validator.rb} +10 -16
  18. data/lib/dm-validations/{generic_validator.rb → validators/generic_validator.rb} +28 -6
  19. data/lib/dm-validations/validators/length_validator.rb +214 -0
  20. data/lib/dm-validations/validators/method_validator.rb +68 -0
  21. data/lib/dm-validations/validators/numeric_validator.rb +171 -0
  22. data/lib/dm-validations/{primitive_validator.rb → validators/primitive_validator.rb} +2 -7
  23. data/lib/dm-validations/{required_field_validator.rb → validators/required_field_validator.rb} +0 -6
  24. data/lib/dm-validations/{uniqueness_validator.rb → validators/uniqueness_validator.rb} +9 -20
  25. data/lib/dm-validations/{within_validator.rb → validators/within_validator.rb} +4 -4
  26. data/lib/dm-validations/version.rb +1 -1
  27. data/spec/fixtures/barcode.rb +32 -0
  28. data/spec/fixtures/basketball_court.rb +58 -0
  29. data/spec/fixtures/basketball_player.rb +37 -0
  30. data/spec/fixtures/beta_tester_account.rb +33 -0
  31. data/spec/fixtures/bill_of_landing.rb +42 -0
  32. data/spec/fixtures/boat_dock.rb +26 -0
  33. data/spec/fixtures/city.rb +25 -0
  34. data/spec/fixtures/company.rb +95 -0
  35. data/spec/fixtures/corporate_world.rb +47 -0
  36. data/spec/fixtures/country.rb +25 -0
  37. data/spec/fixtures/currency.rb +42 -0
  38. data/spec/fixtures/ethernet_frame.rb +56 -0
  39. data/spec/fixtures/event.rb +44 -0
  40. data/spec/fixtures/g3_concert.rb +57 -0
  41. data/spec/fixtures/jabberwock.rb +27 -0
  42. data/spec/fixtures/kayak.rb +28 -0
  43. data/spec/fixtures/lernean_hydra.rb +39 -0
  44. data/spec/fixtures/mathematical_function.rb +34 -0
  45. data/spec/fixtures/memory_object.rb +30 -0
  46. data/spec/fixtures/mittelschnauzer.rb +35 -0
  47. data/spec/fixtures/motor_launch.rb +21 -0
  48. data/spec/fixtures/page.rb +32 -0
  49. data/spec/fixtures/phone_number.rb +28 -0
  50. data/spec/fixtures/pirogue.rb +28 -0
  51. data/spec/fixtures/programming_language.rb +83 -0
  52. data/spec/fixtures/reservation.rb +38 -0
  53. data/spec/fixtures/scm_operation.rb +67 -0
  54. data/spec/fixtures/sms_message.rb +22 -0
  55. data/spec/fixtures/udp_packet.rb +49 -0
  56. data/spec/integration/absent_field_validator/absent_field_validator_spec.rb +86 -0
  57. data/spec/integration/absent_field_validator/spec_helper.rb +7 -0
  58. data/spec/integration/acceptance_validator/acceptance_validator_spec.rb +196 -0
  59. data/spec/integration/acceptance_validator/spec_helper.rb +7 -0
  60. data/spec/integration/automatic_validation/custom_messages_for_inferred_validation_spec.rb +47 -0
  61. data/spec/integration/automatic_validation/disabling_inferred_validation_spec.rb +41 -0
  62. data/spec/integration/automatic_validation/inferred_boolean_properties_validation_spec.rb +104 -0
  63. data/spec/integration/automatic_validation/inferred_float_property_validation_spec.rb +35 -0
  64. data/spec/integration/automatic_validation/inferred_format_validation_spec.rb +33 -0
  65. data/spec/integration/automatic_validation/inferred_integer_properties_validation_spec.rb +73 -0
  66. data/spec/integration/automatic_validation/inferred_length_validation_spec.rb +121 -0
  67. data/spec/integration/automatic_validation/inferred_presence_validation_spec.rb +41 -0
  68. data/spec/integration/automatic_validation/inferred_primitive_validation_spec.rb +20 -0
  69. data/spec/integration/automatic_validation/inferred_within_validation_spec.rb +33 -0
  70. data/spec/integration/automatic_validation/spec_helper.rb +74 -0
  71. data/spec/integration/block_validator/block_validator_spec.rb +32 -0
  72. data/spec/integration/block_validator/spec_helper.rb +5 -0
  73. data/spec/integration/conditional_validation/if_condition_spec.rb +61 -0
  74. data/spec/integration/conditional_validation/spec_helper.rb +5 -0
  75. data/spec/integration/confirmation_validator/confirmation_validator_spec.rb +74 -0
  76. data/spec/integration/confirmation_validator/spec_helper.rb +5 -0
  77. data/spec/integration/datamapper_models/association_validation_spec.rb +23 -0
  78. data/spec/integration/datamapper_models/inheritance_spec.rb +78 -0
  79. data/spec/integration/duplicated_validations/duplicated_validations_spec.rb +22 -0
  80. data/spec/integration/duplicated_validations/spec_helper.rb +5 -0
  81. data/spec/integration/format_validator/email_format_validator_spec.rb +113 -0
  82. data/spec/integration/format_validator/format_validator_spec.rb +60 -0
  83. data/spec/integration/format_validator/regexp_validator_spec.rb +29 -0
  84. data/spec/integration/format_validator/spec_helper.rb +5 -0
  85. data/spec/integration/format_validator/url_format_validator_spec.rb +63 -0
  86. data/spec/integration/length_validator/default_value_spec.rb +12 -0
  87. data/spec/integration/length_validator/equality_spec.rb +79 -0
  88. data/spec/integration/length_validator/error_message_spec.rb +15 -18
  89. data/spec/integration/length_validator/maximum_spec.rb +40 -24
  90. data/spec/integration/length_validator/minimum_spec.rb +32 -21
  91. data/spec/integration/length_validator/range_spec.rb +50 -60
  92. data/spec/integration/length_validator/spec_helper.rb +7 -12
  93. data/spec/integration/method_validator/method_validator_spec.rb +239 -0
  94. data/spec/integration/method_validator/spec_helper.rb +5 -0
  95. data/spec/integration/numeric_validator/equality_with_float_type_spec.rb +61 -0
  96. data/spec/integration/numeric_validator/equality_with_integer_type_spec.rb +37 -0
  97. data/spec/integration/numeric_validator/float_type_spec.rb +42 -56
  98. data/spec/integration/numeric_validator/gt_with_float_type_spec.rb +35 -0
  99. data/spec/integration/numeric_validator/gte_with_float_type_spec.rb +35 -0
  100. data/spec/integration/numeric_validator/integer_only_true_spec.rb +3 -6
  101. data/spec/integration/numeric_validator/integer_type_spec.rb +8 -24
  102. data/spec/integration/numeric_validator/lt_with_float_type_spec.rb +35 -0
  103. data/spec/integration/numeric_validator/lte_with_float_type_spec.rb +35 -0
  104. data/spec/integration/numeric_validator/spec_helper.rb +5 -77
  105. data/spec/integration/primitive_validator/primitive_validator_spec.rb +90 -0
  106. data/spec/integration/primitive_validator/spec_helper.rb +5 -0
  107. data/spec/integration/pure_ruby_objects/plain_old_ruby_object_validation_spec.rb +118 -0
  108. data/spec/integration/required_field_validator/association_spec.rb +5 -8
  109. data/spec/integration/required_field_validator/boolean_type_value_spec.rb +4 -7
  110. data/spec/integration/required_field_validator/date_type_value_spec.rb +3 -6
  111. data/spec/integration/required_field_validator/datetime_type_value_spec.rb +3 -6
  112. data/spec/integration/required_field_validator/float_type_value_spec.rb +3 -6
  113. data/spec/integration/required_field_validator/integer_type_value_spec.rb +2 -5
  114. data/spec/integration/required_field_validator/plain_old_ruby_object_spec.rb +5 -8
  115. data/spec/integration/required_field_validator/shared_examples.rb +1 -1
  116. data/spec/integration/required_field_validator/spec_helper.rb +6 -67
  117. data/spec/integration/required_field_validator/string_type_value_spec.rb +2 -5
  118. data/spec/integration/required_field_validator/text_type_value_spec.rb +2 -5
  119. data/spec/integration/shared/default_validation_context.rb +13 -0
  120. data/spec/integration/shared/valid_and_invalid_model.rb +27 -0
  121. data/spec/integration/uniqueness_validator/spec_helper.rb +5 -0
  122. data/spec/integration/uniqueness_validator/uniqueness_validator_spec.rb +114 -0
  123. data/spec/integration/within_validator/spec_helper.rb +5 -0
  124. data/spec/integration/within_validator/within_validator_spec.rb +164 -0
  125. data/spec/public/resource_spec.rb +68 -0
  126. data/spec/spec.opts +1 -0
  127. data/spec/spec_helper.rb +12 -4
  128. data/spec/unit/contextual_validators/emptiness_spec.rb +50 -0
  129. data/spec/unit/contextual_validators/execution_spec.rb +55 -0
  130. data/spec/unit/contextual_validators/spec_helper.rb +37 -0
  131. data/spec/unit/generic_validator/equality_operator_spec.rb +26 -0
  132. data/spec/unit/validation_errors/adding_spec.rb +54 -0
  133. data/spec/unit/validation_errors/emptiness_spec.rb +38 -0
  134. data/spec/unit/validation_errors/enumerable_spec.rb +32 -0
  135. data/tasks/install.rb +1 -1
  136. data/tasks/spec.rb +4 -4
  137. metadata +118 -55
  138. data/README.txt +0 -72
  139. data/lib/dm-validations/custom_validator.rb +0 -72
  140. data/lib/dm-validations/length_validator.rb +0 -113
  141. data/lib/dm-validations/method_validator.rb +0 -68
  142. data/lib/dm-validations/numeric_validator.rb +0 -83
  143. data/spec/integration/absent_field_validator_spec.rb +0 -36
  144. data/spec/integration/acceptance_validator_spec.rb +0 -87
  145. data/spec/integration/auto_validate_spec.rb +0 -342
  146. data/spec/integration/block_validator_spec.rb +0 -30
  147. data/spec/integration/confirmation_validator_spec.rb +0 -105
  148. data/spec/integration/contextual_validators_spec.rb +0 -27
  149. data/spec/integration/custom_validator_spec.rb +0 -9
  150. data/spec/integration/format_validator_spec.rb +0 -193
  151. data/spec/integration/generic_validator_spec.rb +0 -17
  152. data/spec/integration/length_validator/valid_objects_spec.rb +0 -13
  153. data/spec/integration/method_validator_spec.rb +0 -58
  154. data/spec/integration/numeric_validator_spec.rb +0 -253
  155. data/spec/integration/primitive_validator_spec.rb +0 -30
  156. data/spec/integration/uniqueness_validator_spec.rb +0 -97
  157. data/spec/integration/validation_errors_spec.rb +0 -18
  158. data/spec/integration/validation_spec.rb +0 -404
  159. data/spec/integration/within_validator_spec.rb +0 -79
@@ -0,0 +1,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