dm-core 0.9.9 → 0.9.10
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +10 -0
- data/MIT-LICENSE +1 -1
- data/Rakefile +4 -4
- data/dm-core.gemspec +14 -12
- data/lib/dm-core.rb +1 -1
- data/lib/dm-core/adapters/data_objects_adapter.rb +2 -2
- data/lib/dm-core/adapters/mysql_adapter.rb +1 -1
- data/lib/dm-core/adapters/postgres_adapter.rb +1 -1
- data/lib/dm-core/adapters/sqlite3_adapter.rb +1 -1
- data/lib/dm-core/associations/many_to_one.rb +1 -1
- data/lib/dm-core/associations/one_to_many.rb +18 -18
- data/lib/dm-core/associations/relationship.rb +9 -3
- data/lib/dm-core/associations/relationship_chain.rb +1 -1
- data/lib/dm-core/collection.rb +3 -3
- data/lib/dm-core/model.rb +5 -4
- data/lib/dm-core/resource.rb +11 -5
- data/lib/dm-core/version.rb +1 -1
- data/script/all +3 -4
- data/spec/integration/association_spec.rb +18 -18
- data/spec/integration/association_through_spec.rb +4 -4
- data/spec/integration/associations/many_to_many_spec.rb +9 -9
- data/spec/integration/associations/many_to_one_spec.rb +1 -1
- data/spec/integration/associations/one_to_many_spec.rb +3 -3
- data/spec/integration/collection_spec.rb +2 -2
- data/spec/integration/dependency_queue_spec.rb +1 -1
- data/spec/integration/model_spec.rb +1 -1
- data/spec/integration/mysql_adapter_spec.rb +1 -1
- data/spec/integration/postgres_adapter_spec.rb +16 -16
- data/spec/integration/property_spec.rb +10 -6
- data/spec/integration/query_spec.rb +4 -4
- data/spec/integration/repository_spec.rb +1 -1
- data/spec/integration/sqlite3_adapter_spec.rb +7 -7
- data/spec/integration/sti_spec.rb +6 -6
- data/spec/integration/strategic_eager_loading_spec.rb +14 -11
- data/spec/integration/type_spec.rb +10 -6
- data/spec/lib/logging_helper.rb +11 -11
- data/spec/spec_helper.rb +8 -4
- data/spec/unit/adapters/data_objects_adapter_spec.rb +9 -5
- data/spec/unit/adapters/in_memory_adapter_spec.rb +1 -1
- data/spec/unit/adapters/postgres_adapter_spec.rb +5 -5
- data/spec/unit/associations/many_to_many_spec.rb +2 -2
- data/spec/unit/associations/many_to_one_spec.rb +3 -3
- data/spec/unit/associations/one_to_many_spec.rb +2 -2
- data/spec/unit/associations/relationship_spec.rb +6 -6
- data/spec/unit/associations_spec.rb +21 -21
- data/spec/unit/identity_map_spec.rb +3 -3
- data/spec/unit/is_spec.rb +7 -7
- data/spec/unit/property_spec.rb +7 -7
- data/spec/unit/resource_spec.rb +12 -12
- data/spec/unit/transaction_spec.rb +1 -1
- data/tasks/dm.rb +1 -1
- metadata +6 -6
@@ -4,7 +4,7 @@ if ADAPTER
|
|
4
4
|
describe 'through-associations' do
|
5
5
|
before :all do
|
6
6
|
repository(ADAPTER) do
|
7
|
-
class Tag
|
7
|
+
class ::Tag
|
8
8
|
include DataMapper::Resource
|
9
9
|
def self.default_repository_name
|
10
10
|
ADAPTER
|
@@ -22,7 +22,7 @@ if ADAPTER
|
|
22
22
|
has n, :posts, :through => :taggings
|
23
23
|
end
|
24
24
|
|
25
|
-
class Tagging
|
25
|
+
class ::Tagging
|
26
26
|
include DataMapper::Resource
|
27
27
|
def self.default_repository_name
|
28
28
|
ADAPTER
|
@@ -35,7 +35,7 @@ if ADAPTER
|
|
35
35
|
belongs_to :tag
|
36
36
|
end
|
37
37
|
|
38
|
-
class Post
|
38
|
+
class ::Post
|
39
39
|
include DataMapper::Resource
|
40
40
|
def self.default_repository_name
|
41
41
|
ADAPTER
|
@@ -61,7 +61,7 @@ if ADAPTER
|
|
61
61
|
Post.taggings.tag.voided => true
|
62
62
|
end
|
63
63
|
|
64
|
-
class Relationship
|
64
|
+
class ::Relationship
|
65
65
|
include DataMapper::Resource
|
66
66
|
def self.default_repository_name
|
67
67
|
ADAPTER
|
@@ -2,7 +2,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_hel
|
|
2
2
|
|
3
3
|
describe DataMapper::Associations::ManyToMany::Proxy do
|
4
4
|
before :all do
|
5
|
-
class Editor
|
5
|
+
class ::Editor
|
6
6
|
include DataMapper::Resource
|
7
7
|
|
8
8
|
def self.default_repository_name; ADAPTER end
|
@@ -15,7 +15,7 @@ describe DataMapper::Associations::ManyToMany::Proxy do
|
|
15
15
|
|
16
16
|
Object.send(:remove_const, :Book) if defined?(Book)
|
17
17
|
|
18
|
-
class Book
|
18
|
+
class ::Book
|
19
19
|
include DataMapper::Resource
|
20
20
|
|
21
21
|
def self.default_repository_name; ADAPTER end
|
@@ -190,7 +190,7 @@ describe DataMapper::Associations::ManyToMany::Proxy do
|
|
190
190
|
|
191
191
|
describe "with natural keys" do
|
192
192
|
before :all do
|
193
|
-
class Author
|
193
|
+
class ::Author
|
194
194
|
include DataMapper::Resource
|
195
195
|
|
196
196
|
def self.default_repository_name; ADAPTER end
|
@@ -200,7 +200,7 @@ describe DataMapper::Associations::ManyToMany::Proxy do
|
|
200
200
|
has n, :books, :through => Resource
|
201
201
|
end
|
202
202
|
|
203
|
-
class Book
|
203
|
+
class ::Book
|
204
204
|
has n, :authors, :through => Resource
|
205
205
|
end
|
206
206
|
end
|
@@ -237,7 +237,7 @@ describe DataMapper::Associations::ManyToMany::Proxy do
|
|
237
237
|
|
238
238
|
describe "When join model has non-serial (integer) natural keys." do
|
239
239
|
before :all do
|
240
|
-
class Tag
|
240
|
+
class ::Tag
|
241
241
|
include DataMapper::Resource
|
242
242
|
|
243
243
|
def self.default_repository_name; ADAPTER end
|
@@ -249,7 +249,7 @@ describe DataMapper::Associations::ManyToMany::Proxy do
|
|
249
249
|
has n, :books, :through => :book_taggings
|
250
250
|
end
|
251
251
|
|
252
|
-
class BookTagging
|
252
|
+
class ::BookTagging
|
253
253
|
include DataMapper::Resource
|
254
254
|
|
255
255
|
def self.default_repository_name; ADAPTER end
|
@@ -261,7 +261,7 @@ describe DataMapper::Associations::ManyToMany::Proxy do
|
|
261
261
|
belongs_to :tag
|
262
262
|
end
|
263
263
|
|
264
|
-
class Book
|
264
|
+
class ::Book
|
265
265
|
has n, :book_taggings
|
266
266
|
has n, :tags, :through => :book_taggings
|
267
267
|
end
|
@@ -296,7 +296,7 @@ describe DataMapper::Associations::ManyToMany::Proxy do
|
|
296
296
|
|
297
297
|
describe "with renamed associations" do
|
298
298
|
before :all do
|
299
|
-
class Singer
|
299
|
+
class ::Singer
|
300
300
|
include DataMapper::Resource
|
301
301
|
|
302
302
|
def self.default_repository_name; ADAPTER end
|
@@ -307,7 +307,7 @@ describe DataMapper::Associations::ManyToMany::Proxy do
|
|
307
307
|
has n, :tunes, :through => Resource, :class_name => 'Song'
|
308
308
|
end
|
309
309
|
|
310
|
-
class Song
|
310
|
+
class ::Song
|
311
311
|
include DataMapper::Resource
|
312
312
|
|
313
313
|
def self.default_repository_name; ADAPTER end
|
@@ -58,7 +58,7 @@ if ADAPTER
|
|
58
58
|
step_child = ManyToOneSpec::StepChild.first(:id => @step_child.id)
|
59
59
|
logger do |log|
|
60
60
|
# should retrieve from the IdentityMap
|
61
|
-
child.parent.
|
61
|
+
child.parent.should equal(parent)
|
62
62
|
|
63
63
|
# should retrieve from the datasource
|
64
64
|
other = step_child.parent
|
@@ -2,7 +2,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_hel
|
|
2
2
|
require 'pp'
|
3
3
|
describe "OneToMany" do
|
4
4
|
before(:all) do
|
5
|
-
class Team
|
5
|
+
class ::Team
|
6
6
|
include DataMapper::Resource
|
7
7
|
|
8
8
|
def self.default_repository_name; ADAPTER end
|
@@ -14,10 +14,10 @@ describe "OneToMany" do
|
|
14
14
|
has n, :players
|
15
15
|
end
|
16
16
|
|
17
|
-
class BaseballTeam < Team
|
17
|
+
class ::BaseballTeam < Team
|
18
18
|
end
|
19
19
|
|
20
|
-
class Player
|
20
|
+
class ::Player
|
21
21
|
include DataMapper::Resource
|
22
22
|
|
23
23
|
def self.default_repository_name; ADAPTER end
|
@@ -561,7 +561,7 @@ if ADAPTER
|
|
561
561
|
end
|
562
562
|
|
563
563
|
it "should find a resource in a collection by typecasting the key" do
|
564
|
-
resource = @collection.get(
|
564
|
+
resource = @collection.get(*@nancy.key)
|
565
565
|
resource.should be_kind_of(DataMapper::Resource)
|
566
566
|
resource.id.should == @nancy.id
|
567
567
|
end
|
@@ -569,7 +569,7 @@ if ADAPTER
|
|
569
569
|
it 'should not find a resource not in the collection' do
|
570
570
|
@query.update(:offset => 0, :limit => 3)
|
571
571
|
@david = Zebra.create(:name => 'David', :age => 15, :notes => 'Albino')
|
572
|
-
@collection.get(
|
572
|
+
@collection.get(*@david.key).should be_nil
|
573
573
|
end
|
574
574
|
end
|
575
575
|
|
@@ -8,7 +8,7 @@ if HAS_POSTGRES
|
|
8
8
|
|
9
9
|
describe "auto migrating" do
|
10
10
|
before :all do
|
11
|
-
class Sputnik
|
11
|
+
class ::Sputnik
|
12
12
|
include DataMapper::Resource
|
13
13
|
|
14
14
|
property :id, Serial
|
@@ -32,7 +32,7 @@ if HAS_POSTGRES
|
|
32
32
|
describe '#312' do
|
33
33
|
it "should behave sanely for time fields" do
|
34
34
|
|
35
|
-
class Thing
|
35
|
+
class ::Thing
|
36
36
|
include DataMapper::Resource
|
37
37
|
property :id, Integer, :serial => true
|
38
38
|
property :created_at, Time
|
@@ -57,7 +57,7 @@ if HAS_POSTGRES
|
|
57
57
|
|
58
58
|
describe "querying metadata" do
|
59
59
|
before :all do
|
60
|
-
class Sputnik
|
60
|
+
class ::Sputnik
|
61
61
|
include DataMapper::Resource
|
62
62
|
|
63
63
|
property :id, Serial
|
@@ -86,7 +86,7 @@ if HAS_POSTGRES
|
|
86
86
|
|
87
87
|
describe "handling transactions" do
|
88
88
|
before :all do
|
89
|
-
class Sputnik
|
89
|
+
class ::Sputnik
|
90
90
|
include DataMapper::Resource
|
91
91
|
|
92
92
|
property :id, Serial
|
@@ -118,14 +118,14 @@ if HAS_POSTGRES
|
|
118
118
|
|
119
119
|
describe "reading & writing a database" do
|
120
120
|
before :all do
|
121
|
-
class User
|
121
|
+
class ::User
|
122
122
|
include DataMapper::Resource
|
123
123
|
|
124
124
|
property :id, Serial
|
125
125
|
property :name, DM::Text
|
126
126
|
end
|
127
127
|
|
128
|
-
class Voyager
|
128
|
+
class ::Voyager
|
129
129
|
include DataMapper::Resource
|
130
130
|
storage_names[:postgres] = 'voyagers'
|
131
131
|
|
@@ -163,7 +163,7 @@ if HAS_POSTGRES
|
|
163
163
|
result.should be_kind_of(Array)
|
164
164
|
row = result.first
|
165
165
|
row.should be_kind_of(Struct)
|
166
|
-
row.members.should == %w{id name}
|
166
|
+
row.members.map { |m| m.to_s }.should == %w{id name}
|
167
167
|
|
168
168
|
row.id.should == 1
|
169
169
|
row.name.should == 'Paul'
|
@@ -182,7 +182,7 @@ if HAS_POSTGRES
|
|
182
182
|
|
183
183
|
describe "CRUD for serial Key" do
|
184
184
|
before :all do
|
185
|
-
class VideoGame
|
185
|
+
class ::VideoGame
|
186
186
|
include DataMapper::Resource
|
187
187
|
|
188
188
|
property :id, Serial
|
@@ -282,7 +282,7 @@ if HAS_POSTGRES
|
|
282
282
|
|
283
283
|
describe "CRUD for Composite Key" do
|
284
284
|
before :all do
|
285
|
-
class BankCustomer
|
285
|
+
class ::BankCustomer
|
286
286
|
include DataMapper::Resource
|
287
287
|
|
288
288
|
property :bank, String, :key => true
|
@@ -376,7 +376,7 @@ if HAS_POSTGRES
|
|
376
376
|
|
377
377
|
describe "Ordering a Query" do
|
378
378
|
before :all do
|
379
|
-
class SailBoat
|
379
|
+
class ::SailBoat
|
380
380
|
include DataMapper::Resource
|
381
381
|
property :id, Serial
|
382
382
|
property :name, String
|
@@ -423,7 +423,7 @@ if HAS_POSTGRES
|
|
423
423
|
|
424
424
|
describe "Lazy Loaded Properties" do
|
425
425
|
before :all do
|
426
|
-
class SailBoat
|
426
|
+
class ::SailBoat
|
427
427
|
include DataMapper::Resource
|
428
428
|
property :id, Serial
|
429
429
|
property :notes, String, :lazy => [:notes]
|
@@ -467,7 +467,7 @@ if HAS_POSTGRES
|
|
467
467
|
|
468
468
|
describe "finders" do
|
469
469
|
before :all do
|
470
|
-
class SerialFinderSpec
|
470
|
+
class ::SerialFinderSpec
|
471
471
|
include DataMapper::Resource
|
472
472
|
|
473
473
|
property :id, Serial
|
@@ -528,7 +528,7 @@ if HAS_POSTGRES
|
|
528
528
|
|
529
529
|
describe "belongs_to associations" do
|
530
530
|
before :all do
|
531
|
-
class Engine
|
531
|
+
class ::Engine
|
532
532
|
include DataMapper::Resource
|
533
533
|
def self.default_repository_name; :postgres end
|
534
534
|
|
@@ -536,7 +536,7 @@ if HAS_POSTGRES
|
|
536
536
|
property :name, String
|
537
537
|
end
|
538
538
|
|
539
|
-
class Yard
|
539
|
+
class ::Yard
|
540
540
|
include DataMapper::Resource
|
541
541
|
def self.default_repository_name; :postgres end
|
542
542
|
|
@@ -617,7 +617,7 @@ if HAS_POSTGRES
|
|
617
617
|
|
618
618
|
describe "has n associations" do
|
619
619
|
before :all do
|
620
|
-
class Host
|
620
|
+
class ::Host
|
621
621
|
include DataMapper::Resource
|
622
622
|
def self.default_repository_name; :postgres end
|
623
623
|
|
@@ -627,7 +627,7 @@ if HAS_POSTGRES
|
|
627
627
|
has n, :slices
|
628
628
|
end
|
629
629
|
|
630
|
-
class Slice
|
630
|
+
class ::Slice
|
631
631
|
include DataMapper::Resource
|
632
632
|
def self.default_repository_name; :postgres end
|
633
633
|
|
@@ -1,11 +1,15 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
2
|
|
3
|
-
|
4
|
-
require '
|
3
|
+
if RUBY_VERSION >= '1.9.0'
|
4
|
+
require 'csv'
|
5
|
+
else
|
6
|
+
gem 'fastercsv', '~>1.4.0'
|
7
|
+
require 'fastercsv'
|
8
|
+
end
|
5
9
|
|
6
10
|
describe DataMapper::Property do
|
7
11
|
before do
|
8
|
-
module PropertySpec
|
12
|
+
module ::PropertySpec
|
9
13
|
class Resource
|
10
14
|
include DataMapper::Resource
|
11
15
|
end
|
@@ -23,7 +27,7 @@ if ADAPTER
|
|
23
27
|
describe DataMapper::Property, "with #{ADAPTER}" do
|
24
28
|
describe " tracking strategies" do
|
25
29
|
before :all do
|
26
|
-
class Actor
|
30
|
+
class ::Actor
|
27
31
|
include DataMapper::Resource
|
28
32
|
|
29
33
|
property :id, Serial
|
@@ -145,7 +149,7 @@ if ADAPTER
|
|
145
149
|
|
146
150
|
describe "lazy loading" do
|
147
151
|
before :all do
|
148
|
-
class RowBoat
|
152
|
+
class ::RowBoat
|
149
153
|
include DataMapper::Resource
|
150
154
|
property :id, Serial
|
151
155
|
property :notes, String, :lazy => [:notes]
|
@@ -198,7 +202,7 @@ if ADAPTER
|
|
198
202
|
|
199
203
|
describe 'defaults' do
|
200
204
|
before :all do
|
201
|
-
class Catamaran
|
205
|
+
class ::Catamaran
|
202
206
|
include DataMapper::Resource
|
203
207
|
property :id, Serial
|
204
208
|
property :name, String
|
@@ -424,8 +424,8 @@ if ADAPTER
|
|
424
424
|
factory = DataMapper::Associations::Relationship.new(
|
425
425
|
:factory,
|
426
426
|
ADAPTER,
|
427
|
-
|
428
|
-
|
427
|
+
QuerySpec::Vehicle,
|
428
|
+
QuerySpec::Factory,
|
429
429
|
{ :child_key => [ :factory_id ], :parent_key => [ :id ] }
|
430
430
|
)
|
431
431
|
results = repository(ADAPTER) { QuerySpec::Vehicle.all(:links => [ factory ]) }
|
@@ -446,8 +446,8 @@ if ADAPTER
|
|
446
446
|
region = DataMapper::Associations::Relationship.new(
|
447
447
|
:region,
|
448
448
|
ADAPTER,
|
449
|
-
|
450
|
-
|
449
|
+
QuerySpec::Factory,
|
450
|
+
QuerySpec::Region,
|
451
451
|
{ :child_key => [ :region_id ], :parent_key => [ :id ] }
|
452
452
|
)
|
453
453
|
results = repository(ADAPTER) { QuerySpec::Vehicle.all(:links => [ 'factory', region ]) }
|
@@ -3,7 +3,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
|
3
3
|
if ADAPTER
|
4
4
|
describe DataMapper::Repository, "with #{ADAPTER}" do
|
5
5
|
before :all do
|
6
|
-
class SerialFinderSpec
|
6
|
+
class ::SerialFinderSpec
|
7
7
|
include DataMapper::Resource
|
8
8
|
|
9
9
|
property :id, Serial
|
@@ -8,7 +8,7 @@ if HAS_SQLITE3
|
|
8
8
|
|
9
9
|
describe "auto migrating" do
|
10
10
|
before :all do
|
11
|
-
class Sputnik
|
11
|
+
class ::Sputnik
|
12
12
|
include DataMapper::Resource
|
13
13
|
|
14
14
|
property :id, Serial
|
@@ -30,7 +30,7 @@ if HAS_SQLITE3
|
|
30
30
|
|
31
31
|
describe "querying metadata" do
|
32
32
|
before :all do
|
33
|
-
class Sputnik
|
33
|
+
class ::Sputnik
|
34
34
|
include DataMapper::Resource
|
35
35
|
|
36
36
|
property :id, Serial
|
@@ -76,7 +76,7 @@ if HAS_SQLITE3
|
|
76
76
|
|
77
77
|
describe "handling transactions" do
|
78
78
|
before :all do
|
79
|
-
class Sputnik
|
79
|
+
class ::Sputnik
|
80
80
|
include DataMapper::Resource
|
81
81
|
|
82
82
|
property :id, Serial
|
@@ -108,7 +108,7 @@ if HAS_SQLITE3
|
|
108
108
|
|
109
109
|
describe "reading & writing a database" do
|
110
110
|
before :all do
|
111
|
-
class User
|
111
|
+
class ::User
|
112
112
|
include DataMapper::Resource
|
113
113
|
|
114
114
|
property :id, Serial
|
@@ -134,7 +134,7 @@ if HAS_SQLITE3
|
|
134
134
|
result.should be_kind_of(Array)
|
135
135
|
row = result.first
|
136
136
|
row.should be_kind_of(Struct)
|
137
|
-
row.members.should == %w{id name}
|
137
|
+
row.members.map { |m| m.to_s }.should == %w{id name}
|
138
138
|
|
139
139
|
row.id.should == 1
|
140
140
|
row.name.should == 'Paul'
|
@@ -153,7 +153,7 @@ if HAS_SQLITE3
|
|
153
153
|
|
154
154
|
describe "CRUD for serial Key" do
|
155
155
|
before :all do
|
156
|
-
class VideoGame
|
156
|
+
class ::VideoGame
|
157
157
|
include DataMapper::Resource
|
158
158
|
|
159
159
|
property :id, Serial
|
@@ -255,7 +255,7 @@ if HAS_SQLITE3
|
|
255
255
|
|
256
256
|
describe "CRUD for Composite Key" do
|
257
257
|
before :all do
|
258
|
-
class BankCustomer
|
258
|
+
class ::BankCustomer
|
259
259
|
include DataMapper::Resource
|
260
260
|
|
261
261
|
property :bank, String, :key => true
|