rom 3.3.3 → 4.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -599
- data/lib/rom/version.rb +1 -1
- data/lib/rom.rb +3 -44
- metadata +19 -295
- data/.gitignore +0 -24
- data/.rspec +0 -3
- data/.rubocop.yml +0 -87
- data/.rubocop_todo.yml +0 -46
- data/.travis.yml +0 -24
- data/.yardopts +0 -2
- data/CODE_OF_CONDUCT.md +0 -13
- data/CONTRIBUTING.md +0 -1
- data/Gemfile +0 -54
- data/Guardfile +0 -24
- data/Rakefile +0 -28
- data/lib/rom/array_dataset.rb +0 -44
- data/lib/rom/association_set.rb +0 -49
- data/lib/rom/auto_curry.rb +0 -55
- data/lib/rom/command.rb +0 -494
- data/lib/rom/command_registry.rb +0 -148
- data/lib/rom/commands/class_interface.rb +0 -270
- data/lib/rom/commands/composite.rb +0 -53
- 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 -95
- 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 -90
- data/lib/rom/configuration_dsl/command.rb +0 -41
- data/lib/rom/configuration_dsl/command_dsl.rb +0 -35
- data/lib/rom/configuration_dsl/mapper.rb +0 -36
- data/lib/rom/configuration_dsl/mapper_dsl.rb +0 -43
- data/lib/rom/configuration_dsl/relation.rb +0 -26
- data/lib/rom/configuration_dsl.rb +0 -107
- data/lib/rom/configuration_plugin.rb +0 -17
- data/lib/rom/constants.rb +0 -36
- data/lib/rom/container.rb +0 -233
- data/lib/rom/create_container.rb +0 -60
- data/lib/rom/data_proxy.rb +0 -94
- data/lib/rom/enumerable_dataset.rb +0 -68
- data/lib/rom/environment.rb +0 -70
- data/lib/rom/gateway.rb +0 -196
- data/lib/rom/global/plugin_dsl.rb +0 -47
- data/lib/rom/global.rb +0 -58
- data/lib/rom/initializer.rb +0 -26
- data/lib/rom/lint/enumerable_dataset.rb +0 -54
- data/lib/rom/lint/gateway.rb +0 -120
- 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 -56
- data/lib/rom/memory/dataset.rb +0 -97
- data/lib/rom/memory/gateway.rb +0 -64
- data/lib/rom/memory/relation.rb +0 -62
- data/lib/rom/memory/schema.rb +0 -13
- 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 -122
- data/lib/rom/plugin.rb +0 -20
- data/lib/rom/plugin_base.rb +0 -40
- 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 -21
- data/lib/rom/plugins/relation/instrumentation.rb +0 -51
- data/lib/rom/plugins/relation/key_inference.rb +0 -48
- data/lib/rom/plugins/relation/registry_reader.rb +0 -33
- data/lib/rom/registry.rb +0 -50
- data/lib/rom/relation/class_interface.rb +0 -356
- data/lib/rom/relation/composite.rb +0 -46
- data/lib/rom/relation/curried.rb +0 -109
- data/lib/rom/relation/graph.rb +0 -125
- data/lib/rom/relation/loaded.rb +0 -127
- data/lib/rom/relation/materializable.rb +0 -66
- data/lib/rom/relation/name.rb +0 -102
- data/lib/rom/relation/view_dsl.rb +0 -64
- data/lib/rom/relation.rb +0 -250
- data/lib/rom/relation_registry.rb +0 -9
- data/lib/rom/schema/attribute.rb +0 -390
- data/lib/rom/schema/dsl.rb +0 -67
- data/lib/rom/schema.rb +0 -407
- data/lib/rom/setup/auto_registration.rb +0 -74
- data/lib/rom/setup/auto_registration_strategies/base.rb +0 -16
- data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +0 -63
- data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +0 -20
- 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 -83
- data/lib/rom/setup/finalize.rb +0 -152
- data/lib/rom/setup.rb +0 -65
- data/lib/rom/support/configurable.rb +0 -85
- data/lib/rom/transaction.rb +0 -24
- data/lib/rom/types.rb +0 -49
- 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 -25
- 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/custom_namespace/commands/create_customer.rb +0 -8
- data/spec/fixtures/custom_namespace/mappers/customer_list.rb +0 -8
- data/spec/fixtures/custom_namespace/relations/customers.rb +0 -8
- 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/fixtures/wrong/commands/create_customer.rb +0 -8
- data/spec/fixtures/wrong/mappers/customer_list.rb +0 -8
- data/spec/fixtures/wrong/relations/customers.rb +0 -8
- data/spec/integration/command_registry_spec.rb +0 -47
- data/spec/integration/commands/create_spec.rb +0 -157
- 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 -294
- data/spec/integration/commands/update_spec.rb +0 -86
- data/spec/integration/commands_spec.rb +0 -67
- data/spec/integration/gateways/extending_relations_spec.rb +0 -58
- data/spec/integration/gateways/setting_logger_spec.rb +0 -34
- 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/setup_spec.rb +0 -193
- data/spec/shared/command_behavior.rb +0 -28
- data/spec/shared/command_graph.rb +0 -54
- 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 -59
- data/spec/support/constant_leak_finder.rb +0 -14
- data/spec/support/mutant.rb +0 -10
- data/spec/support/schema.rb +0 -14
- data/spec/support/types.rb +0 -5
- data/spec/test/memory_repository_lint_test.rb +0 -27
- data/spec/unit/rom/array_dataset_spec.rb +0 -59
- data/spec/unit/rom/association_set_spec.rb +0 -48
- data/spec/unit/rom/auto_curry_spec.rb +0 -71
- data/spec/unit/rom/commands/graph_spec.rb +0 -192
- data/spec/unit/rom/commands/lazy_spec.rb +0 -310
- data/spec/unit/rom/commands/pre_and_post_processors_spec.rb +0 -343
- data/spec/unit/rom/commands/result_spec.rb +0 -70
- data/spec/unit/rom/commands_spec.rb +0 -188
- 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 -109
- data/spec/unit/rom/create_container_spec.rb +0 -151
- data/spec/unit/rom/enumerable_dataset_spec.rb +0 -15
- 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/gateway_spec.rb +0 -12
- data/spec/unit/rom/memory/inheritance_spec.rb +0 -32
- data/spec/unit/rom/memory/relation_spec.rb +0 -121
- 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/instrumentation_spec.rb +0 -44
- data/spec/unit/rom/plugins/relation/key_inference_spec.rb +0 -85
- data/spec/unit/rom/registry_spec.rb +0 -86
- data/spec/unit/rom/relation/attribute_reader_spec.rb +0 -17
- data/spec/unit/rom/relation/call_spec.rb +0 -51
- data/spec/unit/rom/relation/composite_spec.rb +0 -106
- data/spec/unit/rom/relation/curried_spec.rb +0 -67
- data/spec/unit/rom/relation/graph_spec.rb +0 -106
- data/spec/unit/rom/relation/lazy/combine_spec.rb +0 -165
- data/spec/unit/rom/relation/lazy/graph_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/output_schema_spec.rb +0 -28
- data/spec/unit/rom/relation/schema_spec.rb +0 -259
- data/spec/unit/rom/relation/view_spec.rb +0 -158
- data/spec/unit/rom/relation_spec.rb +0 -252
- data/spec/unit/rom/schema/accessing_attributes_spec.rb +0 -52
- data/spec/unit/rom/schema/append_spec.rb +0 -17
- data/spec/unit/rom/schema/exclude_spec.rb +0 -15
- data/spec/unit/rom/schema/finalize_spec.rb +0 -59
- data/spec/unit/rom/schema/key_predicate_spec.rb +0 -15
- data/spec/unit/rom/schema/merge_spec.rb +0 -17
- data/spec/unit/rom/schema/prefix_spec.rb +0 -16
- data/spec/unit/rom/schema/project_spec.rb +0 -15
- data/spec/unit/rom/schema/rename_spec.rb +0 -22
- data/spec/unit/rom/schema/type_spec.rb +0 -49
- data/spec/unit/rom/schema/uniq_spec.rb +0 -21
- data/spec/unit/rom/schema/wrap_spec.rb +0 -18
- data/spec/unit/rom/schema_spec.rb +0 -10
- data/spec/unit/rom/setup/auto_registration_spec.rb +0 -214
@@ -1,48 +0,0 @@
|
|
1
|
-
RSpec.describe ROM::AssociationSet do
|
2
|
-
describe '#try' do
|
3
|
-
it 'returns association when it exists' do
|
4
|
-
assoc = spy(:assoc)
|
5
|
-
assoc_set = ROM::AssociationSet.new(users: assoc)
|
6
|
-
|
7
|
-
assoc_set.try(:users, &:done)
|
8
|
-
|
9
|
-
expect(assoc).to have_received(:done)
|
10
|
-
|
11
|
-
assoc_set.try(:user, &:done)
|
12
|
-
|
13
|
-
expect(assoc).to have_received(:done)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'returns false when assoc is not found' do
|
17
|
-
assoc = spy(:assoc)
|
18
|
-
fallback = spy(:fallback)
|
19
|
-
assoc_set = ROM::AssociationSet.new({})
|
20
|
-
|
21
|
-
assoc_set.try(:users, &:done) or fallback.done
|
22
|
-
|
23
|
-
expect(assoc).to_not have_received(:done)
|
24
|
-
expect(fallback).to have_received(:done)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#[]' do
|
29
|
-
let(:users) { BasicObject.new }
|
30
|
-
let(:posts) { BasicObject.new }
|
31
|
-
let(:set) { ROM::AssociationSet.new(users: users, post: posts) }
|
32
|
-
|
33
|
-
it 'fetches association' do
|
34
|
-
expect(set[:users]).to be users
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'tries to fetch under singularized key' do
|
38
|
-
expect(set[:post]).to be posts
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'throws exception on missing association' do
|
42
|
-
expect { set[:labels] }.to raise_error(
|
43
|
-
ROM::Registry::ElementNotFoundError,
|
44
|
-
":labels doesn't exist in ROM::AssociationSet registry"
|
45
|
-
)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'rom/auto_curry'
|
2
|
-
|
3
|
-
RSpec.describe ROM::AutoCurry do
|
4
|
-
subject(:object) { klass.new }
|
5
|
-
|
6
|
-
let(:klass) do
|
7
|
-
Class.new do
|
8
|
-
extend ROM::AutoCurry
|
9
|
-
|
10
|
-
def self.curried(*)
|
11
|
-
self
|
12
|
-
end
|
13
|
-
|
14
|
-
def initialize(*)
|
15
|
-
end
|
16
|
-
|
17
|
-
def arity_0
|
18
|
-
0
|
19
|
-
end
|
20
|
-
|
21
|
-
def arity_1(x)
|
22
|
-
x
|
23
|
-
end
|
24
|
-
|
25
|
-
def arity_2(x, y)
|
26
|
-
[x,y]
|
27
|
-
end
|
28
|
-
|
29
|
-
def arity_many(*args)
|
30
|
-
args
|
31
|
-
end
|
32
|
-
|
33
|
-
def yielding_block(arg)
|
34
|
-
yield(arg)
|
35
|
-
end
|
36
|
-
|
37
|
-
protected
|
38
|
-
|
39
|
-
def leave_me_alone(foo)
|
40
|
-
foo
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'registers auto-curried methods' do
|
46
|
-
expect(object.class.auto_curried_methods).to eql(%i[arity_1 arity_2 arity_many yielding_block])
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'auto-curries method with arity == 0' do
|
50
|
-
expect(object.arity_0).to be(0)
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'auto-curries method with arity == 1' do
|
54
|
-
expect(object.arity_1).to be_instance_of(klass)
|
55
|
-
expect(object.arity_1(1)).to be(1)
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'auto-curries method with arity > 0' do
|
59
|
-
expect(object.arity_2).to be_instance_of(klass)
|
60
|
-
expect(object.arity_2(1, 2)).to eql([1, 2])
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'auto-curries method with arity < 0' do
|
64
|
-
expect(object.arity_many).to eql([])
|
65
|
-
expect(object.arity_many(1, 2)).to eql([1, 2])
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'yields block' do
|
69
|
-
expect(object.yielding_block(1) { |arg| [arg, 2] }).to eql([1, 2])
|
70
|
-
end
|
71
|
-
end
|
@@ -1,192 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'dry-struct'
|
3
|
-
|
4
|
-
RSpec.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
|
-
before :associate
|
79
|
-
|
80
|
-
def associate(task, user)
|
81
|
-
task.merge(user: user[:name])
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
define(:create) do
|
86
|
-
register_as :create_many
|
87
|
-
before :associate
|
88
|
-
|
89
|
-
def associate(tasks, user)
|
90
|
-
tasks.map { |t| t.merge(user: user[:name]) }
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
configuration.commands(:tags) do
|
96
|
-
define(:create) do
|
97
|
-
register_as :create_many
|
98
|
-
before :associate
|
99
|
-
|
100
|
-
def associate(tags, tasks)
|
101
|
-
Array([tasks]).flatten.map { |task|
|
102
|
-
tags.map { |tag| tag.merge(task: task[:title]) }
|
103
|
-
}.flatten
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
describe '#call' do
|
110
|
-
context 'when result is :one in root and its direct children' do
|
111
|
-
it_behaves_like 'a persisted graph' do
|
112
|
-
subject(:command) do
|
113
|
-
create_user.with(user)
|
114
|
-
.combine(create_task.with(task)
|
115
|
-
.combine(create_many_tags.with(tags)))
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
context 'when result is :many for root direct children' do
|
121
|
-
it_behaves_like 'a persisted graph' do
|
122
|
-
subject(:command) do
|
123
|
-
create_user.with(user)
|
124
|
-
.combine(create_many_tasks.with([task])
|
125
|
-
.combine(create_many_tags.with(tags)))
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
describe 'pipeline' do
|
132
|
-
subject(:command) do
|
133
|
-
container.command(:users).as(:entity).create.with(user)
|
134
|
-
.combine(create_task.with(task)
|
135
|
-
.combine(create_many_tags.with(tags)))
|
136
|
-
end
|
137
|
-
|
138
|
-
before do
|
139
|
-
Test::Tag = Class.new(Dry::Struct) {
|
140
|
-
attribute :name, Types::String
|
141
|
-
}
|
142
|
-
|
143
|
-
Test::Task = Class.new(Dry::Struct) {
|
144
|
-
attribute :title, Types::String
|
145
|
-
attribute :tags, Types::Array.member(Test::Tag)
|
146
|
-
}
|
147
|
-
|
148
|
-
Test::User = Class.new(Dry::Struct) {
|
149
|
-
attribute :name, Types::String
|
150
|
-
attribute :task, Test::Task
|
151
|
-
}
|
152
|
-
|
153
|
-
class Test::UserMapper < ROM::Mapper
|
154
|
-
relation :users
|
155
|
-
register_as :entity
|
156
|
-
reject_keys :true
|
157
|
-
|
158
|
-
model Test::User
|
159
|
-
|
160
|
-
attribute :name
|
161
|
-
|
162
|
-
combine :task, on: { name: :user }, type: :hash do
|
163
|
-
model Test::Task
|
164
|
-
|
165
|
-
attribute :title
|
166
|
-
|
167
|
-
combine :tags, on: { title: :task } do
|
168
|
-
model Test::Tag
|
169
|
-
attribute :name
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|
173
|
-
configuration.register_mapper(Test::UserMapper)
|
174
|
-
end
|
175
|
-
|
176
|
-
it 'sends data through the pipeline' do
|
177
|
-
expect(command.call).to eql(
|
178
|
-
Test::User.new(
|
179
|
-
name: 'Jane',
|
180
|
-
task: Test::Task.new(
|
181
|
-
title: 'One',
|
182
|
-
tags: [
|
183
|
-
Test::Tag.new(name: 'red'),
|
184
|
-
Test::Tag.new(name: 'green'),
|
185
|
-
Test::Tag.new(name: 'blue')
|
186
|
-
]
|
187
|
-
)
|
188
|
-
)
|
189
|
-
)
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
@@ -1,310 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.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
|
-
before :associate
|
60
|
-
|
61
|
-
def associate(tuples, user)
|
62
|
-
tuples.map { |tuple| tuple.merge(user: user[:name]) }
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
define(:update) do
|
67
|
-
result :one
|
68
|
-
before :associate
|
69
|
-
|
70
|
-
def associate(tuple, user)
|
71
|
-
tuple.merge(user: user[:name])
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe '#call' do
|
78
|
-
context 'with a create command' do
|
79
|
-
subject(:command) { ROM::Commands::Lazy[create_user].new(create_user, evaluator) }
|
80
|
-
|
81
|
-
it 'evaluates the input and calls command' do
|
82
|
-
command.call(input)
|
83
|
-
|
84
|
-
expect(container.relation(:users)).to match_array([jane])
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
context 'with a create command for many child tuples' do
|
89
|
-
subject(:command) do
|
90
|
-
ROM::Commands::Lazy[create_tasks].new(create_tasks, evaluator)
|
91
|
-
end
|
92
|
-
|
93
|
-
let(:evaluator) { -> input, index { input[:users][index][:tasks] } }
|
94
|
-
|
95
|
-
let(:input) do
|
96
|
-
{ users: [
|
97
|
-
{
|
98
|
-
name: 'Jane',
|
99
|
-
tasks: [{ title: 'Jane Task One' }, { title: 'Jane Task Two' }]
|
100
|
-
},
|
101
|
-
{
|
102
|
-
name: 'Joe',
|
103
|
-
tasks: [{ title: 'Joe Task One' }]
|
104
|
-
}
|
105
|
-
]}
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'evaluates the input and calls command' do
|
109
|
-
command.call(input, input[:users])
|
110
|
-
|
111
|
-
expect(container.relation(:tasks)).to match_array([
|
112
|
-
{ user: 'Jane', title: 'Jane Task One' },
|
113
|
-
{ user: 'Jane', title: 'Jane Task Two' },
|
114
|
-
{ user: 'Joe', title: 'Joe Task One' }
|
115
|
-
])
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context 'with an update command' do
|
120
|
-
subject(:command) do
|
121
|
-
ROM::Commands::Lazy[update_user].new(
|
122
|
-
update_user, evaluator, -> cmd, user { cmd.by_name(user[:name]) })
|
123
|
-
end
|
124
|
-
|
125
|
-
before do
|
126
|
-
create_user[jane]
|
127
|
-
end
|
128
|
-
|
129
|
-
it 'evaluates the input, restricts the relation and calls its command' do
|
130
|
-
input = { user: { name: 'Jane', email: 'jane.doe@rom-rb.org' } }
|
131
|
-
command.call(input)
|
132
|
-
|
133
|
-
expect(container.relation(:users)).to match_array([input[:user]])
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
context 'with an update command for a child tuple' do
|
138
|
-
subject(:command) do
|
139
|
-
ROM::Commands::Lazy[update_task].new(
|
140
|
-
update_task,
|
141
|
-
evaluator,
|
142
|
-
-> cmd, user, task { cmd.by_user(user[:name]).by_title(task[:title]) }
|
143
|
-
)
|
144
|
-
end
|
145
|
-
|
146
|
-
let(:evaluator) { -> input { input[:user][:task] } }
|
147
|
-
|
148
|
-
let(:jane) { { name: 'Jane' } }
|
149
|
-
let(:jane_task) { { user: 'Jane', title: 'Jane Task', priority: 1 } }
|
150
|
-
|
151
|
-
let(:input) { { user: jane.merge(task: jane_task) } }
|
152
|
-
|
153
|
-
before do
|
154
|
-
create_user[jane]
|
155
|
-
create_task[user: 'Jane', title: 'Jane Task', priority: 2]
|
156
|
-
end
|
157
|
-
|
158
|
-
it 'evaluates the input, restricts the relation and calls its command' do
|
159
|
-
command.call(input, input[:user])
|
160
|
-
|
161
|
-
expect(container.relation(:users)).to match_array([jane])
|
162
|
-
|
163
|
-
expect(container.relation(:tasks)).to match_array([jane_task])
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
context 'with an update command for child tuples' do
|
168
|
-
subject(:command) do
|
169
|
-
ROM::Commands::Lazy[update_task].new(
|
170
|
-
update_task,
|
171
|
-
evaluator,
|
172
|
-
-> cmd, user, task { cmd.by_user(user[:name]).by_title(task[:title]) }
|
173
|
-
)
|
174
|
-
end
|
175
|
-
|
176
|
-
let(:evaluator) { -> input { input[:user][:tasks] } }
|
177
|
-
|
178
|
-
let(:jane) { { name: 'Jane' } }
|
179
|
-
let(:jane_tasks) {
|
180
|
-
[
|
181
|
-
{ user: 'Jane', title: 'Jane Task One', priority: 2 },
|
182
|
-
{ user: 'Jane', title: 'Jane Task Two', priority: 3 }
|
183
|
-
]
|
184
|
-
}
|
185
|
-
|
186
|
-
let(:input) { { user: jane.merge(tasks: jane_tasks) } }
|
187
|
-
|
188
|
-
before do
|
189
|
-
create_user[jane]
|
190
|
-
create_task[user: 'Jane', title: 'Jane Task One', priority: 3]
|
191
|
-
create_task[user: 'Jane', title: 'Jane Task Two', priority: 4]
|
192
|
-
end
|
193
|
-
|
194
|
-
it 'evaluates the input, restricts the relation and calls its command' do
|
195
|
-
command.call(input, input[:user])
|
196
|
-
|
197
|
-
expect(container.relation(:users)).to match_array([jane])
|
198
|
-
|
199
|
-
expect(container.relation(:tasks)).to match_array(jane_tasks)
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
context 'with an update command for many parents and their children' do
|
204
|
-
subject(:command) do
|
205
|
-
ROM::Commands::Lazy[update_task].new(
|
206
|
-
update_task,
|
207
|
-
evaluator,
|
208
|
-
-> cmd, user, task { cmd.by_user(user[:name]).by_title(task[:title]) }
|
209
|
-
)
|
210
|
-
end
|
211
|
-
|
212
|
-
let(:evaluator) { -> input, index { input[:users][index][:tasks] } }
|
213
|
-
|
214
|
-
let(:input) do
|
215
|
-
{ users: [
|
216
|
-
{
|
217
|
-
name: 'Jane',
|
218
|
-
tasks: [
|
219
|
-
{ title: 'Jane Task One', priority: 1 },
|
220
|
-
{ title: 'Jane Task Two', priority: 2 }
|
221
|
-
]
|
222
|
-
},
|
223
|
-
{
|
224
|
-
name: 'Joe',
|
225
|
-
tasks: [{ title: 'Joe Task One', priority: 1 }]
|
226
|
-
}
|
227
|
-
]}
|
228
|
-
end
|
229
|
-
|
230
|
-
before do
|
231
|
-
create_user[name: 'Jane']
|
232
|
-
create_user[name: 'Joe']
|
233
|
-
|
234
|
-
create_task[user: 'Jane', title: 'Jane Task One']
|
235
|
-
create_task[user: 'Jane', title: 'Jane Task Two']
|
236
|
-
create_task[user: 'Joe', title: 'Joe Task One']
|
237
|
-
end
|
238
|
-
|
239
|
-
it 'evaluates the input and calls its command' do
|
240
|
-
command.call(input, input[:users])
|
241
|
-
|
242
|
-
expect(container.relation(:tasks)).to match_array([
|
243
|
-
{ user: 'Jane', title: 'Jane Task One', priority: 1 },
|
244
|
-
{ user: 'Jane', title: 'Jane Task Two', priority: 2 },
|
245
|
-
{ user: 'Joe', title: 'Joe Task One', priority: 1 }
|
246
|
-
])
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
context 'with a delete command' do
|
251
|
-
subject(:command) do
|
252
|
-
ROM::Commands::Lazy[delete_user].new(
|
253
|
-
delete_user,
|
254
|
-
evaluator,
|
255
|
-
-> cmd, user { cmd.by_name(user[:name]) }
|
256
|
-
)
|
257
|
-
end
|
258
|
-
|
259
|
-
let(:joe) { { name: 'Joe' } }
|
260
|
-
|
261
|
-
before do
|
262
|
-
create_user[jane]
|
263
|
-
create_user[joe]
|
264
|
-
end
|
265
|
-
|
266
|
-
it 'restricts the relation and calls its command' do
|
267
|
-
command.call(input)
|
268
|
-
|
269
|
-
expect(container.relation(:users)).to match_array([joe])
|
270
|
-
end
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
describe '#>>' do
|
275
|
-
subject(:command) { ROM::Commands::Lazy[create_user].new(create_user, evaluator) }
|
276
|
-
|
277
|
-
it 'composes with another command' do
|
278
|
-
expect(command >> create_task).to be_instance_of(ROM::Commands::Composite)
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
describe '#combine' do
|
283
|
-
subject(:command) { ROM::Commands::Lazy[create_user].new(create_user, evaluator) }
|
284
|
-
|
285
|
-
it 'combines with another command' do
|
286
|
-
expect(command.combine(create_task)).to be_instance_of(ROM::Commands::Graph)
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
describe '#unwrap' do
|
291
|
-
subject(:command) { ROM::Commands::Lazy[create_user].new(create_user, evaluator) }
|
292
|
-
|
293
|
-
it 'returns wrapped command' do
|
294
|
-
expect(command.unwrap).to be(create_user)
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
describe '#method_missing' do
|
299
|
-
subject(:command) { ROM::Commands::Lazy[update_user].new(update_user, evaluator) }
|
300
|
-
|
301
|
-
it 'returns original response if it was not a command' do
|
302
|
-
response = command.result
|
303
|
-
expect(response).to be(:one)
|
304
|
-
end
|
305
|
-
|
306
|
-
it 'raises error when message is unknown' do
|
307
|
-
expect { command.not_here }.to raise_error(NoMethodError, /not_here/)
|
308
|
-
end
|
309
|
-
end
|
310
|
-
end
|