datamapper 0.3.2 → 0.9.3
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 +0 -0
- data/Manifest.txt +5 -0
- data/README.txt +11 -0
- data/Rakefile +70 -0
- data/lib/datamapper.rb +8 -0
- metadata +152 -319
- data/CHANGELOG +0 -145
- data/FAQ +0 -96
- data/MIT-LICENSE +0 -22
- data/QUICKLINKS +0 -12
- data/README +0 -105
- data/environment.rb +0 -62
- data/example.rb +0 -156
- data/lib/data_mapper.rb +0 -88
- data/lib/data_mapper/adapters/abstract_adapter.rb +0 -43
- data/lib/data_mapper/adapters/data_object_adapter.rb +0 -480
- data/lib/data_mapper/adapters/mysql_adapter.rb +0 -72
- data/lib/data_mapper/adapters/postgresql_adapter.rb +0 -258
- data/lib/data_mapper/adapters/sql/coersion.rb +0 -134
- data/lib/data_mapper/adapters/sql/commands/load_command.rb +0 -545
- data/lib/data_mapper/adapters/sql/mappings/associations_set.rb +0 -34
- data/lib/data_mapper/adapters/sql/mappings/column.rb +0 -279
- data/lib/data_mapper/adapters/sql/mappings/conditions.rb +0 -172
- data/lib/data_mapper/adapters/sql/mappings/schema.rb +0 -60
- data/lib/data_mapper/adapters/sql/mappings/table.rb +0 -459
- data/lib/data_mapper/adapters/sql/quoting.rb +0 -24
- data/lib/data_mapper/adapters/sqlite3_adapter.rb +0 -159
- data/lib/data_mapper/associations.rb +0 -106
- data/lib/data_mapper/associations/belongs_to_association.rb +0 -160
- data/lib/data_mapper/associations/has_and_belongs_to_many_association.rb +0 -437
- data/lib/data_mapper/associations/has_many_association.rb +0 -283
- data/lib/data_mapper/associations/has_n_association.rb +0 -143
- data/lib/data_mapper/associations/reference.rb +0 -47
- data/lib/data_mapper/attributes.rb +0 -73
- data/lib/data_mapper/auto_migrations.rb +0 -36
- data/lib/data_mapper/base.rb +0 -17
- data/lib/data_mapper/callbacks.rb +0 -107
- data/lib/data_mapper/context.rb +0 -112
- data/lib/data_mapper/database.rb +0 -234
- data/lib/data_mapper/dependency_queue.rb +0 -28
- data/lib/data_mapper/embedded_value.rb +0 -145
- data/lib/data_mapper/identity_map.rb +0 -47
- data/lib/data_mapper/is/tree.rb +0 -121
- data/lib/data_mapper/migration.rb +0 -155
- data/lib/data_mapper/persistence.rb +0 -852
- data/lib/data_mapper/property.rb +0 -310
- data/lib/data_mapper/query.rb +0 -164
- data/lib/data_mapper/support/blank.rb +0 -35
- data/lib/data_mapper/support/connection_pool.rb +0 -117
- data/lib/data_mapper/support/enumerable.rb +0 -35
- data/lib/data_mapper/support/errors.rb +0 -16
- data/lib/data_mapper/support/inflector.rb +0 -265
- data/lib/data_mapper/support/object.rb +0 -54
- data/lib/data_mapper/support/serialization.rb +0 -96
- data/lib/data_mapper/support/silence.rb +0 -10
- data/lib/data_mapper/support/string.rb +0 -72
- data/lib/data_mapper/support/struct.rb +0 -7
- data/lib/data_mapper/support/symbol.rb +0 -82
- data/lib/data_mapper/support/typed_set.rb +0 -65
- data/lib/data_mapper/types/base.rb +0 -44
- data/lib/data_mapper/types/string.rb +0 -34
- data/lib/data_mapper/validatable_extensions/errors.rb +0 -12
- data/lib/data_mapper/validatable_extensions/macros.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validatable_instance_methods.rb +0 -62
- data/lib/data_mapper/validatable_extensions/validation_base.rb +0 -18
- data/lib/data_mapper/validatable_extensions/validations/formats/email.rb +0 -43
- data/lib/data_mapper/validatable_extensions/validations/validates_acceptance_of.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_confirmation_of.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_each.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_format_of.rb +0 -28
- data/lib/data_mapper/validatable_extensions/validations/validates_length_of.rb +0 -15
- data/lib/data_mapper/validatable_extensions/validations/validates_numericality_of.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_presence_of.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_true_for.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_uniqueness_of.rb +0 -40
- data/lib/data_mapper/validations.rb +0 -20
- data/lib/data_mapper/validations/number_validator.rb +0 -40
- data/lib/data_mapper/validations/string_validator.rb +0 -20
- data/lib/data_mapper/validations/validator.rb +0 -13
- data/performance.rb +0 -307
- data/plugins/can_has_sphinx/LICENSE +0 -23
- data/plugins/can_has_sphinx/README +0 -4
- data/plugins/can_has_sphinx/REVISION +0 -1
- data/plugins/can_has_sphinx/Rakefile +0 -22
- data/plugins/can_has_sphinx/init.rb +0 -1
- data/plugins/can_has_sphinx/install.rb +0 -1
- data/plugins/can_has_sphinx/lib/acts_as_sphinx.rb +0 -123
- data/plugins/can_has_sphinx/lib/sphinx.rb +0 -460
- data/plugins/can_has_sphinx/scripts/sphinx.sh +0 -47
- data/plugins/can_has_sphinx/tasks/acts_as_sphinx_tasks.rake +0 -41
- data/profile_data_mapper.rb +0 -40
- data/rakefile.rb +0 -159
- data/spec/acts_as_tree_spec.rb +0 -67
- data/spec/adapters/data_object_adapter_spec.rb +0 -31
- data/spec/associations/belongs_to_association_spec.rb +0 -98
- data/spec/associations/has_and_belongs_to_many_association_spec.rb +0 -377
- data/spec/associations/has_many_association_spec.rb +0 -337
- data/spec/attributes_spec.rb +0 -52
- data/spec/auto_migrations_spec.rb +0 -101
- data/spec/callbacks_spec.rb +0 -186
- data/spec/can_has_sphinx.rb +0 -5
- data/spec/coersion_spec.rb +0 -41
- data/spec/column_spec.rb +0 -114
- data/spec/count_command_spec.rb +0 -45
- data/spec/database_spec.rb +0 -18
- data/spec/dataobjects_spec.rb +0 -27
- data/spec/delete_command_spec.rb +0 -11
- data/spec/dependency_spec.rb +0 -29
- data/spec/embedded_value_spec.rb +0 -161
- data/spec/fixtures/animals.yaml +0 -33
- data/spec/fixtures/animals_exhibits.yaml +0 -2
- data/spec/fixtures/careers.yaml +0 -5
- data/spec/fixtures/comments.yaml +0 -1
- data/spec/fixtures/exhibits.yaml +0 -90
- data/spec/fixtures/fruit.yaml +0 -6
- data/spec/fixtures/people.yaml +0 -37
- data/spec/fixtures/posts.yaml +0 -3
- data/spec/fixtures/projects.yaml +0 -13
- data/spec/fixtures/sections.yaml +0 -5
- data/spec/fixtures/serializers.yaml +0 -6
- data/spec/fixtures/tasks.yaml +0 -6
- data/spec/fixtures/tasks_tasks.yaml +0 -2
- data/spec/fixtures/tomatoes.yaml +0 -1
- data/spec/fixtures/users.yaml +0 -1
- data/spec/fixtures/zoos.yaml +0 -24
- data/spec/is_a_tree_spec.rb +0 -149
- data/spec/legacy_spec.rb +0 -16
- data/spec/load_command_spec.rb +0 -322
- data/spec/magic_columns_spec.rb +0 -26
- data/spec/migration_spec.rb +0 -267
- data/spec/mock_adapter.rb +0 -20
- data/spec/models/animal.rb +0 -12
- data/spec/models/candidate.rb +0 -8
- data/spec/models/career.rb +0 -7
- data/spec/models/chain.rb +0 -8
- data/spec/models/comment.rb +0 -6
- data/spec/models/exhibit.rb +0 -14
- data/spec/models/fence.rb +0 -7
- data/spec/models/fruit.rb +0 -8
- data/spec/models/job.rb +0 -8
- data/spec/models/person.rb +0 -30
- data/spec/models/post.rb +0 -14
- data/spec/models/project.rb +0 -41
- data/spec/models/sales_person.rb +0 -5
- data/spec/models/section.rb +0 -8
- data/spec/models/serializer.rb +0 -5
- data/spec/models/task.rb +0 -9
- data/spec/models/tomato.rb +0 -27
- data/spec/models/user.rb +0 -12
- data/spec/models/zoo.rb +0 -13
- data/spec/natural_key_spec.rb +0 -36
- data/spec/paranoia_spec.rb +0 -38
- data/spec/persistence_spec.rb +0 -479
- data/spec/postgres_spec.rb +0 -96
- data/spec/property_spec.rb +0 -151
- data/spec/query_spec.rb +0 -77
- data/spec/save_command_spec.rb +0 -94
- data/spec/schema_spec.rb +0 -8
- data/spec/serialize_spec.rb +0 -19
- data/spec/single_table_inheritance_spec.rb +0 -43
- data/spec/spec_helper.rb +0 -45
- data/spec/support/blank_spec.rb +0 -8
- data/spec/support/inflector_spec.rb +0 -41
- data/spec/support/object_spec.rb +0 -9
- data/spec/support/serialization_spec.rb +0 -61
- data/spec/support/silence_spec.rb +0 -15
- data/spec/support/string_spec.rb +0 -7
- data/spec/support/struct_spec.rb +0 -12
- data/spec/support/typed_set_spec.rb +0 -66
- data/spec/symbolic_operators_spec.rb +0 -27
- data/spec/table_spec.rb +0 -79
- data/spec/types/string.rb +0 -81
- data/spec/validates_confirmation_of_spec.rb +0 -55
- data/spec/validates_format_of_spec.rb +0 -78
- data/spec/validates_length_of_spec.rb +0 -117
- data/spec/validates_uniqueness_of_spec.rb +0 -92
- data/spec/validations/number_validator.rb +0 -59
- data/spec/validations/string_validator.rb +0 -14
- data/spec/validations_spec.rb +0 -141
- data/tasks/fixtures.rb +0 -53
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + "/spec_helper"
|
|
2
|
-
|
|
3
|
-
describe Validatable::ValidatesConfirmationOf do
|
|
4
|
-
|
|
5
|
-
before(:all) do
|
|
6
|
-
class Cow
|
|
7
|
-
|
|
8
|
-
include DataMapper::CallbacksHelper
|
|
9
|
-
include DataMapper::Validations
|
|
10
|
-
|
|
11
|
-
attr_accessor :name, :name_confirmation, :age
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it 'should pass validation' do
|
|
16
|
-
class Cow
|
|
17
|
-
validations.clear
|
|
18
|
-
validates_confirmation_of :name, :event => :save
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
betsy = Cow.new
|
|
22
|
-
betsy.valid?.should == true
|
|
23
|
-
|
|
24
|
-
betsy.name = 'Betsy'
|
|
25
|
-
betsy.name_confirmation = ''
|
|
26
|
-
betsy.valid?(:save).should == false
|
|
27
|
-
betsy.errors.full_messages.first.should == 'Name does not match the confirmation'
|
|
28
|
-
|
|
29
|
-
betsy.name = ''
|
|
30
|
-
betsy.name_confirmation = 'Betsy'
|
|
31
|
-
betsy.valid?(:save).should == false
|
|
32
|
-
betsy.errors.full_messages.first.should == 'Name does not match the confirmation'
|
|
33
|
-
|
|
34
|
-
betsy.name = 'Betsy'
|
|
35
|
-
betsy.name_confirmation = 'Betsy'
|
|
36
|
-
betsy.valid?(:save).should == true
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it 'should allow allow a custom error message' do
|
|
40
|
-
class Cow
|
|
41
|
-
validations.clear
|
|
42
|
-
validates_confirmation_of :name, :event => :save, :message => 'You confirm name NOW or else.'
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
betsy = Cow.new
|
|
46
|
-
betsy.valid?.should == true
|
|
47
|
-
|
|
48
|
-
betsy.name = 'Betsy'
|
|
49
|
-
betsy.name_confirmation = ''
|
|
50
|
-
betsy.valid?(:save).should == false
|
|
51
|
-
|
|
52
|
-
betsy.errors.full_messages.first.should == 'You confirm name NOW or else.'
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
end
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + "/spec_helper"
|
|
2
|
-
|
|
3
|
-
context Validatable::ValidatesFormatOf do
|
|
4
|
-
|
|
5
|
-
before(:all) do
|
|
6
|
-
class Employee
|
|
7
|
-
|
|
8
|
-
include DataMapper::CallbacksHelper
|
|
9
|
-
include DataMapper::Validations
|
|
10
|
-
|
|
11
|
-
attr_accessor :email
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it 'must have a valid email address' do
|
|
16
|
-
class Employee
|
|
17
|
-
validations.clear
|
|
18
|
-
validates_format_of :email, :with => :email_address, :on => :save
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
e = Employee.new
|
|
22
|
-
e.valid?.should == true
|
|
23
|
-
|
|
24
|
-
[
|
|
25
|
-
'test test@example.com', 'test@example', 'test#example.com',
|
|
26
|
-
'tester@exampl$.com', '[scizzle]@example.com', '.test@example.com'
|
|
27
|
-
].all? { |test_email|
|
|
28
|
-
e.email = test_email
|
|
29
|
-
puts "Email is: #{test_email}"
|
|
30
|
-
e.valid?(:save).should == false
|
|
31
|
-
e.errors.full_messages.first.should == "#{test_email} is not a valid email address"
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
e.email = 'test@example.com'
|
|
35
|
-
e.valid?(:save).should == true
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it 'must have a valid organization code' do
|
|
39
|
-
class Employee
|
|
40
|
-
validations.clear
|
|
41
|
-
|
|
42
|
-
attr_accessor :organization_code
|
|
43
|
-
|
|
44
|
-
# WARNING: contrived example
|
|
45
|
-
# The organization code must be A#### or B######X12
|
|
46
|
-
validates_format_of :organization_code, :on => :save, :with => /(A\d{4}|[B-Z]\d{6}X12)/
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
e = Employee.new
|
|
50
|
-
e.valid?.should == true
|
|
51
|
-
|
|
52
|
-
e.organization_code = 'BLAH :)'
|
|
53
|
-
e.valid?(:save).should == false
|
|
54
|
-
e.errors.full_messages.first.should == 'Organization code is invalid'
|
|
55
|
-
|
|
56
|
-
e.organization_code = 'A1234'
|
|
57
|
-
e.valid?(:save).should == true
|
|
58
|
-
|
|
59
|
-
e.organization_code = 'B123456X12'
|
|
60
|
-
e.valid?(:save).should == true
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
it 'should allow custom error messages' do
|
|
65
|
-
class Employee
|
|
66
|
-
validations.clear
|
|
67
|
-
validates_format_of :email, :with => :email_address, :on => :save, :message => "Me needs good email, m'kay?"
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
e = Employee.new
|
|
71
|
-
e.valid?.should == true
|
|
72
|
-
|
|
73
|
-
e.valid?(:save).should == false
|
|
74
|
-
e.errors.full_messages.first.should == "Me needs good email, m'kay?"
|
|
75
|
-
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
end
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + "/spec_helper"
|
|
2
|
-
|
|
3
|
-
describe Validatable::ValidatesLengthOf do
|
|
4
|
-
|
|
5
|
-
before(:all) do
|
|
6
|
-
class Cow
|
|
7
|
-
|
|
8
|
-
include DataMapper::CallbacksHelper
|
|
9
|
-
include DataMapper::Validations
|
|
10
|
-
|
|
11
|
-
attr_accessor :name, :age
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it 'should not have a name shorter than 3 characters' do
|
|
16
|
-
class Cow
|
|
17
|
-
validations.clear
|
|
18
|
-
validates_length_of :name, :minimum => 3, :event => :save
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
betsy = Cow.new
|
|
22
|
-
betsy.valid?.should == true
|
|
23
|
-
|
|
24
|
-
betsy.valid?(:save).should == false
|
|
25
|
-
betsy.errors.full_messages.first.should == 'Name must be more than 2 characters long'
|
|
26
|
-
|
|
27
|
-
betsy.name = 'Be'
|
|
28
|
-
betsy.valid?(:save).should == false
|
|
29
|
-
betsy.errors.full_messages.first.should == 'Name must be more than 2 characters long'
|
|
30
|
-
|
|
31
|
-
betsy.name = 'Bet'
|
|
32
|
-
betsy.valid?(:save).should == true
|
|
33
|
-
|
|
34
|
-
betsy.name = 'Bets'
|
|
35
|
-
betsy.valid?(:save).should == true
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
it 'should not have a name longer than 10 characters' do
|
|
40
|
-
class Cow
|
|
41
|
-
validations.clear
|
|
42
|
-
validates_length_of :name, :maximum => 10, :event => :save
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
betsy = Cow.new
|
|
46
|
-
betsy.valid?.should == true
|
|
47
|
-
betsy.valid?(:save).should == true
|
|
48
|
-
|
|
49
|
-
betsy.name = 'Testicular Fortitude'
|
|
50
|
-
betsy.valid?(:save).should == false
|
|
51
|
-
betsy.errors.full_messages.first.should == 'Name must be less than 11 characters long'
|
|
52
|
-
|
|
53
|
-
betsy.name = 'Betsy'
|
|
54
|
-
betsy.valid?(:save).should == true
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
it 'should have a name that is 8 characters long' do
|
|
58
|
-
class Cow
|
|
59
|
-
validations.clear
|
|
60
|
-
validates_length_of :name, :is => 8, :event => :save
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
# Context is not save
|
|
64
|
-
betsy = Cow.new
|
|
65
|
-
betsy.valid?.should == true
|
|
66
|
-
|
|
67
|
-
# Context is :save
|
|
68
|
-
betsy.valid?(:save).should == false
|
|
69
|
-
|
|
70
|
-
betsy.name = 'Testicular Fortitude'
|
|
71
|
-
betsy.valid?(:save).should == false
|
|
72
|
-
betsy.errors.full_messages.first.should == 'Name must be 8 characters long'
|
|
73
|
-
|
|
74
|
-
betsy.name = 'Samooela'
|
|
75
|
-
betsy.valid?(:save).should == true
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
it 'should have a name that is between 10 and 15 characters long' do
|
|
79
|
-
class Cow
|
|
80
|
-
validations.clear
|
|
81
|
-
validates_length_of :name, :within => (10..15), :event => :save
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
# Context is not save
|
|
85
|
-
betsy = Cow.new
|
|
86
|
-
betsy.valid?.should == true
|
|
87
|
-
|
|
88
|
-
# Context is :save
|
|
89
|
-
betsy.valid?(:save)
|
|
90
|
-
betsy.errors.full_messages.first
|
|
91
|
-
|
|
92
|
-
betsy.valid?(:save).should == false
|
|
93
|
-
betsy.errors.full_messages.first.should == 'Name must be between 10 and 15 characters long'
|
|
94
|
-
|
|
95
|
-
betsy.name = 'Smoooooot'
|
|
96
|
-
betsy.valid?(:save).should == false
|
|
97
|
-
|
|
98
|
-
betsy.name = 'Smooooooooooooooooooot'
|
|
99
|
-
betsy.valid?(:save).should == false
|
|
100
|
-
|
|
101
|
-
betsy.name = 'Smootenstein'
|
|
102
|
-
betsy.valid?(:save).should == true
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
it 'should allow custom error messages' do
|
|
106
|
-
class Cow
|
|
107
|
-
validations.clear
|
|
108
|
-
validates_length_of :name, :is => 8, :event => :save, :message => '8 letters, no more, no less.'
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
betsy = Cow.new
|
|
112
|
-
betsy.valid?.should == true
|
|
113
|
-
|
|
114
|
-
betsy.valid?(:save).should == false
|
|
115
|
-
betsy.errors.full_messages.first.should == '8 letters, no more, no less.'
|
|
116
|
-
end
|
|
117
|
-
end
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + "/spec_helper"
|
|
2
|
-
|
|
3
|
-
describe Validatable::ValidatesUniquenessOf do
|
|
4
|
-
|
|
5
|
-
before(:all) do
|
|
6
|
-
fixtures('people')
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
it 'must have a unique name' do
|
|
10
|
-
class Animal
|
|
11
|
-
validations.clear
|
|
12
|
-
validates_uniqueness_of :name, :event => :save
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
bugaboo = Animal.new
|
|
16
|
-
bugaboo.valid?.should == true
|
|
17
|
-
|
|
18
|
-
bugaboo.name = 'Bear'
|
|
19
|
-
bugaboo.valid?(:save).should == false
|
|
20
|
-
bugaboo.errors.full_messages.first.should == 'Name has already been taken'
|
|
21
|
-
|
|
22
|
-
bugaboo.name = 'Bugaboo'
|
|
23
|
-
bugaboo.valid?(:save).should == true
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it 'must have a unique name for their occupation' do
|
|
27
|
-
class Person
|
|
28
|
-
validations.clear
|
|
29
|
-
validates_uniqueness_of :name, :event => :save, :scope => :occupation
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
new_programmer_scott = Person.new(:name => 'Scott', :age => 29, :occupation => 'Programmer')
|
|
33
|
-
garbage_man_scott = Person.new(:name => 'Scott', :age => 25, :occupation => 'Garbage Man')
|
|
34
|
-
|
|
35
|
-
# Should be valid even though there is another 'Scott' already in the database
|
|
36
|
-
garbage_man_scott.valid?(:save).should == true
|
|
37
|
-
|
|
38
|
-
# Should NOT be valid, there is already a Programmer names Scott, adding one more
|
|
39
|
-
# would destroy the universe or something
|
|
40
|
-
new_programmer_scott.valid?(:save).should == false
|
|
41
|
-
new_programmer_scott.errors.full_messages.first.should == "Name has already been taken"
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it 'must have a unique name for their occupation and career_name' do
|
|
45
|
-
class Person
|
|
46
|
-
validations.clear
|
|
47
|
-
validates_uniqueness_of :name, :event => :save, :scope => [:occupation, :career_name]
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
new_programmer_scott = Person.new(:name => 'Scott', :age => 29, :occupation => 'Programmer', :career_name => 'Programmer')
|
|
51
|
-
junior_programmer_scott = Person.new(:name => 'Scott', :age => 25, :occupation => 'Programmer', :career_name => 'Junior Programmer')
|
|
52
|
-
|
|
53
|
-
# Should be valid even though there is another 'Scott' already in the database
|
|
54
|
-
junior_programmer_scott.valid?(:save).should == true
|
|
55
|
-
|
|
56
|
-
# Should NOT be valid, there is already a Programmer names Scott, adding one more
|
|
57
|
-
# would destroy the universe or something
|
|
58
|
-
new_programmer_scott.valid?(:save).should == false
|
|
59
|
-
new_programmer_scott.errors.full_messages.first.should == "Name has already been taken"
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
it "should allow custom error messages" do
|
|
63
|
-
class Animal
|
|
64
|
-
validations.clear
|
|
65
|
-
validates_uniqueness_of :name, :event => :save, :message => 'You try to steal my name? I kill you!'
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
bugaboo = Animal.new
|
|
69
|
-
bugaboo.valid?.should == true
|
|
70
|
-
|
|
71
|
-
bugaboo.name = 'Bear'
|
|
72
|
-
bugaboo.valid?(:save).should == false
|
|
73
|
-
bugaboo.errors.full_messages.first.should == 'You try to steal my name? I kill you!'
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
it "should not interfere with the destruction of an object" do
|
|
77
|
-
pending "see: http://wm.lighthouseapp.com/projects/4819-datamapper/tickets/139"
|
|
78
|
-
|
|
79
|
-
## creating two dups so that we have invalid records in the db
|
|
80
|
-
Project.create(:title => 'Dup')
|
|
81
|
-
Project.create(:title => 'Dup')
|
|
82
|
-
|
|
83
|
-
class Project
|
|
84
|
-
validations.clear
|
|
85
|
-
validates_uniqueness_of :title, :message => 'You try to steal my title? I kill you!'
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
project = Project.first(:title => 'Dup')
|
|
89
|
-
project.destroy!.should == true
|
|
90
|
-
|
|
91
|
-
end
|
|
92
|
-
end
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + "/../spec_helper"
|
|
2
|
-
|
|
3
|
-
describe DataMapper::Validations::NumberValidator do
|
|
4
|
-
before(:each) do
|
|
5
|
-
@v = DataMapper::Validations::NumberValidator.new
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
it "should validate 'less than'" do
|
|
9
|
-
@v < 10
|
|
10
|
-
|
|
11
|
-
@v.errors_for(11).should_not be_empty
|
|
12
|
-
@v.errors_for(10).should_not be_empty
|
|
13
|
-
@v.errors_for(9).should be_empty
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "should validate 'less than or equals'" do
|
|
17
|
-
@v <= 10
|
|
18
|
-
|
|
19
|
-
@v.errors_for(11).should_not be_empty
|
|
20
|
-
@v.errors_for(10).should be_empty
|
|
21
|
-
@v.errors_for(9).should be_empty
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "should validate 'greater than'" do
|
|
25
|
-
@v > 10
|
|
26
|
-
|
|
27
|
-
@v.errors_for(11).should be_empty
|
|
28
|
-
@v.errors_for(10).should_not be_empty
|
|
29
|
-
@v.errors_for(9).should_not be_empty
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it "should validate 'greater than or equals'" do
|
|
33
|
-
@v >= 10
|
|
34
|
-
|
|
35
|
-
@v.errors_for(11).should be_empty
|
|
36
|
-
@v.errors_for(10).should be_empty
|
|
37
|
-
@v.errors_for(9).should_not be_empty
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it "should validate 'between' (inclusive)" do
|
|
41
|
-
@v.between(1 .. 10)
|
|
42
|
-
|
|
43
|
-
@v.errors_for(11).should_not be_empty
|
|
44
|
-
@v.errors_for(0).should_not be_empty
|
|
45
|
-
@v.errors_for(10).should be_empty
|
|
46
|
-
@v.errors_for(1).should be_empty
|
|
47
|
-
@v.errors_for(5).should be_empty
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it "should validate 'between' (exclusive)" do
|
|
51
|
-
@v.between(1 ... 10)
|
|
52
|
-
|
|
53
|
-
@v.errors_for(11).should_not be_empty
|
|
54
|
-
@v.errors_for(0).should_not be_empty
|
|
55
|
-
@v.errors_for(10).should_not be_empty
|
|
56
|
-
@v.errors_for(1).should be_empty
|
|
57
|
-
@v.errors_for(5).should be_empty
|
|
58
|
-
end
|
|
59
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + "/../spec_helper"
|
|
2
|
-
|
|
3
|
-
describe DataMapper::Validations::StringValidator do
|
|
4
|
-
before(:each) do
|
|
5
|
-
@v = DataMapper::Validations::StringValidator.new
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
it "should validate 'matches'" do
|
|
9
|
-
@v.matches /aabb/
|
|
10
|
-
|
|
11
|
-
@v.errors_for("cde").should_not be_empty
|
|
12
|
-
@v.errors_for("aabbb").should be_empty
|
|
13
|
-
end
|
|
14
|
-
end
|
data/spec/validations_spec.rb
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + "/spec_helper"
|
|
2
|
-
|
|
3
|
-
describe Validatable do
|
|
4
|
-
|
|
5
|
-
before(:all) do
|
|
6
|
-
class Cow
|
|
7
|
-
|
|
8
|
-
include DataMapper::CallbacksHelper
|
|
9
|
-
include DataMapper::Validations
|
|
10
|
-
|
|
11
|
-
attr_accessor :name, :age
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it 'should allow you to specify not-null fields for different events' do
|
|
16
|
-
class Cow
|
|
17
|
-
validations.clear
|
|
18
|
-
validates_presence_of :name, :event => :save
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
betsy = Cow.new
|
|
22
|
-
betsy.valid?.should == true
|
|
23
|
-
|
|
24
|
-
betsy.valid?(:save).should == false
|
|
25
|
-
betsy.errors.full_messages.first.should == 'Name must not be blank'
|
|
26
|
-
|
|
27
|
-
betsy.name = 'Betsy'
|
|
28
|
-
betsy.valid?(:save).should == true
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it 'should be able to use ":on" for an event alias' do
|
|
32
|
-
class Cow
|
|
33
|
-
validations.clear
|
|
34
|
-
validates_presence_of :name, :age, :on => :create
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
maggie = Cow.new
|
|
38
|
-
maggie.valid?.should == true
|
|
39
|
-
|
|
40
|
-
maggie.valid?(:create).should == false
|
|
41
|
-
maggie.errors.full_messages.should include('Age must not be blank')
|
|
42
|
-
maggie.errors.full_messages.should include('Name must not be blank')
|
|
43
|
-
|
|
44
|
-
maggie.name = 'Maggie'
|
|
45
|
-
maggie.age = 29
|
|
46
|
-
maggie.valid?(:create).should == true
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it 'should default to a general event if unspecified' do
|
|
50
|
-
class Cow
|
|
51
|
-
validations.clear
|
|
52
|
-
validates_presence_of :name, :age
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
rhonda = Cow.new
|
|
56
|
-
rhonda.valid?.should == false
|
|
57
|
-
rhonda.errors.should have(2).full_messages
|
|
58
|
-
|
|
59
|
-
rhonda.errors.full_messages.should include('Age must not be blank')
|
|
60
|
-
rhonda.errors.full_messages.should include('Name must not be blank')
|
|
61
|
-
|
|
62
|
-
rhonda.name = 'Rhonda'
|
|
63
|
-
rhonda.age = 44
|
|
64
|
-
rhonda.valid?.should == true
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
it "should always run validations without a specific event" do
|
|
68
|
-
class Cow
|
|
69
|
-
validations.clear
|
|
70
|
-
validates_presence_of :name
|
|
71
|
-
validates_presence_of :age, :on => :save
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
isabel = Cow.new
|
|
75
|
-
isabel.valid?.should == false
|
|
76
|
-
isabel.errors.should have(1).full_messages
|
|
77
|
-
isabel.errors.full_messages.should include('Name must not be blank')
|
|
78
|
-
isabel.errors.on(:name).should == ['Name must not be blank']
|
|
79
|
-
|
|
80
|
-
isabel.valid?(:save).should == false
|
|
81
|
-
isabel.errors.should have(2).full_messages
|
|
82
|
-
|
|
83
|
-
isabel.errors.full_messages.should include('Age must not be blank')
|
|
84
|
-
isabel.errors.full_messages.should include('Name must not be blank')
|
|
85
|
-
isabel.errors.on(:name).should == ['Name must not be blank']
|
|
86
|
-
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
it 'should have 1 validation error' do
|
|
90
|
-
class VPOTest
|
|
91
|
-
|
|
92
|
-
include DataMapper::CallbacksHelper
|
|
93
|
-
include DataMapper::Validations
|
|
94
|
-
|
|
95
|
-
attr_accessor :name, :whatever
|
|
96
|
-
|
|
97
|
-
validates_presence_of :name
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
o = VPOTest.new
|
|
101
|
-
o.should_not be_valid
|
|
102
|
-
o.errors.should have(1).full_messages
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
it 'should translate error messages' do
|
|
106
|
-
String::translations["%s must not be blank"] = "%s should not be blank!"
|
|
107
|
-
|
|
108
|
-
beth = Cow.new
|
|
109
|
-
beth.age = 30
|
|
110
|
-
|
|
111
|
-
beth.should_not be_valid
|
|
112
|
-
|
|
113
|
-
beth.errors.full_messages.should include('Name should not be blank!')
|
|
114
|
-
|
|
115
|
-
String::translations.delete("%s must not be blank")
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
it 'should be able to find specific error message' do
|
|
119
|
-
class Cow
|
|
120
|
-
validations.clear
|
|
121
|
-
validates_presence_of :name
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
gertie = Cow.new
|
|
125
|
-
gertie.should_not be_valid
|
|
126
|
-
gertie.errors.on(:name).should == ['Name must not be blank']
|
|
127
|
-
gertie.errors.on(:age).should == nil
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
it "should be able to specify custom error messages" do
|
|
131
|
-
class Cow
|
|
132
|
-
validations.clear
|
|
133
|
-
validates_presence_of :name, :message => 'Give me a name, bub!'
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
gertie = Cow.new
|
|
137
|
-
gertie.should_not be_valid
|
|
138
|
-
gertie.errors.on(:name).should == ['Give me a name, bub!']
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
end
|