datamapper-dm-core 0.9.11 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,32 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
-
|
3
|
-
if [ HAS_SQLITE3, HAS_MYSQL, HAS_POSTGRES ].include?(ADAPTER)
|
4
|
-
describe DataMapper::Adapters::DataObjectsAdapter, "with #{ADAPTER}" do
|
5
|
-
describe 'a connection' do
|
6
|
-
before do
|
7
|
-
@adapter = DataMapper::Repository.adapters[ADAPTER]
|
8
|
-
@transaction = DataMapper::Transaction.new(@adapter)
|
9
|
-
|
10
|
-
@command = mock('command', :execute_non_query => nil)
|
11
|
-
@connection = mock('connection', :create_command => @command)
|
12
|
-
DataObjects::Connection.stub!(:new).and_return(@connection)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should close automatically when no longer needed' do
|
16
|
-
@connection.should_receive(:close)
|
17
|
-
@adapter.execute('SELECT 1')
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'should not close when a current transaction is active' do
|
21
|
-
@connection.should_receive(:create_command).with('SELECT 1').twice.and_return(@command)
|
22
|
-
@connection.should_not_receive(:close)
|
23
|
-
|
24
|
-
@transaction.begin
|
25
|
-
@transaction.within do
|
26
|
-
@adapter.execute('SELECT 1')
|
27
|
-
@adapter.execute('SELECT 1')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
-
|
3
|
-
describe "DataMapper::DependencyQueue" do
|
4
|
-
before :each do
|
5
|
-
@q = DataMapper::DependencyQueue.new
|
6
|
-
@dependencies = @q.instance_variable_get("@dependencies")
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "#add" do
|
10
|
-
it "should store the supplied callback in @dependencies" do
|
11
|
-
@q.add('MissingConstant') { true }
|
12
|
-
@dependencies['MissingConstant'].first.call.should == true
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "#resolve!" do
|
17
|
-
describe "(when dependency is not defined)" do
|
18
|
-
it "should not alter @dependencies" do
|
19
|
-
@q.add('MissingConstant') { true }
|
20
|
-
old_dependencies = @dependencies.dup
|
21
|
-
@q.resolve!
|
22
|
-
old_dependencies.should == @dependencies
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "(when dependency is defined)" do
|
27
|
-
before :each do
|
28
|
-
@q.add('MissingConstant') { |klass| klass.instance_variable_set("@resolved", true) } # add before MissingConstant is loaded
|
29
|
-
|
30
|
-
class ::MissingConstant
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should execute stored callbacks" do
|
35
|
-
@q.resolve!
|
36
|
-
MissingConstant.instance_variable_get("@resolved").should == true
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should clear @dependencies" do
|
40
|
-
@q.resolve!
|
41
|
-
@dependencies['MissingConstant'].should be_empty
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
@@ -1,197 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
-
|
3
|
-
if ADAPTER
|
4
|
-
module ::ModelSpec
|
5
|
-
class STI
|
6
|
-
include DataMapper::Resource
|
7
|
-
|
8
|
-
def self.default_repository_name
|
9
|
-
ADAPTER
|
10
|
-
end
|
11
|
-
|
12
|
-
property :id, Serial
|
13
|
-
property :name, String
|
14
|
-
property :type, Discriminator
|
15
|
-
end
|
16
|
-
|
17
|
-
class STIDescendant < STI
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "DataMapper::Model with #{ADAPTER}" do
|
22
|
-
before do
|
23
|
-
repository(ADAPTER) do
|
24
|
-
ModelSpec::STI.auto_migrate!
|
25
|
-
end
|
26
|
-
|
27
|
-
@planet = DataMapper::Model.new('planet') do
|
28
|
-
def self.default_repository_name; ADAPTER end
|
29
|
-
property :name, String, :key => true
|
30
|
-
property :distance, Integer
|
31
|
-
end
|
32
|
-
|
33
|
-
@moon = DataMapper::Model.new('moon') do
|
34
|
-
def self.default_repository_name; ADAPTER end
|
35
|
-
property :id, DM::Serial
|
36
|
-
property :name, String
|
37
|
-
end
|
38
|
-
|
39
|
-
@planet.auto_migrate!(ADAPTER)
|
40
|
-
@moon.auto_migrate!(ADAPTER)
|
41
|
-
|
42
|
-
repository(ADAPTER) do
|
43
|
-
@moon.create(:name => "Charon")
|
44
|
-
@moon.create(:name => "Phobos")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe '.new' do
|
49
|
-
it 'should be able to persist' do
|
50
|
-
repository(ADAPTER) do
|
51
|
-
pluto = @planet.new
|
52
|
-
pluto.name = 'Pluto'
|
53
|
-
pluto.distance = 1_000_000
|
54
|
-
pluto.save
|
55
|
-
|
56
|
-
clone = @planet.get!('Pluto')
|
57
|
-
clone.name.should == 'Pluto'
|
58
|
-
clone.distance.should == 1_000_000
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe ".get" do
|
64
|
-
include LoggingHelper
|
65
|
-
|
66
|
-
it "should typecast key" do
|
67
|
-
resource = nil
|
68
|
-
lambda {
|
69
|
-
repository(ADAPTER) do
|
70
|
-
resource = @moon.get("1")
|
71
|
-
end
|
72
|
-
}.should_not raise_error
|
73
|
-
resource.should be_kind_of(DataMapper::Resource)
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should use the identity map within a repository block" do
|
77
|
-
logger do |log|
|
78
|
-
repository(ADAPTER) do
|
79
|
-
@moon.get("1")
|
80
|
-
@moon.get(1)
|
81
|
-
end
|
82
|
-
log.readlines.size.should == 1
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should not use the identity map outside a repository block" do
|
87
|
-
logger do |log|
|
88
|
-
@moon.get(1)
|
89
|
-
@moon.get(1)
|
90
|
-
log.readlines.size.should == 2
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe ".base_model" do
|
96
|
-
describe "(when called on base model)" do
|
97
|
-
it "should refer to itself" do
|
98
|
-
ModelSpec::STI.base_model.should == ModelSpec::STI
|
99
|
-
end
|
100
|
-
end
|
101
|
-
describe "(when called on descendant model)" do
|
102
|
-
it "should refer to the base model" do
|
103
|
-
ModelSpec::STIDescendant.base_model.should == ModelSpec::STI.base_model
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'should provide #load' do
|
109
|
-
ModelSpec::STI.should respond_to(:load)
|
110
|
-
end
|
111
|
-
|
112
|
-
describe '#load' do
|
113
|
-
it 'should load resources with nil discriminator fields' do
|
114
|
-
resource = ModelSpec::STI.create(:name => 'resource')
|
115
|
-
query = ModelSpec::STI.all.query
|
116
|
-
fields = query.fields
|
117
|
-
|
118
|
-
fields.should == ModelSpec::STI.properties(ADAPTER).slice(:id, :name, :type)
|
119
|
-
|
120
|
-
# would blow up prior to fix
|
121
|
-
lambda {
|
122
|
-
ModelSpec::STI.load([ resource.id, resource.name, nil ], query)
|
123
|
-
}.should_not raise_error(NoMethodError)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
it { ModelSpec::STI.should respond_to(:copy) }
|
128
|
-
|
129
|
-
([ :sqlite3, :mysql, :postgres ] - [ ADAPTER ]).each do |alternate|
|
130
|
-
describe '#copy' do
|
131
|
-
describe 'between identical models' do
|
132
|
-
before do
|
133
|
-
ModelSpec::STI.auto_migrate!(alternate)
|
134
|
-
|
135
|
-
ModelSpec::STI.create(:name => 'Record 1')
|
136
|
-
ModelSpec::STI.create(:name => 'Record 2')
|
137
|
-
|
138
|
-
# copy from the default to the alternate repository
|
139
|
-
@return = @resources = ModelSpec::STI.copy(:default, alternate)
|
140
|
-
end
|
141
|
-
|
142
|
-
it 'should return an Enumerable' do
|
143
|
-
@return.should be_a_kind_of(Enumerable)
|
144
|
-
end
|
145
|
-
|
146
|
-
it 'should return Resources' do
|
147
|
-
@return.each { |r| r.should be_a_kind_of(DataMapper::Resource) }
|
148
|
-
end
|
149
|
-
|
150
|
-
it 'should have each Resource set to the expected Repository' do
|
151
|
-
@resources.each { |r| r.repository.name.should == alternate }
|
152
|
-
end
|
153
|
-
|
154
|
-
it 'should create the Resources in the expected Repository' do
|
155
|
-
ModelSpec::STI.all(:repository => repository(alternate)).should == @resources
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
describe 'between different models' do
|
160
|
-
before do
|
161
|
-
# add an extra property to the alternate model
|
162
|
-
repository(alternate) do
|
163
|
-
ModelSpec::STI.property :status, String, :default => 'new'
|
164
|
-
end
|
165
|
-
|
166
|
-
ModelSpec::STI.auto_migrate!(alternate)
|
167
|
-
|
168
|
-
# add new resources to the alternate repository
|
169
|
-
repository(alternate) do
|
170
|
-
ModelSpec::STI.create(:name => 'Record 1')
|
171
|
-
ModelSpec::STI.create(:name => 'Record 2')
|
172
|
-
end
|
173
|
-
|
174
|
-
# copy from the alternate to the default repository
|
175
|
-
@return = @resources = ModelSpec::STI.copy(alternate, :default)
|
176
|
-
end
|
177
|
-
|
178
|
-
it 'should return an Enumerable' do
|
179
|
-
@return.should be_a_kind_of(Enumerable)
|
180
|
-
end
|
181
|
-
|
182
|
-
it 'should return Resources' do
|
183
|
-
@return.each { |r| r.should be_a_kind_of(DataMapper::Resource) }
|
184
|
-
end
|
185
|
-
|
186
|
-
it 'should have each Resource set to the expected Repository' do
|
187
|
-
@resources.each { |r| r.repository.name.should == :default }
|
188
|
-
end
|
189
|
-
|
190
|
-
it 'should create the Resources in the expected Repository' do
|
191
|
-
ModelSpec::STI.all.should == @resources
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
-
|
3
|
-
if HAS_MYSQL
|
4
|
-
describe DataMapper::Adapters::MysqlAdapter do
|
5
|
-
before :all do
|
6
|
-
@adapter = repository(:mysql).adapter
|
7
|
-
end
|
8
|
-
|
9
|
-
before :all do
|
10
|
-
class ::Sputnik
|
11
|
-
include DataMapper::Resource
|
12
|
-
|
13
|
-
property :id, Serial
|
14
|
-
property :name, DM::Text
|
15
|
-
property :object, Object
|
16
|
-
|
17
|
-
auto_migrate!(:mysql)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should handle Object type" do
|
22
|
-
time = Time.now
|
23
|
-
repository(:mysql) do
|
24
|
-
Sputnik.create(:name => "Sputnik", :object => time)
|
25
|
-
Sputnik.first.object.should == time
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "auto migrating" do
|
30
|
-
it "#upgrade_model should work" do
|
31
|
-
@adapter.destroy_model_storage(repository(:mysql), Sputnik)
|
32
|
-
@adapter.storage_exists?("sputniks").should == false
|
33
|
-
Sputnik.auto_migrate!(:mysql)
|
34
|
-
@adapter.storage_exists?("sputniks").should == true
|
35
|
-
@adapter.field_exists?("sputniks", "new_prop").should == false
|
36
|
-
Sputnik.property :new_prop, Integer
|
37
|
-
Sputnik.auto_upgrade!(:mysql)
|
38
|
-
@adapter.field_exists?("sputniks", "new_prop").should == true
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "querying metadata" do
|
43
|
-
it "#storage_exists? should return true for tables that exist" do
|
44
|
-
@adapter.storage_exists?("sputniks").should == true
|
45
|
-
end
|
46
|
-
|
47
|
-
it "#storage_exists? should return false for tables that don't exist" do
|
48
|
-
@adapter.storage_exists?("space turds").should == false
|
49
|
-
end
|
50
|
-
|
51
|
-
it "#field_exists? should return true for columns that exist" do
|
52
|
-
@adapter.field_exists?("sputniks", "name").should == true
|
53
|
-
end
|
54
|
-
|
55
|
-
it "#storage_exists? should return false for tables that don't exist" do
|
56
|
-
@adapter.field_exists?("sputniks", "plur").should == false
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe "handling transactions" do
|
61
|
-
before do
|
62
|
-
@transaction = DataMapper::Transaction.new(@adapter)
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should rollback changes when #rollback_transaction is called" do
|
66
|
-
repository(:mysql) do
|
67
|
-
@transaction.commit do |trans|
|
68
|
-
Sputnik.create(:name => 'my pretty sputnik')
|
69
|
-
trans.rollback
|
70
|
-
end
|
71
|
-
Sputnik.all(:name => 'my pretty sputnik').should be_empty
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should commit changes when #commit_transaction is called" do
|
76
|
-
repository(:mysql) do
|
77
|
-
@transaction.commit do
|
78
|
-
Sputnik.create(:name => 'my pretty sputnik')
|
79
|
-
end
|
80
|
-
Sputnik.all(:name => 'my pretty sputnik').size.should == 1
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|