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 CHANGED
@@ -71,7 +71,7 @@
71
71
  source 'http://rubygems.org'
72
72
 
73
73
  DATAMAPPER = 'git://github.com/datamapper'
74
- DM_VERSION = '~> 1.0.0.rc2'
74
+ DM_VERSION = '~> 1.0.0.rc3'
75
75
 
76
76
  group :runtime do # Runtime dependencies (as in the gemspec)
77
77
 
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/dm-more/tree/master/%s' % gem.name
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.rc2'
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.rc2'
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.rc2
1
+ 1.0.0.rc3
@@ -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.rc2"
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-19}
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-more/tree/master/dm-validations}
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.rc2"])
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.rc2"])
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.rc2"])
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.rc2"])
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.rc2"])
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.rc2"])
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
- cattr_writer :default_error_messages
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 be_true
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 be_false
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 be_true
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 be_true
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.all.destroy!
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.all.destroy!
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.all.destroy!
70
- DataMapper::Validations::Fixtures::Department.all.destroy!
71
- DataMapper::Validations::Fixtures::User.all.destroy!
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.all.destroy!
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 be_true
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 be_false
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.all.destroy!
38
- DataMapper::Validations::Fixtures::Department.all.destroy!
39
- DataMapper::Validations::Fixtures::User.all.destroy!
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 be_false
59
+ @response.should be(false)
60
60
  end
61
61
 
62
62
  it 'should set errors' do
data/spec/rcov.opts CHANGED
@@ -1,4 +1,4 @@
1
- --exclude "spec"
1
+ --exclude "spec,^/"
2
2
  --sort coverage
3
3
  --callsites
4
4
  --xrefs
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 be_true
23
- @validator_two.call(@target).should be_true
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 be_true
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 be_true
38
- @validator_two.call(@target).should be_false
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 be_false
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
@@ -35,4 +35,7 @@ rescue LoadError
35
35
  end
36
36
  end
37
37
 
38
+ task :spec => :check_dependencies
39
+ task :rcov => :check_dependencies
40
+
38
41
  task :default => :spec
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: 977940575
4
+ hash: 977940572
5
5
  prerelease: true
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
9
  - 0
10
- - rc2
11
- version: 1.0.0.rc2
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 00:00:00 -07:00
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: 977940575
30
+ hash: 977940572
31
31
  segments:
32
32
  - 1
33
33
  - 0
34
34
  - 0
35
- - rc2
36
- version: 1.0.0.rc2
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: 977940575
62
+ hash: 977940572
63
63
  segments:
64
64
  - 1
65
65
  - 0
66
66
  - 0
67
- - rc2
68
- version: 1.0.0.rc2
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-more/tree/master/dm-validations
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