datamapper-dm-core 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/.autotest +17 -14
- data/.gitignore +3 -1
- data/FAQ +6 -5
- data/History.txt +5 -39
- data/Manifest.txt +67 -76
- data/QUICKLINKS +1 -1
- data/README.txt +21 -15
- data/Rakefile +16 -15
- data/SPECS +2 -29
- data/TODO +1 -1
- data/dm-core.gemspec +11 -15
- data/lib/dm-core/adapters/abstract_adapter.rb +182 -185
- data/lib/dm-core/adapters/data_objects_adapter.rb +482 -534
- data/lib/dm-core/adapters/in_memory_adapter.rb +90 -69
- data/lib/dm-core/adapters/mysql_adapter.rb +22 -115
- data/lib/dm-core/adapters/oracle_adapter.rb +249 -0
- data/lib/dm-core/adapters/postgres_adapter.rb +7 -173
- data/lib/dm-core/adapters/sqlite3_adapter.rb +4 -97
- data/lib/dm-core/adapters/yaml_adapter.rb +116 -0
- data/lib/dm-core/adapters.rb +135 -16
- data/lib/dm-core/associations/many_to_many.rb +372 -90
- data/lib/dm-core/associations/many_to_one.rb +220 -73
- data/lib/dm-core/associations/one_to_many.rb +319 -255
- data/lib/dm-core/associations/one_to_one.rb +66 -53
- data/lib/dm-core/associations/relationship.rb +560 -158
- data/lib/dm-core/collection.rb +1104 -381
- data/lib/dm-core/core_ext/kernel.rb +12 -0
- data/lib/dm-core/core_ext/symbol.rb +10 -0
- data/lib/dm-core/identity_map.rb +4 -34
- data/lib/dm-core/migrations.rb +1283 -0
- data/lib/dm-core/model/descendant_set.rb +81 -0
- data/lib/dm-core/model/hook.rb +45 -0
- data/lib/dm-core/model/is.rb +32 -0
- data/lib/dm-core/model/property.rb +248 -0
- data/lib/dm-core/model/relationship.rb +335 -0
- data/lib/dm-core/model/scope.rb +90 -0
- data/lib/dm-core/model.rb +570 -369
- data/lib/dm-core/property.rb +753 -280
- data/lib/dm-core/property_set.rb +141 -98
- data/lib/dm-core/query/conditions/comparison.rb +814 -0
- data/lib/dm-core/query/conditions/operation.rb +247 -0
- data/lib/dm-core/query/direction.rb +43 -0
- data/lib/dm-core/query/operator.rb +42 -0
- data/lib/dm-core/query/path.rb +102 -0
- data/lib/dm-core/query/sort.rb +45 -0
- data/lib/dm-core/query.rb +974 -492
- data/lib/dm-core/repository.rb +147 -107
- data/lib/dm-core/resource.rb +644 -429
- data/lib/dm-core/spec/adapter_shared_spec.rb +294 -0
- data/lib/dm-core/spec/data_objects_adapter_shared_spec.rb +106 -0
- data/lib/dm-core/support/chainable.rb +20 -0
- data/lib/dm-core/support/deprecate.rb +12 -0
- data/lib/dm-core/support/equalizer.rb +23 -0
- data/lib/dm-core/support/logger.rb +13 -0
- data/lib/dm-core/{naming_conventions.rb → support/naming_conventions.rb} +6 -6
- data/lib/dm-core/transaction.rb +333 -92
- data/lib/dm-core/type.rb +98 -60
- data/lib/dm-core/types/boolean.rb +1 -1
- data/lib/dm-core/types/discriminator.rb +34 -20
- data/lib/dm-core/types/object.rb +7 -4
- data/lib/dm-core/types/paranoid_boolean.rb +11 -9
- data/lib/dm-core/types/paranoid_datetime.rb +11 -9
- data/lib/dm-core/types/serial.rb +3 -3
- data/lib/dm-core/types/text.rb +3 -4
- data/lib/dm-core/version.rb +1 -1
- data/lib/dm-core.rb +106 -110
- data/script/performance.rb +102 -109
- data/script/profile.rb +169 -38
- data/spec/lib/adapter_helpers.rb +105 -0
- data/spec/lib/collection_helpers.rb +18 -0
- data/spec/lib/counter_adapter.rb +34 -0
- data/spec/lib/pending_helpers.rb +27 -0
- data/spec/lib/rspec_immediate_feedback_formatter.rb +53 -0
- data/spec/public/associations/many_to_many_spec.rb +193 -0
- data/spec/public/associations/many_to_one_spec.rb +73 -0
- data/spec/public/associations/one_to_many_spec.rb +77 -0
- data/spec/public/associations/one_to_one_spec.rb +156 -0
- data/spec/public/collection_spec.rb +65 -0
- data/spec/public/model/relationship_spec.rb +924 -0
- data/spec/public/model_spec.rb +159 -0
- data/spec/public/property_spec.rb +829 -0
- data/spec/public/resource_spec.rb +71 -0
- data/spec/public/sel_spec.rb +44 -0
- data/spec/public/setup_spec.rb +145 -0
- data/spec/public/shared/association_collection_shared_spec.rb +317 -0
- data/spec/public/shared/collection_shared_spec.rb +1723 -0
- data/spec/public/shared/finder_shared_spec.rb +1619 -0
- data/spec/public/shared/resource_shared_spec.rb +924 -0
- data/spec/public/shared/sel_shared_spec.rb +112 -0
- data/spec/public/transaction_spec.rb +129 -0
- data/spec/public/types/discriminator_spec.rb +130 -0
- data/spec/semipublic/adapters/abstract_adapter_spec.rb +30 -0
- data/spec/semipublic/adapters/in_memory_adapter_spec.rb +12 -0
- data/spec/semipublic/adapters/mysql_adapter_spec.rb +17 -0
- data/spec/semipublic/adapters/oracle_adapter_spec.rb +194 -0
- data/spec/semipublic/adapters/postgres_adapter_spec.rb +17 -0
- data/spec/semipublic/adapters/sqlite3_adapter_spec.rb +17 -0
- data/spec/semipublic/adapters/yaml_adapter_spec.rb +12 -0
- data/spec/semipublic/associations/many_to_one_spec.rb +53 -0
- data/spec/semipublic/associations/relationship_spec.rb +194 -0
- data/spec/semipublic/associations_spec.rb +177 -0
- data/spec/semipublic/collection_spec.rb +142 -0
- data/spec/semipublic/property_spec.rb +61 -0
- data/spec/semipublic/query/conditions_spec.rb +528 -0
- data/spec/semipublic/query/path_spec.rb +443 -0
- data/spec/semipublic/query_spec.rb +2626 -0
- data/spec/semipublic/resource_spec.rb +47 -0
- data/spec/semipublic/shared/resource_shared_spec.rb +126 -0
- data/spec/spec.opts +3 -1
- data/spec/spec_helper.rb +80 -57
- data/tasks/ci.rb +19 -31
- data/tasks/dm.rb +43 -48
- data/tasks/doc.rb +8 -11
- data/tasks/gemspec.rb +5 -5
- data/tasks/hoe.rb +15 -16
- data/tasks/install.rb +8 -10
- metadata +72 -93
- data/lib/dm-core/associations/relationship_chain.rb +0 -81
- data/lib/dm-core/associations.rb +0 -207
- data/lib/dm-core/auto_migrations.rb +0 -105
- data/lib/dm-core/dependency_queue.rb +0 -32
- data/lib/dm-core/hook.rb +0 -11
- data/lib/dm-core/is.rb +0 -16
- data/lib/dm-core/logger.rb +0 -232
- data/lib/dm-core/migrations/destructive_migrations.rb +0 -17
- data/lib/dm-core/migrator.rb +0 -29
- data/lib/dm-core/scope.rb +0 -58
- data/lib/dm-core/support/array.rb +0 -13
- data/lib/dm-core/support/assertions.rb +0 -8
- data/lib/dm-core/support/errors.rb +0 -23
- data/lib/dm-core/support/kernel.rb +0 -11
- data/lib/dm-core/support/symbol.rb +0 -41
- data/lib/dm-core/support.rb +0 -7
- data/lib/dm-core/type_map.rb +0 -80
- data/lib/dm-core/types.rb +0 -19
- data/script/all +0 -4
- data/spec/integration/association_spec.rb +0 -1382
- data/spec/integration/association_through_spec.rb +0 -203
- data/spec/integration/associations/many_to_many_spec.rb +0 -449
- data/spec/integration/associations/many_to_one_spec.rb +0 -163
- data/spec/integration/associations/one_to_many_spec.rb +0 -188
- data/spec/integration/auto_migrations_spec.rb +0 -413
- data/spec/integration/collection_spec.rb +0 -1073
- data/spec/integration/data_objects_adapter_spec.rb +0 -32
- data/spec/integration/dependency_queue_spec.rb +0 -46
- data/spec/integration/model_spec.rb +0 -197
- data/spec/integration/mysql_adapter_spec.rb +0 -85
- data/spec/integration/postgres_adapter_spec.rb +0 -731
- data/spec/integration/property_spec.rb +0 -253
- data/spec/integration/query_spec.rb +0 -514
- data/spec/integration/repository_spec.rb +0 -61
- data/spec/integration/resource_spec.rb +0 -513
- data/spec/integration/sqlite3_adapter_spec.rb +0 -352
- data/spec/integration/sti_spec.rb +0 -273
- data/spec/integration/strategic_eager_loading_spec.rb +0 -156
- data/spec/integration/transaction_spec.rb +0 -75
- data/spec/integration/type_spec.rb +0 -275
- data/spec/lib/logging_helper.rb +0 -18
- data/spec/lib/mock_adapter.rb +0 -27
- data/spec/lib/model_loader.rb +0 -100
- data/spec/lib/publicize_methods.rb +0 -28
- data/spec/models/content.rb +0 -16
- data/spec/models/vehicles.rb +0 -34
- data/spec/models/zoo.rb +0 -48
- data/spec/unit/adapters/abstract_adapter_spec.rb +0 -133
- data/spec/unit/adapters/adapter_shared_spec.rb +0 -15
- data/spec/unit/adapters/data_objects_adapter_spec.rb +0 -632
- data/spec/unit/adapters/in_memory_adapter_spec.rb +0 -98
- data/spec/unit/adapters/postgres_adapter_spec.rb +0 -133
- data/spec/unit/associations/many_to_many_spec.rb +0 -32
- data/spec/unit/associations/many_to_one_spec.rb +0 -159
- data/spec/unit/associations/one_to_many_spec.rb +0 -393
- data/spec/unit/associations/one_to_one_spec.rb +0 -7
- data/spec/unit/associations/relationship_spec.rb +0 -71
- data/spec/unit/associations_spec.rb +0 -242
- data/spec/unit/auto_migrations_spec.rb +0 -111
- data/spec/unit/collection_spec.rb +0 -182
- data/spec/unit/data_mapper_spec.rb +0 -35
- data/spec/unit/identity_map_spec.rb +0 -126
- data/spec/unit/is_spec.rb +0 -80
- data/spec/unit/migrator_spec.rb +0 -33
- data/spec/unit/model_spec.rb +0 -321
- data/spec/unit/naming_conventions_spec.rb +0 -36
- data/spec/unit/property_set_spec.rb +0 -90
- data/spec/unit/property_spec.rb +0 -753
- data/spec/unit/query_spec.rb +0 -571
- data/spec/unit/repository_spec.rb +0 -93
- data/spec/unit/resource_spec.rb +0 -649
- data/spec/unit/scope_spec.rb +0 -142
- data/spec/unit/transaction_spec.rb +0 -493
- data/spec/unit/type_map_spec.rb +0 -114
- data/spec/unit/type_spec.rb +0 -119
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
require 'pathname'
|
|
2
|
-
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
|
3
|
-
|
|
4
|
-
require DataMapper.root / 'lib' / 'dm-core' / 'repository'
|
|
5
|
-
require DataMapper.root / 'lib' / 'dm-core' / 'resource'
|
|
6
|
-
require DataMapper.root / 'lib' / 'dm-core' / 'auto_migrations'
|
|
7
|
-
|
|
8
|
-
describe DataMapper::AutoMigrations do
|
|
9
|
-
|
|
10
|
-
before :all do
|
|
11
|
-
@cow = Class.new do
|
|
12
|
-
include DataMapper::Resource
|
|
13
|
-
|
|
14
|
-
property :name, String, :key => true
|
|
15
|
-
property :age, Integer
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
before(:each) do
|
|
20
|
-
DataMapper::Resource.descendants.clear
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
after(:each) do
|
|
24
|
-
DataMapper::Resource.descendants.clear
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it "should add the resource class to AutoMigrator's models on a mixin" do
|
|
28
|
-
@class = Class.new do
|
|
29
|
-
include DataMapper::Resource
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
DataMapper::Resource.descendants.should include(@class)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it "should add the #auto_migrate! method on a mixin" do
|
|
36
|
-
@cat = Class.new do
|
|
37
|
-
include DataMapper::Resource
|
|
38
|
-
|
|
39
|
-
property :name, String, :key => true
|
|
40
|
-
property :age, Integer
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
@cat.should respond_to(:auto_migrate!)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it "should add the #auto_upgrade! method on a mixin" do
|
|
47
|
-
@cat = Class.new do
|
|
48
|
-
include DataMapper::Resource
|
|
49
|
-
|
|
50
|
-
property :name, String, :key => true
|
|
51
|
-
property :age, Integer
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
@cat.should respond_to(:auto_upgrade!)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
it "should not conflict with other Migrators on a mixin" do
|
|
58
|
-
migrator_class = Class.new(DataMapper::Migrator)
|
|
59
|
-
|
|
60
|
-
included_proc = lambda { |model| migrator_class.models << model }
|
|
61
|
-
|
|
62
|
-
migrator_mixin = Module.new do
|
|
63
|
-
self.class.send(:define_method, :included, &included_proc)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
model_class = Class.new do
|
|
67
|
-
include DataMapper::Resource
|
|
68
|
-
include migrator_mixin
|
|
69
|
-
|
|
70
|
-
property :name, String
|
|
71
|
-
property :age, String
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
DataMapper::Resource.descendants.should include(model_class)
|
|
75
|
-
migrator_class.models.should include(model_class)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
describe "#auto_migrate" do
|
|
79
|
-
before do
|
|
80
|
-
@repository_name = mock('repository name')
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it "should call each model's auto_migrate! method" do
|
|
84
|
-
models = [:cat, :dog, :fish, :cow].map {|m| mock(m)}
|
|
85
|
-
|
|
86
|
-
models.each do |model|
|
|
87
|
-
DataMapper::Resource.descendants << model
|
|
88
|
-
model.should_receive(:auto_migrate_down!).with(@repository_name)
|
|
89
|
-
model.should_receive(:auto_migrate_up!).with(@repository_name)
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
DataMapper::AutoMigrator.auto_migrate(@repository_name)
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
describe "#auto_upgrade" do
|
|
96
|
-
before do
|
|
97
|
-
@repository_name = mock('repository name')
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
it "should call each model's auto_upgrade! method" do
|
|
101
|
-
models = [:cat, :dog, :fish, :cow].map {|m| mock(m)}
|
|
102
|
-
|
|
103
|
-
models.each do |model|
|
|
104
|
-
DataMapper::Resource.descendants << model
|
|
105
|
-
model.should_receive(:auto_upgrade!).with(@repository_name)
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
DataMapper::AutoMigrator.auto_upgrade(@repository_name)
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
|
2
|
-
|
|
3
|
-
# ensure the Collection is extremely similar to an Array
|
|
4
|
-
# since it will be returned by Respository#all to return
|
|
5
|
-
# multiple resources to the caller
|
|
6
|
-
describe DataMapper::Collection do
|
|
7
|
-
before do
|
|
8
|
-
@property = mock('property')
|
|
9
|
-
@model = mock('model', :inheritance_property => [ @property ], :key => [ @property ])
|
|
10
|
-
@query = mock('query', :kind_of? => true, :fields => [ @property ], :model => @model)
|
|
11
|
-
|
|
12
|
-
@collection = DataMapper::Collection.new(@query) {}
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it 'should provide #<<' do
|
|
16
|
-
@collection.should respond_to(:<<)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it 'should provide #all' do
|
|
20
|
-
@collection.should respond_to(:all)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it 'should provide #at' do
|
|
24
|
-
@collection.should respond_to(:at)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it 'should provide #build' do
|
|
28
|
-
@collection.should respond_to(:build)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it 'should provide #clear' do
|
|
32
|
-
@collection.should respond_to(:clear)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it 'should provide #collect!' do
|
|
36
|
-
@collection.should respond_to(:collect!)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it 'should provide #concat' do
|
|
40
|
-
@collection.should respond_to(:concat)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it 'should provide #create' do
|
|
44
|
-
@collection.should respond_to(:create)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it 'should provide #delete' do
|
|
48
|
-
@collection.should respond_to(:delete)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it 'should provide #delete_at' do
|
|
52
|
-
@collection.should respond_to(:delete_at)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it 'should provide #destroy!' do
|
|
56
|
-
@collection.should respond_to(:destroy!)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
it 'should provide #each' do
|
|
60
|
-
@collection.should respond_to(:each)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
it 'should provide #each_index' do
|
|
64
|
-
@collection.should respond_to(:each_index)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
it 'should provide #eql?' do
|
|
68
|
-
@collection.should respond_to(:eql?)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it 'should provide #fetch' do
|
|
72
|
-
@collection.should respond_to(:fetch)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
it 'should provide #first' do
|
|
76
|
-
@collection.should respond_to(:first)
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
it 'should provide #freeze' do
|
|
80
|
-
@collection.should respond_to(:freeze)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it 'should provide #get' do
|
|
84
|
-
@collection.should respond_to(:get)
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
it 'should provide #get!' do
|
|
88
|
-
@collection.should respond_to(:get!)
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
it 'should provide #insert' do
|
|
92
|
-
@collection.should respond_to(:insert)
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
it 'should provide #last' do
|
|
96
|
-
@collection.should respond_to(:last)
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it 'should provide #load' do
|
|
100
|
-
@collection.should respond_to(:load)
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
it 'should provide #loaded?' do
|
|
104
|
-
@collection.should respond_to(:loaded?)
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
it 'should provide #pop' do
|
|
108
|
-
@collection.should respond_to(:pop)
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
it 'should provide #push' do
|
|
112
|
-
@collection.should respond_to(:push)
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
it 'should provide #properties' do
|
|
116
|
-
@collection.should respond_to(:properties)
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
it 'should provide #reject' do
|
|
120
|
-
@collection.should respond_to(:reject)
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
it 'should provide #reject!' do
|
|
124
|
-
@collection.should respond_to(:reject!)
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
it 'should provide #relationships' do
|
|
128
|
-
@collection.should respond_to(:relationships)
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
it 'should provide #reload' do
|
|
132
|
-
@collection.should respond_to(:reload)
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
it 'should provide #reverse' do
|
|
136
|
-
@collection.should respond_to(:reverse)
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
it 'should provide #reverse!' do
|
|
140
|
-
@collection.should respond_to(:reverse!)
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
it 'should provide #reverse_each' do
|
|
144
|
-
@collection.should respond_to(:reverse_each)
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
it 'should provide #select' do
|
|
148
|
-
@collection.should respond_to(:select)
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
it 'should provide #shift' do
|
|
152
|
-
@collection.should respond_to(:shift)
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
it 'should provide #slice' do
|
|
156
|
-
@collection.should respond_to(:slice)
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
it 'should provide #slice!' do
|
|
160
|
-
@collection.should respond_to(:slice!)
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
it 'should provide #sort' do
|
|
164
|
-
@collection.should respond_to(:sort)
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
it 'should provide #sort!' do
|
|
168
|
-
@collection.should respond_to(:sort!)
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
it 'should provide #unshift' do
|
|
172
|
-
@collection.should respond_to(:unshift)
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
it 'should provide #update!' do
|
|
176
|
-
@collection.should respond_to(:update!)
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
it 'should provide #values_at' do
|
|
180
|
-
@collection.should respond_to(:values_at)
|
|
181
|
-
end
|
|
182
|
-
end
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
|
2
|
-
|
|
3
|
-
describe DataMapper do
|
|
4
|
-
describe ".dependency_queue" do
|
|
5
|
-
before(:all) do
|
|
6
|
-
@q = DataMapper.dependency_queue
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
it "should return a dependency queue" do
|
|
10
|
-
@q.should be_a_kind_of(DataMapper::DependencyQueue)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "should only create one dependency queue" do
|
|
14
|
-
@q.should == DataMapper.dependency_queue
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
describe ".prepare" do
|
|
19
|
-
it "should pass the default repository to the block if no argument is given" do
|
|
20
|
-
DataMapper.should_receive(:repository).with(no_args).and_return :default_repo
|
|
21
|
-
|
|
22
|
-
DataMapper.prepare do |r|
|
|
23
|
-
r.should == :default_repo
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it "should allow custom type maps to be defined inside the prepare block" do
|
|
28
|
-
lambda {
|
|
29
|
-
DataMapper.prepare do |r|
|
|
30
|
-
r.map(String).to(:VARCHAR).with(:size => 1000)
|
|
31
|
-
end
|
|
32
|
-
}.should_not raise_error
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
|
2
|
-
|
|
3
|
-
describe "DataMapper::IdentityMap" do
|
|
4
|
-
before(:all) do
|
|
5
|
-
class ::Cow
|
|
6
|
-
include DataMapper::Resource
|
|
7
|
-
property :id, Integer, :key => true
|
|
8
|
-
property :name, String
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
class ::Chicken
|
|
12
|
-
include DataMapper::Resource
|
|
13
|
-
property :name, String
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
class ::Pig
|
|
17
|
-
include DataMapper::Resource
|
|
18
|
-
property :id, Integer, :key => true
|
|
19
|
-
property :composite, Integer, :key => true
|
|
20
|
-
property :name, String
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "should use a second level cache if created with on"
|
|
25
|
-
|
|
26
|
-
it "should return nil on #get when it does not find the requested instance" do
|
|
27
|
-
map = DataMapper::IdentityMap.new
|
|
28
|
-
map.get([23]).should be_nil
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "should return an instance on #get when it finds the requested instance" do
|
|
32
|
-
betsy = Cow.new({:id=>23,:name=>'Betsy'})
|
|
33
|
-
map = DataMapper::IdentityMap.new
|
|
34
|
-
map.set(betsy.key, betsy)
|
|
35
|
-
map.get([23]).should == betsy
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it "should store an instance on #set" do
|
|
39
|
-
betsy = Cow.new({:id=>23,:name=>'Betsy'})
|
|
40
|
-
map = DataMapper::IdentityMap.new
|
|
41
|
-
map.set(betsy.key, betsy)
|
|
42
|
-
map.get([23]).should == betsy
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it "should store instances with composite keys on #set" do
|
|
46
|
-
pig = Pig.new({:id=>1,:composite=>1,:name=> 'Pig'})
|
|
47
|
-
piggy = Pig.new({:id=>1,:composite=>2,:name=>'Piggy'})
|
|
48
|
-
|
|
49
|
-
map = DataMapper::IdentityMap.new
|
|
50
|
-
map.set(pig.key, pig)
|
|
51
|
-
map.set(piggy.key, piggy)
|
|
52
|
-
|
|
53
|
-
map.get([1,1]).should == pig
|
|
54
|
-
map.get([1,2]).should == piggy
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
it "should remove an instance on #delete" do
|
|
58
|
-
betsy = Cow.new({:id=>23,:name=>'Betsy'})
|
|
59
|
-
map = DataMapper::IdentityMap.new
|
|
60
|
-
map.set(betsy.key, betsy)
|
|
61
|
-
map.delete([23])
|
|
62
|
-
map.get([23]).should be_nil
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
describe "Second Level Caching" do
|
|
67
|
-
|
|
68
|
-
before :all do
|
|
69
|
-
@mock_class = Class.new do
|
|
70
|
-
def get(key); raise NotImplementedError end
|
|
71
|
-
def set(key, instance); raise NotImplementedError end
|
|
72
|
-
def delete(key); raise NotImplementedError end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
it 'should expose a standard API' do
|
|
77
|
-
cache = @mock_class.new
|
|
78
|
-
cache.should respond_to(:get)
|
|
79
|
-
cache.should respond_to(:set)
|
|
80
|
-
cache.should respond_to(:delete)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it 'should provide values when the first level cache entry is empty' do
|
|
84
|
-
cache = @mock_class.new
|
|
85
|
-
key = %w[ test ]
|
|
86
|
-
|
|
87
|
-
cache.should_receive(:get).with(key).and_return('resource')
|
|
88
|
-
|
|
89
|
-
map = DataMapper::IdentityMap.new(cache)
|
|
90
|
-
map.get(key).should == 'resource'
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
it 'should be set when the first level cache entry is set' do
|
|
94
|
-
cache = @mock_class.new
|
|
95
|
-
betsy = Cow.new(:id => 23, :name => 'Betsy')
|
|
96
|
-
|
|
97
|
-
cache.should_receive(:set).with(betsy.key, betsy).and_return(betsy)
|
|
98
|
-
|
|
99
|
-
map = DataMapper::IdentityMap.new(cache)
|
|
100
|
-
map.set(betsy.key, betsy).should == betsy
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
it 'should be deleted when the first level cache entry is deleted' do
|
|
104
|
-
cache = @mock_class.new
|
|
105
|
-
betsy = Cow.new(:id => 23, :name => 'Betsy')
|
|
106
|
-
|
|
107
|
-
cache.stub!(:set)
|
|
108
|
-
cache.should_receive(:delete).with(betsy.key).and_return(betsy)
|
|
109
|
-
|
|
110
|
-
map = DataMapper::IdentityMap.new(cache)
|
|
111
|
-
map.set(betsy.key, betsy).should == betsy
|
|
112
|
-
map.delete(betsy.key).should == betsy
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
it 'should not provide values when the first level cache entry is full' do
|
|
116
|
-
cache = @mock_class.new
|
|
117
|
-
betsy = Cow.new(:id => 23, :name => 'Betsy')
|
|
118
|
-
|
|
119
|
-
cache.stub!(:set)
|
|
120
|
-
cache.should_not_receive(:get)
|
|
121
|
-
|
|
122
|
-
map = DataMapper::IdentityMap.new(cache)
|
|
123
|
-
map.set(betsy.key, betsy).should == betsy
|
|
124
|
-
map.get(betsy.key).should == betsy
|
|
125
|
-
end
|
|
126
|
-
end
|
data/spec/unit/is_spec.rb
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
|
2
|
-
|
|
3
|
-
describe "DataMapper::Is" do
|
|
4
|
-
describe ".is" do
|
|
5
|
-
|
|
6
|
-
module ::DataMapper
|
|
7
|
-
|
|
8
|
-
module Is
|
|
9
|
-
module Example
|
|
10
|
-
|
|
11
|
-
def is_example(*args)
|
|
12
|
-
@args = args
|
|
13
|
-
|
|
14
|
-
extend DataMapper::Is::Example::ClassMethods
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def is_example_args
|
|
18
|
-
@args
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
module ClassMethods
|
|
22
|
-
def example_class_method
|
|
23
|
-
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
module Model
|
|
31
|
-
include DataMapper::Is::Example
|
|
32
|
-
end # module Model
|
|
33
|
-
end # module DataMapper
|
|
34
|
-
|
|
35
|
-
class ::House
|
|
36
|
-
include DataMapper::Resource
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
class ::Cabin
|
|
40
|
-
include DataMapper::Resource
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it "should raise error unless it finds the plugin" do
|
|
44
|
-
lambda do
|
|
45
|
-
class ::House
|
|
46
|
-
is :no_plugin_by_this_name
|
|
47
|
-
end
|
|
48
|
-
end.should raise_error(DataMapper::PluginNotFoundError)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it "should call plugin is_* method" do
|
|
52
|
-
lambda do
|
|
53
|
-
class ::House
|
|
54
|
-
is :example
|
|
55
|
-
end
|
|
56
|
-
end.should_not raise_error
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
it "should pass through arguments to plugin is_* method" do
|
|
60
|
-
class ::House
|
|
61
|
-
is :example ,:option1 => :ping, :option2 => :pong
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
House.is_example_args.length.should == 1
|
|
65
|
-
House.is_example_args.first[:option2].should == :pong
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it "should not add class_methods before the plugin is activated" do
|
|
69
|
-
Cabin.respond_to?(:example_class_method).should be_false
|
|
70
|
-
|
|
71
|
-
class ::Cabin
|
|
72
|
-
is :example
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
Cabin.respond_to?(:example_class_method).should be_true
|
|
76
|
-
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
end
|
|
80
|
-
end
|
data/spec/unit/migrator_spec.rb
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
require 'pathname'
|
|
2
|
-
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
|
3
|
-
|
|
4
|
-
describe DataMapper::Migrator do
|
|
5
|
-
before(:each) do
|
|
6
|
-
DataMapper::Migrator.subclasses.clear
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
after(:each) do
|
|
10
|
-
DataMapper::Migrator.subclasses.clear
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "should keep track of subclasses" do
|
|
14
|
-
lambda { Class.new(DataMapper::Migrator) }.should change{ DataMapper::Migrator.subclasses.size }.by(1)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "should define a class level 'models' method for each subclass" do
|
|
18
|
-
klass = Class.new(DataMapper::Migrator)
|
|
19
|
-
|
|
20
|
-
klass.should respond_to(:models)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it "should keep subclass models seperated" do
|
|
24
|
-
klass_a = Class.new(DataMapper::Migrator)
|
|
25
|
-
klass_b = Class.new(DataMapper::Migrator)
|
|
26
|
-
|
|
27
|
-
klass_a.models << :foo
|
|
28
|
-
|
|
29
|
-
klass_b.models.should be_empty
|
|
30
|
-
|
|
31
|
-
klass_a.models.should == [:foo]
|
|
32
|
-
end
|
|
33
|
-
end
|