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,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/format_validator/spec_helper'
|
3
|
+
|
4
|
+
describe DataMapper::Validate::Fixtures::BillOfLading do
|
5
|
+
def valid_attributes
|
6
|
+
{ :id => 1, :doc_no => 'A1234', :email => 'user@example.com', :url => 'http://example.com' }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "with doc no with value of 'BAD CODE :)'" do
|
10
|
+
before :all do
|
11
|
+
@model = DataMapper::Validate::Fixtures::BillOfLading.new(valid_attributes.merge(:doc_no => 'BAD CODE :)'))
|
12
|
+
end
|
13
|
+
|
14
|
+
it_should_behave_like 'invalid model'
|
15
|
+
|
16
|
+
it "has meaningful error message on invalid field" do
|
17
|
+
@model.errors.on(:doc_no).should == [ 'Doc no has an invalid format' ]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "with doc no with value of 'A1234'" do
|
22
|
+
before :all do
|
23
|
+
@model = DataMapper::Validate::Fixtures::BillOfLading.new(valid_attributes.merge(:doc_no => 'A1234'))
|
24
|
+
end
|
25
|
+
|
26
|
+
it_should_behave_like 'valid model'
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "with doc no with value of 'B123456X12'" do
|
30
|
+
before :all do
|
31
|
+
@model = DataMapper::Validate::Fixtures::BillOfLading.new(valid_attributes.merge(:doc_no => 'B123456X12'))
|
32
|
+
end
|
33
|
+
|
34
|
+
it_should_behave_like 'valid model'
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "with missing url" do
|
38
|
+
before :all do
|
39
|
+
@model = DataMapper::Validate::Fixtures::BillOfLading.new(valid_attributes.except(:url))
|
40
|
+
end
|
41
|
+
|
42
|
+
it_should_behave_like 'invalid model'
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "with blank name" do
|
46
|
+
before :all do
|
47
|
+
@model = DataMapper::Validate::Fixtures::BillOfLading.new(valid_attributes.merge(:username => ''))
|
48
|
+
end
|
49
|
+
|
50
|
+
it_should_behave_like 'valid model'
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "with blank email" do
|
54
|
+
before :all do
|
55
|
+
@model = DataMapper::Validate::Fixtures::BillOfLading.new(valid_attributes.merge(:email => ''))
|
56
|
+
end
|
57
|
+
|
58
|
+
it_should_behave_like 'valid model'
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/format_validator/spec_helper'
|
3
|
+
|
4
|
+
describe DataMapper::Validate::Fixtures::BillOfLading do
|
5
|
+
def valid_attributes
|
6
|
+
{ :id => 1, :doc_no => 'A1234', :email => 'user@example.com', :url => 'http://example.com' }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "with code of 123456" do
|
10
|
+
before :all do
|
11
|
+
@model = DataMapper::Validate::Fixtures::BillOfLading.new(valid_attributes.merge(:code => '123456'))
|
12
|
+
end
|
13
|
+
|
14
|
+
it_should_behave_like 'valid model'
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
describe "with code of 12" do
|
19
|
+
before :all do
|
20
|
+
@model = DataMapper::Validate::Fixtures::BillOfLading.new(valid_attributes.merge(:code => '12'))
|
21
|
+
end
|
22
|
+
|
23
|
+
it_should_behave_like 'invalid model'
|
24
|
+
|
25
|
+
it "has a meaningful error message" do
|
26
|
+
@model.errors.on(:code).should == [ 'Code format is invalid' ]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/format_validator/spec_helper'
|
3
|
+
|
4
|
+
describe DataMapper::Validate::Fixtures::BillOfLading do
|
5
|
+
def valid_attributes
|
6
|
+
{ :id => 1, :doc_no => 'A1234', :email => 'user@example.com', :url => 'http://example.com' }
|
7
|
+
end
|
8
|
+
|
9
|
+
[ 'http:// example.com', 'ftp://example.com', 'http://.com', 'http://', 'test', '...',
|
10
|
+
# these are valid URIs from RFC perspective,
|
11
|
+
# but too often not the case for web apps
|
12
|
+
#
|
13
|
+
# TODO: add another format that is strictly
|
14
|
+
# RFC compliant so it can be used, for instance,
|
15
|
+
# for internal apps that may refer to local domains
|
16
|
+
# like http://backend:8080
|
17
|
+
"http://localhost:4000", "http://localhost" ].each do |uri|
|
18
|
+
describe "with URL of #{uri}" do
|
19
|
+
before :all do
|
20
|
+
@model = DataMapper::Validate::Fixtures::BillOfLading.new(valid_attributes.merge(:url => uri))
|
21
|
+
end
|
22
|
+
|
23
|
+
it_should_behave_like "invalid model"
|
24
|
+
|
25
|
+
it "has a meaningful error message" do
|
26
|
+
@model.errors.on(:url).should == [ 'Url has an invalid format' ]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end # each
|
30
|
+
|
31
|
+
|
32
|
+
[ 'http://apple.com',
|
33
|
+
'http://www.apple.com',
|
34
|
+
"http://apple.com/",
|
35
|
+
"http://apple.com/iphone",
|
36
|
+
"http://www.google.com/search?client=safari&rls=en-us&q=LED&ie=UTF-8&oe=UTF-8",
|
37
|
+
"http://books.google.com",
|
38
|
+
"http://books.google.com/",
|
39
|
+
"http://db2.clouds.megacorp.net:8080",
|
40
|
+
"https://github.com",
|
41
|
+
"https://github.com/",
|
42
|
+
"http://www.example.com:8088/never/ending/path/segments/",
|
43
|
+
"http://db2.clouds.megacorp.net:8080/resources/10",
|
44
|
+
"http://www.example.com:8088/never/ending/path/segments",
|
45
|
+
"http://books.google.com/books?id=uSUJ3VhH4BsC&printsec=frontcover&dq=subject:%22+Linguistics+%22&as_brr=3&ei=DAHPSbGQE5rEzATk1sShAQ&rview=1",
|
46
|
+
"http://books.google.com:80/books?uid=14472359158468915761&rview=1",
|
47
|
+
"http://books.google.com/books?id=Ar3-TXCYXUkC&printsec=frontcover&rview=1",
|
48
|
+
"http://books.google.com/books/vp6ae081e454d30f89b6bca94e0f96fc14.js",
|
49
|
+
"http://www.google.com/images/cleardot.gif",
|
50
|
+
"http://books.google.com:80/books?id=Ar3-TXCYXUkC&printsec=frontcover&rview=1#PPA5,M1",
|
51
|
+
"http://www.hulu.com/watch/64923/terminator-the-sarah-connor-chronicles-to-the-lighthouse",
|
52
|
+
"http://hulu.com:80/browse/popular/tv",
|
53
|
+
"http://www.hulu.com/watch/62475/the-simpsons-gone-maggie-gone#s-p1-so-i0"
|
54
|
+
].each do |uri|
|
55
|
+
describe "with URL of #{uri}" do
|
56
|
+
before :all do
|
57
|
+
@model = DataMapper::Validate::Fixtures::BillOfLading.new(valid_attributes.merge(:url => uri))
|
58
|
+
end
|
59
|
+
|
60
|
+
it_should_behave_like "valid model"
|
61
|
+
end
|
62
|
+
end # each
|
63
|
+
end # describe DataMapper::Validate::Fixtures::BillOfLading
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/length_validator/spec_helper'
|
3
|
+
|
4
|
+
describe ::DataMapper::Validate::Fixtures::BoatDock do
|
5
|
+
before :all do
|
6
|
+
@model = ::DataMapper::Validate::Fixtures::BoatDock.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "with default values that are valid" do
|
10
|
+
it_should_behave_like "valid model"
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'integration/length_validator/spec_helper'
|
5
|
+
|
6
|
+
describe "entity with wrong destination MAC address length", :shared => true do
|
7
|
+
it "has error message with range bounds" do
|
8
|
+
@model.errors.on(:destination_mac).should == [ 'Destination mac must be 6 characters long' ]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
describe DataMapper::Validate::Fixtures::EthernetFrame do
|
14
|
+
before :all do
|
15
|
+
@model = DataMapper::Validate::Fixtures::EthernetFrame.valid_instance
|
16
|
+
@model.link_support_fragmentation = false
|
17
|
+
end
|
18
|
+
|
19
|
+
it_should_behave_like "valid model"
|
20
|
+
|
21
|
+
describe "with destination MAC 3 'bits' long" do
|
22
|
+
before :all do
|
23
|
+
@model.destination_mac = "123"
|
24
|
+
@model.valid?
|
25
|
+
end
|
26
|
+
|
27
|
+
it_should_behave_like "invalid model"
|
28
|
+
|
29
|
+
it_should_behave_like "entity with wrong destination MAC address length"
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "with destination MAC 8 'bits' long" do
|
33
|
+
before :all do
|
34
|
+
@model.destination_mac = "123abce8"
|
35
|
+
@model.valid?
|
36
|
+
end
|
37
|
+
|
38
|
+
it_should_behave_like "invalid model"
|
39
|
+
|
40
|
+
it_should_behave_like "entity with wrong destination MAC address length"
|
41
|
+
end
|
42
|
+
|
43
|
+
# arguable but reasonable for 80% of cases
|
44
|
+
# to treat nil as a 0 lengh value
|
45
|
+
# reported in
|
46
|
+
# http://datamapper.lighthouseapp.com/projects/20609/tickets/646
|
47
|
+
describe "that has no destination MAC address" do
|
48
|
+
before :all do
|
49
|
+
@model.destination_mac = nil
|
50
|
+
@model.valid?
|
51
|
+
end
|
52
|
+
|
53
|
+
it_should_behave_like "invalid model"
|
54
|
+
|
55
|
+
it_should_behave_like "entity with wrong destination MAC address length"
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "with a 6 'bits' destination MAC address" do
|
59
|
+
before :all do
|
60
|
+
@model.destination_mac = "a1b2c3"
|
61
|
+
@model.valid?
|
62
|
+
end
|
63
|
+
|
64
|
+
it_should_behave_like "valid model"
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "with multibyte characters" do
|
68
|
+
before :all do
|
69
|
+
@model = DataMapper::Validate::Fixtures::Currency.valid_instance(
|
70
|
+
:name => 'Euro',
|
71
|
+
:code => 'EUR',
|
72
|
+
:symbol => '€'
|
73
|
+
)
|
74
|
+
@model.valid?
|
75
|
+
end
|
76
|
+
|
77
|
+
it_should_behave_like "valid model"
|
78
|
+
end
|
79
|
+
end
|
@@ -1,23 +1,20 @@
|
|
1
|
-
require '
|
2
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/length_validator/spec_helper'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
describe DataMapper::Validate::Fixtures::Jabberwock do
|
5
|
+
before :all do
|
6
|
+
@model = DataMapper::Validate::Fixtures::Jabberwock.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "without snickersnack" do
|
10
|
+
before :all do
|
11
|
+
@model.snickersnack = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
it_should_behave_like "invalid model"
|
7
15
|
|
8
|
-
|
9
|
-
|
10
|
-
class Jabberwock
|
11
|
-
include DataMapper::Resource
|
12
|
-
property :id, Integer, :key => true
|
13
|
-
property :snickersnack, String
|
14
|
-
validates_length :snickersnack, :within => 3..40, :message => "worble warble"
|
16
|
+
it "has custom error message" do
|
17
|
+
@model.errors.on(:snickersnack).should == [ 'worble warble' ]
|
15
18
|
end
|
16
|
-
wock = Jabberwock.new
|
17
|
-
wock.should_not be_valid
|
18
|
-
wock.errors.on(:snickersnack).should include('worble warble')
|
19
|
-
wock.snickersnack = "hello"
|
20
|
-
wock.id = 1
|
21
|
-
wock.should be_valid
|
22
19
|
end
|
23
20
|
end
|
@@ -1,31 +1,47 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/length_validator/spec_helper'
|
3
|
+
|
4
|
+
describe "barcode with invalid code length", :shared => true do
|
5
|
+
it "has a meaninful error message with length restrictions mentioned" do
|
6
|
+
@model.errors.on(:code).should == [ 'Code must be at most 10 characters long' ]
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ::DataMapper::Validate::Fixtures::Barcode do
|
11
|
+
before :all do
|
12
|
+
@model = DataMapper::Validate::Fixtures::Barcode.valid_instance
|
13
|
+
end
|
14
|
+
|
15
|
+
it_should_behave_like "valid model"
|
16
|
+
|
17
|
+
describe "with a 17 characters long code" do
|
18
|
+
before :all do
|
19
|
+
@model.code = "18283849284728124"
|
20
|
+
@model.valid?
|
13
21
|
end
|
14
22
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
launch.errors.on(:name).should include('Name must be less than 5 characters long')
|
23
|
+
it_should_behave_like "invalid model"
|
24
|
+
|
25
|
+
it_should_behave_like "barcode with invalid code length"
|
19
26
|
end
|
20
27
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
28
|
+
describe "with a 7 characters long code" do
|
29
|
+
before :all do
|
30
|
+
@model.code = "8372786"
|
31
|
+
@model.valid?
|
25
32
|
end
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
33
|
+
|
34
|
+
it_should_behave_like "valid model"
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "with an 11 characters long code" do
|
38
|
+
before :all do
|
39
|
+
@model.code = "83727868754"
|
40
|
+
@model.valid?
|
41
|
+
end
|
42
|
+
|
43
|
+
it_should_behave_like "invalid model"
|
44
|
+
|
45
|
+
it_should_behave_like "barcode with invalid code length"
|
30
46
|
end
|
31
47
|
end
|
@@ -1,31 +1,42 @@
|
|
1
|
-
require '
|
2
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/length_validator/spec_helper'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
describe "entity with a name shorter than 2 characters", :shared => true do
|
5
|
+
it "has a meaninful error message with length restrictions mentioned" do
|
6
|
+
@model.errors.on(:name).should == [ 'Name must be at least 2 characters long' ]
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ::DataMapper::Validate::Fixtures::Mittelschnauzer do
|
11
|
+
before :all do
|
12
|
+
@model = DataMapper::Validate::Fixtures::Mittelschnauzer.valid_instance
|
13
|
+
end
|
14
|
+
|
15
|
+
it_should_behave_like "valid model"
|
7
16
|
|
8
|
-
describe
|
9
|
-
|
10
|
-
|
11
|
-
|
17
|
+
describe "with a 13 characters long name" do
|
18
|
+
it_should_behave_like "valid model"
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "with a single character name" do
|
22
|
+
before :all do
|
23
|
+
@model.name = "R"
|
24
|
+
@model.valid?
|
12
25
|
end
|
13
26
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
launch.errors.on(:name).should include('Name must be more than 3 characters long')
|
27
|
+
it_should_behave_like "invalid model"
|
28
|
+
|
29
|
+
it_should_behave_like "entity with a name shorter than 2 characters"
|
18
30
|
end
|
19
31
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
32
|
+
describe "with blank name" do
|
33
|
+
before :all do
|
34
|
+
@model.name = ""
|
35
|
+
@model.valid?
|
24
36
|
end
|
25
37
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
launch.errors.on(:name).should include('Name must be more than 3 characters long')
|
38
|
+
it_should_behave_like "invalid model"
|
39
|
+
|
40
|
+
it_should_behave_like "entity with a name shorter than 2 characters"
|
30
41
|
end
|
31
42
|
end
|
@@ -1,47 +1,52 @@
|
|
1
|
-
require '
|
2
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/length_validator/spec_helper'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
describe DataMapper::Validate::Fixtures::EthernetFrame do
|
5
|
+
before :all do
|
6
|
+
@model = DataMapper::Validate::Fixtures::EthernetFrame.valid_instance
|
7
|
+
@model.link_support_fragmentation = false
|
8
|
+
end
|
7
9
|
|
8
|
-
|
9
|
-
validators.clear!
|
10
|
-
validates_length :name, :in => (3..5)
|
11
|
-
end
|
10
|
+
it_should_behave_like "valid model"
|
12
11
|
|
12
|
+
describe "with payload that is 7 'bits' long (too short)" do
|
13
|
+
before :all do
|
14
|
+
@model.payload = "1234567"
|
15
|
+
@model.valid?
|
16
|
+
end
|
13
17
|
|
14
|
-
|
15
|
-
before :each do
|
16
|
-
@launch = MotorLaunch.new
|
17
|
-
end
|
18
|
+
it_should_behave_like "invalid model"
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
@launch.name = 'a'
|
22
|
-
@launch.valid?
|
20
|
+
it "has error message with range bounds" do
|
21
|
+
@model.errors.on(:payload).should == [ 'Payload must be between 46 and 1500 characters long' ]
|
23
22
|
end
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
|
26
|
+
describe "with a one character long payload (too short)" do
|
27
|
+
before :all do
|
28
|
+
@model.payload = 'a'
|
29
|
+
@model.valid?
|
27
30
|
end
|
28
|
-
|
29
|
-
|
31
|
+
|
32
|
+
it_should_behave_like "invalid model"
|
33
|
+
|
34
|
+
it "has error message with range bounds" do
|
35
|
+
@model.errors.on(:payload).should == [ 'Payload must be between 46 and 1500 characters long' ]
|
30
36
|
end
|
31
37
|
end
|
32
38
|
|
33
39
|
|
34
|
-
describe "with a
|
35
|
-
before :
|
36
|
-
@
|
37
|
-
@
|
40
|
+
describe "with a 1600 'bits' long payload (needs fragmentation)" do
|
41
|
+
before :all do
|
42
|
+
@model.payload = 'a'
|
43
|
+
@model.valid?
|
38
44
|
end
|
39
45
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
@launch.errors.on(:name).should include('Name must be between 3 and 5 characters long')
|
46
|
+
it_should_behave_like "invalid model"
|
47
|
+
|
48
|
+
it "has error message with range bounds" do
|
49
|
+
@model.errors.on(:payload).should == [ 'Payload must be between 46 and 1500 characters long' ]
|
45
50
|
end
|
46
51
|
end
|
47
52
|
|
@@ -50,46 +55,31 @@ describe MotorLaunch do
|
|
50
55
|
# to treat nil as a 0 lengh value
|
51
56
|
# reported in
|
52
57
|
# http://datamapper.lighthouseapp.com/projects/20609/tickets/646
|
53
|
-
describe "
|
54
|
-
before :
|
55
|
-
@
|
56
|
-
@
|
58
|
+
describe "that has no payload" do
|
59
|
+
before :all do
|
60
|
+
@model.payload = nil
|
61
|
+
@model.valid?
|
57
62
|
end
|
58
63
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
@launch.errors.on(:name).should include('Name must be between 3 and 5 characters long')
|
64
|
+
it_should_behave_like "invalid model"
|
65
|
+
|
66
|
+
it "has error message with range bounds" do
|
67
|
+
@model.errors.on(:payload).should == [ 'Payload must be between 46 and 1500 characters long' ]
|
64
68
|
end
|
65
69
|
end
|
66
70
|
|
67
71
|
|
68
72
|
|
69
|
-
describe "with a
|
70
|
-
before :
|
71
|
-
@
|
72
|
-
@
|
73
|
-
end
|
74
|
-
|
75
|
-
it "is valid" do
|
76
|
-
@launch.should be_valid
|
77
|
-
end
|
78
|
-
it "has blank error message" do
|
79
|
-
@launch.errors.on(:name).should be_blank
|
73
|
+
describe "with a 50 characters long payload" do
|
74
|
+
before :all do
|
75
|
+
@model.payload = 'Imagine yourself a beautiful bag full of bits here'
|
76
|
+
@model.valid?
|
80
77
|
end
|
81
|
-
end
|
82
|
-
|
83
78
|
|
79
|
+
it_should_behave_like "valid model"
|
84
80
|
|
85
|
-
|
86
|
-
|
87
|
-
validators.clear!
|
88
|
-
validates_length :name, :within => (3..5)
|
81
|
+
it "has blank error message" do
|
82
|
+
@model.errors.on(:payload).should be_blank
|
89
83
|
end
|
90
|
-
|
91
|
-
launch = MotorLaunch.new
|
92
|
-
launch.name = 'Ride'
|
93
|
-
launch.valid?.should == true
|
94
84
|
end
|
95
85
|
end
|