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,38 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe DataMapper::Validate::ValidationErrors do
|
5
|
+
before :all do
|
6
|
+
@model = DataMapper::Validate::ValidationErrors.new(Object.new)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "initially" do
|
10
|
+
it "is empty" do
|
11
|
+
@model.should be_empty
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Not sure if this is worth having at all,
|
16
|
+
# just keeping old spec suite bits in place
|
17
|
+
# if they make no harm — MK
|
18
|
+
describe "after enquiry" do
|
19
|
+
before :all do
|
20
|
+
@model.on(:property)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "is still empty" do
|
24
|
+
@model.should be_empty
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
describe "after errors being added" do
|
30
|
+
before :all do
|
31
|
+
@model.add(:property, "can't be valid, no way")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "is no longer empty" do
|
35
|
+
@model.should_not be_empty
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe DataMapper::Validate::ValidationErrors do
|
5
|
+
before :all do
|
6
|
+
@model = DataMapper::Validate::ValidationErrors.new(Object.new)
|
7
|
+
@model.add(:ip_address, "must have valid format")
|
8
|
+
@model.add(:full_name, "can't be blank")
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#each" do
|
12
|
+
it "iterates over properties and yields error message arrays" do
|
13
|
+
params = []
|
14
|
+
@model.each do |param|
|
15
|
+
params << param
|
16
|
+
end
|
17
|
+
|
18
|
+
params.should == [ [ 'must have valid format' ], [ "can't be blank" ] ]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
describe "#map" do
|
24
|
+
before :all do
|
25
|
+
@model.add(:ip_address, "must belong to a local subnet")
|
26
|
+
end
|
27
|
+
it "maps error message arrays using provided block" do
|
28
|
+
projection = @model.map { |ary| ary }
|
29
|
+
projection.should == [ [ 'must have valid format', 'must belong to a local subnet' ], [ "can't be blank" ] ]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/tasks/install.rb
CHANGED
@@ -4,7 +4,7 @@ end
|
|
4
4
|
|
5
5
|
desc "Install #{GEM_NAME} #{GEM_VERSION}"
|
6
6
|
task :install => [ :package ] do
|
7
|
-
sudo_gem "install
|
7
|
+
sudo_gem "install pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources"
|
8
8
|
end
|
9
9
|
|
10
10
|
desc "Uninstall #{GEM_NAME} #{GEM_VERSION}"
|
data/tasks/spec.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
begin
|
2
|
-
gem 'rspec', '~>1.2'
|
3
|
-
require 'spec'
|
4
2
|
require 'spec/rake/spectask'
|
5
3
|
|
6
4
|
task :default => [ :spec ]
|
@@ -8,16 +6,18 @@ begin
|
|
8
6
|
desc 'Run specifications'
|
9
7
|
Spec::Rake::SpecTask.new(:spec) do |t|
|
10
8
|
t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
|
11
|
-
t.
|
9
|
+
t.libs << 'lib' << 'spec' # needed for CI rake spec task, duplicated in spec_helper
|
12
10
|
|
13
11
|
begin
|
14
|
-
|
12
|
+
require 'rcov'
|
15
13
|
t.rcov = JRUBY ? false : (ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true)
|
16
14
|
t.rcov_opts << '--exclude' << 'spec'
|
17
15
|
t.rcov_opts << '--text-summary'
|
18
16
|
t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
|
19
17
|
rescue LoadError
|
20
18
|
# rcov not installed
|
19
|
+
rescue SyntaxError
|
20
|
+
# rcov syntax invalid
|
21
21
|
end
|
22
22
|
end
|
23
23
|
rescue LoadError
|
metadata
CHANGED
@@ -1,28 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Guy van den Berg
|
7
|
+
- Guy van den Berg, DataMapper development team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-16 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
|
17
|
-
type: :runtime
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - "="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.9.11
|
24
|
-
version:
|
25
|
-
description: DataMapper plugin for performing validations on data models
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Library for performing validations on DM models and pure Ruby object
|
26
17
|
email:
|
27
18
|
- vandenberg.guy [a] gmail [d] com
|
28
19
|
executables: []
|
@@ -30,61 +21,121 @@ executables: []
|
|
30
21
|
extensions: []
|
31
22
|
|
32
23
|
extra_rdoc_files:
|
33
|
-
- README.
|
24
|
+
- README.rdoc
|
34
25
|
- LICENSE
|
35
26
|
- TODO
|
36
|
-
- History.
|
27
|
+
- History.rdoc
|
37
28
|
files:
|
38
|
-
- History.
|
29
|
+
- History.rdoc
|
39
30
|
- LICENSE
|
40
31
|
- Manifest.txt
|
41
|
-
- README.
|
32
|
+
- README.rdoc
|
42
33
|
- Rakefile
|
43
34
|
- TODO
|
44
35
|
- lib/dm-validations.rb
|
45
|
-
- lib/dm-validations/absent_field_validator.rb
|
46
|
-
- lib/dm-validations/acceptance_validator.rb
|
47
36
|
- lib/dm-validations/auto_validate.rb
|
48
|
-
- lib/dm-validations/block_validator.rb
|
49
|
-
- lib/dm-validations/confirmation_validator.rb
|
50
37
|
- lib/dm-validations/contextual_validators.rb
|
51
|
-
- lib/dm-validations/
|
52
|
-
- lib/dm-validations/format_validator.rb
|
38
|
+
- lib/dm-validations/exceptions.rb
|
53
39
|
- lib/dm-validations/formats/email.rb
|
54
40
|
- lib/dm-validations/formats/url.rb
|
55
|
-
- lib/dm-validations/
|
56
|
-
- lib/dm-validations/length_validator.rb
|
57
|
-
- lib/dm-validations/method_validator.rb
|
58
|
-
- lib/dm-validations/numeric_validator.rb
|
59
|
-
- lib/dm-validations/primitive_validator.rb
|
60
|
-
- lib/dm-validations/required_field_validator.rb
|
41
|
+
- lib/dm-validations/support/context.rb
|
61
42
|
- lib/dm-validations/support/object.rb
|
62
|
-
- lib/dm-validations/uniqueness_validator.rb
|
63
43
|
- lib/dm-validations/validation_errors.rb
|
44
|
+
- lib/dm-validations/validators/absent_field_validator.rb
|
45
|
+
- lib/dm-validations/validators/acceptance_validator.rb
|
46
|
+
- lib/dm-validations/validators/block_validator.rb
|
47
|
+
- lib/dm-validations/validators/confirmation_validator.rb
|
48
|
+
- lib/dm-validations/validators/format_validator.rb
|
49
|
+
- lib/dm-validations/validators/generic_validator.rb
|
50
|
+
- lib/dm-validations/validators/length_validator.rb
|
51
|
+
- lib/dm-validations/validators/method_validator.rb
|
52
|
+
- lib/dm-validations/validators/numeric_validator.rb
|
53
|
+
- lib/dm-validations/validators/primitive_validator.rb
|
54
|
+
- lib/dm-validations/validators/required_field_validator.rb
|
55
|
+
- lib/dm-validations/validators/uniqueness_validator.rb
|
56
|
+
- lib/dm-validations/validators/within_validator.rb
|
64
57
|
- lib/dm-validations/version.rb
|
65
|
-
-
|
66
|
-
- spec/
|
67
|
-
- spec/
|
68
|
-
- spec/
|
69
|
-
- spec/
|
70
|
-
- spec/
|
71
|
-
- spec/
|
72
|
-
- spec/
|
73
|
-
- spec/
|
74
|
-
- spec/
|
58
|
+
- spec/fixtures/barcode.rb
|
59
|
+
- spec/fixtures/basketball_court.rb
|
60
|
+
- spec/fixtures/basketball_player.rb
|
61
|
+
- spec/fixtures/beta_tester_account.rb
|
62
|
+
- spec/fixtures/bill_of_landing.rb
|
63
|
+
- spec/fixtures/boat_dock.rb
|
64
|
+
- spec/fixtures/city.rb
|
65
|
+
- spec/fixtures/company.rb
|
66
|
+
- spec/fixtures/corporate_world.rb
|
67
|
+
- spec/fixtures/country.rb
|
68
|
+
- spec/fixtures/currency.rb
|
69
|
+
- spec/fixtures/ethernet_frame.rb
|
70
|
+
- spec/fixtures/event.rb
|
71
|
+
- spec/fixtures/g3_concert.rb
|
72
|
+
- spec/fixtures/jabberwock.rb
|
73
|
+
- spec/fixtures/kayak.rb
|
74
|
+
- spec/fixtures/lernean_hydra.rb
|
75
|
+
- spec/fixtures/mathematical_function.rb
|
76
|
+
- spec/fixtures/memory_object.rb
|
77
|
+
- spec/fixtures/mittelschnauzer.rb
|
78
|
+
- spec/fixtures/motor_launch.rb
|
79
|
+
- spec/fixtures/page.rb
|
80
|
+
- spec/fixtures/phone_number.rb
|
81
|
+
- spec/fixtures/pirogue.rb
|
82
|
+
- spec/fixtures/programming_language.rb
|
83
|
+
- spec/fixtures/reservation.rb
|
84
|
+
- spec/fixtures/scm_operation.rb
|
85
|
+
- spec/fixtures/sms_message.rb
|
86
|
+
- spec/fixtures/udp_packet.rb
|
87
|
+
- spec/integration/absent_field_validator/absent_field_validator_spec.rb
|
88
|
+
- spec/integration/absent_field_validator/spec_helper.rb
|
89
|
+
- spec/integration/acceptance_validator/acceptance_validator_spec.rb
|
90
|
+
- spec/integration/acceptance_validator/spec_helper.rb
|
91
|
+
- spec/integration/automatic_validation/custom_messages_for_inferred_validation_spec.rb
|
92
|
+
- spec/integration/automatic_validation/disabling_inferred_validation_spec.rb
|
93
|
+
- spec/integration/automatic_validation/inferred_boolean_properties_validation_spec.rb
|
94
|
+
- spec/integration/automatic_validation/inferred_float_property_validation_spec.rb
|
95
|
+
- spec/integration/automatic_validation/inferred_format_validation_spec.rb
|
96
|
+
- spec/integration/automatic_validation/inferred_integer_properties_validation_spec.rb
|
97
|
+
- spec/integration/automatic_validation/inferred_length_validation_spec.rb
|
98
|
+
- spec/integration/automatic_validation/inferred_presence_validation_spec.rb
|
99
|
+
- spec/integration/automatic_validation/inferred_primitive_validation_spec.rb
|
100
|
+
- spec/integration/automatic_validation/inferred_within_validation_spec.rb
|
101
|
+
- spec/integration/automatic_validation/spec_helper.rb
|
102
|
+
- spec/integration/block_validator/block_validator_spec.rb
|
103
|
+
- spec/integration/block_validator/spec_helper.rb
|
104
|
+
- spec/integration/conditional_validation/if_condition_spec.rb
|
105
|
+
- spec/integration/conditional_validation/spec_helper.rb
|
106
|
+
- spec/integration/confirmation_validator/confirmation_validator_spec.rb
|
107
|
+
- spec/integration/confirmation_validator/spec_helper.rb
|
108
|
+
- spec/integration/datamapper_models/association_validation_spec.rb
|
109
|
+
- spec/integration/datamapper_models/inheritance_spec.rb
|
110
|
+
- spec/integration/duplicated_validations/duplicated_validations_spec.rb
|
111
|
+
- spec/integration/duplicated_validations/spec_helper.rb
|
112
|
+
- spec/integration/format_validator/email_format_validator_spec.rb
|
113
|
+
- spec/integration/format_validator/format_validator_spec.rb
|
114
|
+
- spec/integration/format_validator/regexp_validator_spec.rb
|
115
|
+
- spec/integration/format_validator/spec_helper.rb
|
116
|
+
- spec/integration/format_validator/url_format_validator_spec.rb
|
117
|
+
- spec/integration/length_validator/default_value_spec.rb
|
118
|
+
- spec/integration/length_validator/equality_spec.rb
|
75
119
|
- spec/integration/length_validator/error_message_spec.rb
|
76
120
|
- spec/integration/length_validator/maximum_spec.rb
|
77
121
|
- spec/integration/length_validator/minimum_spec.rb
|
78
122
|
- spec/integration/length_validator/range_spec.rb
|
79
123
|
- spec/integration/length_validator/spec_helper.rb
|
80
|
-
- spec/integration/
|
81
|
-
- spec/integration/
|
124
|
+
- spec/integration/method_validator/method_validator_spec.rb
|
125
|
+
- spec/integration/method_validator/spec_helper.rb
|
126
|
+
- spec/integration/numeric_validator/equality_with_float_type_spec.rb
|
127
|
+
- spec/integration/numeric_validator/equality_with_integer_type_spec.rb
|
82
128
|
- spec/integration/numeric_validator/float_type_spec.rb
|
129
|
+
- spec/integration/numeric_validator/gt_with_float_type_spec.rb
|
130
|
+
- spec/integration/numeric_validator/gte_with_float_type_spec.rb
|
83
131
|
- spec/integration/numeric_validator/integer_only_true_spec.rb
|
84
132
|
- spec/integration/numeric_validator/integer_type_spec.rb
|
133
|
+
- spec/integration/numeric_validator/lt_with_float_type_spec.rb
|
134
|
+
- spec/integration/numeric_validator/lte_with_float_type_spec.rb
|
85
135
|
- spec/integration/numeric_validator/spec_helper.rb
|
86
|
-
- spec/integration/
|
87
|
-
- spec/integration/
|
136
|
+
- spec/integration/primitive_validator/primitive_validator_spec.rb
|
137
|
+
- spec/integration/primitive_validator/spec_helper.rb
|
138
|
+
- spec/integration/pure_ruby_objects/plain_old_ruby_object_validation_spec.rb
|
88
139
|
- spec/integration/required_field_validator/association_spec.rb
|
89
140
|
- spec/integration/required_field_validator/boolean_type_value_spec.rb
|
90
141
|
- spec/integration/required_field_validator/date_type_value_spec.rb
|
@@ -96,20 +147,32 @@ files:
|
|
96
147
|
- spec/integration/required_field_validator/spec_helper.rb
|
97
148
|
- spec/integration/required_field_validator/string_type_value_spec.rb
|
98
149
|
- spec/integration/required_field_validator/text_type_value_spec.rb
|
99
|
-
- spec/integration/
|
100
|
-
- spec/integration/
|
101
|
-
- spec/integration/
|
102
|
-
- spec/integration/
|
150
|
+
- spec/integration/shared/default_validation_context.rb
|
151
|
+
- spec/integration/shared/valid_and_invalid_model.rb
|
152
|
+
- spec/integration/uniqueness_validator/spec_helper.rb
|
153
|
+
- spec/integration/uniqueness_validator/uniqueness_validator_spec.rb
|
154
|
+
- spec/integration/within_validator/spec_helper.rb
|
155
|
+
- spec/integration/within_validator/within_validator_spec.rb
|
156
|
+
- spec/public/resource_spec.rb
|
103
157
|
- spec/spec.opts
|
104
158
|
- spec/spec_helper.rb
|
159
|
+
- spec/unit/contextual_validators/emptiness_spec.rb
|
160
|
+
- spec/unit/contextual_validators/execution_spec.rb
|
161
|
+
- spec/unit/contextual_validators/spec_helper.rb
|
162
|
+
- spec/unit/generic_validator/equality_operator_spec.rb
|
163
|
+
- spec/unit/validation_errors/adding_spec.rb
|
164
|
+
- spec/unit/validation_errors/emptiness_spec.rb
|
165
|
+
- spec/unit/validation_errors/enumerable_spec.rb
|
105
166
|
- tasks/install.rb
|
106
167
|
- tasks/spec.rb
|
107
168
|
has_rdoc: true
|
108
|
-
homepage: http://github.com/
|
169
|
+
homepage: http://github.com/datamapper/dm-more/tree/master/dm-validations
|
170
|
+
licenses: []
|
171
|
+
|
109
172
|
post_install_message:
|
110
173
|
rdoc_options:
|
111
174
|
- --main
|
112
|
-
- README.
|
175
|
+
- README.rdoc
|
113
176
|
require_paths:
|
114
177
|
- lib
|
115
178
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -127,9 +190,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
190
|
requirements: []
|
128
191
|
|
129
192
|
rubyforge_project: datamapper
|
130
|
-
rubygems_version: 1.3.
|
193
|
+
rubygems_version: 1.3.5
|
131
194
|
signing_key:
|
132
|
-
specification_version:
|
133
|
-
summary:
|
195
|
+
specification_version: 3
|
196
|
+
summary: Library for performing validations on DM models and pure Ruby object
|
134
197
|
test_files: []
|
135
198
|
|
data/README.txt
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
This is a DataMapper plugin that provides validations for DataMapper model
|
2
|
-
classes.
|
3
|
-
|
4
|
-
== Setup
|
5
|
-
DataMapper validation capabilities are automatically available when you
|
6
|
-
'require dm-validations' into your application.
|
7
|
-
|
8
|
-
More specifically, DataMapper::Validate is automatically included into
|
9
|
-
DataMapper::Resource when you require dm-validations.
|
10
|
-
|
11
|
-
== Specifying Model Validations
|
12
|
-
There are two primary ways to implement validations for your models:
|
13
|
-
|
14
|
-
1) Placing validation methods with properties as params in your class
|
15
|
-
definitions like:
|
16
|
-
- validates_length :name
|
17
|
-
- validates_length [:name, :description]
|
18
|
-
|
19
|
-
2) Using auto-validations, please see DataMapper::Validate::AutoValidate
|
20
|
-
|
21
|
-
An example class with validations declared:
|
22
|
-
|
23
|
-
require 'dm-validations'
|
24
|
-
|
25
|
-
class Account
|
26
|
-
include DataMapper::Resource
|
27
|
-
|
28
|
-
property :name, String
|
29
|
-
validates_length :name
|
30
|
-
end
|
31
|
-
|
32
|
-
See all of the DataMapper::Validate module's XYZValidator(s) to learn about the
|
33
|
-
complete collections of validators available to you.
|
34
|
-
|
35
|
-
== Validating
|
36
|
-
DataMapper validations, when included, alter the default save/create/update
|
37
|
-
process for a model. Unless you specify a context the resource must be
|
38
|
-
valid in the :default context before saving.
|
39
|
-
|
40
|
-
You may manually validate a resource using the valid? method, which will
|
41
|
-
return true if the resource is valid, and false if it is invalid.
|
42
|
-
|
43
|
-
In addition to the valid? method, there is also an all_valid? method that
|
44
|
-
recursively walks both the current object and its associated objects and returns
|
45
|
-
its true/false result for the entire walk.
|
46
|
-
|
47
|
-
== Working with Validation Errors
|
48
|
-
If your validators find errors in your model, they will populate the
|
49
|
-
DataMapper::Validate::ValidationErrors object that is available through each of
|
50
|
-
your models via calls to your model's errors method.
|
51
|
-
|
52
|
-
For example:
|
53
|
-
|
54
|
-
my_account = Account.new(:name => "Jose")
|
55
|
-
if my_account.save
|
56
|
-
# my_account is valid and has been saved
|
57
|
-
else
|
58
|
-
my_account.errors.each do |e|
|
59
|
-
puts e
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
See DataMapper::Validate::ValidationErrors for all you can do with your model's
|
64
|
-
errors method.
|
65
|
-
|
66
|
-
== Contextual Validations
|
67
|
-
|
68
|
-
DataMapper Validations also provide a means of grouping your validations into
|
69
|
-
contexts. This enables you to run different sets of validations under ...
|
70
|
-
different contexts.
|
71
|
-
|
72
|
-
TO BE ADDED... For now, see
|
@@ -1,72 +0,0 @@
|
|
1
|
-
#require File.dirname(__FILE__) + '/formats/email'
|
2
|
-
|
3
|
-
module DataMapper
|
4
|
-
module Validate
|
5
|
-
|
6
|
-
##
|
7
|
-
#
|
8
|
-
# @author Guy van den Berg
|
9
|
-
# @since 0.9
|
10
|
-
class CustomValidator < GenericValidator
|
11
|
-
|
12
|
-
def initialize(field_name, options = {}, &b)
|
13
|
-
#super(field_name, options)
|
14
|
-
#@field_name, @options = field_name, options
|
15
|
-
#@options[:allow_nil] = false unless @options.has_key?(:allow_nil)
|
16
|
-
end
|
17
|
-
|
18
|
-
def call(target)
|
19
|
-
#field_value = target.instance_variable_get("@#{@field_name}")
|
20
|
-
#return true if @options[:allow_nil] && field_value.nil?
|
21
|
-
|
22
|
-
#validation = (@options[:as] || @options[:with])
|
23
|
-
#error_message = nil
|
24
|
-
|
25
|
-
# Figure out what to use as the actual validator.
|
26
|
-
# If a symbol is passed to :as, look up
|
27
|
-
# the canned validation in FORMATS.
|
28
|
-
#
|
29
|
-
#validator = if validation.is_a? Symbol
|
30
|
-
# if FORMATS[validation].is_a? Array
|
31
|
-
# error_message = FORMATS[validation][1]
|
32
|
-
# FORMATS[validation][0]
|
33
|
-
# else
|
34
|
-
# FORMATS[validation] || validation
|
35
|
-
# end
|
36
|
-
#else
|
37
|
-
# validation
|
38
|
-
#end
|
39
|
-
|
40
|
-
#valid = case validator
|
41
|
-
#when Proc then validator.call(field_value)
|
42
|
-
#when Regexp then validator =~ field_value
|
43
|
-
#else raise UnknownValidationFormat, "Can't determine how to validate #{target.class}##{@field_name} with #{validator.inspect}"
|
44
|
-
#end
|
45
|
-
|
46
|
-
#unless valid
|
47
|
-
# field = Inflector.humanize(@field_name)
|
48
|
-
# value = field_value
|
49
|
-
#
|
50
|
-
# error_message = @options[:message] || error_message || '%s is invalid'.t(field)
|
51
|
-
# error_message = error_message.call(field, value) if Proc === error_message
|
52
|
-
#
|
53
|
-
# add_error(target, error_message, @field_name)
|
54
|
-
#end
|
55
|
-
|
56
|
-
#return valid
|
57
|
-
end
|
58
|
-
|
59
|
-
#class UnknownValidationFormat < StandardError; end
|
60
|
-
|
61
|
-
end # class CustomValidator
|
62
|
-
|
63
|
-
module ValidatesFormatOf
|
64
|
-
|
65
|
-
#def validates_format_of(*fields)
|
66
|
-
#opts = opts_from_validator_args(fields)
|
67
|
-
#add_validator_to_context(opts, fields, DataMapper::Validate::FormatValidator)
|
68
|
-
#end
|
69
|
-
|
70
|
-
end # module ValidatesFormatOf
|
71
|
-
end # module Validate
|
72
|
-
end # module DataMapper
|