dm-validations 1.0.0.rc2 → 1.0.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/dm-validations.gemspec +12 -10
- data/lib/dm-validations/validation_errors.rb +9 -1
- data/spec/integration/method_validator/method_validator_spec.rb +4 -4
- data/spec/integration/uniqueness_validator/uniqueness_validator_spec.rb +5 -5
- data/spec/public/resource_spec.rb +7 -7
- data/spec/rcov.opts +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/contextual_validators/execution_spec.rb +6 -6
- data/spec/unit/validation_errors/reading_spec.rb +35 -0
- data/tasks/spec.rake +3 -0
- metadata +13 -11
data/Gemfile
CHANGED
data/LICENSE
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
Copyright (c) 2007 Guy van den Berg
|
2
|
-
Copyright (c) 2008, 2009 DataMapper development team
|
2
|
+
Copyright (c) 2008, 2009, 2010 DataMapper development team
|
3
3
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
a copy of this software and associated documentation files (the
|
data/Rakefile
CHANGED
@@ -10,15 +10,15 @@ begin
|
|
10
10
|
gem.summary = 'Library for performing validations on DM models and pure Ruby object'
|
11
11
|
gem.description = gem.summary
|
12
12
|
gem.email = 'vandenberg.guy [a] gmail [d] com'
|
13
|
-
gem.homepage = 'http://github.com/datamapper
|
13
|
+
gem.homepage = 'http://github.com/datamapper/%s' % gem.name
|
14
14
|
gem.authors = [ 'Guy van den Berg' ]
|
15
15
|
|
16
16
|
gem.rubyforge_project = 'datamapper'
|
17
17
|
|
18
|
-
gem.add_dependency 'dm-core', '~> 1.0.0.
|
18
|
+
gem.add_dependency 'dm-core', '~> 1.0.0.rc3'
|
19
19
|
|
20
20
|
gem.add_development_dependency 'rspec', '~> 1.3'
|
21
|
-
gem.add_development_dependency 'dm-types', '~> 1.0.0.
|
21
|
+
gem.add_development_dependency 'dm-types', '~> 1.0.0.rc3'
|
22
22
|
end
|
23
23
|
|
24
24
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.0.
|
1
|
+
1.0.0.rc3
|
data/dm-validations.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dm-validations}
|
8
|
-
s.version = "1.0.0.
|
8
|
+
s.version = "1.0.0.rc3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Guy van den Berg"]
|
12
|
-
s.date = %q{2010-05-
|
12
|
+
s.date = %q{2010-05-27}
|
13
13
|
s.description = %q{Library for performing validations on DM models and pure Ruby object}
|
14
14
|
s.email = %q{vandenberg.guy [a] gmail [d] com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -155,6 +155,7 @@ Gem::Specification.new do |s|
|
|
155
155
|
"spec/unit/validation_errors/adding_spec.rb",
|
156
156
|
"spec/unit/validation_errors/emptiness_spec.rb",
|
157
157
|
"spec/unit/validation_errors/enumerable_spec.rb",
|
158
|
+
"spec/unit/validation_errors/reading_spec.rb",
|
158
159
|
"tasks/ci.rake",
|
159
160
|
"tasks/local_gemfile.rake",
|
160
161
|
"tasks/metrics.rake",
|
@@ -162,7 +163,7 @@ Gem::Specification.new do |s|
|
|
162
163
|
"tasks/yard.rake",
|
163
164
|
"tasks/yardstick.rake"
|
164
165
|
]
|
165
|
-
s.homepage = %q{http://github.com/datamapper/dm-
|
166
|
+
s.homepage = %q{http://github.com/datamapper/dm-validations}
|
166
167
|
s.rdoc_options = ["--charset=UTF-8"]
|
167
168
|
s.require_paths = ["lib"]
|
168
169
|
s.rubyforge_project = %q{datamapper}
|
@@ -275,7 +276,8 @@ Gem::Specification.new do |s|
|
|
275
276
|
"spec/unit/generic_validator/equality_operator_spec.rb",
|
276
277
|
"spec/unit/validation_errors/adding_spec.rb",
|
277
278
|
"spec/unit/validation_errors/emptiness_spec.rb",
|
278
|
-
"spec/unit/validation_errors/enumerable_spec.rb"
|
279
|
+
"spec/unit/validation_errors/enumerable_spec.rb",
|
280
|
+
"spec/unit/validation_errors/reading_spec.rb"
|
279
281
|
]
|
280
282
|
|
281
283
|
if s.respond_to? :specification_version then
|
@@ -283,18 +285,18 @@ Gem::Specification.new do |s|
|
|
283
285
|
s.specification_version = 3
|
284
286
|
|
285
287
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
286
|
-
s.add_runtime_dependency(%q<dm-core>, ["~> 1.0.0.
|
288
|
+
s.add_runtime_dependency(%q<dm-core>, ["~> 1.0.0.rc3"])
|
287
289
|
s.add_development_dependency(%q<rspec>, ["~> 1.3"])
|
288
|
-
s.add_development_dependency(%q<dm-types>, ["~> 1.0.0.
|
290
|
+
s.add_development_dependency(%q<dm-types>, ["~> 1.0.0.rc3"])
|
289
291
|
else
|
290
|
-
s.add_dependency(%q<dm-core>, ["~> 1.0.0.
|
292
|
+
s.add_dependency(%q<dm-core>, ["~> 1.0.0.rc3"])
|
291
293
|
s.add_dependency(%q<rspec>, ["~> 1.3"])
|
292
|
-
s.add_dependency(%q<dm-types>, ["~> 1.0.0.
|
294
|
+
s.add_dependency(%q<dm-types>, ["~> 1.0.0.rc3"])
|
293
295
|
end
|
294
296
|
else
|
295
|
-
s.add_dependency(%q<dm-core>, ["~> 1.0.0.
|
297
|
+
s.add_dependency(%q<dm-core>, ["~> 1.0.0.rc3"])
|
296
298
|
s.add_dependency(%q<rspec>, ["~> 1.3"])
|
297
|
-
s.add_dependency(%q<dm-types>, ["~> 1.0.0.
|
299
|
+
s.add_dependency(%q<dm-types>, ["~> 1.0.0.rc3"])
|
298
300
|
end
|
299
301
|
end
|
300
302
|
|
@@ -35,7 +35,9 @@ module DataMapper
|
|
35
35
|
}
|
36
36
|
|
37
37
|
# Holds a hash with all the default error messages that can be replaced by your own copy or localizations.
|
38
|
-
|
38
|
+
def self.default_error_messages=(default_error_messages)
|
39
|
+
@@default_error_messages = default_error_messages
|
40
|
+
end
|
39
41
|
|
40
42
|
def self.default_error_message(key, field, *values)
|
41
43
|
field = ActiveSupport::Inflector.humanize(field)
|
@@ -107,6 +109,12 @@ module DataMapper
|
|
107
109
|
errors.send(meth, *args, &block)
|
108
110
|
end
|
109
111
|
|
112
|
+
def [](property_name)
|
113
|
+
if property_errors = errors[property_name.to_sym]
|
114
|
+
property_errors
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
110
118
|
private
|
111
119
|
def errors
|
112
120
|
@errors
|
@@ -7,7 +7,7 @@ describe "a good fit for DSLs", :shared => true do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it "is totally fine for DSLs" do
|
10
|
-
@model.ensure_appropriate_for_dsls.should
|
10
|
+
@model.ensure_appropriate_for_dsls.should be(true)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -17,7 +17,7 @@ describe "a poor candidate for DSLs", :shared => true do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it "is unappropriate for DSLs" do
|
20
|
-
@model.ensure_appropriate_for_dsls.first.should
|
20
|
+
@model.ensure_appropriate_for_dsls.first.should be(false)
|
21
21
|
end
|
22
22
|
|
23
23
|
it "has a (more or less) meaningful error message" do
|
@@ -32,7 +32,7 @@ describe "a good fit for game engine core", :shared => true do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it "is appropriate for system programming" do
|
35
|
-
@model.ensure_appropriate_for_system_programming.should
|
35
|
+
@model.ensure_appropriate_for_system_programming.should be(true)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -50,7 +50,7 @@ describe "a good fit for kernel hacking", :shared => true do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
it "is appropriate for system programming" do
|
53
|
-
@model.ensure_appropriate_for_system_programming.should
|
53
|
+
@model.ensure_appropriate_for_system_programming.should be(true)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -6,7 +6,7 @@ describe 'uniqueness_validator/uniqueness_validator_spec' do
|
|
6
6
|
|
7
7
|
describe 'DataMapper::Validations::Fixtures::Department' do
|
8
8
|
before :all do
|
9
|
-
DataMapper::Validations::Fixtures::Department.
|
9
|
+
DataMapper::Validations::Fixtures::Department.destroy!
|
10
10
|
|
11
11
|
DataMapper::Validations::Fixtures::Department.create(:name => "HR").should be_saved
|
12
12
|
end
|
@@ -30,7 +30,7 @@ describe 'uniqueness_validator/uniqueness_validator_spec' do
|
|
30
30
|
|
31
31
|
describe 'DataMapper::Validations::Fixtures::Organisation' do
|
32
32
|
before :all do
|
33
|
-
DataMapper::Validations::Fixtures::Organisation.
|
33
|
+
DataMapper::Validations::Fixtures::Organisation.destroy!
|
34
34
|
|
35
35
|
@model = DataMapper.repository do
|
36
36
|
DataMapper::Validations::Fixtures::Organisation.create(:name => 'Apple', :domain => 'apple.com')
|
@@ -66,9 +66,9 @@ describe 'uniqueness_validator/uniqueness_validator_spec' do
|
|
66
66
|
|
67
67
|
describe 'DataMapper::Validations::Fixtures::User' do
|
68
68
|
before :all do
|
69
|
-
DataMapper::Validations::Fixtures::Organisation.
|
70
|
-
DataMapper::Validations::Fixtures::Department.
|
71
|
-
DataMapper::Validations::Fixtures::User.
|
69
|
+
DataMapper::Validations::Fixtures::Organisation.destroy!
|
70
|
+
DataMapper::Validations::Fixtures::Department.destroy!
|
71
|
+
DataMapper::Validations::Fixtures::User.destroy!
|
72
72
|
|
73
73
|
DataMapper.repository do
|
74
74
|
@organization = DataMapper::Validations::Fixtures::Organisation.create(:name => 'Org 101', :domain => '101')
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'DataMapper::Resource' do
|
4
4
|
before :all do
|
5
|
-
DataMapper::Validations::Fixtures::Barcode.
|
5
|
+
DataMapper::Validations::Fixtures::Barcode.destroy!
|
6
6
|
|
7
7
|
@resource = DataMapper::Validations::Fixtures::Barcode.new
|
8
8
|
end
|
@@ -14,7 +14,7 @@ describe 'DataMapper::Resource' do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'should return true' do
|
17
|
-
@response.should
|
17
|
+
@response.should be(true)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -24,7 +24,7 @@ describe 'DataMapper::Resource' do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'should return false' do
|
27
|
-
@response.should
|
27
|
+
@response.should be(false)
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'should set errors' do
|
@@ -34,9 +34,9 @@ describe 'DataMapper::Resource' do
|
|
34
34
|
|
35
35
|
describe 'when provided invalid attributes and a context' do
|
36
36
|
before :all do
|
37
|
-
DataMapper::Validations::Fixtures::Organisation.
|
38
|
-
DataMapper::Validations::Fixtures::Department.
|
39
|
-
DataMapper::Validations::Fixtures::User.
|
37
|
+
DataMapper::Validations::Fixtures::Organisation.destroy!
|
38
|
+
DataMapper::Validations::Fixtures::Department.destroy!
|
39
|
+
DataMapper::Validations::Fixtures::User.destroy!
|
40
40
|
|
41
41
|
organization = DataMapper::Validations::Fixtures::Organisation.create(:name => 'Org 101', :domain => '101')
|
42
42
|
dept = DataMapper::Validations::Fixtures::Department.create(:name => 'accounting')
|
@@ -56,7 +56,7 @@ describe 'DataMapper::Resource' do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'should return false' do
|
59
|
-
@response.should
|
59
|
+
@response.should be(false)
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'should set errors' do
|
data/spec/rcov.opts
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -10,6 +10,7 @@ Pathname.glob((SPEC_ROOT + 'fixtures/**/*.rb').to_s).each { |file| require file
|
|
10
10
|
Pathname.glob((SPEC_ROOT + 'integration/shared/**/*.rb').to_s).each { |file| require file }
|
11
11
|
|
12
12
|
DataMapper::Spec.setup
|
13
|
+
DataMapper.finalize
|
13
14
|
|
14
15
|
Spec::Runner.configure do |config|
|
15
16
|
config.extend(DataMapper::Spec::Adapters::Helpers)
|
@@ -19,14 +19,14 @@ describe 'DataMapper::Validations::ContextualValidators' do
|
|
19
19
|
describe "when target satisfies all validators" do
|
20
20
|
before do
|
21
21
|
@target = DataMapper::Validations::Fixtures::PieceOfSoftware.new(:name => 'gcc', :operating_system => "Mac OS X")
|
22
|
-
@validator_one.call(@target).should
|
23
|
-
@validator_two.call(@target).should
|
22
|
+
@validator_one.call(@target).should be(true)
|
23
|
+
@validator_two.call(@target).should be(true)
|
24
24
|
|
25
25
|
@result = @model.execute(:default, @target)
|
26
26
|
end
|
27
27
|
|
28
28
|
it "returns true" do
|
29
|
-
@result.should
|
29
|
+
@result.should be(true)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -34,14 +34,14 @@ describe 'DataMapper::Validations::ContextualValidators' do
|
|
34
34
|
describe "when target does not satisfy all validators" do
|
35
35
|
before do
|
36
36
|
@target = DataMapper::Validations::Fixtures::PieceOfSoftware.new(:name => 'Skitch', :operating_system => "Haiku")
|
37
|
-
@validator_one.call(@target).should
|
38
|
-
@validator_two.call(@target).should
|
37
|
+
@validator_one.call(@target).should be(true)
|
38
|
+
@validator_two.call(@target).should be(false)
|
39
39
|
|
40
40
|
@result = @model.execute(:default, @target)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "returns true" do
|
44
|
-
@result.should
|
44
|
+
@result.should be(false)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
shared_examples_for 'a validation error reader' do
|
5
|
+
context 'and that property has no associated errors' do
|
6
|
+
it 'should return an empty array' do
|
7
|
+
@errors[@property].should == []
|
8
|
+
end
|
9
|
+
end
|
10
|
+
context 'and that property has associated error(s)' do
|
11
|
+
it 'should return a non empty array' do
|
12
|
+
@errors.add(@property.to_sym, 'invalid')
|
13
|
+
@errors[@property].should_not be_empty
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'DataMapper::Validations::ValidationErrors' do
|
19
|
+
describe '[]' do
|
20
|
+
describe 'when passing the argument as a String' do
|
21
|
+
before(:each) do
|
22
|
+
@errors = DataMapper::Validations::ValidationErrors.new(Object.new)
|
23
|
+
@property = 'name'
|
24
|
+
end
|
25
|
+
it_should_behave_like 'a validation error reader'
|
26
|
+
end
|
27
|
+
describe 'when passing the argument as a Symbol' do
|
28
|
+
before(:each) do
|
29
|
+
@errors = DataMapper::Validations::ValidationErrors.new(Object.new)
|
30
|
+
@property = :name
|
31
|
+
end
|
32
|
+
it_should_behave_like 'a validation error reader'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/tasks/spec.rake
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 977940572
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
9
|
- 0
|
10
|
-
-
|
11
|
-
version: 1.0.0.
|
10
|
+
- rc3
|
11
|
+
version: 1.0.0.rc3
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Guy van den Berg
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-05-
|
19
|
+
date: 2010-05-27 00:00:00 -07:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -27,13 +27,13 @@ dependencies:
|
|
27
27
|
requirements:
|
28
28
|
- - ~>
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
hash:
|
30
|
+
hash: 977940572
|
31
31
|
segments:
|
32
32
|
- 1
|
33
33
|
- 0
|
34
34
|
- 0
|
35
|
-
-
|
36
|
-
version: 1.0.0.
|
35
|
+
- rc3
|
36
|
+
version: 1.0.0.rc3
|
37
37
|
type: :runtime
|
38
38
|
version_requirements: *id001
|
39
39
|
- !ruby/object:Gem::Dependency
|
@@ -59,13 +59,13 @@ dependencies:
|
|
59
59
|
requirements:
|
60
60
|
- - ~>
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
hash:
|
62
|
+
hash: 977940572
|
63
63
|
segments:
|
64
64
|
- 1
|
65
65
|
- 0
|
66
66
|
- 0
|
67
|
-
-
|
68
|
-
version: 1.0.0.
|
67
|
+
- rc3
|
68
|
+
version: 1.0.0.rc3
|
69
69
|
type: :development
|
70
70
|
version_requirements: *id003
|
71
71
|
description: Library for performing validations on DM models and pure Ruby object
|
@@ -216,6 +216,7 @@ files:
|
|
216
216
|
- spec/unit/validation_errors/adding_spec.rb
|
217
217
|
- spec/unit/validation_errors/emptiness_spec.rb
|
218
218
|
- spec/unit/validation_errors/enumerable_spec.rb
|
219
|
+
- spec/unit/validation_errors/reading_spec.rb
|
219
220
|
- tasks/ci.rake
|
220
221
|
- tasks/local_gemfile.rake
|
221
222
|
- tasks/metrics.rake
|
@@ -223,7 +224,7 @@ files:
|
|
223
224
|
- tasks/yard.rake
|
224
225
|
- tasks/yardstick.rake
|
225
226
|
has_rdoc: true
|
226
|
-
homepage: http://github.com/datamapper/dm-
|
227
|
+
homepage: http://github.com/datamapper/dm-validations
|
227
228
|
licenses: []
|
228
229
|
|
229
230
|
post_install_message:
|
@@ -366,3 +367,4 @@ test_files:
|
|
366
367
|
- spec/unit/validation_errors/adding_spec.rb
|
367
368
|
- spec/unit/validation_errors/emptiness_spec.rb
|
368
369
|
- spec/unit/validation_errors/enumerable_spec.rb
|
370
|
+
- spec/unit/validation_errors/reading_spec.rb
|