rom 0.9.1 → 1.0.0.beta1
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.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +30 -12
- data/.travis.yml +1 -1
- data/CHANGELOG.md +24 -0
- data/Gemfile +7 -3
- data/README.md +24 -11
- data/lib/rom.rb +9 -26
- data/lib/rom/command.rb +113 -75
- data/lib/rom/commands/class_interface.rb +115 -0
- data/lib/rom/commands/graph.rb +17 -23
- data/lib/rom/commands/graph/builder.rb +176 -0
- data/lib/rom/commands/graph/class_interface.rb +8 -2
- data/lib/rom/commands/graph/input_evaluator.rb +13 -9
- data/lib/rom/commands/lazy.rb +23 -17
- data/lib/rom/commands/lazy/create.rb +23 -0
- data/lib/rom/commands/lazy/delete.rb +27 -0
- data/lib/rom/commands/lazy/update.rb +34 -0
- data/lib/rom/commands/result.rb +14 -0
- data/lib/rom/commands/update.rb +0 -4
- data/lib/rom/configuration.rb +86 -0
- data/lib/rom/{setup_dsl/setup.rb → configuration_dsl.rb} +9 -7
- data/lib/rom/configuration_dsl/command.rb +43 -0
- data/lib/rom/{setup_dsl → configuration_dsl}/command_dsl.rb +5 -4
- data/lib/rom/configuration_dsl/mapper.rb +37 -0
- data/lib/rom/{setup_dsl → configuration_dsl}/mapper_dsl.rb +11 -5
- data/lib/rom/configuration_dsl/relation.rb +26 -0
- data/lib/rom/configuration_plugin.rb +17 -0
- data/lib/rom/constants.rb +5 -12
- data/lib/rom/container.rb +11 -8
- data/lib/rom/create_container.rb +61 -0
- data/lib/rom/environment.rb +27 -241
- data/lib/rom/gateway.rb +18 -2
- data/lib/rom/global.rb +24 -0
- data/lib/rom/global/plugin_dsl.rb +2 -0
- data/lib/rom/lint/spec.rb +0 -12
- data/lib/rom/lint/test.rb +0 -31
- data/lib/rom/memory/commands.rb +2 -2
- data/lib/rom/memory/gateway.rb +2 -0
- data/lib/rom/pipeline.rb +1 -1
- data/lib/rom/plugin_base.rb +1 -1
- data/lib/rom/plugin_registry.rb +12 -10
- data/lib/rom/plugins/configuration/configuration_dsl.rb +16 -0
- data/lib/rom/plugins/relation/key_inference.rb +31 -0
- data/lib/rom/plugins/relation/view.rb +90 -0
- data/lib/rom/plugins/relation/view/dsl.rb +32 -0
- data/lib/rom/relation.rb +1 -11
- data/lib/rom/relation/class_interface.rb +37 -50
- data/lib/rom/setup.rb +13 -104
- data/lib/rom/setup/auto_registration.rb +55 -0
- data/lib/rom/setup/finalize.rb +113 -127
- data/lib/rom/setup/finalize/commands.rb +67 -0
- data/lib/rom/setup/finalize/mappers.rb +36 -0
- data/lib/rom/setup/finalize/relations.rb +53 -0
- data/lib/rom/support/configurable.rb +21 -7
- data/lib/rom/version.rb +1 -1
- data/rakelib/mutant.rake +4 -1
- data/rom.gemspec +3 -4
- data/spec/fixtures/app/commands/create_user.rb +2 -0
- data/spec/fixtures/app/mappers/user_list.rb +2 -0
- data/spec/fixtures/app/relations/users.rb +2 -0
- data/spec/fixtures/lib/persistence/commands/create_user.rb +6 -0
- data/spec/fixtures/lib/persistence/mappers/user_list.rb +6 -0
- data/spec/fixtures/lib/persistence/relations/users.rb +6 -0
- data/spec/{unit/rom → integration}/command_registry_spec.rb +8 -9
- data/spec/integration/commands/create_spec.rb +17 -13
- data/spec/integration/commands/delete_spec.rb +12 -11
- data/spec/integration/commands/error_handling_spec.rb +5 -4
- data/spec/integration/commands/graph_builder_spec.rb +213 -0
- data/spec/integration/commands/graph_spec.rb +112 -49
- data/spec/integration/commands/update_spec.rb +14 -11
- data/spec/integration/commands_spec.rb +60 -0
- data/spec/integration/mappers/combine_spec.rb +7 -6
- data/spec/integration/mappers/deep_embedded_spec.rb +5 -6
- data/spec/integration/mappers/definition_dsl_spec.rb +19 -18
- data/spec/integration/mappers/embedded_spec.rb +11 -12
- data/spec/integration/mappers/exclude_spec.rb +5 -6
- data/spec/integration/mappers/fold_spec.rb +8 -7
- data/spec/integration/mappers/group_spec.rb +16 -15
- data/spec/integration/mappers/overwrite_attributes_value_spec.rb +5 -5
- data/spec/integration/mappers/prefix_separator_spec.rb +5 -7
- data/spec/integration/mappers/prefix_spec.rb +5 -7
- data/spec/integration/mappers/prefixing_attributes_spec.rb +7 -7
- data/spec/integration/mappers/registering_custom_mappers_spec.rb +4 -5
- data/spec/integration/mappers/renaming_attributes_spec.rb +18 -18
- data/spec/integration/mappers/step_spec.rb +11 -12
- data/spec/integration/mappers/symbolizing_attributes_spec.rb +11 -8
- data/spec/integration/mappers/unfold_spec.rb +9 -10
- data/spec/integration/mappers/ungroup_spec.rb +10 -11
- data/spec/integration/mappers/unwrap_spec.rb +10 -15
- data/spec/integration/mappers/wrap_spec.rb +16 -15
- data/spec/{unit/rom → integration}/memory/commands/create_spec.rb +7 -5
- data/spec/{unit/rom → integration}/memory/commands/delete_spec.rb +7 -5
- data/spec/{unit/rom → integration}/memory/commands/update_spec.rb +7 -5
- data/spec/integration/multi_env_spec.rb +16 -124
- data/spec/integration/multi_repo_spec.rb +9 -9
- data/spec/integration/relations/default_dataset_spec.rb +15 -0
- data/spec/integration/relations/inheritance_spec.rb +5 -7
- data/spec/integration/relations/reading_spec.rb +32 -65
- data/spec/integration/relations/registry_dsl_spec.rb +5 -4
- data/spec/integration/repositories/extending_relations_spec.rb +6 -7
- data/spec/integration/repositories/setting_logger_spec.rb +5 -7
- data/spec/integration/setup_spec.rb +49 -61
- data/spec/shared/command_graph.rb +50 -0
- data/spec/shared/container.rb +9 -0
- data/spec/shared/gateway_only.rb +6 -0
- data/spec/shared/no_container.rb +16 -0
- data/spec/shared/one_behavior.rb +4 -4
- data/spec/shared/users_and_tasks.rb +5 -17
- data/spec/spec_helper.rb +5 -3
- data/spec/test/memory_repository_lint_test.rb +1 -1
- data/spec/unit/rom/auto_registration_spec.rb +54 -0
- data/spec/unit/rom/commands/graph_spec.rb +18 -44
- data/spec/unit/rom/commands/lazy_spec.rb +246 -35
- data/spec/unit/rom/commands/result_spec.rb +56 -0
- data/spec/unit/rom/commands_spec.rb +9 -73
- data/spec/unit/rom/configurable_spec.rb +49 -0
- data/spec/unit/rom/configuration_spec.rb +61 -0
- data/spec/unit/rom/container_spec.rb +39 -33
- data/spec/unit/rom/create_container_spec.rb +151 -0
- data/spec/unit/rom/environment_spec.rb +123 -0
- data/spec/unit/rom/gateway_spec.rb +58 -2
- data/spec/unit/rom/global_spec.rb +10 -7
- data/spec/unit/rom/plugin_spec.rb +44 -25
- data/spec/unit/rom/plugins/relation/key_inference_spec.rb +27 -0
- data/spec/unit/rom/plugins/relation/view_spec.rb +47 -0
- data/spec/unit/rom/relation/composite_spec.rb +20 -20
- data/spec/unit/rom/relation/curried_spec.rb +10 -11
- data/spec/unit/rom/relation/graph_spec.rb +27 -27
- data/spec/unit/rom/relation/lazy/combine_spec.rb +26 -20
- data/spec/unit/rom/relation/lazy_spec.rb +38 -38
- data/spec/unit/rom/relation/loaded_spec.rb +2 -3
- data/spec/unit/rom/relation_spec.rb +39 -2
- metadata +58 -66
- data/lib/rom/commands/abstract.rb +0 -184
- data/lib/rom/environment_plugin.rb +0 -17
- data/lib/rom/environment_plugins/auto_registration.rb +0 -38
- data/lib/rom/repository.rb +0 -16
- data/lib/rom/setup_dsl/command.rb +0 -36
- data/lib/rom/setup_dsl/mapper.rb +0 -32
- data/lib/rom/setup_dsl/relation.rb +0 -30
- data/spec/integration/inline_setup_spec.rb +0 -65
- data/spec/unit/rom/repository_spec.rb +0 -12
- data/spec/unit/rom/setup_spec.rb +0 -253
@@ -1,14 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe 'Commands / Error handling'
|
3
|
+
describe 'Commands / Error handling' do
|
4
|
+
include_context 'container'
|
4
5
|
include_context 'users and tasks'
|
5
6
|
|
6
7
|
before do
|
7
|
-
|
8
|
-
|
8
|
+
configuration.relation(:users)
|
9
|
+
configuration.commands(:users) { define(:create) }
|
9
10
|
end
|
10
11
|
|
11
|
-
subject(:users) {
|
12
|
+
subject(:users) { container.commands.users }
|
12
13
|
|
13
14
|
it 'rescues from ROM::CommandError' do
|
14
15
|
result = false
|
@@ -0,0 +1,213 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'Command graph builder' do
|
4
|
+
include_context 'command graph'
|
5
|
+
|
6
|
+
it 'allows defining a simple create command graph' do
|
7
|
+
command = container.command.create(user: :users)
|
8
|
+
|
9
|
+
other = container.command([{ user: :users }, [:create]])
|
10
|
+
|
11
|
+
expect(command).to eql(other)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'allows defining a create command graph with simple nesting' do
|
15
|
+
configuration.commands(:books) do
|
16
|
+
define(:create) { result :many }
|
17
|
+
end
|
18
|
+
|
19
|
+
command = container.command.create(user: :users) do |user|
|
20
|
+
user.create(:books)
|
21
|
+
end
|
22
|
+
|
23
|
+
other = container.command([{ user: :users }, [:create, [
|
24
|
+
[{ books: :books }, [:create]]
|
25
|
+
]]])
|
26
|
+
|
27
|
+
expect(command).to eql(other)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'allows defining a create command graph with multiple levels of nesting' do
|
31
|
+
configuration.commands(:books) do
|
32
|
+
define(:create) { result :many }
|
33
|
+
end
|
34
|
+
|
35
|
+
configuration.commands(:tags) do
|
36
|
+
define(:create) { result :many }
|
37
|
+
end
|
38
|
+
|
39
|
+
command = container.command.create(user: :users) do |user|
|
40
|
+
user.create(novels: :books) do |novels|
|
41
|
+
novels.create(:tags)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
other = container.command([{ user: :users }, [:create, [
|
46
|
+
[{ novels: :books }, [:create, [
|
47
|
+
[{ tags: :tags }, [:create]]
|
48
|
+
]]]
|
49
|
+
]]])
|
50
|
+
|
51
|
+
expect(command).to eql(other)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'allows defining a create command graph with multiple nested commands' do
|
55
|
+
configuration.commands(:books) do
|
56
|
+
define(:create) { result :many }
|
57
|
+
end
|
58
|
+
|
59
|
+
configuration.commands(:tags) do
|
60
|
+
define(:create) { result :many }
|
61
|
+
end
|
62
|
+
|
63
|
+
command = container.command.create(user: :users) do |user|
|
64
|
+
user.create(:books)
|
65
|
+
user.create(tag: :tags)
|
66
|
+
end
|
67
|
+
|
68
|
+
other = container.command([{ user: :users }, [:create, [
|
69
|
+
[{ books: :books }, [:create]],
|
70
|
+
[{ tag: :tags }, [:create]]
|
71
|
+
]]])
|
72
|
+
|
73
|
+
expect(command).to eql(other)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'allows defining a create command graph with multiple nested commands in multiple levels' do
|
77
|
+
configuration.commands(:tasks) do
|
78
|
+
define(:create) { result :many }
|
79
|
+
end
|
80
|
+
|
81
|
+
configuration.commands(:books) do
|
82
|
+
define(:create) { result :many }
|
83
|
+
end
|
84
|
+
|
85
|
+
configuration.commands(:tags) do
|
86
|
+
define(:create) { result :many }
|
87
|
+
end
|
88
|
+
|
89
|
+
command = container.command.create(user: :users) do |user|
|
90
|
+
user.create(:tasks).each do |task|
|
91
|
+
task.create(:tags)
|
92
|
+
end
|
93
|
+
user.create(:books).each do |book|
|
94
|
+
book.create(:tags)
|
95
|
+
book.create(:tasks)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
other = container.command([{ user: :users }, [:create, [
|
100
|
+
[{ tasks: :tasks }, [:create, [
|
101
|
+
[{ tags: :tags }, [:create]]
|
102
|
+
]]],
|
103
|
+
[{ books: :books }, [:create, [
|
104
|
+
[{ tags: :tags }, [:create]],
|
105
|
+
[{ tasks: :tasks }, [:create]]
|
106
|
+
]]]
|
107
|
+
]]])
|
108
|
+
|
109
|
+
expect(command).to eql(other)
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'allows defining a create command graph using the each sugar' do
|
113
|
+
configuration.commands(:books) do
|
114
|
+
define(:create) { result :many }
|
115
|
+
end
|
116
|
+
|
117
|
+
command = container.command.create(user: :users) do |user|
|
118
|
+
user.create(novels: :books).each do |novel|
|
119
|
+
novel.create(:tags)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
other = container.command([{ user: :users }, [:create, [
|
124
|
+
[{ novels: :books }, [:create, [
|
125
|
+
[{ tags: :tags }, [:create]]
|
126
|
+
]]]
|
127
|
+
]]])
|
128
|
+
|
129
|
+
expect(command).to eql(other)
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'allows restricting a relation with a proc' do
|
133
|
+
configuration.commands(:users) do
|
134
|
+
define(:update) { result :one }
|
135
|
+
end
|
136
|
+
|
137
|
+
configuration.commands(:tasks) do
|
138
|
+
define(:update) { result :many }
|
139
|
+
end
|
140
|
+
|
141
|
+
users_proc = -> users, user do
|
142
|
+
users.by_name(user[:name])
|
143
|
+
end
|
144
|
+
|
145
|
+
tasks_proc = -> tasks, user, task do
|
146
|
+
tasks.by_user_and_title(user[:name], task[:title])
|
147
|
+
end
|
148
|
+
|
149
|
+
users = container.command.restrict(:users, &users_proc)
|
150
|
+
command = container.command.update(user: users) do |user|
|
151
|
+
tasks = user.restrict(:tasks, &tasks_proc)
|
152
|
+
user.update(tasks)
|
153
|
+
end
|
154
|
+
|
155
|
+
other = container.command([
|
156
|
+
{ user: :users },
|
157
|
+
[
|
158
|
+
{ update: users_proc },
|
159
|
+
[
|
160
|
+
[
|
161
|
+
:tasks,
|
162
|
+
[{ update: tasks_proc }]
|
163
|
+
]
|
164
|
+
]
|
165
|
+
]
|
166
|
+
])
|
167
|
+
|
168
|
+
expect(command).to eql(other)
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'allows chaining a command to a restriction' do
|
172
|
+
configuration.commands(:users) do
|
173
|
+
define(:update) { result :one }
|
174
|
+
end
|
175
|
+
|
176
|
+
configuration.commands(:tasks) do
|
177
|
+
define(:update) { result :many }
|
178
|
+
end
|
179
|
+
|
180
|
+
users_proc = -> users, user do
|
181
|
+
users.by_name(user[:name])
|
182
|
+
end
|
183
|
+
|
184
|
+
tasks_proc = -> tasks, user, task do
|
185
|
+
tasks.by_user_and_title(user[:name], task[:title])
|
186
|
+
end
|
187
|
+
|
188
|
+
command = container.command.restrict(:users, &users_proc).update(from: :user) do |user|
|
189
|
+
user.restrict(:tasks, &tasks_proc).update
|
190
|
+
end
|
191
|
+
|
192
|
+
other = container.command([
|
193
|
+
{ user: :users },
|
194
|
+
[
|
195
|
+
{ update: users_proc },
|
196
|
+
[
|
197
|
+
[
|
198
|
+
:tasks,
|
199
|
+
[{ update: tasks_proc }]
|
200
|
+
]
|
201
|
+
]
|
202
|
+
]
|
203
|
+
])
|
204
|
+
|
205
|
+
expect(command).to eql(other)
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'raises when unknown command is accessed' do
|
209
|
+
expect {
|
210
|
+
container.command.not_here(:users)
|
211
|
+
}.to raise_error(ROM::Registry::ElementNotFoundError, /not_here/)
|
212
|
+
end
|
213
|
+
end
|
@@ -1,40 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'Building up a command graph for nested input' do
|
4
|
-
|
5
|
-
let(:setup) { ROM.setup(:memory) }
|
6
|
-
|
7
|
-
before do
|
8
|
-
setup.relation :users
|
9
|
-
setup.relation :tasks
|
10
|
-
setup.relation :books
|
11
|
-
setup.relation :tags
|
12
|
-
|
13
|
-
setup.commands(:users) do
|
14
|
-
define(:create) do
|
15
|
-
result :one
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
setup.commands(:books) do
|
20
|
-
define(:create) do
|
21
|
-
def execute(tuples, user)
|
22
|
-
super(tuples.map { |t| t.merge(user: user.fetch(:name)) })
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
setup.commands(:tags) do
|
28
|
-
define(:create) do
|
29
|
-
def execute(tuples, task)
|
30
|
-
super(tuples.map { |t| t.merge(task: task.fetch(:title)) })
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
4
|
+
include_context 'command graph'
|
35
5
|
|
36
6
|
it 'creates a command graph for nested input :one result as root' do
|
37
|
-
|
7
|
+
configuration.commands(:tasks) do
|
38
8
|
define(:create) do
|
39
9
|
result :one
|
40
10
|
|
@@ -69,24 +39,24 @@ describe 'Building up a command graph for nested input' do
|
|
69
39
|
]
|
70
40
|
]
|
71
41
|
|
72
|
-
command =
|
42
|
+
command = container.command(options)
|
73
43
|
|
74
44
|
command.call(input)
|
75
45
|
|
76
|
-
expect(
|
46
|
+
expect(container.relation(:users)).to match_array([
|
77
47
|
{ name: 'Jane' }
|
78
48
|
])
|
79
49
|
|
80
|
-
expect(
|
50
|
+
expect(container.relation(:tasks)).to match_array([
|
81
51
|
{ title: 'Task One', user: 'Jane' }
|
82
52
|
])
|
83
53
|
|
84
|
-
expect(
|
54
|
+
expect(container.relation(:books)).to match_array([
|
85
55
|
{ title: 'Book One', user: 'Jane' },
|
86
56
|
{ title: 'Book Two', user: 'Jane' }
|
87
57
|
])
|
88
58
|
|
89
|
-
expect(
|
59
|
+
expect(container.relation(:tags)).to match_array([
|
90
60
|
{ name: 'red', task: 'Task One' },
|
91
61
|
{ name: 'green', task: 'Task One' },
|
92
62
|
{ name: 'blue', task: 'Task One' }
|
@@ -94,7 +64,7 @@ describe 'Building up a command graph for nested input' do
|
|
94
64
|
end
|
95
65
|
|
96
66
|
it 'creates a command graph for nested input with :many results as root' do
|
97
|
-
|
67
|
+
configuration.commands(:tasks) do
|
98
68
|
define(:create) do
|
99
69
|
def execute(tuples, user)
|
100
70
|
super(tuples.map { |t| t.merge(user: user.fetch(:name)) })
|
@@ -121,33 +91,126 @@ describe 'Building up a command graph for nested input' do
|
|
121
91
|
options = [
|
122
92
|
{ user: :users }, [
|
123
93
|
:create, [
|
124
|
-
[:tasks, [:create, [:tags, [:create]]]]
|
94
|
+
[:tasks, [:create, [:tags, [:create]]]]
|
125
95
|
]
|
126
96
|
]
|
127
97
|
]
|
128
98
|
|
129
|
-
command =
|
99
|
+
command = container.command(options)
|
130
100
|
|
131
101
|
command.call(input)
|
132
102
|
|
133
|
-
expect(
|
103
|
+
expect(container.relation(:users)).to match_array([
|
134
104
|
{ name: 'Jane' }
|
135
105
|
])
|
136
106
|
|
137
|
-
expect(
|
107
|
+
expect(container.relation(:tasks)).to match_array([
|
138
108
|
{ title: 'Task One', user: 'Jane' },
|
139
109
|
{ title: 'Task Two', user: 'Jane' }
|
140
110
|
])
|
141
111
|
|
142
|
-
expect(
|
112
|
+
expect(container.relation(:tags)).to match_array([
|
143
113
|
{ name: 'red', task: 'Task One' },
|
144
114
|
{ name: 'green', task: 'Task One' },
|
145
115
|
{ name: 'blue', task: 'Task Two' }
|
146
116
|
])
|
147
117
|
end
|
148
118
|
|
119
|
+
|
120
|
+
it 'updates graph elements cleanly' do
|
121
|
+
configuration.commands(:tasks) do
|
122
|
+
define(:create) do
|
123
|
+
def execute(tuples, user)
|
124
|
+
super(tuples.map { |t| t.merge(user: user.fetch(:name)) })
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
define(:update) do
|
129
|
+
result :one
|
130
|
+
|
131
|
+
def execute(tuple, user)
|
132
|
+
super(tuple.merge(user: user.fetch(:name)))
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
define(:delete) do
|
137
|
+
register_as :complete
|
138
|
+
result :one
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
configuration.commands(:users) do
|
143
|
+
define(:update) do
|
144
|
+
result :one
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
initial = {
|
149
|
+
user: {
|
150
|
+
name: 'Johnny',
|
151
|
+
email: 'johnny@doe.org',
|
152
|
+
tasks: [
|
153
|
+
{ title: 'Change Name' },
|
154
|
+
{ title: 'Finish that novel' }
|
155
|
+
]
|
156
|
+
}
|
157
|
+
}
|
158
|
+
|
159
|
+
updated = {
|
160
|
+
user: {
|
161
|
+
name: 'Johnny',
|
162
|
+
email: 'johnathan@doe.org',
|
163
|
+
completed: [{ title: 'Change Name' }],
|
164
|
+
tasks: [{ title: 'Finish that novel', priority: 1 }]
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
create = container.command([{ user: :users }, [:create, [:tasks, [:create]]]])
|
169
|
+
|
170
|
+
update = container.command([
|
171
|
+
{ user: :users },
|
172
|
+
[
|
173
|
+
{ update: -> cmd, user { cmd.by_name(user[:name]) } },
|
174
|
+
[
|
175
|
+
[
|
176
|
+
{ completed: :tasks },
|
177
|
+
[{ complete: -> cmd, user, task { cmd.by_user_and_title(user[:name], task[:title]) } }]
|
178
|
+
],
|
179
|
+
[
|
180
|
+
:tasks,
|
181
|
+
[{ update: -> cmd, user, task { cmd.by_user_and_title(user[:name], task[:title]) } }]
|
182
|
+
]
|
183
|
+
]
|
184
|
+
]
|
185
|
+
])
|
186
|
+
|
187
|
+
create.call(initial)
|
188
|
+
|
189
|
+
container.command(:tasks).create.call(
|
190
|
+
[{ title: 'Task One'}], { name: 'Jane' }
|
191
|
+
)
|
192
|
+
|
193
|
+
expect(container.relation(:tasks)).to match_array([
|
194
|
+
{ title: 'Change Name', user: 'Johnny' },
|
195
|
+
{ title: 'Finish that novel', user: 'Johnny' },
|
196
|
+
{ title: 'Task One', user: 'Jane' }
|
197
|
+
])
|
198
|
+
|
199
|
+
update.call(updated)
|
200
|
+
|
201
|
+
expect(container.relation(:users)).to match_array([
|
202
|
+
{ name: 'Johnny', email: 'johnathan@doe.org' }
|
203
|
+
])
|
204
|
+
|
205
|
+
expect(container.relation(:tasks)).to match_array([
|
206
|
+
{ title: 'Task One', user: 'Jane' },
|
207
|
+
{ title: 'Finish that novel', priority: 1, user: 'Johnny' }
|
208
|
+
])
|
209
|
+
end
|
210
|
+
|
211
|
+
|
149
212
|
it 'works with auto-mapping' do
|
150
|
-
|
213
|
+
configuration.mappers do
|
151
214
|
define(:users) do
|
152
215
|
register_as :entity
|
153
216
|
reject_keys true
|
@@ -168,7 +231,7 @@ describe 'Building up a command graph for nested input' do
|
|
168
231
|
end
|
169
232
|
end
|
170
233
|
|
171
|
-
|
234
|
+
configuration.commands(:tasks) do
|
172
235
|
define(:create) do
|
173
236
|
def execute(tuples, user)
|
174
237
|
super(tuples.map { |t| t.merge(user: user.fetch(:name)) })
|
@@ -195,12 +258,12 @@ describe 'Building up a command graph for nested input' do
|
|
195
258
|
options = [
|
196
259
|
{ user: :users }, [
|
197
260
|
:create, [
|
198
|
-
[:tasks, [:create, [:tags, [:create]]]]
|
261
|
+
[:tasks, [:create, [:tags, [:create]]]]
|
199
262
|
]
|
200
263
|
]
|
201
264
|
]
|
202
265
|
|
203
|
-
command =
|
266
|
+
command = container.command(options).as(:entity)
|
204
267
|
|
205
268
|
result = command.call(input).one
|
206
269
|
|
@@ -216,10 +279,10 @@ describe 'Building up a command graph for nested input' do
|
|
216
279
|
{ user: :users }, [:create, [{ book: :books }, [:create]]]
|
217
280
|
]
|
218
281
|
|
219
|
-
command =
|
282
|
+
command = container.command(options)
|
220
283
|
|
221
284
|
expect {
|
222
285
|
command.call(input)
|
223
|
-
}.to raise_error(ROM::
|
286
|
+
}.to raise_error(ROM::KeyMissing, /book/)
|
224
287
|
end
|
225
288
|
end
|