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,47 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe 'ROM::CommandRegistry' do
|
4
|
-
include_context 'container'
|
5
|
-
|
6
|
-
let(:users) { container.command(:users) }
|
7
|
-
|
8
|
-
before do
|
9
|
-
configuration.relation(:users)
|
10
|
-
|
11
|
-
configuration.register_command(Class.new(ROM::Commands::Create[:memory]) do
|
12
|
-
register_as :create
|
13
|
-
relation :users
|
14
|
-
end)
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '#[]' do
|
18
|
-
it 'fetches a command from the registry' do
|
19
|
-
expect(users[:create]).to be_a(ROM::Commands::Create[:memory])
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'throws an error when the command is not found' do
|
23
|
-
expect { users[:not_found] }.to raise_error(
|
24
|
-
ROM::CommandRegistry::CommandNotFoundError,
|
25
|
-
'There is no :not_found command for :users relation'
|
26
|
-
)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe '#try' do
|
31
|
-
it 'returns a success result object on successful execution' do
|
32
|
-
result = users.try { users.create.call(name: 'Jane') }
|
33
|
-
|
34
|
-
expect(result).to match_array([{ name: 'Jane' }])
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'returns a success result on successful curried-command execution' do
|
38
|
-
result = users.try { users.create.curry(name: 'Jane') }
|
39
|
-
|
40
|
-
expect(result).to match_array([{ name: 'Jane' }])
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'allows checking if a command is available using respond_to?' do
|
44
|
-
expect(users).to respond_to(:create)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,157 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'dry-struct'
|
3
|
-
|
4
|
-
RSpec.describe 'Commands / Create' do
|
5
|
-
include_context 'container'
|
6
|
-
include_context 'users and tasks'
|
7
|
-
|
8
|
-
let(:users) { container.commands.users }
|
9
|
-
let(:tasks) { container.commands.tasks }
|
10
|
-
|
11
|
-
before do
|
12
|
-
configuration.relation(:users)
|
13
|
-
configuration.relation(:tasks)
|
14
|
-
|
15
|
-
class Test::CreateUser < ROM::Commands::Create[:memory]
|
16
|
-
relation :users
|
17
|
-
register_as :create
|
18
|
-
result :one
|
19
|
-
end
|
20
|
-
|
21
|
-
class Test::CreateTask < ROM::Commands::Create[:memory]
|
22
|
-
relation :tasks
|
23
|
-
register_as :create
|
24
|
-
result :one
|
25
|
-
before :associate
|
26
|
-
|
27
|
-
def associate(task, user)
|
28
|
-
task.merge(name: user.to_h[:name])
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
Test::User = Class.new(Dry::Struct) do
|
33
|
-
attribute :name, Types::String
|
34
|
-
attribute :email, Types::String
|
35
|
-
end
|
36
|
-
|
37
|
-
Test::Task = Class.new(Dry::Struct) do
|
38
|
-
attribute :name, Types::String
|
39
|
-
attribute :title, Types::String
|
40
|
-
end
|
41
|
-
|
42
|
-
class Test::UserMapper < ROM::Mapper
|
43
|
-
relation :users
|
44
|
-
register_as :entity
|
45
|
-
model Test::User
|
46
|
-
attribute :name
|
47
|
-
attribute :email
|
48
|
-
end
|
49
|
-
|
50
|
-
class Test::TaskMapper < ROM::Mapper
|
51
|
-
relation :tasks
|
52
|
-
register_as :entity
|
53
|
-
model Test::Task
|
54
|
-
attribute :name
|
55
|
-
attribute :title
|
56
|
-
end
|
57
|
-
|
58
|
-
configuration.register_command(Test::CreateUser, Test::CreateTask)
|
59
|
-
configuration.register_mapper(Test::UserMapper, Test::TaskMapper)
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'inserts user on successful validation' do
|
63
|
-
result = users.try {
|
64
|
-
users.create.call(name: 'Piotr', email: 'piotr@solnic.eu')
|
65
|
-
}
|
66
|
-
|
67
|
-
expect(result.value).to eql(name: 'Piotr', email: 'piotr@solnic.eu')
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'inserts user and associated task when things go well' do
|
71
|
-
result = users.try {
|
72
|
-
command = users.create.with(name: 'Piotr', email: 'piotr@solnic.eu')
|
73
|
-
command >>= tasks.create.with(title: 'Finish command-api')
|
74
|
-
command
|
75
|
-
}
|
76
|
-
|
77
|
-
expect(result.value).to eql(name: 'Piotr', title: 'Finish command-api')
|
78
|
-
end
|
79
|
-
|
80
|
-
describe '"result" option' do
|
81
|
-
it 'returns a single tuple when set to :one' do
|
82
|
-
configuration.commands(:users) do
|
83
|
-
define(:create_one, type: :create) do
|
84
|
-
result :one
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
tuple = { name: 'Piotr', email: 'piotr@solnic.eu' }
|
89
|
-
|
90
|
-
result = users.try {
|
91
|
-
users.create_one.call(tuple)
|
92
|
-
}
|
93
|
-
|
94
|
-
expect(result.value).to eql(tuple)
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'allows only valid result types' do
|
98
|
-
expect {
|
99
|
-
configuration.commands(:users) do
|
100
|
-
define(:create_one, type: :create) do
|
101
|
-
result :invalid_type
|
102
|
-
end
|
103
|
-
end
|
104
|
-
container
|
105
|
-
}.to raise_error(Dry::Types::ConstraintError)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
describe 'sending result through a mapper' do
|
110
|
-
let(:attributes) do
|
111
|
-
{ name: 'Jane', email: 'jane@doe.org' }
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'uses registered mapper to process the result for :one result' do
|
115
|
-
command = container.command(:users).as(:entity).create
|
116
|
-
result = command[attributes]
|
117
|
-
|
118
|
-
expect(result).to eql(Test::User.new(attributes))
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'with two composed commands respects the :result option' do
|
122
|
-
mapper_input = nil
|
123
|
-
|
124
|
-
mapper = proc do |tuples|
|
125
|
-
mapper_input = tuples
|
126
|
-
end
|
127
|
-
|
128
|
-
left = container.command(:users).as(:entity).create.with(
|
129
|
-
name: 'Jane', email: 'jane@doe.org'
|
130
|
-
)
|
131
|
-
|
132
|
-
right = container.command(:tasks).as(:entity).create.with(
|
133
|
-
title: 'Jane task'
|
134
|
-
)
|
135
|
-
|
136
|
-
command = left >> right >> mapper
|
137
|
-
|
138
|
-
result = command.call
|
139
|
-
|
140
|
-
task = Test::Task.new(name: 'Jane', title: 'Jane task')
|
141
|
-
|
142
|
-
expect(mapper_input).to eql([task])
|
143
|
-
expect(result).to eql(task)
|
144
|
-
end
|
145
|
-
|
146
|
-
it 'uses registered mapper to process the result for :many results' do
|
147
|
-
configuration.commands(:users) do
|
148
|
-
define(:create_many, type: :create)
|
149
|
-
end
|
150
|
-
|
151
|
-
command = container.command(:users).as(:entity).create_many
|
152
|
-
result = command[attributes]
|
153
|
-
|
154
|
-
expect(result).to eql([Test::User.new(attributes)])
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe 'Commands / Delete' do
|
4
|
-
include_context 'container'
|
5
|
-
include_context 'users and tasks'
|
6
|
-
|
7
|
-
subject(:users) { container.commands.users }
|
8
|
-
|
9
|
-
before do
|
10
|
-
configuration.relation(:users) do
|
11
|
-
def by_name(name)
|
12
|
-
restrict(name: name)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'deletes all tuples when there is no restriction' do
|
18
|
-
configuration.commands(:users) do
|
19
|
-
define(:delete)
|
20
|
-
end
|
21
|
-
|
22
|
-
result = users.try { users.delete.call }
|
23
|
-
|
24
|
-
expect(result).to match_array([
|
25
|
-
{ name: 'Jane', email: 'jane@doe.org' },
|
26
|
-
{ name: 'Joe', email: 'joe@doe.org' }
|
27
|
-
])
|
28
|
-
|
29
|
-
expect(container.relation(:users)).to match_array([])
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'deletes tuples matching restriction' do
|
33
|
-
configuration.commands(:users) do
|
34
|
-
define(:delete)
|
35
|
-
end
|
36
|
-
|
37
|
-
result = users.try { users.delete.by_name('Joe').call }
|
38
|
-
|
39
|
-
expect(result).to match_array([{ name: 'Joe', email: 'joe@doe.org' }])
|
40
|
-
|
41
|
-
expect(container.relation(:users)).to match_array([
|
42
|
-
{ name: 'Jane', email: 'jane@doe.org' }
|
43
|
-
])
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'returns untouched relation if there are no tuples to delete' do
|
47
|
-
configuration.commands(:users) do
|
48
|
-
define(:delete)
|
49
|
-
end
|
50
|
-
|
51
|
-
result = users.try { users.delete.by_name('Not here').call }
|
52
|
-
|
53
|
-
expect(result).to match_array([])
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'returns deleted tuple when result is set to :one' do
|
57
|
-
configuration.commands(:users) do
|
58
|
-
define(:delete_one, type: :delete) do
|
59
|
-
result :one
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
result = users.try { users.delete_one.by_name('Jane').call }
|
64
|
-
|
65
|
-
expect(result.value).to eql(name: 'Jane', email: 'jane@doe.org')
|
66
|
-
end
|
67
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe 'Commands / Error handling' do
|
4
|
-
include_context 'container'
|
5
|
-
include_context 'users and tasks'
|
6
|
-
|
7
|
-
before do
|
8
|
-
configuration.relation(:users)
|
9
|
-
configuration.commands(:users) { define(:create) }
|
10
|
-
end
|
11
|
-
|
12
|
-
subject(:users) { container.commands.users }
|
13
|
-
|
14
|
-
it 'rescues from ROM::CommandError' do
|
15
|
-
result = false
|
16
|
-
expect(users.try { raise ROM::CommandError } >-> _test { result = true })
|
17
|
-
.to be_instance_of(ROM::Commands::Result::Failure)
|
18
|
-
expect(result).to be(false)
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'raises other errors' do
|
22
|
-
expect { users.try { raise ArgumentError, 'test' } }
|
23
|
-
.to raise_error(ArgumentError, 'test')
|
24
|
-
end
|
25
|
-
end
|
@@ -1,213 +0,0 @@
|
|
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::CommandRegistry::CommandNotFoundError, /not_here/)
|
212
|
-
end
|
213
|
-
end
|