praxis-mapper 3.4.0 → 4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/CHANGELOG.md +20 -1
- data/lib/praxis-mapper.rb +7 -0
- data/lib/praxis-mapper/connection_factories/sequel.rb +66 -0
- data/lib/praxis-mapper/connection_factories/simple.rb +27 -0
- data/lib/praxis-mapper/connection_manager.rb +29 -50
- data/lib/praxis-mapper/identity_map.rb +37 -13
- data/lib/praxis-mapper/identity_map_extensions/persistence.rb +83 -0
- data/lib/praxis-mapper/query/base.rb +1 -1
- data/lib/praxis-mapper/query/sequel.rb +11 -0
- data/lib/praxis-mapper/sequel_compat.rb +99 -0
- data/lib/praxis-mapper/version.rb +1 -1
- data/praxis-mapper.gemspec +2 -0
- data/spec/factories/all.rb +32 -0
- data/spec/praxis-mapper/connection_factories/sequel_spec.rb +67 -0
- data/spec/praxis-mapper/connection_factories/simple_spec.rb +29 -0
- data/spec/praxis-mapper/connection_manager_spec.rb +49 -71
- data/spec/praxis-mapper/identity_map_extensions/persistence_spec.rb +122 -0
- data/spec/praxis-mapper/sequel_compat_spec.rb +106 -0
- data/spec/spec_helper.rb +19 -4
- data/spec/support/spec_sequel_models.rb +110 -0
- metadata +46 -2
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Praxis::Mapper::SequelCompat do
|
5
|
+
|
6
|
+
context 'class methods' do
|
7
|
+
|
8
|
+
subject(:model) { PostModel }
|
9
|
+
its(:identities) { should eq [:id] }
|
10
|
+
its(:repository_name) { should be :sequel}
|
11
|
+
|
12
|
+
it 'handles composite primary keys' do
|
13
|
+
CommentModel.identities.should eq [[:author_id, :post_id]]
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'instances loaded through an identity map' do
|
19
|
+
|
20
|
+
let!(:comment) { create(:comment) }
|
21
|
+
let(:user) { comment.author }
|
22
|
+
let(:post) { comment.post }
|
23
|
+
|
24
|
+
let(:identity_map) { Praxis::Mapper::IdentityMap.new }
|
25
|
+
|
26
|
+
let(:loaded_comment) { identity_map.get(CommentModel, [:author_id, :post_id] => [comment.author_id, comment.post_id]) }
|
27
|
+
let(:loaded_post) { identity_map.get(PostModel, id: post.id) }
|
28
|
+
let(:loaded_user) { identity_map.get(UserModel, id: user.id) }
|
29
|
+
|
30
|
+
before do
|
31
|
+
identity_map.load(CommentModel) do
|
32
|
+
track :author, :post
|
33
|
+
end
|
34
|
+
identity_map.finalize!
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
it 'are actually loaded properly' do
|
39
|
+
loaded_comment.should eq comment
|
40
|
+
loaded_post.should eq post
|
41
|
+
loaded_user.should eq user
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'are not modified' do
|
45
|
+
loaded_comment.modified?.should be false
|
46
|
+
loaded_post.modified?.should be false
|
47
|
+
loaded_user.modified?.should be false
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'association accessors' do
|
51
|
+
it 'are wired up correctly' do
|
52
|
+
loaded_comment.author.should be loaded_user
|
53
|
+
loaded_comment.post.should be loaded_post
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'that have composite keys' do
|
58
|
+
let!(:composite_record) { create(:composite) }
|
59
|
+
let!(:other_records) { create_list(:other, 5, composite: composite_record) }
|
60
|
+
|
61
|
+
context 'tracking a one_to_many association' do
|
62
|
+
before do
|
63
|
+
identity_map.load(CompositeIdSequelModel) do
|
64
|
+
track :others
|
65
|
+
end
|
66
|
+
identity_map.finalize!
|
67
|
+
end
|
68
|
+
|
69
|
+
let(:loaded_composite) do
|
70
|
+
identity_map.get(
|
71
|
+
CompositeIdSequelModel,
|
72
|
+
[:id, :type] => [composite_record.id, composite_record.type])
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
it 'loads and handles associations properly' do
|
78
|
+
identity_map.all(OtherSequelModel).should =~ other_records
|
79
|
+
loaded_composite.others.should =~ other_records
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'tracking a many_to_one association' do
|
85
|
+
before do
|
86
|
+
identity_map.load(OtherSequelModel) do
|
87
|
+
track :composite
|
88
|
+
end
|
89
|
+
identity_map.finalize!
|
90
|
+
end
|
91
|
+
|
92
|
+
let(:loaded_others) { identity_map.all(OtherSequelModel) }
|
93
|
+
|
94
|
+
it 'loads and handles associations properly' do
|
95
|
+
identity_map.all(CompositeIdSequelModel).should =~ [composite_record]
|
96
|
+
loaded_others.all? do |loaded_other|
|
97
|
+
loaded_other.composite == composite_record
|
98
|
+
end.should be true
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -14,14 +14,12 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
14
14
|
|
15
15
|
|
16
16
|
|
17
|
-
Bundler.setup
|
18
|
-
|
19
|
-
#Bundler.require(:default, :development, :test)
|
20
|
-
|
21
17
|
|
22
18
|
require 'praxis-mapper'
|
23
19
|
require 'active_support/core_ext/kernel'
|
24
20
|
|
21
|
+
|
22
|
+
require_relative 'support/spec_sequel_models'
|
25
23
|
require_relative 'support/spec_models'
|
26
24
|
require_relative 'support/spec_resources'
|
27
25
|
require_relative 'spec_fixtures'
|
@@ -29,9 +27,11 @@ require_relative 'spec_fixtures'
|
|
29
27
|
require 'praxis-mapper/support'
|
30
28
|
|
31
29
|
require 'randexp'
|
30
|
+
require 'factory_girl'
|
32
31
|
|
33
32
|
require 'pry'
|
34
33
|
|
34
|
+
|
35
35
|
RSpec.configure do |config|
|
36
36
|
config.backtrace_exclusion_patterns = [
|
37
37
|
/\/lib\d*\/ruby\//,
|
@@ -42,7 +42,15 @@ RSpec.configure do |config|
|
|
42
42
|
/org\/jruby\/.*.java/
|
43
43
|
]
|
44
44
|
|
45
|
+
config.include FactoryGirl::Syntax::Methods
|
46
|
+
|
45
47
|
config.before(:suite) do
|
48
|
+
FactoryGirl.find_definitions
|
49
|
+
Sequel::Model.db.transaction do
|
50
|
+
FactoryGirl.lint
|
51
|
+
raise Sequel::Rollback
|
52
|
+
end
|
53
|
+
|
46
54
|
Praxis::Mapper.finalize!
|
47
55
|
|
48
56
|
Praxis::Mapper::ConnectionManager.repository(:default, query: Praxis::Mapper::Support::MemoryQuery) do
|
@@ -60,4 +68,11 @@ RSpec.configure do |config|
|
|
60
68
|
Praxis::Mapper::IdentityMap.current.clear!
|
61
69
|
end
|
62
70
|
|
71
|
+
config.around(:each) do |example|
|
72
|
+
Sequel::Model.db.transaction do
|
73
|
+
example.run
|
74
|
+
raise Sequel::Rollback
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
63
78
|
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
|
2
|
+
#Sequel::Model.db = Sequel.mock
|
3
|
+
#Sequel::Model.db.columns = [:id]
|
4
|
+
|
5
|
+
DB = Sequel.sqlite
|
6
|
+
|
7
|
+
DB.create_table! :users do
|
8
|
+
primary_key :id
|
9
|
+
|
10
|
+
String :name
|
11
|
+
String :email
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
DB.create_table! :posts do
|
16
|
+
primary_key :id
|
17
|
+
Integer :author_id
|
18
|
+
|
19
|
+
String :title
|
20
|
+
String :body
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
DB.create_table! :comments do
|
25
|
+
|
26
|
+
Integer :author_id
|
27
|
+
Integer :post_id
|
28
|
+
|
29
|
+
String :body
|
30
|
+
|
31
|
+
primary_key [:author_id, :post_id]
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
DB.create_table! :composite_ids do
|
36
|
+
String :id
|
37
|
+
String :type
|
38
|
+
|
39
|
+
String :name
|
40
|
+
|
41
|
+
primary_key [:id, :type]
|
42
|
+
end
|
43
|
+
|
44
|
+
DB.create_table! :others do
|
45
|
+
primary_key :id
|
46
|
+
|
47
|
+
String :composite_id
|
48
|
+
String :composite_type
|
49
|
+
end
|
50
|
+
|
51
|
+
Praxis::Mapper::ConnectionManager.setup do
|
52
|
+
repository(:sequel, query: Praxis::Mapper::Query::Sequel) do
|
53
|
+
DB
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class UserModel < Sequel::Model(:users)
|
58
|
+
include Praxis::Mapper::SequelCompat
|
59
|
+
|
60
|
+
repository_name :sequel
|
61
|
+
|
62
|
+
one_to_many :posts, class: 'PostModel'
|
63
|
+
one_to_many :comments, class: 'CommentModel'
|
64
|
+
|
65
|
+
many_to_many :commented_posts, class: 'PostModel',
|
66
|
+
join_table: 'comments', join_model: 'CommentModel'
|
67
|
+
end
|
68
|
+
|
69
|
+
class PostModel < Sequel::Model(:posts)
|
70
|
+
include Praxis::Mapper::SequelCompat
|
71
|
+
|
72
|
+
repository_name :sequel
|
73
|
+
|
74
|
+
many_to_one :author, class: 'UserModel'
|
75
|
+
one_to_many :comments, class: 'CommentModel'
|
76
|
+
end
|
77
|
+
|
78
|
+
class CommentModel < Sequel::Model(:comments)
|
79
|
+
include Praxis::Mapper::SequelCompat
|
80
|
+
|
81
|
+
repository_name :sequel
|
82
|
+
|
83
|
+
set_primary_key [:author_id, :post_id]
|
84
|
+
|
85
|
+
many_to_one :author, class: 'UserModel'
|
86
|
+
many_to_one :post, class: 'PostModel'
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
class CompositeIdSequelModel < Sequel::Model(:composite_ids)
|
91
|
+
include Praxis::Mapper::SequelCompat
|
92
|
+
|
93
|
+
repository_name :sequel
|
94
|
+
|
95
|
+
set_primary_key [:id, :type]
|
96
|
+
|
97
|
+
one_to_many :others,
|
98
|
+
class: 'OtherSequelModel',
|
99
|
+
key: [:composite_id, :composite_type]
|
100
|
+
end
|
101
|
+
|
102
|
+
class OtherSequelModel < Sequel::Model(:others)
|
103
|
+
include Praxis::Mapper::SequelCompat
|
104
|
+
|
105
|
+
repository_name :sequel
|
106
|
+
|
107
|
+
many_to_one :composite,
|
108
|
+
class: 'CompositeIdSequelModel',
|
109
|
+
key: [:composite_id, :composite_type]
|
110
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: praxis-mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: '4.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josep M. Blanquer
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-06-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: randexp
|
@@ -207,6 +207,34 @@ dependencies:
|
|
207
207
|
- - "~>"
|
208
208
|
- !ruby/object:Gem::Version
|
209
209
|
version: '1'
|
210
|
+
- !ruby/object:Gem::Dependency
|
211
|
+
name: sqlite3
|
212
|
+
requirement: !ruby/object:Gem::Requirement
|
213
|
+
requirements:
|
214
|
+
- - ">="
|
215
|
+
- !ruby/object:Gem::Version
|
216
|
+
version: '0'
|
217
|
+
type: :development
|
218
|
+
prerelease: false
|
219
|
+
version_requirements: !ruby/object:Gem::Requirement
|
220
|
+
requirements:
|
221
|
+
- - ">="
|
222
|
+
- !ruby/object:Gem::Version
|
223
|
+
version: '0'
|
224
|
+
- !ruby/object:Gem::Dependency
|
225
|
+
name: factory_girl
|
226
|
+
requirement: !ruby/object:Gem::Requirement
|
227
|
+
requirements:
|
228
|
+
- - ">="
|
229
|
+
- !ruby/object:Gem::Version
|
230
|
+
version: '0'
|
231
|
+
type: :development
|
232
|
+
prerelease: false
|
233
|
+
version_requirements: !ruby/object:Gem::Requirement
|
234
|
+
requirements:
|
235
|
+
- - ">="
|
236
|
+
- !ruby/object:Gem::Version
|
237
|
+
version: '0'
|
210
238
|
description:
|
211
239
|
email:
|
212
240
|
- blanquer@gmail.com
|
@@ -226,9 +254,12 @@ files:
|
|
226
254
|
- Rakefile
|
227
255
|
- lib/praxis-mapper.rb
|
228
256
|
- lib/praxis-mapper/config_hash.rb
|
257
|
+
- lib/praxis-mapper/connection_factories/sequel.rb
|
258
|
+
- lib/praxis-mapper/connection_factories/simple.rb
|
229
259
|
- lib/praxis-mapper/connection_manager.rb
|
230
260
|
- lib/praxis-mapper/finalizable.rb
|
231
261
|
- lib/praxis-mapper/identity_map.rb
|
262
|
+
- lib/praxis-mapper/identity_map_extensions/persistence.rb
|
232
263
|
- lib/praxis-mapper/logging.rb
|
233
264
|
- lib/praxis-mapper/model.rb
|
234
265
|
- lib/praxis-mapper/query/base.rb
|
@@ -236,6 +267,7 @@ files:
|
|
236
267
|
- lib/praxis-mapper/query/sql.rb
|
237
268
|
- lib/praxis-mapper/query_statistics.rb
|
238
269
|
- lib/praxis-mapper/resource.rb
|
270
|
+
- lib/praxis-mapper/sequel_compat.rb
|
239
271
|
- lib/praxis-mapper/support.rb
|
240
272
|
- lib/praxis-mapper/support/factory_girl.rb
|
241
273
|
- lib/praxis-mapper/support/memory_query.rb
|
@@ -244,7 +276,11 @@ files:
|
|
244
276
|
- lib/praxis-mapper/support/schema_loader.rb
|
245
277
|
- lib/praxis-mapper/version.rb
|
246
278
|
- praxis-mapper.gemspec
|
279
|
+
- spec/factories/all.rb
|
280
|
+
- spec/praxis-mapper/connection_factories/sequel_spec.rb
|
281
|
+
- spec/praxis-mapper/connection_factories/simple_spec.rb
|
247
282
|
- spec/praxis-mapper/connection_manager_spec.rb
|
283
|
+
- spec/praxis-mapper/identity_map_extensions/persistence_spec.rb
|
248
284
|
- spec/praxis-mapper/identity_map_spec.rb
|
249
285
|
- spec/praxis-mapper/logging_spec.rb
|
250
286
|
- spec/praxis-mapper/memory_repository_spec.rb
|
@@ -253,11 +289,13 @@ files:
|
|
253
289
|
- spec/praxis-mapper/query/sequel_spec.rb
|
254
290
|
- spec/praxis-mapper/query/sql_spec.rb
|
255
291
|
- spec/praxis-mapper/resource_spec.rb
|
292
|
+
- spec/praxis-mapper/sequel_compat_spec.rb
|
256
293
|
- spec/praxis_mapper_spec.rb
|
257
294
|
- spec/spec_fixtures.rb
|
258
295
|
- spec/spec_helper.rb
|
259
296
|
- spec/support/spec_models.rb
|
260
297
|
- spec/support/spec_resources.rb
|
298
|
+
- spec/support/spec_sequel_models.rb
|
261
299
|
homepage: https://github.com/rightscale/praxis-mapper
|
262
300
|
licenses:
|
263
301
|
- MIT
|
@@ -283,7 +321,11 @@ signing_key:
|
|
283
321
|
specification_version: 4
|
284
322
|
summary: A multi-datastore library designed for efficiency in loading large datasets.
|
285
323
|
test_files:
|
324
|
+
- spec/factories/all.rb
|
325
|
+
- spec/praxis-mapper/connection_factories/sequel_spec.rb
|
326
|
+
- spec/praxis-mapper/connection_factories/simple_spec.rb
|
286
327
|
- spec/praxis-mapper/connection_manager_spec.rb
|
328
|
+
- spec/praxis-mapper/identity_map_extensions/persistence_spec.rb
|
287
329
|
- spec/praxis-mapper/identity_map_spec.rb
|
288
330
|
- spec/praxis-mapper/logging_spec.rb
|
289
331
|
- spec/praxis-mapper/memory_repository_spec.rb
|
@@ -292,9 +334,11 @@ test_files:
|
|
292
334
|
- spec/praxis-mapper/query/sequel_spec.rb
|
293
335
|
- spec/praxis-mapper/query/sql_spec.rb
|
294
336
|
- spec/praxis-mapper/resource_spec.rb
|
337
|
+
- spec/praxis-mapper/sequel_compat_spec.rb
|
295
338
|
- spec/praxis_mapper_spec.rb
|
296
339
|
- spec/spec_fixtures.rb
|
297
340
|
- spec/spec_helper.rb
|
298
341
|
- spec/support/spec_models.rb
|
299
342
|
- spec/support/spec_resources.rb
|
343
|
+
- spec/support/spec_sequel_models.rb
|
300
344
|
has_rdoc:
|