rom 2.0.2 → 4.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +35 -430
- data/LICENSE +1 -1
- data/README.md +83 -11
- data/lib/rom/version.rb +1 -1
- data/lib/rom.rb +3 -46
- metadata +30 -236
- data/.gitignore +0 -24
- data/.rspec +0 -3
- data/.rubocop.yml +0 -87
- data/.rubocop_todo.yml +0 -46
- data/.travis.yml +0 -28
- data/CODE_OF_CONDUCT.md +0 -13
- data/CONTRIBUTING.md +0 -1
- data/Gemfile +0 -41
- data/Guardfile +0 -24
- data/Rakefile +0 -22
- data/lib/rom/association_set.rb +0 -26
- data/lib/rom/command.rb +0 -173
- data/lib/rom/command_registry.rb +0 -153
- data/lib/rom/commands/class_interface.rb +0 -148
- data/lib/rom/commands/composite.rb +0 -54
- data/lib/rom/commands/create.rb +0 -13
- data/lib/rom/commands/delete.rb +0 -14
- data/lib/rom/commands/graph/builder.rb +0 -176
- data/lib/rom/commands/graph/class_interface.rb +0 -62
- data/lib/rom/commands/graph/input_evaluator.rb +0 -62
- data/lib/rom/commands/graph.rb +0 -103
- data/lib/rom/commands/lazy/create.rb +0 -23
- data/lib/rom/commands/lazy/delete.rb +0 -27
- data/lib/rom/commands/lazy/update.rb +0 -34
- data/lib/rom/commands/lazy.rb +0 -99
- data/lib/rom/commands/result.rb +0 -96
- data/lib/rom/commands/update.rb +0 -14
- data/lib/rom/commands.rb +0 -3
- data/lib/rom/configuration.rb +0 -88
- data/lib/rom/configuration_dsl/command.rb +0 -43
- data/lib/rom/configuration_dsl/command_dsl.rb +0 -35
- data/lib/rom/configuration_dsl/mapper.rb +0 -37
- data/lib/rom/configuration_dsl/mapper_dsl.rb +0 -44
- data/lib/rom/configuration_dsl/relation.rb +0 -26
- data/lib/rom/configuration_dsl.rb +0 -78
- data/lib/rom/configuration_plugin.rb +0 -17
- data/lib/rom/constants.rb +0 -30
- data/lib/rom/container.rb +0 -231
- data/lib/rom/create_container.rb +0 -61
- data/lib/rom/environment.rb +0 -70
- data/lib/rom/gateway.rb +0 -154
- data/lib/rom/global/plugin_dsl.rb +0 -49
- data/lib/rom/global.rb +0 -60
- data/lib/rom/lint/enumerable_dataset.rb +0 -54
- data/lib/rom/lint/gateway.rb +0 -94
- data/lib/rom/lint/linter.rb +0 -78
- data/lib/rom/lint/spec.rb +0 -20
- data/lib/rom/lint/test.rb +0 -98
- data/lib/rom/mapper_registry.rb +0 -35
- data/lib/rom/memory/commands.rb +0 -58
- data/lib/rom/memory/dataset.rb +0 -98
- data/lib/rom/memory/gateway.rb +0 -64
- data/lib/rom/memory/relation.rb +0 -49
- data/lib/rom/memory/storage.rb +0 -59
- data/lib/rom/memory/types.rb +0 -9
- data/lib/rom/memory.rb +0 -4
- data/lib/rom/pipeline.rb +0 -106
- data/lib/rom/plugin.rb +0 -17
- data/lib/rom/plugin_base.rb +0 -31
- data/lib/rom/plugin_registry.rb +0 -173
- data/lib/rom/plugins/command/schema.rb +0 -37
- data/lib/rom/plugins/configuration/configuration_dsl.rb +0 -17
- data/lib/rom/plugins/relation/key_inference.rb +0 -46
- data/lib/rom/plugins/relation/registry_reader.rb +0 -32
- data/lib/rom/plugins/relation/view/dsl.rb +0 -32
- data/lib/rom/plugins/relation/view.rb +0 -95
- data/lib/rom/relation/class_interface.rb +0 -230
- data/lib/rom/relation/composite.rb +0 -46
- data/lib/rom/relation/curried.rb +0 -104
- data/lib/rom/relation/graph.rb +0 -115
- data/lib/rom/relation/loaded.rb +0 -118
- data/lib/rom/relation/materializable.rb +0 -66
- data/lib/rom/relation/name.rb +0 -102
- data/lib/rom/relation.rb +0 -172
- data/lib/rom/relation_registry.rb +0 -9
- data/lib/rom/schema/dsl.rb +0 -58
- data/lib/rom/schema.rb +0 -89
- data/lib/rom/setup/auto_registration.rb +0 -69
- data/lib/rom/setup/auto_registration_strategies/base.rb +0 -11
- data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +0 -22
- data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +0 -19
- data/lib/rom/setup/auto_registration_strategies/with_namespace.rb +0 -18
- data/lib/rom/setup/finalize/finalize_commands.rb +0 -47
- data/lib/rom/setup/finalize/finalize_mappers.rb +0 -36
- data/lib/rom/setup/finalize/finalize_relations.rb +0 -60
- data/lib/rom/setup/finalize.rb +0 -146
- data/lib/rom/setup.rb +0 -55
- data/lib/rom/support/configurable.rb +0 -80
- data/lib/rom/types.rb +0 -18
- data/log/.gitkeep +0 -0
- data/rakelib/benchmark.rake +0 -15
- data/rakelib/mutant.rake +0 -19
- data/rakelib/rubocop.rake +0 -18
- data/rom.gemspec +0 -26
- data/spec/fixtures/app/commands/create_user.rb +0 -2
- data/spec/fixtures/app/mappers/user_list.rb +0 -2
- data/spec/fixtures/app/my_commands/create_user.rb +0 -2
- data/spec/fixtures/app/my_mappers/user_list.rb +0 -2
- data/spec/fixtures/app/my_relations/users.rb +0 -2
- data/spec/fixtures/app/relations/users.rb +0 -2
- data/spec/fixtures/custom/commands/create_user.rb +0 -6
- data/spec/fixtures/custom/mappers/user_list.rb +0 -6
- data/spec/fixtures/custom/relations/users.rb +0 -6
- data/spec/fixtures/lib/persistence/commands/create_user.rb +0 -6
- data/spec/fixtures/lib/persistence/mappers/user_list.rb +0 -6
- data/spec/fixtures/lib/persistence/my_commands/create_user.rb +0 -6
- data/spec/fixtures/lib/persistence/my_mappers/user_list.rb +0 -6
- data/spec/fixtures/lib/persistence/my_relations/users.rb +0 -6
- data/spec/fixtures/lib/persistence/relations/users.rb +0 -6
- data/spec/integration/command_registry_spec.rb +0 -60
- data/spec/integration/commands/create_spec.rb +0 -177
- data/spec/integration/commands/delete_spec.rb +0 -67
- data/spec/integration/commands/error_handling_spec.rb +0 -25
- data/spec/integration/commands/graph_builder_spec.rb +0 -213
- data/spec/integration/commands/graph_spec.rb +0 -288
- data/spec/integration/commands/update_spec.rb +0 -109
- data/spec/integration/commands_spec.rb +0 -67
- data/spec/integration/mappers/combine_spec.rb +0 -117
- data/spec/integration/mappers/deep_embedded_spec.rb +0 -44
- data/spec/integration/mappers/definition_dsl_spec.rb +0 -206
- data/spec/integration/mappers/embedded_spec.rb +0 -62
- data/spec/integration/mappers/exclude_spec.rb +0 -27
- data/spec/integration/mappers/fold_spec.rb +0 -71
- data/spec/integration/mappers/group_spec.rb +0 -163
- data/spec/integration/mappers/overwrite_attributes_value_spec.rb +0 -51
- data/spec/integration/mappers/prefix_separator_spec.rb +0 -52
- data/spec/integration/mappers/prefix_spec.rb +0 -48
- data/spec/integration/mappers/prefixing_attributes_spec.rb +0 -37
- data/spec/integration/mappers/registering_custom_mappers_spec.rb +0 -28
- data/spec/integration/mappers/renaming_attributes_spec.rb +0 -125
- data/spec/integration/mappers/reusing_mappers_spec.rb +0 -43
- data/spec/integration/mappers/step_spec.rb +0 -119
- data/spec/integration/mappers/symbolizing_attributes_spec.rb +0 -77
- data/spec/integration/mappers/unfold_spec.rb +0 -92
- data/spec/integration/mappers/ungroup_spec.rb +0 -126
- data/spec/integration/mappers/unwrap_spec.rb +0 -93
- data/spec/integration/mappers/wrap_spec.rb +0 -155
- data/spec/integration/memory/commands/create_spec.rb +0 -23
- data/spec/integration/memory/commands/delete_spec.rb +0 -23
- data/spec/integration/memory/commands/update_spec.rb +0 -23
- data/spec/integration/multi_env_spec.rb +0 -69
- data/spec/integration/multi_repo_spec.rb +0 -46
- data/spec/integration/relations/default_dataset_spec.rb +0 -38
- data/spec/integration/relations/inheritance_spec.rb +0 -37
- data/spec/integration/relations/reading_spec.rb +0 -169
- data/spec/integration/relations/registry_dsl_spec.rb +0 -45
- data/spec/integration/repositories/extending_relations_spec.rb +0 -58
- data/spec/integration/repositories/setting_logger_spec.rb +0 -34
- data/spec/integration/setup_spec.rb +0 -160
- data/spec/shared/command_behavior.rb +0 -28
- data/spec/shared/command_graph.rb +0 -50
- data/spec/shared/container.rb +0 -9
- data/spec/shared/enumerable_dataset.rb +0 -52
- data/spec/shared/gateway_only.rb +0 -6
- data/spec/shared/materializable.rb +0 -36
- data/spec/shared/no_container.rb +0 -16
- data/spec/shared/one_behavior.rb +0 -26
- data/spec/shared/proxy.rb +0 -0
- data/spec/shared/users_and_tasks.rb +0 -10
- data/spec/spec_helper.rb +0 -52
- data/spec/support/constant_leak_finder.rb +0 -14
- data/spec/support/mutant.rb +0 -10
- data/spec/support/types.rb +0 -5
- data/spec/test/memory_repository_lint_test.rb +0 -27
- data/spec/unit/rom/association_set_spec.rb +0 -23
- data/spec/unit/rom/commands/graph_spec.rb +0 -191
- data/spec/unit/rom/commands/lazy_spec.rb +0 -307
- data/spec/unit/rom/commands/result_spec.rb +0 -70
- data/spec/unit/rom/commands_spec.rb +0 -165
- data/spec/unit/rom/configurable_spec.rb +0 -49
- data/spec/unit/rom/configuration_spec.rb +0 -61
- data/spec/unit/rom/container_spec.rb +0 -99
- data/spec/unit/rom/create_container_spec.rb +0 -151
- data/spec/unit/rom/environment_spec.rb +0 -123
- data/spec/unit/rom/gateway_spec.rb +0 -146
- data/spec/unit/rom/mapper_registry_spec.rb +0 -25
- data/spec/unit/rom/memory/commands_spec.rb +0 -43
- data/spec/unit/rom/memory/dataset_spec.rb +0 -31
- data/spec/unit/rom/memory/relation_spec.rb +0 -109
- data/spec/unit/rom/memory/repository_spec.rb +0 -12
- data/spec/unit/rom/memory/storage_spec.rb +0 -45
- data/spec/unit/rom/plugin_spec.rb +0 -150
- data/spec/unit/rom/plugins/command/schema_spec.rb +0 -66
- data/spec/unit/rom/plugins/relation/key_inference_spec.rb +0 -85
- data/spec/unit/rom/plugins/relation/view_spec.rb +0 -51
- data/spec/unit/rom/relation/composite_spec.rb +0 -89
- data/spec/unit/rom/relation/curried_spec.rb +0 -52
- data/spec/unit/rom/relation/graph_spec.rb +0 -92
- data/spec/unit/rom/relation/lazy/combine_spec.rb +0 -165
- data/spec/unit/rom/relation/lazy_spec.rb +0 -214
- data/spec/unit/rom/relation/loaded_spec.rb +0 -53
- data/spec/unit/rom/relation/name_spec.rb +0 -58
- data/spec/unit/rom/relation/schema_spec.rb +0 -117
- data/spec/unit/rom/relation_spec.rb +0 -237
- data/spec/unit/rom/schema_spec.rb +0 -10
- data/spec/unit/rom/setup/auto_registration_spec.rb +0 -152
@@ -1,191 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'dry-struct'
|
3
|
-
|
4
|
-
describe ROM::Commands::Graph do
|
5
|
-
shared_examples_for 'a persisted graph' do
|
6
|
-
it 'returns nested results' do
|
7
|
-
expect(command.call).to match_array([
|
8
|
-
# parent users
|
9
|
-
[
|
10
|
-
{ name: 'Jane' }
|
11
|
-
],
|
12
|
-
[
|
13
|
-
[
|
14
|
-
# user tasks
|
15
|
-
[
|
16
|
-
{ title: 'One', user: 'Jane' }
|
17
|
-
],
|
18
|
-
[
|
19
|
-
# task tags
|
20
|
-
[
|
21
|
-
{ name: 'red', task: 'One' },
|
22
|
-
{ name: 'green', task: 'One' },
|
23
|
-
{ name: 'blue', task: 'One' }
|
24
|
-
]
|
25
|
-
]
|
26
|
-
]
|
27
|
-
]
|
28
|
-
])
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'persisted relations' do
|
32
|
-
before { command.call }
|
33
|
-
|
34
|
-
it 'inserts root' do
|
35
|
-
expect(container.relation(:users)).to match_array([{ name: 'Jane' }])
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'inserts root nodes' do
|
39
|
-
expect(container.relation(:tasks)).to match_array([{ user: 'Jane', title: 'One' }])
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'inserts nested graph nodes' do
|
43
|
-
expect(container.relation(:tags)).to match_array([
|
44
|
-
{ name: 'red', task: 'One' },
|
45
|
-
{ name: 'green', task: 'One' },
|
46
|
-
{ name: 'blue', task: 'One' }
|
47
|
-
])
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
include_context 'container'
|
53
|
-
|
54
|
-
let(:create_user) { container.command(:users).create }
|
55
|
-
let(:create_task) { container.command(:tasks).create }
|
56
|
-
|
57
|
-
let(:create_many_tasks) { container.command(:tasks).create_many }
|
58
|
-
let(:create_many_tags) { container.command(:tags).create_many }
|
59
|
-
|
60
|
-
let(:user) { { name: 'Jane' } }
|
61
|
-
let(:task) { { title: 'One' } }
|
62
|
-
let(:tags) { [{ name: 'red' }, { name: 'green' }, { name: 'blue' }] }
|
63
|
-
|
64
|
-
before do
|
65
|
-
configuration.relation(:users)
|
66
|
-
configuration.relation(:tasks)
|
67
|
-
configuration.relation(:tags)
|
68
|
-
|
69
|
-
configuration.commands(:users) do
|
70
|
-
define(:create) do
|
71
|
-
result :one
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
configuration.commands(:tasks) do
|
76
|
-
define(:create) do
|
77
|
-
result :one
|
78
|
-
|
79
|
-
def execute(task, user)
|
80
|
-
super(task.merge(user: user[:name]))
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
define(:create) do
|
85
|
-
register_as :create_many
|
86
|
-
|
87
|
-
def execute(tasks, user)
|
88
|
-
super(tasks.map { |t| t.merge(user: user[:name]) })
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
configuration.commands(:tags) do
|
94
|
-
define(:create) do
|
95
|
-
register_as :create_many
|
96
|
-
|
97
|
-
def execute(tags, tasks)
|
98
|
-
super(
|
99
|
-
Array([tasks]).flatten.map { |task|
|
100
|
-
tags.map { |tag| tag.merge(task: task[:title]) }
|
101
|
-
}.flatten
|
102
|
-
)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe '#call' do
|
109
|
-
context 'when result is :one in root and its direct children' do
|
110
|
-
it_behaves_like 'a persisted graph' do
|
111
|
-
subject(:command) do
|
112
|
-
create_user.with(user)
|
113
|
-
.combine(create_task.with(task)
|
114
|
-
.combine(create_many_tags.with(tags)))
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context 'when result is :many for root direct children' do
|
120
|
-
it_behaves_like 'a persisted graph' do
|
121
|
-
subject(:command) do
|
122
|
-
create_user.with(user)
|
123
|
-
.combine(create_many_tasks.with([task])
|
124
|
-
.combine(create_many_tags.with(tags)))
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
describe 'pipeline' do
|
131
|
-
subject(:command) do
|
132
|
-
container.command(:users).as(:entity).create.with(user)
|
133
|
-
.combine(create_task.with(task)
|
134
|
-
.combine(create_many_tags.with(tags)))
|
135
|
-
end
|
136
|
-
|
137
|
-
before do
|
138
|
-
Test::Tag = Class.new(Dry::Struct) {
|
139
|
-
attribute :name, Types::String
|
140
|
-
}
|
141
|
-
|
142
|
-
Test::Task = Class.new(Dry::Struct) {
|
143
|
-
attribute :title, Types::String
|
144
|
-
attribute :tags, Types::Array.member(Test::Tag)
|
145
|
-
}
|
146
|
-
|
147
|
-
Test::User = Class.new(Dry::Struct) {
|
148
|
-
attribute :name, Types::String
|
149
|
-
attribute :task, Test::Task
|
150
|
-
}
|
151
|
-
|
152
|
-
class Test::UserMapper < ROM::Mapper
|
153
|
-
relation :users
|
154
|
-
register_as :entity
|
155
|
-
reject_keys :true
|
156
|
-
|
157
|
-
model Test::User
|
158
|
-
|
159
|
-
attribute :name
|
160
|
-
|
161
|
-
combine :task, on: { name: :user }, type: :hash do
|
162
|
-
model Test::Task
|
163
|
-
|
164
|
-
attribute :title
|
165
|
-
|
166
|
-
combine :tags, on: { title: :task } do
|
167
|
-
model Test::Tag
|
168
|
-
attribute :name
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
172
|
-
configuration.register_mapper(Test::UserMapper)
|
173
|
-
end
|
174
|
-
|
175
|
-
it 'sends data through the pipeline' do
|
176
|
-
expect(command.call).to eql(
|
177
|
-
Test::User.new(
|
178
|
-
name: 'Jane',
|
179
|
-
task: Test::Task.new(
|
180
|
-
title: 'One',
|
181
|
-
tags: [
|
182
|
-
Test::Tag.new(name: 'red'),
|
183
|
-
Test::Tag.new(name: 'green'),
|
184
|
-
Test::Tag.new(name: 'blue')
|
185
|
-
]
|
186
|
-
)
|
187
|
-
)
|
188
|
-
)
|
189
|
-
end
|
190
|
-
end
|
191
|
-
end
|
@@ -1,307 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ROM::Commands::Lazy do
|
4
|
-
include_context 'container'
|
5
|
-
|
6
|
-
let(:create_user) { container.command(:users).create }
|
7
|
-
let(:update_user) { container.command(:users).update }
|
8
|
-
let(:delete_user) { container.command(:users).delete }
|
9
|
-
|
10
|
-
let(:create_task) { container.command(:tasks).create }
|
11
|
-
let(:create_tasks) { container.command(:tasks).create_many }
|
12
|
-
let(:update_task) { container.command(:tasks).update }
|
13
|
-
|
14
|
-
let(:input) { { user: { name: 'Jane', email: 'jane@doe.org' } } }
|
15
|
-
let(:jane) { input[:user] }
|
16
|
-
let(:evaluator) { -> input { input[:user] } }
|
17
|
-
|
18
|
-
before do
|
19
|
-
configuration.relation(:tasks) do
|
20
|
-
def by_user_and_title(user, title)
|
21
|
-
by_user(user).by_title(title)
|
22
|
-
end
|
23
|
-
|
24
|
-
def by_user(user)
|
25
|
-
restrict(user: user)
|
26
|
-
end
|
27
|
-
|
28
|
-
def by_title(title)
|
29
|
-
restrict(title: title)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
configuration.relation(:users) do
|
34
|
-
def by_name(name)
|
35
|
-
restrict(name: name)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
configuration.commands(:users) do
|
40
|
-
define(:create) do
|
41
|
-
result :one
|
42
|
-
end
|
43
|
-
|
44
|
-
define(:update) do
|
45
|
-
result :one
|
46
|
-
end
|
47
|
-
|
48
|
-
define(:delete) do
|
49
|
-
result :one
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
configuration.commands(:tasks) do
|
54
|
-
define(:create) do
|
55
|
-
result :one
|
56
|
-
end
|
57
|
-
|
58
|
-
define(:create_many, type: :create) do
|
59
|
-
def execute(tuples, user)
|
60
|
-
super(tuples.map { |tuple| tuple.merge(user: user[:name]) })
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
define(:update) do
|
65
|
-
result :one
|
66
|
-
|
67
|
-
def execute(tuple, user)
|
68
|
-
super(tuple.merge(user: user[:name]))
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe '#call' do
|
75
|
-
context 'with a create command' do
|
76
|
-
subject(:command) { ROM::Commands::Lazy[create_user].new(create_user, evaluator) }
|
77
|
-
|
78
|
-
it 'evaluates the input and calls command' do
|
79
|
-
command.call(input)
|
80
|
-
|
81
|
-
expect(container.relation(:users)).to match_array([jane])
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context 'with a create command for many child tuples' do
|
86
|
-
subject(:command) do
|
87
|
-
ROM::Commands::Lazy[create_tasks].new(create_tasks, evaluator)
|
88
|
-
end
|
89
|
-
|
90
|
-
let(:evaluator) { -> input, index { input[:users][index][:tasks] } }
|
91
|
-
|
92
|
-
let(:input) do
|
93
|
-
{ users: [
|
94
|
-
{
|
95
|
-
name: 'Jane',
|
96
|
-
tasks: [{ title: 'Jane Task One' }, { title: 'Jane Task Two' }]
|
97
|
-
},
|
98
|
-
{
|
99
|
-
name: 'Joe',
|
100
|
-
tasks: [{ title: 'Joe Task One' }]
|
101
|
-
}
|
102
|
-
]}
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'evaluates the input and calls command' do
|
106
|
-
command.call(input, input[:users])
|
107
|
-
|
108
|
-
expect(container.relation(:tasks)).to match_array([
|
109
|
-
{ user: 'Jane', title: 'Jane Task One' },
|
110
|
-
{ user: 'Jane', title: 'Jane Task Two' },
|
111
|
-
{ user: 'Joe', title: 'Joe Task One' }
|
112
|
-
])
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
context 'with an update command' do
|
117
|
-
subject(:command) do
|
118
|
-
ROM::Commands::Lazy[update_user].new(
|
119
|
-
update_user, evaluator, -> cmd, user { cmd.by_name(user[:name]) })
|
120
|
-
end
|
121
|
-
|
122
|
-
before do
|
123
|
-
create_user[jane]
|
124
|
-
end
|
125
|
-
|
126
|
-
it 'evaluates the input, restricts the relation and calls its command' do
|
127
|
-
input = { user: { name: 'Jane', email: 'jane.doe@rom-rb.org' } }
|
128
|
-
command.call(input)
|
129
|
-
|
130
|
-
expect(container.relation(:users)).to match_array([input[:user]])
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
context 'with an update command for a child tuple' do
|
135
|
-
subject(:command) do
|
136
|
-
ROM::Commands::Lazy[update_task].new(
|
137
|
-
update_task,
|
138
|
-
evaluator,
|
139
|
-
-> cmd, user, task { cmd.by_user(user[:name]).by_title(task[:title]) }
|
140
|
-
)
|
141
|
-
end
|
142
|
-
|
143
|
-
let(:evaluator) { -> input { input[:user][:task] } }
|
144
|
-
|
145
|
-
let(:jane) { { name: 'Jane' } }
|
146
|
-
let(:jane_task) { { user: 'Jane', title: 'Jane Task', priority: 1 } }
|
147
|
-
|
148
|
-
let(:input) { { user: jane.merge(task: jane_task) } }
|
149
|
-
|
150
|
-
before do
|
151
|
-
create_user[jane]
|
152
|
-
create_task[user: 'Jane', title: 'Jane Task', priority: 2]
|
153
|
-
end
|
154
|
-
|
155
|
-
it 'evaluates the input, restricts the relation and calls its command' do
|
156
|
-
command.call(input, input[:user])
|
157
|
-
|
158
|
-
expect(container.relation(:users)).to match_array([jane])
|
159
|
-
|
160
|
-
expect(container.relation(:tasks)).to match_array([jane_task])
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
context 'with an update command for child tuples' do
|
165
|
-
subject(:command) do
|
166
|
-
ROM::Commands::Lazy[update_task].new(
|
167
|
-
update_task,
|
168
|
-
evaluator,
|
169
|
-
-> cmd, user, task { cmd.by_user(user[:name]).by_title(task[:title]) }
|
170
|
-
)
|
171
|
-
end
|
172
|
-
|
173
|
-
let(:evaluator) { -> input { input[:user][:tasks] } }
|
174
|
-
|
175
|
-
let(:jane) { { name: 'Jane' } }
|
176
|
-
let(:jane_tasks) {
|
177
|
-
[
|
178
|
-
{ user: 'Jane', title: 'Jane Task One', priority: 2 },
|
179
|
-
{ user: 'Jane', title: 'Jane Task Two', priority: 3 }
|
180
|
-
]
|
181
|
-
}
|
182
|
-
|
183
|
-
let(:input) { { user: jane.merge(tasks: jane_tasks) } }
|
184
|
-
|
185
|
-
before do
|
186
|
-
create_user[jane]
|
187
|
-
create_task[user: 'Jane', title: 'Jane Task One', priority: 3]
|
188
|
-
create_task[user: 'Jane', title: 'Jane Task Two', priority: 4]
|
189
|
-
end
|
190
|
-
|
191
|
-
it 'evaluates the input, restricts the relation and calls its command' do
|
192
|
-
command.call(input, input[:user])
|
193
|
-
|
194
|
-
expect(container.relation(:users)).to match_array([jane])
|
195
|
-
|
196
|
-
expect(container.relation(:tasks)).to match_array(jane_tasks)
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
context 'with an update command for many parents and their children' do
|
201
|
-
subject(:command) do
|
202
|
-
ROM::Commands::Lazy[update_task].new(
|
203
|
-
update_task,
|
204
|
-
evaluator,
|
205
|
-
-> cmd, user, task { cmd.by_user(user[:name]).by_title(task[:title]) }
|
206
|
-
)
|
207
|
-
end
|
208
|
-
|
209
|
-
let(:evaluator) { -> input, index { input[:users][index][:tasks] } }
|
210
|
-
|
211
|
-
let(:input) do
|
212
|
-
{ users: [
|
213
|
-
{
|
214
|
-
name: 'Jane',
|
215
|
-
tasks: [
|
216
|
-
{ title: 'Jane Task One', priority: 1 },
|
217
|
-
{ title: 'Jane Task Two', priority: 2 }
|
218
|
-
]
|
219
|
-
},
|
220
|
-
{
|
221
|
-
name: 'Joe',
|
222
|
-
tasks: [{ title: 'Joe Task One', priority: 1 }]
|
223
|
-
}
|
224
|
-
]}
|
225
|
-
end
|
226
|
-
|
227
|
-
before do
|
228
|
-
create_user[name: 'Jane']
|
229
|
-
create_user[name: 'Joe']
|
230
|
-
|
231
|
-
create_task[user: 'Jane', title: 'Jane Task One']
|
232
|
-
create_task[user: 'Jane', title: 'Jane Task Two']
|
233
|
-
create_task[user: 'Joe', title: 'Joe Task One']
|
234
|
-
end
|
235
|
-
|
236
|
-
it 'evaluates the input and calls its command' do
|
237
|
-
command.call(input, input[:users])
|
238
|
-
|
239
|
-
expect(container.relation(:tasks)).to match_array([
|
240
|
-
{ user: 'Jane', title: 'Jane Task One', priority: 1 },
|
241
|
-
{ user: 'Jane', title: 'Jane Task Two', priority: 2 },
|
242
|
-
{ user: 'Joe', title: 'Joe Task One', priority: 1 }
|
243
|
-
])
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
context 'with a delete command' do
|
248
|
-
subject(:command) do
|
249
|
-
ROM::Commands::Lazy[delete_user].new(
|
250
|
-
delete_user,
|
251
|
-
evaluator,
|
252
|
-
-> cmd, user { cmd.by_name(user[:name]) }
|
253
|
-
)
|
254
|
-
end
|
255
|
-
|
256
|
-
let(:joe) { { name: 'Joe' } }
|
257
|
-
|
258
|
-
before do
|
259
|
-
create_user[jane]
|
260
|
-
create_user[joe]
|
261
|
-
end
|
262
|
-
|
263
|
-
it 'restricts the relation and calls its command' do
|
264
|
-
command.call(input)
|
265
|
-
|
266
|
-
expect(container.relation(:users)).to match_array([joe])
|
267
|
-
end
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
describe '#>>' do
|
272
|
-
subject(:command) { ROM::Commands::Lazy[create_user].new(create_user, evaluator) }
|
273
|
-
|
274
|
-
it 'composes with another command' do
|
275
|
-
expect(command >> create_task).to be_instance_of(ROM::Commands::Composite)
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
|
-
describe '#combine' do
|
280
|
-
subject(:command) { ROM::Commands::Lazy[create_user].new(create_user, evaluator) }
|
281
|
-
|
282
|
-
it 'combines with another command' do
|
283
|
-
expect(command.combine(create_task)).to be_instance_of(ROM::Commands::Graph)
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
describe '#unwrap' do
|
288
|
-
subject(:command) { ROM::Commands::Lazy[create_user].new(create_user, evaluator) }
|
289
|
-
|
290
|
-
it 'returns wrapped command' do
|
291
|
-
expect(command.unwrap).to be(create_user)
|
292
|
-
end
|
293
|
-
end
|
294
|
-
|
295
|
-
describe '#method_missing' do
|
296
|
-
subject(:command) { ROM::Commands::Lazy[update_user].new(update_user, evaluator) }
|
297
|
-
|
298
|
-
it 'returns original response if it was not a command' do
|
299
|
-
response = command.result
|
300
|
-
expect(response).to be(:one)
|
301
|
-
end
|
302
|
-
|
303
|
-
it 'raises error when message is unknown' do
|
304
|
-
expect { command.not_here }.to raise_error(NoMethodError, /not_here/)
|
305
|
-
end
|
306
|
-
end
|
307
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ROM::Commands::Result do
|
4
|
-
describe '#value' do
|
5
|
-
subject(:result) { ROM::Commands::Result::Success }
|
6
|
-
|
7
|
-
it 'bubble up nested values' do
|
8
|
-
data = double(to_ary: ['foo'])
|
9
|
-
r = result.new(result.new(result.new(data)))
|
10
|
-
|
11
|
-
expect(r.value).to eq(data)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe '#success?' do
|
16
|
-
context 'not launched command' do
|
17
|
-
subject(:command) { ROM::Commands::Result }
|
18
|
-
|
19
|
-
it 'returns false' do
|
20
|
-
expect(command.new.success?).to eq(false)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'successful command' do
|
25
|
-
subject(:result) { ROM::Commands::Result::Success }
|
26
|
-
|
27
|
-
it 'returns true' do
|
28
|
-
data = double(to_ary: ['foo'])
|
29
|
-
expect(result.new(data).success?).to eq(true)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'failed command' do
|
34
|
-
subject(:result) { ROM::Commands::Result::Failure }
|
35
|
-
|
36
|
-
it 'returns false' do
|
37
|
-
error = double(:error)
|
38
|
-
expect(result.new(error).success?).to eq(false)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe '#failure?' do
|
44
|
-
context 'not launched command' do
|
45
|
-
subject(:command) { ROM::Commands::Result }
|
46
|
-
|
47
|
-
it 'returns false' do
|
48
|
-
expect(command.new.success?).to eq(false)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context 'successful command' do
|
53
|
-
subject(:result) { ROM::Commands::Result::Success }
|
54
|
-
|
55
|
-
it 'returns false' do
|
56
|
-
data = double(to_ary: ['foo'])
|
57
|
-
expect(result.new(data).failure?).to eq(false)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context 'failed command' do
|
62
|
-
subject(:result) { ROM::Commands::Result::Failure }
|
63
|
-
|
64
|
-
it 'returns true' do
|
65
|
-
error = double(:error)
|
66
|
-
expect(result.new(error).failure?).to eq(true)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|