rom 0.5.0 → 0.6.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +19 -15
- data/.rubocop_todo.yml +28 -0
- data/.travis.yml +8 -1
- data/CHANGELOG.md +40 -0
- data/Gemfile +10 -2
- data/Guardfile +12 -10
- data/README.md +42 -43
- data/Rakefile +13 -23
- data/lib/rom.rb +19 -27
- data/lib/rom/command.rb +118 -0
- data/lib/rom/command_registry.rb +13 -27
- data/lib/rom/commands.rb +1 -59
- data/lib/rom/commands/abstract.rb +147 -0
- data/lib/rom/commands/composite.rb +47 -0
- data/lib/rom/commands/create.rb +2 -17
- data/lib/rom/commands/delete.rb +5 -25
- data/lib/rom/commands/result.rb +5 -5
- data/lib/rom/commands/update.rb +3 -27
- data/lib/rom/constants.rb +19 -0
- data/lib/rom/env.rb +85 -35
- data/lib/rom/global.rb +173 -42
- data/lib/rom/header.rb +5 -5
- data/lib/rom/header/attribute.rb +2 -2
- data/lib/rom/lint/enumerable_dataset.rb +52 -0
- data/lib/rom/lint/linter.rb +64 -0
- data/lib/rom/lint/repository.rb +78 -0
- data/lib/rom/lint/spec.rb +20 -0
- data/lib/rom/lint/test.rb +98 -0
- data/lib/rom/mapper.rb +32 -5
- data/lib/rom/mapper/attribute_dsl.rb +240 -0
- data/lib/rom/mapper/dsl.rb +100 -0
- data/lib/rom/mapper/model_dsl.rb +55 -0
- data/lib/rom/mapper_registry.rb +8 -1
- data/lib/rom/memory.rb +4 -0
- data/lib/rom/memory/commands.rb +46 -0
- data/lib/rom/memory/dataset.rb +72 -0
- data/lib/rom/memory/relation.rb +44 -0
- data/lib/rom/memory/repository.rb +62 -0
- data/lib/rom/memory/storage.rb +57 -0
- data/lib/rom/model_builder.rb +44 -5
- data/lib/rom/processor.rb +1 -1
- data/lib/rom/processor/transproc.rb +109 -16
- data/lib/rom/reader.rb +91 -39
- data/lib/rom/relation.rb +165 -26
- data/lib/rom/relation/composite.rb +132 -0
- data/lib/rom/relation/curried.rb +48 -0
- data/lib/rom/relation/lazy.rb +173 -0
- data/lib/rom/relation/loaded.rb +75 -0
- data/lib/rom/relation/registry_reader.rb +23 -0
- data/lib/rom/repository.rb +93 -34
- data/lib/rom/setup.rb +54 -98
- data/lib/rom/setup/finalize.rb +85 -76
- data/lib/rom/setup_dsl/command.rb +36 -0
- data/lib/rom/setup_dsl/command_dsl.rb +34 -0
- data/lib/rom/setup_dsl/mapper.rb +32 -0
- data/lib/rom/setup_dsl/mapper_dsl.rb +30 -0
- data/lib/rom/setup_dsl/relation.rb +21 -0
- data/lib/rom/setup_dsl/setup.rb +75 -0
- data/lib/rom/support/array_dataset.rb +38 -0
- data/lib/rom/support/class_builder.rb +44 -0
- data/lib/rom/support/class_macros.rb +56 -0
- data/lib/rom/support/data_proxy.rb +102 -0
- data/lib/rom/support/enumerable_dataset.rb +58 -0
- data/lib/rom/support/inflector.rb +73 -0
- data/lib/rom/support/options.rb +188 -0
- data/lib/rom/support/registry.rb +4 -8
- data/lib/rom/version.rb +1 -1
- data/rakelib/benchmark.rake +13 -0
- data/rakelib/mutant.rake +16 -0
- data/rakelib/rubocop.rake +18 -0
- data/rom.gemspec +4 -7
- data/spec/integration/commands/create_spec.rb +32 -24
- data/spec/integration/commands/delete_spec.rb +15 -7
- data/spec/integration/commands/update_spec.rb +13 -11
- data/spec/integration/mappers/deep_embedded_spec.rb +4 -11
- data/spec/integration/mappers/definition_dsl_spec.rb +31 -44
- data/spec/integration/mappers/embedded_spec.rb +9 -24
- data/spec/integration/mappers/group_spec.rb +22 -30
- data/spec/integration/mappers/prefixing_attributes_spec.rb +18 -23
- data/spec/integration/mappers/renaming_attributes_spec.rb +23 -38
- data/spec/integration/mappers/symbolizing_attributes_spec.rb +18 -24
- data/spec/integration/mappers/wrap_spec.rb +22 -30
- data/spec/integration/multi_repo_spec.rb +15 -37
- data/spec/integration/relations/reading_spec.rb +82 -14
- data/spec/integration/repositories/extending_relations_spec.rb +50 -0
- data/spec/integration/{adapters → repositories}/setting_logger_spec.rb +6 -5
- data/spec/integration/setup_spec.rb +59 -62
- data/spec/shared/enumerable_dataset.rb +49 -0
- data/spec/shared/one_behavior.rb +26 -0
- data/spec/shared/users_and_tasks.rb +11 -23
- data/spec/spec_helper.rb +16 -7
- data/spec/support/constant_leak_finder.rb +14 -0
- data/spec/test/memory_repository_lint_test.rb +27 -0
- data/spec/unit/rom/command_registry_spec.rb +44 -0
- data/spec/unit/rom/commands/result_spec.rb +14 -0
- data/spec/unit/rom/commands_spec.rb +174 -0
- data/spec/unit/rom/env_spec.rb +40 -7
- data/spec/unit/rom/global_spec.rb +14 -0
- data/spec/unit/rom/{mapper_builder_spec.rb → mapper/dsl_spec.rb} +52 -38
- data/spec/unit/rom/mapper_spec.rb +51 -10
- data/spec/unit/rom/{adapter/memory → memory}/dataset_spec.rb +6 -4
- data/spec/unit/rom/memory/repository_spec.rb +12 -0
- data/spec/unit/rom/memory/storage_spec.rb +45 -0
- data/spec/unit/rom/model_builder_spec.rb +4 -3
- data/spec/unit/rom/processor/transproc_spec.rb +1 -0
- data/spec/unit/rom/reader_spec.rb +97 -24
- data/spec/unit/rom/relation/composite_spec.rb +65 -0
- data/spec/unit/rom/relation/lazy_spec.rb +145 -0
- data/spec/unit/rom/relation/loaded_spec.rb +28 -0
- data/spec/unit/rom/relation_spec.rb +111 -6
- data/spec/unit/rom/repository_spec.rb +59 -9
- data/spec/unit/rom/setup_spec.rb +99 -11
- data/spec/unit/rom/support/array_dataset_spec.rb +59 -0
- data/spec/unit/rom/support/class_builder_spec.rb +42 -0
- data/spec/unit/rom/support/enumerable_dataset_spec.rb +17 -0
- data/spec/unit/rom/support/inflector_spec.rb +89 -0
- data/spec/unit/rom/support/options_spec.rb +119 -0
- metadata +74 -112
- data/lib/rom/adapter.rb +0 -191
- data/lib/rom/adapter/memory.rb +0 -32
- data/lib/rom/adapter/memory/commands.rb +0 -31
- data/lib/rom/adapter/memory/dataset.rb +0 -67
- data/lib/rom/adapter/memory/storage.rb +0 -26
- data/lib/rom/commands/with_options.rb +0 -18
- data/lib/rom/config.rb +0 -70
- data/lib/rom/mapper_builder.rb +0 -52
- data/lib/rom/mapper_builder/mapper_dsl.rb +0 -114
- data/lib/rom/mapper_builder/model_dsl.rb +0 -29
- data/lib/rom/reader_builder.rb +0 -48
- data/lib/rom/relation_builder.rb +0 -62
- data/lib/rom/setup/base_relation_dsl.rb +0 -46
- data/lib/rom/setup/command_dsl.rb +0 -46
- data/lib/rom/setup/mapper_dsl.rb +0 -19
- data/lib/rom/setup/relation_dsl.rb +0 -20
- data/lib/rom/setup/schema_dsl.rb +0 -33
- data/spec/integration/adapters/extending_relations_spec.rb +0 -41
- data/spec/integration/commands/try_spec.rb +0 -27
- data/spec/integration/schema_spec.rb +0 -77
- data/spec/unit/config_spec.rb +0 -60
- data/spec/unit/rom/adapter_spec.rb +0 -79
- data/spec/unit/rom_spec.rb +0 -14
@@ -5,14 +5,6 @@ describe 'Mapper definition DSL' do
|
|
5
5
|
|
6
6
|
let(:header) { mapper.header }
|
7
7
|
|
8
|
-
before do
|
9
|
-
setup.relation(:users) do
|
10
|
-
def email_index
|
11
|
-
project(:email)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
8
|
describe 'wrapped relation mapper' do
|
17
9
|
before do
|
18
10
|
setup.relation(:tasks) do
|
@@ -25,7 +17,7 @@ describe 'Mapper definition DSL' do
|
|
25
17
|
|
26
18
|
setup.mappers do
|
27
19
|
define(:tasks) do
|
28
|
-
model name: 'Task'
|
20
|
+
model name: 'Test::Task'
|
29
21
|
|
30
22
|
attribute :title
|
31
23
|
attribute :priority
|
@@ -36,7 +28,7 @@ describe 'Mapper definition DSL' do
|
|
36
28
|
it 'allows defining wrapped attributes via options hash' do
|
37
29
|
setup.mappers do
|
38
30
|
define(:with_user, parent: :tasks) do
|
39
|
-
model name: 'TaskWithUser'
|
31
|
+
model name: 'Test::TaskWithUser'
|
40
32
|
|
41
33
|
attribute :title
|
42
34
|
attribute :priority
|
@@ -47,12 +39,12 @@ describe 'Mapper definition DSL' do
|
|
47
39
|
|
48
40
|
rom = setup.finalize
|
49
41
|
|
50
|
-
TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
|
42
|
+
Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
|
51
43
|
|
52
44
|
jane = rom.read(:tasks).with_user.to_a.last
|
53
45
|
|
54
46
|
expect(jane).to eql(
|
55
|
-
TaskWithUser.new(
|
47
|
+
Test::TaskWithUser.new(
|
56
48
|
title: 'be cool',
|
57
49
|
priority: 2,
|
58
50
|
user: { email: 'jane@doe.org' }
|
@@ -63,7 +55,7 @@ describe 'Mapper definition DSL' do
|
|
63
55
|
it 'allows defining wrapped attributes via options block' do
|
64
56
|
setup.mappers do
|
65
57
|
define(:with_user, parent: :tasks) do
|
66
|
-
model name: 'TaskWithUser'
|
58
|
+
model name: 'Test::TaskWithUser'
|
67
59
|
|
68
60
|
attribute :title
|
69
61
|
attribute :priority
|
@@ -76,12 +68,12 @@ describe 'Mapper definition DSL' do
|
|
76
68
|
|
77
69
|
rom = setup.finalize
|
78
70
|
|
79
|
-
TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
|
71
|
+
Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
|
80
72
|
|
81
73
|
jane = rom.read(:tasks).with_user.to_a.last
|
82
74
|
|
83
75
|
expect(jane).to eql(
|
84
|
-
TaskWithUser.new(
|
76
|
+
Test::TaskWithUser.new(
|
85
77
|
title: 'be cool',
|
86
78
|
priority: 2,
|
87
79
|
user: { email: 'jane@doe.org' }
|
@@ -92,17 +84,17 @@ describe 'Mapper definition DSL' do
|
|
92
84
|
it 'allows defining nested wrapped attributes via a block' do
|
93
85
|
setup.mappers do
|
94
86
|
define(:with_user, parent: :tasks, inherit_header: false) do
|
95
|
-
model name: 'TaskWithUser'
|
87
|
+
model name: 'Test::TaskWithUser'
|
96
88
|
|
97
89
|
attribute :title
|
98
90
|
attribute :priority
|
99
91
|
|
100
92
|
wrap :user do
|
101
|
-
model name: 'TaskUser'
|
93
|
+
model name: 'Test::TaskUser'
|
102
94
|
attribute :name
|
103
95
|
|
104
96
|
wrap :contact do
|
105
|
-
model name: 'Contact'
|
97
|
+
model name: 'Test::Contact'
|
106
98
|
attribute :email
|
107
99
|
end
|
108
100
|
end
|
@@ -111,18 +103,18 @@ describe 'Mapper definition DSL' do
|
|
111
103
|
|
112
104
|
rom = setup.finalize
|
113
105
|
|
114
|
-
TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
|
115
|
-
TaskUser.send(:include, Equalizer.new(:name, :contact))
|
116
|
-
Contact.send(:include, Equalizer.new(:email))
|
106
|
+
Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
|
107
|
+
Test::TaskUser.send(:include, Equalizer.new(:name, :contact))
|
108
|
+
Test::Contact.send(:include, Equalizer.new(:email))
|
117
109
|
|
118
110
|
jane = rom.read(:tasks).with_user.to_a.last
|
119
111
|
|
120
112
|
expect(jane).to eql(
|
121
|
-
TaskWithUser.new(
|
113
|
+
Test::TaskWithUser.new(
|
122
114
|
title: 'be cool',
|
123
115
|
priority: 2,
|
124
|
-
user: TaskUser.new(
|
125
|
-
name: 'Jane', contact: Contact.new(email: 'jane@doe.org')
|
116
|
+
user: Test::TaskUser.new(
|
117
|
+
name: 'Jane', contact: Test::Contact.new(email: 'jane@doe.org')
|
126
118
|
)
|
127
119
|
)
|
128
120
|
)
|
@@ -131,13 +123,13 @@ describe 'Mapper definition DSL' do
|
|
131
123
|
it 'allows defining wrapped attributes mapped to a model' do
|
132
124
|
setup.mappers do
|
133
125
|
define(:with_user, parent: :tasks) do
|
134
|
-
model name: 'TaskWithUser'
|
126
|
+
model name: 'Test::TaskWithUser'
|
135
127
|
|
136
128
|
attribute :title
|
137
129
|
attribute :priority
|
138
130
|
|
139
131
|
wrap :user do
|
140
|
-
model name: 'User'
|
132
|
+
model name: 'Test::User'
|
141
133
|
attribute :email
|
142
134
|
end
|
143
135
|
end
|
@@ -145,16 +137,16 @@ describe 'Mapper definition DSL' do
|
|
145
137
|
|
146
138
|
rom = setup.finalize
|
147
139
|
|
148
|
-
TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
|
149
|
-
User.send(:include, Equalizer.new(:email))
|
140
|
+
Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
|
141
|
+
Test::User.send(:include, Equalizer.new(:email))
|
150
142
|
|
151
143
|
jane = rom.read(:tasks).with_user.to_a.last
|
152
144
|
|
153
145
|
expect(jane).to eql(
|
154
|
-
TaskWithUser.new(
|
146
|
+
Test::TaskWithUser.new(
|
155
147
|
title: 'be cool',
|
156
148
|
priority: 2,
|
157
|
-
user: User.new(email: 'jane@doe.org')
|
149
|
+
user: Test::User.new(email: 'jane@doe.org')
|
158
150
|
)
|
159
151
|
)
|
160
152
|
end
|
@@ -1,44 +1,24 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'rom/memory'
|
2
3
|
|
3
|
-
describe 'Using in-memory
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
right: 'memory://localhost/tasks',
|
8
|
-
main: 'memory://localhost/main'
|
9
|
-
)
|
10
|
-
|
11
|
-
setup.schema do
|
12
|
-
base_relation :users do
|
13
|
-
repository :left
|
14
|
-
attribute :user_id
|
15
|
-
attribute :name
|
16
|
-
end
|
17
|
-
|
18
|
-
base_relation :tasks do
|
19
|
-
repository :right
|
20
|
-
attribute :user_id
|
21
|
-
attribute :title
|
22
|
-
end
|
23
|
-
|
24
|
-
base_relation :users_and_tasks do
|
25
|
-
repository :main
|
4
|
+
describe 'Using in-memory repositories for cross-repo access' do
|
5
|
+
let(:setup) do
|
6
|
+
ROM.setup(left: :memory, right: :memory, main: :memory)
|
7
|
+
end
|
26
8
|
|
27
|
-
|
28
|
-
|
29
|
-
attribute :title
|
30
|
-
end
|
31
|
-
end
|
9
|
+
let(:repositories) { rom.repositories }
|
10
|
+
let(:rom) { setup.finalize }
|
32
11
|
|
33
|
-
|
12
|
+
it 'works' do
|
13
|
+
setup.relation(:users, repository: :left) do
|
34
14
|
def by_name(name)
|
35
15
|
restrict(name: name)
|
36
16
|
end
|
37
17
|
end
|
38
18
|
|
39
|
-
setup.relation(:tasks)
|
19
|
+
setup.relation(:tasks, repository: :right)
|
40
20
|
|
41
|
-
setup.relation(:users_and_tasks) do
|
21
|
+
setup.relation(:users_and_tasks, repository: :main) do
|
42
22
|
def by_user(name)
|
43
23
|
join(users.by_name(name), tasks)
|
44
24
|
end
|
@@ -50,12 +30,10 @@ describe 'Using in-memory adapter for cross-repo access' do
|
|
50
30
|
end
|
51
31
|
end
|
52
32
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
rom.right.tasks << { user_id: 1, title: 'Have fun' }
|
58
|
-
rom.right.tasks << { user_id: 2, title: 'Have fun' }
|
33
|
+
repositories[:left][:users] << { user_id: 1, name: 'Joe' }
|
34
|
+
repositories[:left][:users] << { user_id: 2, name: 'Jane' }
|
35
|
+
repositories[:right][:tasks] << { user_id: 1, title: 'Have fun' }
|
36
|
+
repositories[:right][:tasks] << { user_id: 2, title: 'Have fun' }
|
59
37
|
|
60
38
|
expect(rom.read(:users_and_tasks).by_user('Jane').to_a).to eql([
|
61
39
|
{ user_id: 2, name: 'Jane', tasks: [{ title: 'Have fun' }] }
|
@@ -18,14 +18,19 @@ describe 'Reading relations' do
|
|
18
18
|
|
19
19
|
setup.mappers do
|
20
20
|
define(:users) do
|
21
|
-
model name: 'User'
|
21
|
+
model name: 'Test::User'
|
22
|
+
|
23
|
+
attribute :name
|
24
|
+
attribute :email
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
28
|
+
rom = setup.finalize
|
29
|
+
|
25
30
|
users = rom.read(:users).sorted.by_name('Jane')
|
26
31
|
user = users.first
|
27
32
|
|
28
|
-
expect(user).to be_an_instance_of(User)
|
33
|
+
expect(user).to be_an_instance_of(Test::User)
|
29
34
|
expect(user.name).to eql 'Jane'
|
30
35
|
expect(user.email).to eql 'jane@doe.org'
|
31
36
|
end
|
@@ -45,11 +50,14 @@ describe 'Reading relations' do
|
|
45
50
|
|
46
51
|
setup.mappers do
|
47
52
|
define(:users) do
|
48
|
-
model name: 'User'
|
53
|
+
model name: 'Test::User'
|
54
|
+
|
55
|
+
attribute :name
|
56
|
+
attribute :email
|
49
57
|
end
|
50
58
|
|
51
59
|
define(:with_tasks, parent: :users) do
|
52
|
-
model name: 'UserWithTasks'
|
60
|
+
model name: 'Test::UserWithTasks'
|
53
61
|
|
54
62
|
group tasks: [:title, :priority]
|
55
63
|
end
|
@@ -57,8 +65,8 @@ describe 'Reading relations' do
|
|
57
65
|
|
58
66
|
rom = setup.finalize
|
59
67
|
|
60
|
-
User.send(:include, Equalizer.new(:name, :email))
|
61
|
-
UserWithTasks.send(:include, Equalizer.new(:name, :email, :tasks))
|
68
|
+
Test::User.send(:include, Equalizer.new(:name, :email))
|
69
|
+
Test::UserWithTasks.send(:include, Equalizer.new(:name, :email, :tasks))
|
62
70
|
|
63
71
|
keys = rom.read(:users).with_tasks.header.keys
|
64
72
|
expect(keys).to eql([:name, :email, :tasks])
|
@@ -66,7 +74,7 @@ describe 'Reading relations' do
|
|
66
74
|
user = rom.read(:users).sorted.first
|
67
75
|
|
68
76
|
expect(user).to eql(
|
69
|
-
User.new(name: "Jane", email: "jane@doe.org")
|
77
|
+
Test::User.new(name: "Jane", email: "jane@doe.org")
|
70
78
|
)
|
71
79
|
|
72
80
|
expect(rom.read(:users)).to_not respond_to(:join)
|
@@ -74,7 +82,7 @@ describe 'Reading relations' do
|
|
74
82
|
user = rom.read(:users).with_tasks.sorted.first
|
75
83
|
|
76
84
|
expect(user).to eql(
|
77
|
-
UserWithTasks.new(
|
85
|
+
Test::UserWithTasks.new(
|
78
86
|
name: "Jane",
|
79
87
|
email: "jane@doe.org",
|
80
88
|
tasks: [{ title: "be cool", priority: 2 }])
|
@@ -96,11 +104,14 @@ describe 'Reading relations' do
|
|
96
104
|
|
97
105
|
setup.mappers do
|
98
106
|
define(:users) do
|
99
|
-
model name: 'User'
|
107
|
+
model name: 'Test::User'
|
108
|
+
|
109
|
+
attribute :name
|
110
|
+
attribute :email
|
100
111
|
end
|
101
112
|
|
102
113
|
define(:with_task, parent: :users) do
|
103
|
-
model name: 'UserWithTask'
|
114
|
+
model name: 'Test::UserWithTask'
|
104
115
|
|
105
116
|
wrap task: [:title, :priority]
|
106
117
|
end
|
@@ -108,8 +119,8 @@ describe 'Reading relations' do
|
|
108
119
|
|
109
120
|
rom = setup.finalize
|
110
121
|
|
111
|
-
User.send(:include, Equalizer.new(:name, :email))
|
112
|
-
UserWithTask.send(:include, Equalizer.new(:name, :email, :task))
|
122
|
+
Test::User.send(:include, Equalizer.new(:name, :email))
|
123
|
+
Test::UserWithTask.send(:include, Equalizer.new(:name, :email, :task))
|
113
124
|
|
114
125
|
keys = rom.read(:users).with_task.header.keys
|
115
126
|
expect(keys).to eql([:name, :email, :task])
|
@@ -117,8 +128,8 @@ describe 'Reading relations' do
|
|
117
128
|
user = rom.read(:users).sorted.with_task.first
|
118
129
|
|
119
130
|
expect(user).to eql(
|
120
|
-
UserWithTask.new(name: "Jane", email: "jane@doe.org",
|
121
|
-
|
131
|
+
Test::UserWithTask.new(name: "Jane", email: "jane@doe.org",
|
132
|
+
task: { title: "be cool", priority: 2 })
|
122
133
|
)
|
123
134
|
end
|
124
135
|
|
@@ -139,4 +150,61 @@ describe 'Reading relations' do
|
|
139
150
|
|
140
151
|
expect(user).to eql(name: "Jane", email: "jane@doe.org")
|
141
152
|
end
|
153
|
+
|
154
|
+
it 'allows cherry-picking of a mapper' do
|
155
|
+
setup.relation(:users)
|
156
|
+
|
157
|
+
setup.mappers do
|
158
|
+
define(:users) do
|
159
|
+
attribute :name
|
160
|
+
attribute :email
|
161
|
+
end
|
162
|
+
|
163
|
+
define(:prefixer, parent: :users) do
|
164
|
+
attribute :user_name, from: :name
|
165
|
+
attribute :user_email, from: :email
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
rom = setup.finalize
|
170
|
+
user = rom.read(:users).map(:prefixer).first
|
171
|
+
|
172
|
+
expect(user).to eql(user_name: 'Joe', user_email: "joe@doe.org")
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'allows passing a block to retrieve relations for mapping' do
|
176
|
+
setup.relation(:users) do
|
177
|
+
def by_name(name)
|
178
|
+
restrict(name: name)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
setup.mappers do
|
183
|
+
define(:users) do
|
184
|
+
attribute :name
|
185
|
+
attribute :email
|
186
|
+
end
|
187
|
+
|
188
|
+
define(:prefixer, parent: :users) do
|
189
|
+
attribute :user_name, from: :name
|
190
|
+
attribute :user_email, from: :email
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
rom = setup.finalize
|
195
|
+
|
196
|
+
expect {
|
197
|
+
rom.relation(:users) { |users| users.not_here }
|
198
|
+
}.to raise_error(NoMethodError, /not_here/)
|
199
|
+
|
200
|
+
expect {
|
201
|
+
rom.relation(:users) { |users| users.by_name('Joe') }.as(:not_here)
|
202
|
+
}.to raise_error(ROM::MapperMissingError, /not_here/)
|
203
|
+
|
204
|
+
user = rom.relation(:users) { |users|
|
205
|
+
users.by_name('Joe')
|
206
|
+
}.map_with(:prefixer).call.first
|
207
|
+
|
208
|
+
expect(user).to eql(user_name: 'Joe', user_email: "joe@doe.org")
|
209
|
+
end
|
142
210
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rom/memory'
|
3
|
+
|
4
|
+
describe 'Repository' do
|
5
|
+
let!(:setup) { ROM.setup(:memory) }
|
6
|
+
|
7
|
+
let(:rom) { setup.finalize }
|
8
|
+
|
9
|
+
before do
|
10
|
+
module ROM
|
11
|
+
module Memory
|
12
|
+
class Relation < ROM::Relation
|
13
|
+
def self.freaking_awesome?
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
17
|
+
def freaking_cool?
|
18
|
+
true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
shared_examples_for 'extended relation' do
|
26
|
+
it 'can extend relation class' do
|
27
|
+
expect(rom.relations.users.class).to be_freaking_awesome
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'can extend relation instance' do
|
31
|
+
expect(rom.relations.users).to be_freaking_cool
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'using DSL' do
|
36
|
+
it_behaves_like 'extended relation' do
|
37
|
+
before do
|
38
|
+
setup.relation(:users)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'using class definition' do
|
44
|
+
it_behaves_like 'extended relation' do
|
45
|
+
before do
|
46
|
+
Class.new(ROM::Relation[:memory]) { dataset :users }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'rom/memory'
|
2
3
|
|
3
4
|
require 'logger'
|
4
5
|
|
5
|
-
describe '
|
6
|
+
describe 'Repositories / Setting logger' do
|
6
7
|
let(:logger_class) do
|
7
8
|
Class.new do
|
8
9
|
attr_reader :messages
|
@@ -21,14 +22,14 @@ describe 'Adapters / Setting logger' do
|
|
21
22
|
logger_class.new
|
22
23
|
end
|
23
24
|
|
24
|
-
it 'sets up a logger for a given
|
25
|
-
setup = ROM.setup(
|
25
|
+
it 'sets up a logger for a given repository' do
|
26
|
+
setup = ROM.setup(:memory)
|
26
27
|
|
27
|
-
setup.
|
28
|
+
setup.default.use_logger(logger)
|
28
29
|
|
29
30
|
rom = setup.finalize
|
30
31
|
|
31
|
-
rom.
|
32
|
+
rom.repositories[:default].logger.info("test")
|
32
33
|
|
33
34
|
expect(logger.messages).to eql(["test"])
|
34
35
|
end
|