dm-validations 0.10.2 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +36 -0
- data/Gemfile +143 -0
- data/README.rdoc +52 -102
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/dm-validations.gemspec +126 -14
- data/lib/dm-validations.rb +78 -18
- data/lib/dm-validations/auto_validate.rb +27 -23
- data/lib/dm-validations/contextual_validators.rb +3 -3
- data/lib/dm-validations/formats/email.rb +3 -3
- data/lib/dm-validations/formats/url.rb +3 -3
- data/lib/dm-validations/support/context.rb +1 -1
- data/lib/dm-validations/validation_errors.rb +5 -7
- data/lib/dm-validations/validators/absent_field_validator.rb +13 -9
- data/lib/dm-validations/validators/acceptance_validator.rb +10 -7
- data/lib/dm-validations/validators/block_validator.rb +3 -3
- data/lib/dm-validations/validators/confirmation_validator.rb +10 -7
- data/lib/dm-validations/validators/format_validator.rb +14 -10
- data/lib/dm-validations/validators/generic_validator.rb +3 -3
- data/lib/dm-validations/validators/length_validator.rb +10 -7
- data/lib/dm-validations/validators/method_validator.rb +3 -3
- data/lib/dm-validations/validators/numeric_validator.rb +25 -14
- data/lib/dm-validations/validators/primitive_validator.rb +12 -8
- data/lib/dm-validations/validators/required_field_validator.rb +12 -9
- data/lib/dm-validations/validators/uniqueness_validator.rb +9 -6
- data/lib/dm-validations/validators/within_validator.rb +3 -3
- data/spec/fixtures/barcode.rb +10 -2
- data/spec/fixtures/basketball_court.rb +7 -7
- data/spec/fixtures/basketball_player.rb +3 -3
- data/spec/fixtures/beta_tester_account.rb +4 -4
- data/spec/fixtures/bill_of_landing.rb +7 -7
- data/spec/fixtures/boat_dock.rb +2 -2
- data/spec/fixtures/city.rb +1 -1
- data/spec/fixtures/company.rb +7 -7
- data/spec/fixtures/corporate_world.rb +24 -26
- data/spec/fixtures/country.rb +1 -1
- data/spec/fixtures/currency.rb +4 -4
- data/spec/fixtures/ethernet_frame.rb +5 -5
- data/spec/fixtures/event.rb +2 -2
- data/spec/fixtures/g3_concert.rb +3 -3
- data/spec/fixtures/jabberwock.rb +2 -2
- data/spec/fixtures/kayak.rb +2 -2
- data/spec/fixtures/lernean_hydra.rb +3 -3
- data/spec/fixtures/mathematical_function.rb +2 -2
- data/spec/fixtures/memory_object.rb +3 -3
- data/spec/fixtures/mittelschnauzer.rb +3 -3
- data/spec/fixtures/motor_launch.rb +1 -1
- data/spec/fixtures/page.rb +3 -3
- data/spec/fixtures/phone_number.rb +2 -2
- data/spec/fixtures/pirogue.rb +2 -2
- data/spec/fixtures/programming_language.rb +3 -3
- data/spec/fixtures/reservation.rb +5 -5
- data/spec/fixtures/scm_operation.rb +42 -45
- data/spec/fixtures/sms_message.rb +1 -1
- data/spec/fixtures/udp_packet.rb +3 -3
- data/spec/integration/absent_field_validator/absent_field_validator_spec.rb +6 -6
- data/spec/integration/acceptance_validator/acceptance_validator_spec.rb +3 -3
- data/spec/integration/automatic_validation/inferred_length_validation_spec.rb +5 -5
- data/spec/integration/automatic_validation/spec_helper.rb +1 -1
- data/spec/integration/block_validator/block_validator_spec.rb +2 -2
- data/spec/integration/conditional_validation/if_condition_spec.rb +3 -3
- data/spec/integration/confirmation_validator/confirmation_validator_spec.rb +3 -3
- data/spec/integration/datamapper_models/association_validation_spec.rb +5 -5
- data/spec/integration/datamapper_models/inheritance_spec.rb +6 -6
- data/spec/integration/duplicated_validations/duplicated_validations_spec.rb +3 -3
- data/spec/integration/format_validator/email_format_validator_spec.rb +6 -6
- data/spec/integration/format_validator/format_validator_spec.rb +8 -8
- data/spec/integration/format_validator/regexp_validator_spec.rb +4 -4
- data/spec/integration/format_validator/url_format_validator_spec.rb +4 -4
- data/spec/integration/length_validator/default_value_spec.rb +3 -3
- data/spec/integration/length_validator/equality_spec.rb +4 -4
- data/spec/integration/length_validator/error_message_spec.rb +3 -3
- data/spec/integration/length_validator/maximum_spec.rb +3 -3
- data/spec/integration/length_validator/minimum_spec.rb +3 -3
- data/spec/integration/length_validator/range_spec.rb +3 -3
- data/spec/integration/method_validator/method_validator_spec.rb +8 -8
- data/spec/integration/numeric_validator/equality_with_float_type_spec.rb +7 -7
- data/spec/integration/numeric_validator/equality_with_integer_type_spec.rb +5 -5
- data/spec/integration/numeric_validator/float_type_spec.rb +3 -3
- data/spec/integration/numeric_validator/gt_with_float_type_spec.rb +3 -3
- data/spec/integration/numeric_validator/gte_with_float_type_spec.rb +3 -3
- data/spec/integration/numeric_validator/lt_with_float_type_spec.rb +3 -3
- data/spec/integration/numeric_validator/lte_with_float_type_spec.rb +3 -3
- data/spec/integration/primitive_validator/primitive_validator_spec.rb +4 -4
- data/spec/integration/pure_ruby_objects/plain_old_ruby_object_validation_spec.rb +4 -4
- data/spec/integration/required_field_validator/association_spec.rb +19 -51
- data/spec/integration/required_field_validator/boolean_type_value_spec.rb +4 -1
- data/spec/integration/required_field_validator/date_type_value_spec.rb +4 -2
- data/spec/integration/required_field_validator/datetime_type_value_spec.rb +4 -2
- data/spec/integration/required_field_validator/float_type_value_spec.rb +4 -2
- data/spec/integration/required_field_validator/integer_type_value_spec.rb +4 -2
- data/spec/integration/required_field_validator/plain_old_ruby_object_spec.rb +6 -4
- data/spec/integration/required_field_validator/string_type_value_spec.rb +3 -1
- data/spec/integration/required_field_validator/text_type_value_spec.rb +3 -1
- data/spec/integration/shared/valid_and_invalid_model.rb +8 -0
- data/spec/integration/uniqueness_validator/uniqueness_validator_spec.rb +29 -25
- data/spec/integration/within_validator/within_validator_spec.rb +6 -6
- data/spec/public/resource_spec.rb +47 -9
- data/spec/spec_helper.rb +13 -27
- data/spec/unit/contextual_validators/emptiness_spec.rb +4 -4
- data/spec/unit/contextual_validators/execution_spec.rb +6 -6
- data/spec/unit/contextual_validators/spec_helper.rb +3 -3
- data/spec/unit/generic_validator/equality_operator_spec.rb +7 -7
- data/spec/unit/validation_errors/adding_spec.rb +2 -2
- data/spec/unit/validation_errors/emptiness_spec.rb +2 -2
- data/spec/unit/validation_errors/enumerable_spec.rb +2 -2
- data/tasks/local_gemfile.rake +18 -0
- data/tasks/spec.rake +0 -3
- metadata +157 -25
data/.gitignore
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
## MAC OS
|
2
|
+
.DS_Store
|
3
|
+
|
4
|
+
## TEXTMATE
|
5
|
+
*.tmproj
|
6
|
+
tmtags
|
7
|
+
|
8
|
+
## EMACS
|
9
|
+
*~
|
10
|
+
\#*
|
11
|
+
.\#*
|
12
|
+
|
13
|
+
## VIM
|
14
|
+
*.swp
|
15
|
+
|
16
|
+
## Rubinius
|
17
|
+
*.rbc
|
18
|
+
|
19
|
+
## PROJECT::GENERAL
|
20
|
+
*.gem
|
21
|
+
coverage
|
22
|
+
rdoc
|
23
|
+
pkg
|
24
|
+
tmp
|
25
|
+
doc
|
26
|
+
log
|
27
|
+
.yardoc
|
28
|
+
measurements
|
29
|
+
|
30
|
+
## BUNDLER
|
31
|
+
.bundle
|
32
|
+
Gemfile.local
|
33
|
+
Gemfile.lock
|
34
|
+
|
35
|
+
## PROJECT::SPECIFIC
|
36
|
+
spec/db/
|
data/Gemfile
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
# If you're working on more than one datamapper gem at a time, then it's
|
2
|
+
# recommended to create a local Gemfile and use this instead of the git
|
3
|
+
# sources. This will make sure that you are developing against your
|
4
|
+
# other local datamapper sources that you currently work on. Gemfile.local
|
5
|
+
# will behave identically to the standard Gemfile apart from the fact that
|
6
|
+
# it fetches the datamapper gems from local paths. This means that you can use
|
7
|
+
# the same environment variables, like ADAPTER(S) or PLUGIN(S) when running
|
8
|
+
# bundle commands. Gemfile.local is added to .gitignore, so you don't need to
|
9
|
+
# worry about accidentally checking local development paths into git.
|
10
|
+
# In order to create a local Gemfile, all you need to do is run:
|
11
|
+
#
|
12
|
+
# bundle exec rake local_gemfile
|
13
|
+
#
|
14
|
+
# This will give you a Gemfile.local file that points to your local clones of
|
15
|
+
# the various datamapper gems. It's assumed that all datamapper repo clones
|
16
|
+
# reside in the same directory. You can use the Gemfile.local like so for
|
17
|
+
# running any bundle command:
|
18
|
+
#
|
19
|
+
# BUNDLE_GEMFILE=Gemfile.local bundle foo
|
20
|
+
#
|
21
|
+
# You can also specify which adapter(s) should be part of the bundle by setting
|
22
|
+
# an environment variable. This of course also works when using the Gemfile.local
|
23
|
+
#
|
24
|
+
# bundle foo # dm-sqlite-adapter
|
25
|
+
# ADAPTER=mysql bundle foo # dm-mysql-adapter
|
26
|
+
# ADAPTERS=sqlite,mysql bundle foo # dm-sqlite-adapter and dm-mysql-adapter
|
27
|
+
#
|
28
|
+
# Of course you can also use the ADAPTER(S) variable when using the Gemfile.local
|
29
|
+
# and running specs against selected adapters.
|
30
|
+
#
|
31
|
+
# For easily working with adapters supported on your machine, it's recommended
|
32
|
+
# that you first install all adapters that you are planning to use or work on
|
33
|
+
# by doing something like
|
34
|
+
#
|
35
|
+
# ADAPTERS=sqlite,mysql,postgres bundle install
|
36
|
+
#
|
37
|
+
# This will clone the various repositories and make them available to bundler.
|
38
|
+
# Once you have them installed you can easily switch between adapters for the
|
39
|
+
# various development tasks. Running something like
|
40
|
+
#
|
41
|
+
# ADAPTER=mysql bundle exec rake spec
|
42
|
+
#
|
43
|
+
# will make sure that the dm-mysql-adapter is part of the bundle, and will be used
|
44
|
+
# when running the specs.
|
45
|
+
#
|
46
|
+
# You can also specify which plugin(s) should be part of the bundle by setting
|
47
|
+
# an environment variable. This also works when using the Gemfile.local
|
48
|
+
#
|
49
|
+
# bundle foo # dm-migrations
|
50
|
+
# PLUGINS=dm-validations bundle foo # dm-migrations and dm-validations
|
51
|
+
# PLUGINS=dm-validations,dm-types bundle foo # dm-migrations, dm-validations and dm-types
|
52
|
+
#
|
53
|
+
# Of course you can combine the PLUGIN(S) and ADAPTER(S) env vars to run specs
|
54
|
+
# for certain adapter/plugin combinations.
|
55
|
+
#
|
56
|
+
# Finally, to speed up running specs and other tasks, it's recommended to run
|
57
|
+
#
|
58
|
+
# bundle lock
|
59
|
+
#
|
60
|
+
# after running 'bundle install' for the first time. This will make 'bundle exec' run
|
61
|
+
# a lot faster compared to the unlocked version. With an unlocked bundle you would
|
62
|
+
# typically just run 'bundle install' from time to time to fetch the latest sources from
|
63
|
+
# upstream. When you locked your bundle, you need to run
|
64
|
+
#
|
65
|
+
# bundle install --relock
|
66
|
+
#
|
67
|
+
# to make sure to fetch the latest updates and then lock the bundle again. Gemfile.lock
|
68
|
+
# is added to the .gitignore file, so you don't need to worry about accidentally checking
|
69
|
+
# it into version control.
|
70
|
+
|
71
|
+
source 'http://rubygems.org'
|
72
|
+
|
73
|
+
DATAMAPPER = 'git://github.com/datamapper'
|
74
|
+
DM_VERSION = '~> 1.0.0.rc1'
|
75
|
+
|
76
|
+
group :runtime do # Runtime dependencies (as in the gemspec)
|
77
|
+
|
78
|
+
if ENV['EXTLIB']
|
79
|
+
gem 'extlib', '~> 0.9.15', :git => "#{DATAMAPPER}/extlib.git"
|
80
|
+
else
|
81
|
+
gem 'activesupport', '~> 3.0.0.beta3', :git => 'git://github.com/rails/rails.git', :require => nil
|
82
|
+
end
|
83
|
+
|
84
|
+
gem 'dm-core', DM_VERSION, :git => "#{DATAMAPPER}/dm-core.git"
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
group(:development) do # Development dependencies (as in the gemspec)
|
89
|
+
|
90
|
+
gem 'dm-types', DM_VERSION, :git => "#{DATAMAPPER}/dm-types.git"
|
91
|
+
|
92
|
+
gem 'rake', '~> 0.8.7'
|
93
|
+
gem 'rspec', '~> 1.3'
|
94
|
+
gem 'jeweler', '~> 1.4'
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
group :quality do # These gems contain rake tasks that check the quality of the source code
|
99
|
+
|
100
|
+
gem 'metric_fu', '~> 1.3'
|
101
|
+
gem 'rcov', '~> 0.9.7'
|
102
|
+
gem 'reek', '~> 1.2.7'
|
103
|
+
gem 'roodi', '~> 2.1'
|
104
|
+
gem 'yard', '~> 0.5'
|
105
|
+
gem 'yardstick', '~> 0.1'
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
group :datamapper do # We need this because we want to pin these dependencies to their git master sources
|
110
|
+
|
111
|
+
adapters = ENV['ADAPTER'] || ENV['ADAPTERS']
|
112
|
+
adapters = adapters.to_s.gsub(',',' ').split(' ') - ['in_memory']
|
113
|
+
|
114
|
+
unless adapters.empty?
|
115
|
+
|
116
|
+
DO_VERSION = '~> 0.10.2'
|
117
|
+
DM_DO_ADAPTERS = %w[sqlite postgres mysql oracle sqlserver]
|
118
|
+
|
119
|
+
gem 'data_objects', DO_VERSION, :git => "#{DATAMAPPER}/do.git"
|
120
|
+
|
121
|
+
adapters.each do |adapter|
|
122
|
+
if DM_DO_ADAPTERS.any? { |dm_do_adapter| dm_do_adapter =~ /#{adapter}/ }
|
123
|
+
adapter = 'sqlite3' if adapter == 'sqlite'
|
124
|
+
gem "do_#{adapter}", DO_VERSION, :git => "#{DATAMAPPER}/do.git"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
gem 'dm-do-adapter', DM_VERSION, :git => "#{DATAMAPPER}/dm-do-adapter.git"
|
129
|
+
|
130
|
+
adapters.each do |adapter|
|
131
|
+
gem "dm-#{adapter}-adapter", DM_VERSION, :git => "#{DATAMAPPER}/dm-#{adapter}-adapter.git"
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
plugins = ENV['PLUGINS'] || ENV['PLUGIN']
|
137
|
+
plugins = (plugins.to_s.gsub(',',' ').split(' ') + ['dm-migrations']).uniq
|
138
|
+
|
139
|
+
plugins.each do |plugin|
|
140
|
+
gem plugin, DM_VERSION, :git => "#{DATAMAPPER}/#{plugin}.git"
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
data/README.rdoc
CHANGED
@@ -1,75 +1,41 @@
|
|
1
|
-
This is a DataMapper plugin that provides validations for DataMapper model
|
2
|
-
classes.
|
1
|
+
This is a DataMapper plugin that provides validations for DataMapper model classes.
|
3
2
|
|
4
3
|
== Setup
|
5
|
-
DataMapper validation capabilities are automatically available for DataMapper
|
6
|
-
resources when you require dm-validations' into your application. For
|
7
|
-
pure Ruby classes, require 'dm-validations' and then include DataMapper::Validate
|
8
|
-
module like so:
|
9
|
-
|
10
|
-
class ProgrammingLanguage
|
11
|
-
#
|
12
|
-
# Behaviors
|
13
|
-
#
|
14
|
-
|
15
|
-
include ::DataMapper::Validate
|
16
|
-
|
17
|
-
#
|
18
|
-
# Accessors
|
19
|
-
#
|
20
|
-
|
21
|
-
attr_accessor :name, :allows_manual_memory_management, :allows_optional_parentheses
|
22
|
-
|
23
|
-
#
|
24
|
-
# Validations
|
25
|
-
#
|
26
|
-
|
27
|
-
validates_present :name
|
28
|
-
validates_with_method :ensure_allows_optional_parentheses, :when => [:implementing_a_dsl]
|
29
|
-
validates_with_method :ensure_allows_manual_memory_management, :when => [:doing_system_programming]
|
30
|
-
end
|
31
|
-
|
4
|
+
DataMapper validation capabilities are automatically available for DataMapper resources when you require dm-validations' in your application. There is no need to manually include anything, every DataMapper::Resource will be able to handle validations once this gem got required.
|
32
5
|
|
33
6
|
== Specifying Model Validations
|
34
|
-
There are two primary ways to implement validations for your models:
|
35
|
-
|
36
|
-
1) Placing validation methods with properties as params in your class
|
37
|
-
definitions like:
|
38
|
-
- validates_length :name
|
39
|
-
- validates_length [:name, :description]
|
40
7
|
|
41
|
-
|
8
|
+
There are two primary ways to implement validations for your models
|
42
9
|
|
43
|
-
|
10
|
+
1) Placing validation methods with properties as params in your class
|
44
11
|
|
12
|
+
require 'dm-core'
|
45
13
|
require 'dm-validations'
|
46
14
|
|
47
|
-
class
|
15
|
+
class ProgrammingLanguage
|
48
16
|
include DataMapper::Resource
|
49
|
-
|
50
17
|
property :name, String
|
51
|
-
|
18
|
+
validates_presence_of :name
|
19
|
+
end
|
20
|
+
|
21
|
+
2) Using auto-validations, please see DataMapper::Validations::AutoValidations. Note that not all validations that are provided via validation methods, are also available as autovalidation options. If they are available, they're functionally equivalent though.
|
22
|
+
|
23
|
+
class ProgrammingLanguage
|
24
|
+
include DataMapper::Resource
|
25
|
+
property :name, String, :required => true
|
52
26
|
end
|
53
27
|
|
54
|
-
See all of the DataMapper::Validate module's XYZValidator(s) to learn about the
|
55
|
-
complete collections of validators available to you.
|
28
|
+
See all of the DataMapper::Validate module's XYZValidator(s) to learn about the complete collections of validators available to you.
|
56
29
|
|
57
30
|
== Validating
|
58
|
-
DataMapper validations, when included, alter the default save/create/update
|
59
|
-
process for a model. Unless you specify a context the resource must be
|
60
|
-
valid in the :default context before saving.
|
61
31
|
|
62
|
-
|
63
|
-
return true if the resource is valid, and false if it is invalid.
|
32
|
+
DataMapper validations, when included, alter the default save/create/update process for a model. Unless you specify a context the resource must be valid in the :default context before saving.
|
64
33
|
|
65
|
-
|
66
|
-
recursively walks both the current object and its associated objects and returns
|
67
|
-
its true/false result for the entire walk.
|
34
|
+
You may manually validate a resource using the valid? method, which will return true if the resource is valid, and false if it is invalid.
|
68
35
|
|
69
36
|
== Working with Validation Errors
|
70
|
-
|
71
|
-
DataMapper::
|
72
|
-
your models via calls to your model's errors method.
|
37
|
+
|
38
|
+
If your validators find errors in your model, they will populate the DataMapper::Validations::ValidationErrors object that is available through each of your models via calls to your model's errors method.
|
73
39
|
|
74
40
|
For example:
|
75
41
|
|
@@ -82,7 +48,7 @@ For example:
|
|
82
48
|
end
|
83
49
|
end
|
84
50
|
|
85
|
-
See DataMapper::
|
51
|
+
See DataMapper::Validations::ValidationErrors for all you can do with your model's
|
86
52
|
errors method.
|
87
53
|
|
88
54
|
== Contextual Validations
|
@@ -95,35 +61,32 @@ for publishing, exporting, importing and so on.
|
|
95
61
|
|
96
62
|
Again, using our example for pure Ruby class validations:
|
97
63
|
|
98
|
-
class ProgrammingLanguage
|
99
|
-
#
|
100
|
-
# Behaviors
|
101
|
-
#
|
64
|
+
class ProgrammingLanguage
|
102
65
|
|
103
|
-
|
66
|
+
include DataMapper::Resource
|
104
67
|
|
105
|
-
|
106
|
-
# Accessors
|
107
|
-
#
|
68
|
+
property :name, String
|
108
69
|
|
109
|
-
|
70
|
+
def ensure_allows_manual_memory_management
|
71
|
+
# ...
|
72
|
+
end
|
110
73
|
|
111
|
-
|
112
|
-
|
113
|
-
|
74
|
+
def ensure_allows_optional_parentheses
|
75
|
+
# ...
|
76
|
+
end
|
114
77
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
end
|
78
|
+
validates_presence_of :name
|
79
|
+
validates_with_method :ensure_allows_optional_parentheses, :when => [:implementing_a_dsl]
|
80
|
+
validates_with_method :ensure_allows_manual_memory_management, :when => [:doing_system_programming]
|
81
|
+
end
|
119
82
|
|
120
83
|
ProgrammingLanguage instance now use #valid? method with one of two context symbols:
|
121
84
|
|
122
|
-
@ruby.valid?(:implementing_a_dsl) # => true
|
123
|
-
@ruby.valid?(:doing_system_programming) # => false
|
85
|
+
@ruby.valid?(:implementing_a_dsl) # => true
|
86
|
+
@ruby.valid?(:doing_system_programming) # => false
|
124
87
|
|
125
|
-
@c.valid?(:implementing_a_dsl) # => false
|
126
|
-
@c.valid?(:doing_system_programming) # => true
|
88
|
+
@c.valid?(:implementing_a_dsl) # => false
|
89
|
+
@c.valid?(:doing_system_programming) # => true
|
127
90
|
|
128
91
|
Each context causes different set of validations to be triggered. If you don't
|
129
92
|
specify a context using :when, :on or :group options (they are all aliases and do
|
@@ -131,41 +94,28 @@ the same thing), default context name is :default. When you do model.valid? (wit
|
|
131
94
|
specifying context explicitly), again, :default context is used. One validation
|
132
95
|
can be used in two, three or five contexts if you like:
|
133
96
|
|
134
|
-
class Book
|
135
|
-
|
136
|
-
#
|
137
|
-
# Behaviors
|
138
|
-
#
|
139
|
-
|
140
|
-
# this time it is a DM model
|
141
|
-
include ::DataMapper::Resource
|
142
|
-
|
143
|
-
#
|
144
|
-
# Accessors
|
145
|
-
#
|
97
|
+
class Book
|
146
98
|
|
147
|
-
|
148
|
-
property :name, String
|
99
|
+
include ::DataMapper::Resource
|
149
100
|
|
150
|
-
|
151
|
-
|
101
|
+
property :id, Serial
|
102
|
+
property :name, String
|
152
103
|
|
153
|
-
|
154
|
-
|
155
|
-
#
|
104
|
+
property :agreed_title, String
|
105
|
+
property :finished_toc, Boolean
|
156
106
|
|
157
|
-
|
158
|
-
|
159
|
-
|
107
|
+
# used in all contexts, including default
|
108
|
+
validates_presence_of :name, :when => [:default, :sending_to_print]
|
109
|
+
validates_presence_of :agreed_title, :when => [:sending_to_print]
|
160
110
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
111
|
+
validates_with_block :toc, :when => [:sending_to_print] do
|
112
|
+
if self.finished_toc
|
113
|
+
[true]
|
114
|
+
else
|
115
|
+
[false, "TOC must be finalized before you send a book to print"]
|
116
|
+
end
|
166
117
|
end
|
167
118
|
end
|
168
|
-
end
|
169
119
|
|
170
120
|
In the example above, name is validated for presence in both :default context and
|
171
121
|
:sending_to_print context, while TOC related block validation and title presence validation
|
data/Rakefile
CHANGED
@@ -15,10 +15,10 @@ begin
|
|
15
15
|
|
16
16
|
gem.rubyforge_project = 'datamapper'
|
17
17
|
|
18
|
-
gem.add_dependency 'dm-core', '~> 0.
|
18
|
+
gem.add_dependency 'dm-core', '~> 1.0.0.rc1'
|
19
19
|
|
20
|
-
gem.add_development_dependency 'rspec',
|
21
|
-
gem.add_development_dependency '
|
20
|
+
gem.add_development_dependency 'rspec', '~> 1.3'
|
21
|
+
gem.add_development_dependency 'dm-types', '~> 1.0.0.rc1'
|
22
22
|
end
|
23
23
|
|
24
24
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.0.rc1
|
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 = "0.
|
8
|
+
s.version = "1.0.0.rc1"
|
9
9
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
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{
|
12
|
+
s.date = %q{2010-05-19}
|
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 = [
|
@@ -17,7 +17,9 @@ Gem::Specification.new do |s|
|
|
17
17
|
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
|
-
"
|
20
|
+
".gitignore",
|
21
|
+
"Gemfile",
|
22
|
+
"LICENSE",
|
21
23
|
"README.rdoc",
|
22
24
|
"Rakefile",
|
23
25
|
"VERSION",
|
@@ -154,6 +156,7 @@ Gem::Specification.new do |s|
|
|
154
156
|
"spec/unit/validation_errors/emptiness_spec.rb",
|
155
157
|
"spec/unit/validation_errors/enumerable_spec.rb",
|
156
158
|
"tasks/ci.rake",
|
159
|
+
"tasks/local_gemfile.rake",
|
157
160
|
"tasks/metrics.rake",
|
158
161
|
"tasks/spec.rake",
|
159
162
|
"tasks/yard.rake",
|
@@ -163,26 +166,135 @@ Gem::Specification.new do |s|
|
|
163
166
|
s.rdoc_options = ["--charset=UTF-8"]
|
164
167
|
s.require_paths = ["lib"]
|
165
168
|
s.rubyforge_project = %q{datamapper}
|
166
|
-
s.rubygems_version = %q{1.3.
|
169
|
+
s.rubygems_version = %q{1.3.6}
|
167
170
|
s.summary = %q{Library for performing validations on DM models and pure Ruby object}
|
171
|
+
s.test_files = [
|
172
|
+
"spec/fixtures/barcode.rb",
|
173
|
+
"spec/fixtures/basketball_court.rb",
|
174
|
+
"spec/fixtures/basketball_player.rb",
|
175
|
+
"spec/fixtures/beta_tester_account.rb",
|
176
|
+
"spec/fixtures/bill_of_landing.rb",
|
177
|
+
"spec/fixtures/boat_dock.rb",
|
178
|
+
"spec/fixtures/city.rb",
|
179
|
+
"spec/fixtures/company.rb",
|
180
|
+
"spec/fixtures/corporate_world.rb",
|
181
|
+
"spec/fixtures/country.rb",
|
182
|
+
"spec/fixtures/currency.rb",
|
183
|
+
"spec/fixtures/ethernet_frame.rb",
|
184
|
+
"spec/fixtures/event.rb",
|
185
|
+
"spec/fixtures/g3_concert.rb",
|
186
|
+
"spec/fixtures/jabberwock.rb",
|
187
|
+
"spec/fixtures/kayak.rb",
|
188
|
+
"spec/fixtures/lernean_hydra.rb",
|
189
|
+
"spec/fixtures/mathematical_function.rb",
|
190
|
+
"spec/fixtures/memory_object.rb",
|
191
|
+
"spec/fixtures/mittelschnauzer.rb",
|
192
|
+
"spec/fixtures/motor_launch.rb",
|
193
|
+
"spec/fixtures/page.rb",
|
194
|
+
"spec/fixtures/phone_number.rb",
|
195
|
+
"spec/fixtures/pirogue.rb",
|
196
|
+
"spec/fixtures/programming_language.rb",
|
197
|
+
"spec/fixtures/reservation.rb",
|
198
|
+
"spec/fixtures/scm_operation.rb",
|
199
|
+
"spec/fixtures/sms_message.rb",
|
200
|
+
"spec/fixtures/udp_packet.rb",
|
201
|
+
"spec/integration/absent_field_validator/absent_field_validator_spec.rb",
|
202
|
+
"spec/integration/absent_field_validator/spec_helper.rb",
|
203
|
+
"spec/integration/acceptance_validator/acceptance_validator_spec.rb",
|
204
|
+
"spec/integration/acceptance_validator/spec_helper.rb",
|
205
|
+
"spec/integration/automatic_validation/custom_messages_for_inferred_validation_spec.rb",
|
206
|
+
"spec/integration/automatic_validation/disabling_inferred_validation_spec.rb",
|
207
|
+
"spec/integration/automatic_validation/inferred_boolean_properties_validation_spec.rb",
|
208
|
+
"spec/integration/automatic_validation/inferred_float_property_validation_spec.rb",
|
209
|
+
"spec/integration/automatic_validation/inferred_format_validation_spec.rb",
|
210
|
+
"spec/integration/automatic_validation/inferred_integer_properties_validation_spec.rb",
|
211
|
+
"spec/integration/automatic_validation/inferred_length_validation_spec.rb",
|
212
|
+
"spec/integration/automatic_validation/inferred_presence_validation_spec.rb",
|
213
|
+
"spec/integration/automatic_validation/inferred_primitive_validation_spec.rb",
|
214
|
+
"spec/integration/automatic_validation/inferred_within_validation_spec.rb",
|
215
|
+
"spec/integration/automatic_validation/spec_helper.rb",
|
216
|
+
"spec/integration/block_validator/block_validator_spec.rb",
|
217
|
+
"spec/integration/block_validator/spec_helper.rb",
|
218
|
+
"spec/integration/conditional_validation/if_condition_spec.rb",
|
219
|
+
"spec/integration/conditional_validation/spec_helper.rb",
|
220
|
+
"spec/integration/confirmation_validator/confirmation_validator_spec.rb",
|
221
|
+
"spec/integration/confirmation_validator/spec_helper.rb",
|
222
|
+
"spec/integration/datamapper_models/association_validation_spec.rb",
|
223
|
+
"spec/integration/datamapper_models/inheritance_spec.rb",
|
224
|
+
"spec/integration/duplicated_validations/duplicated_validations_spec.rb",
|
225
|
+
"spec/integration/duplicated_validations/spec_helper.rb",
|
226
|
+
"spec/integration/format_validator/email_format_validator_spec.rb",
|
227
|
+
"spec/integration/format_validator/format_validator_spec.rb",
|
228
|
+
"spec/integration/format_validator/regexp_validator_spec.rb",
|
229
|
+
"spec/integration/format_validator/spec_helper.rb",
|
230
|
+
"spec/integration/format_validator/url_format_validator_spec.rb",
|
231
|
+
"spec/integration/length_validator/default_value_spec.rb",
|
232
|
+
"spec/integration/length_validator/equality_spec.rb",
|
233
|
+
"spec/integration/length_validator/error_message_spec.rb",
|
234
|
+
"spec/integration/length_validator/maximum_spec.rb",
|
235
|
+
"spec/integration/length_validator/minimum_spec.rb",
|
236
|
+
"spec/integration/length_validator/range_spec.rb",
|
237
|
+
"spec/integration/length_validator/spec_helper.rb",
|
238
|
+
"spec/integration/method_validator/method_validator_spec.rb",
|
239
|
+
"spec/integration/method_validator/spec_helper.rb",
|
240
|
+
"spec/integration/numeric_validator/equality_with_float_type_spec.rb",
|
241
|
+
"spec/integration/numeric_validator/equality_with_integer_type_spec.rb",
|
242
|
+
"spec/integration/numeric_validator/float_type_spec.rb",
|
243
|
+
"spec/integration/numeric_validator/gt_with_float_type_spec.rb",
|
244
|
+
"spec/integration/numeric_validator/gte_with_float_type_spec.rb",
|
245
|
+
"spec/integration/numeric_validator/integer_only_true_spec.rb",
|
246
|
+
"spec/integration/numeric_validator/integer_type_spec.rb",
|
247
|
+
"spec/integration/numeric_validator/lt_with_float_type_spec.rb",
|
248
|
+
"spec/integration/numeric_validator/lte_with_float_type_spec.rb",
|
249
|
+
"spec/integration/numeric_validator/spec_helper.rb",
|
250
|
+
"spec/integration/primitive_validator/primitive_validator_spec.rb",
|
251
|
+
"spec/integration/primitive_validator/spec_helper.rb",
|
252
|
+
"spec/integration/pure_ruby_objects/plain_old_ruby_object_validation_spec.rb",
|
253
|
+
"spec/integration/required_field_validator/association_spec.rb",
|
254
|
+
"spec/integration/required_field_validator/boolean_type_value_spec.rb",
|
255
|
+
"spec/integration/required_field_validator/date_type_value_spec.rb",
|
256
|
+
"spec/integration/required_field_validator/datetime_type_value_spec.rb",
|
257
|
+
"spec/integration/required_field_validator/float_type_value_spec.rb",
|
258
|
+
"spec/integration/required_field_validator/integer_type_value_spec.rb",
|
259
|
+
"spec/integration/required_field_validator/plain_old_ruby_object_spec.rb",
|
260
|
+
"spec/integration/required_field_validator/shared_examples.rb",
|
261
|
+
"spec/integration/required_field_validator/spec_helper.rb",
|
262
|
+
"spec/integration/required_field_validator/string_type_value_spec.rb",
|
263
|
+
"spec/integration/required_field_validator/text_type_value_spec.rb",
|
264
|
+
"spec/integration/shared/default_validation_context.rb",
|
265
|
+
"spec/integration/shared/valid_and_invalid_model.rb",
|
266
|
+
"spec/integration/uniqueness_validator/spec_helper.rb",
|
267
|
+
"spec/integration/uniqueness_validator/uniqueness_validator_spec.rb",
|
268
|
+
"spec/integration/within_validator/spec_helper.rb",
|
269
|
+
"spec/integration/within_validator/within_validator_spec.rb",
|
270
|
+
"spec/public/resource_spec.rb",
|
271
|
+
"spec/spec_helper.rb",
|
272
|
+
"spec/unit/contextual_validators/emptiness_spec.rb",
|
273
|
+
"spec/unit/contextual_validators/execution_spec.rb",
|
274
|
+
"spec/unit/contextual_validators/spec_helper.rb",
|
275
|
+
"spec/unit/generic_validator/equality_operator_spec.rb",
|
276
|
+
"spec/unit/validation_errors/adding_spec.rb",
|
277
|
+
"spec/unit/validation_errors/emptiness_spec.rb",
|
278
|
+
"spec/unit/validation_errors/enumerable_spec.rb"
|
279
|
+
]
|
168
280
|
|
169
281
|
if s.respond_to? :specification_version then
|
170
282
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
171
283
|
s.specification_version = 3
|
172
284
|
|
173
285
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
174
|
-
s.add_runtime_dependency(%q<dm-core>, ["~> 0.
|
175
|
-
s.add_development_dependency(%q<rspec>, ["~> 1.
|
176
|
-
s.add_development_dependency(%q<
|
286
|
+
s.add_runtime_dependency(%q<dm-core>, ["~> 1.0.0.rc1"])
|
287
|
+
s.add_development_dependency(%q<rspec>, ["~> 1.3"])
|
288
|
+
s.add_development_dependency(%q<dm-types>, ["~> 1.0.0.rc1"])
|
177
289
|
else
|
178
|
-
s.add_dependency(%q<dm-core>, ["~> 0.
|
179
|
-
s.add_dependency(%q<rspec>, ["~> 1.
|
180
|
-
s.add_dependency(%q<
|
290
|
+
s.add_dependency(%q<dm-core>, ["~> 1.0.0.rc1"])
|
291
|
+
s.add_dependency(%q<rspec>, ["~> 1.3"])
|
292
|
+
s.add_dependency(%q<dm-types>, ["~> 1.0.0.rc1"])
|
181
293
|
end
|
182
294
|
else
|
183
|
-
s.add_dependency(%q<dm-core>, ["~> 0.
|
184
|
-
s.add_dependency(%q<rspec>, ["~> 1.
|
185
|
-
s.add_dependency(%q<
|
295
|
+
s.add_dependency(%q<dm-core>, ["~> 1.0.0.rc1"])
|
296
|
+
s.add_dependency(%q<rspec>, ["~> 1.3"])
|
297
|
+
s.add_dependency(%q<dm-types>, ["~> 1.0.0.rc1"])
|
186
298
|
end
|
187
299
|
end
|
188
300
|
|