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,343 +0,0 @@
|
|
1
|
-
require 'rom/command'
|
2
|
-
require 'rom/memory'
|
3
|
-
|
4
|
-
RSpec.describe ROM::Commands::Create[:memory], 'before/after hooks' do
|
5
|
-
let(:relation) do
|
6
|
-
spy(:relation)
|
7
|
-
end
|
8
|
-
|
9
|
-
describe '#before' do
|
10
|
-
subject(:command) do
|
11
|
-
Class.new(ROM::Commands::Create[:memory]) do
|
12
|
-
before :init
|
13
|
-
before :normalize
|
14
|
-
|
15
|
-
def init(*)
|
16
|
-
end
|
17
|
-
|
18
|
-
def normalize(*)
|
19
|
-
end
|
20
|
-
|
21
|
-
def prepare(*)
|
22
|
-
end
|
23
|
-
end.build(relation)
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'returns a new command with configured before hooks' do
|
27
|
-
expect(command.before(:prepare).before_hooks).to eql(%i[init normalize prepare])
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe '#after' do
|
32
|
-
subject(:command) do
|
33
|
-
Class.new(ROM::Commands::Create[:memory]) do
|
34
|
-
after :finalize
|
35
|
-
after :filter
|
36
|
-
|
37
|
-
def finalize(*)
|
38
|
-
end
|
39
|
-
|
40
|
-
def filter(*)
|
41
|
-
end
|
42
|
-
|
43
|
-
def prepare(*)
|
44
|
-
end
|
45
|
-
end.build(relation)
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'returns a new command with configured after hooks' do
|
49
|
-
expect(command.after(:prepare).after_hooks).to eql(%i[finalize filter prepare])
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'worker with before' do
|
53
|
-
with_before_and_after = command.before(:filter).after(:finalize)
|
54
|
-
|
55
|
-
expect(with_before_and_after.before_hooks).to eql(%i[filter])
|
56
|
-
expect(with_before_and_after.after_hooks).to eql(%i[finalize filter finalize])
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'without curried args' do
|
61
|
-
subject(:command) do
|
62
|
-
Class.new(ROM::Commands::Create[:memory]) do
|
63
|
-
result :many
|
64
|
-
before :prepare
|
65
|
-
after :finalize
|
66
|
-
|
67
|
-
def execute(tuples)
|
68
|
-
input = tuples.map.with_index { |tuple, idx| tuple.merge(id: idx + 1) }
|
69
|
-
relation.insert(input)
|
70
|
-
input
|
71
|
-
end
|
72
|
-
|
73
|
-
def prepare(tuples)
|
74
|
-
tuples.map { |tuple| tuple.merge(prepared: true) }
|
75
|
-
end
|
76
|
-
|
77
|
-
def finalize(tuples)
|
78
|
-
tuples.map { |tuple| tuple.merge(finalized: true) }
|
79
|
-
end
|
80
|
-
end.build(relation)
|
81
|
-
end
|
82
|
-
|
83
|
-
let(:tuples) do
|
84
|
-
[{ name: 'Jane' }, { name: 'Joe' }]
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'applies before/after hooks' do
|
88
|
-
insert_tuples = [
|
89
|
-
{ id: 1, name: 'Jane', prepared: true },
|
90
|
-
{ id: 2, name: 'Joe', prepared: true }
|
91
|
-
]
|
92
|
-
|
93
|
-
result = [
|
94
|
-
{ id: 1, name: 'Jane', prepared: true, finalized: true },
|
95
|
-
{ id: 2, name: 'Joe', prepared: true, finalized: true }
|
96
|
-
]
|
97
|
-
|
98
|
-
expect(command.call(tuples)).to eql(result)
|
99
|
-
|
100
|
-
expect(relation).to have_received(:insert).with(insert_tuples)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context 'with one curried arg' do
|
105
|
-
subject(:command) do
|
106
|
-
Class.new(ROM::Commands::Create[:memory]) do
|
107
|
-
result :many
|
108
|
-
before :prepare
|
109
|
-
after :finalize
|
110
|
-
|
111
|
-
def execute(tuples)
|
112
|
-
input = tuples.map.with_index { |tuple, idx| tuple.merge(id: idx + 1) }
|
113
|
-
relation.insert(input)
|
114
|
-
input
|
115
|
-
end
|
116
|
-
|
117
|
-
def prepare(tuples, name)
|
118
|
-
tuples.map.with_index { |tuple, idx| tuple.merge(name: "#{name} #{idx + 1}") }
|
119
|
-
end
|
120
|
-
|
121
|
-
def finalize(tuples, *)
|
122
|
-
tuples.map { |tuple| tuple.merge(finalized: true) }
|
123
|
-
end
|
124
|
-
end.build(relation)
|
125
|
-
end
|
126
|
-
|
127
|
-
let(:tuples) do
|
128
|
-
[{ email: 'user-1@test.com' }, { email: 'user-2@test.com' }]
|
129
|
-
end
|
130
|
-
|
131
|
-
let(:relation) do
|
132
|
-
spy(:relation)
|
133
|
-
end
|
134
|
-
|
135
|
-
it 'applies before/after hooks' do
|
136
|
-
insert_tuples = [
|
137
|
-
{ id: 1, email: 'user-1@test.com', name: 'User 1' },
|
138
|
-
{ id: 2, email: 'user-2@test.com', name: 'User 2' }
|
139
|
-
]
|
140
|
-
|
141
|
-
result = [
|
142
|
-
{ id: 1, email: 'user-1@test.com', name: 'User 1', finalized: true },
|
143
|
-
{ id: 2, email: 'user-2@test.com', name: 'User 2', finalized: true }
|
144
|
-
]
|
145
|
-
|
146
|
-
expect(command.with(tuples).call('User')).to eql(result)
|
147
|
-
|
148
|
-
expect(relation).to have_received(:insert).with(insert_tuples)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
context 'with 2 curried args' do
|
153
|
-
subject(:command) do
|
154
|
-
Class.new(ROM::Commands::Create[:memory]) do
|
155
|
-
result :many
|
156
|
-
before :prepare
|
157
|
-
after :finalize
|
158
|
-
|
159
|
-
def execute(tuples)
|
160
|
-
input = tuples.map.with_index { |tuple, idx| tuple.merge(id: idx + 1) }
|
161
|
-
relation.insert(input)
|
162
|
-
input
|
163
|
-
end
|
164
|
-
|
165
|
-
def prepare(tuples, name)
|
166
|
-
tuples.map.with_index { |tuple, idx| tuple.merge(name: "#{name} #{idx + 1}") }
|
167
|
-
end
|
168
|
-
|
169
|
-
def finalize(tuples, *)
|
170
|
-
tuples.map { |tuple| tuple.merge(finalized: true) }
|
171
|
-
end
|
172
|
-
end.build(relation)
|
173
|
-
end
|
174
|
-
|
175
|
-
let(:tuples) do
|
176
|
-
[{ email: 'user-1@test.com' }, { email: 'user-2@test.com' }]
|
177
|
-
end
|
178
|
-
|
179
|
-
let(:relation) do
|
180
|
-
spy(:relation)
|
181
|
-
end
|
182
|
-
|
183
|
-
it 'applies before/after hooks' do
|
184
|
-
insert_tuples = [
|
185
|
-
{ id: 1, email: 'user-1@test.com', name: 'User 1' },
|
186
|
-
{ id: 2, email: 'user-2@test.com', name: 'User 2' }
|
187
|
-
]
|
188
|
-
|
189
|
-
result = [
|
190
|
-
{ id: 1, email: 'user-1@test.com', name: 'User 1', finalized: true },
|
191
|
-
{ id: 2, email: 'user-2@test.com', name: 'User 2', finalized: true }
|
192
|
-
]
|
193
|
-
|
194
|
-
expect(command.with(tuples, 'User').call).to eql(result)
|
195
|
-
|
196
|
-
expect(relation).to have_received(:insert).with(insert_tuples)
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
context 'with pre-set opts' do
|
201
|
-
subject(:command) do
|
202
|
-
Class.new(ROM::Commands::Create[:memory]) do
|
203
|
-
result :many
|
204
|
-
before prepare: { prepared: true }
|
205
|
-
after finalize: { finalized: true }
|
206
|
-
|
207
|
-
def execute(tuples)
|
208
|
-
input = tuples.map.with_index { |tuple, idx| tuple.merge(id: idx + 1) }
|
209
|
-
relation.insert(input)
|
210
|
-
input
|
211
|
-
end
|
212
|
-
|
213
|
-
def prepare(tuples, opts)
|
214
|
-
tuples.map { |tuple| tuple.merge(opts) }
|
215
|
-
end
|
216
|
-
|
217
|
-
def finalize(tuples, opts)
|
218
|
-
tuples.map { |tuple| tuple.merge(opts) }
|
219
|
-
end
|
220
|
-
end.build(relation)
|
221
|
-
end
|
222
|
-
|
223
|
-
let(:tuples) do
|
224
|
-
[{ name: 'Jane' }, { name: 'Joe' }]
|
225
|
-
end
|
226
|
-
|
227
|
-
let(:relation) do
|
228
|
-
spy(:relation)
|
229
|
-
end
|
230
|
-
|
231
|
-
it 'applies before/after hooks' do
|
232
|
-
insert_tuples = [
|
233
|
-
{ id: 1, name: 'Jane', prepared: true },
|
234
|
-
{ id: 2, name: 'Joe', prepared: true }
|
235
|
-
]
|
236
|
-
|
237
|
-
result = [
|
238
|
-
{ id: 1, name: 'Jane', prepared: true, finalized: true },
|
239
|
-
{ id: 2, name: 'Joe', prepared: true, finalized: true }
|
240
|
-
]
|
241
|
-
|
242
|
-
expect(command.call(tuples)).to eql(result)
|
243
|
-
|
244
|
-
expect(relation).to have_received(:insert).with(insert_tuples)
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
context 'with pre-set opts for a curried command' do
|
249
|
-
subject(:command) do
|
250
|
-
Class.new(ROM::Commands::Create[:memory]) do
|
251
|
-
result :many
|
252
|
-
before prepare: { prepared: true }
|
253
|
-
after finalize: { finalized: true }
|
254
|
-
|
255
|
-
def execute(tuples)
|
256
|
-
input = tuples.map.with_index { |tuple, idx| tuple.merge(id: idx + 1) }
|
257
|
-
relation.insert(input)
|
258
|
-
input
|
259
|
-
end
|
260
|
-
|
261
|
-
def prepare(tuples, parent, opts)
|
262
|
-
tuples.map { |tuple| tuple.merge(opts).merge(parent_size: parent.size) }
|
263
|
-
end
|
264
|
-
|
265
|
-
def finalize(tuples, parent, opts)
|
266
|
-
tuples.map { |tuple| tuple.merge(opts).merge(user_id: parent[:id]) }
|
267
|
-
end
|
268
|
-
end.build(relation)
|
269
|
-
end
|
270
|
-
|
271
|
-
let(:tuples) do
|
272
|
-
[{ name: 'Jane' }, { name: 'Joe' }]
|
273
|
-
end
|
274
|
-
|
275
|
-
let(:relation) do
|
276
|
-
spy(:relation)
|
277
|
-
end
|
278
|
-
|
279
|
-
it 'applies before/after hooks' do
|
280
|
-
insert_tuples = [
|
281
|
-
{ id: 1, name: 'Jane', parent_size: 1, prepared: true },
|
282
|
-
{ id: 2, name: 'Joe', parent_size: 1, prepared: true }
|
283
|
-
]
|
284
|
-
|
285
|
-
result = [
|
286
|
-
{ id: 1, name: 'Jane', parent_size: 1, user_id: 1, prepared: true, finalized: true },
|
287
|
-
{ id: 2, name: 'Joe', parent_size: 1, user_id: 1, prepared: true, finalized: true }
|
288
|
-
]
|
289
|
-
|
290
|
-
expect(command.with(tuples).call(id: 1)).to eql(result)
|
291
|
-
|
292
|
-
expect(relation).to have_received(:insert).with(insert_tuples)
|
293
|
-
end
|
294
|
-
end
|
295
|
-
|
296
|
-
context 'calling with multiple args' do
|
297
|
-
subject(:command) do
|
298
|
-
Class.new(ROM::Commands::Create[:memory]) do
|
299
|
-
result :many
|
300
|
-
before prepare: { prepared: true }
|
301
|
-
after finalize: { finalized: true }
|
302
|
-
|
303
|
-
def execute(tuples)
|
304
|
-
input = tuples.map.with_index { |tuple, idx| tuple.merge(id: idx + 1) }
|
305
|
-
relation.insert(input)
|
306
|
-
input
|
307
|
-
end
|
308
|
-
|
309
|
-
def prepare(tuples, parent, opts)
|
310
|
-
tuples.map { |tuple| tuple.merge(opts).merge(parent_size: parent.size) }
|
311
|
-
end
|
312
|
-
|
313
|
-
def finalize(tuples, parent, opts)
|
314
|
-
tuples.map { |tuple| tuple.merge(opts).merge(user_id: parent[:id]) }
|
315
|
-
end
|
316
|
-
end.build(relation)
|
317
|
-
end
|
318
|
-
|
319
|
-
let(:tuples) do
|
320
|
-
[{ name: 'Jane' }, { name: 'Joe' }]
|
321
|
-
end
|
322
|
-
|
323
|
-
let(:relation) do
|
324
|
-
spy(:relation)
|
325
|
-
end
|
326
|
-
|
327
|
-
it 'applies before/after hooks' do
|
328
|
-
insert_tuples = [
|
329
|
-
{ id: 1, name: 'Jane', parent_size: 1, prepared: true },
|
330
|
-
{ id: 2, name: 'Joe', parent_size: 1, prepared: true }
|
331
|
-
]
|
332
|
-
|
333
|
-
result = [
|
334
|
-
{ id: 1, name: 'Jane', parent_size: 1, user_id: 1, prepared: true, finalized: true },
|
335
|
-
{ id: 2, name: 'Joe', parent_size: 1, user_id: 1, prepared: true, finalized: true }
|
336
|
-
]
|
337
|
-
|
338
|
-
expect(command.call(tuples, id: 1)).to eql(result)
|
339
|
-
|
340
|
-
expect(relation).to have_received(:insert).with(insert_tuples)
|
341
|
-
end
|
342
|
-
end
|
343
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.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
|
@@ -1,188 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe 'Commands' do
|
4
|
-
include_context 'gateway only'
|
5
|
-
include_context 'users and tasks'
|
6
|
-
|
7
|
-
let(:users_relation) do
|
8
|
-
Class.new(ROM::Memory::Relation) do
|
9
|
-
def by_id(id)
|
10
|
-
restrict(id: id)
|
11
|
-
end
|
12
|
-
end.new(users_dataset)
|
13
|
-
end
|
14
|
-
|
15
|
-
describe '.build_class' do
|
16
|
-
it 'creates a command class constant' do
|
17
|
-
klass = ROM::ConfigurationDSL::Command.build_class(:create, :users, adapter: :memory) {
|
18
|
-
def super?
|
19
|
-
true
|
20
|
-
end
|
21
|
-
}
|
22
|
-
|
23
|
-
expect(klass.name).to eql('ROM::Memory::Commands::Create[Users]')
|
24
|
-
expect(klass.register_as).to eql(:create)
|
25
|
-
|
26
|
-
command = klass.build(users_relation)
|
27
|
-
|
28
|
-
expect(command).to be_a(ROM::Memory::Commands::Create)
|
29
|
-
expect(command).to be_super
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '.create_class' do
|
34
|
-
it 'builds a class' do
|
35
|
-
klass = ROM::Command.create_class(:create, ROM::Memory::Commands::Create)
|
36
|
-
|
37
|
-
expect(klass.name).to eql('ROM::Memory::Commands::Create[:create]')
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'builds a class and yields it' do
|
41
|
-
klass = ROM::Command.create_class(:create, ROM::Memory::Commands::Create) do |k|
|
42
|
-
k.result :one
|
43
|
-
k
|
44
|
-
end
|
45
|
-
|
46
|
-
expect(klass.name).to eql('ROM::Memory::Commands::Create[:create]')
|
47
|
-
expect(klass.result).to be(:one)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe '.build' do
|
52
|
-
it 'returns create command when type is set to :create' do
|
53
|
-
klass = Class.new(ROM::Commands::Create[:memory]) do
|
54
|
-
relation :users
|
55
|
-
end
|
56
|
-
|
57
|
-
command = klass.build(users_relation)
|
58
|
-
|
59
|
-
expect(command).to be_kind_of(ROM::Memory::Commands::Create)
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'returns update command when type is set to :update' do
|
63
|
-
klass = Class.new(ROM::Commands::Update[:memory]) do
|
64
|
-
relation :users
|
65
|
-
end
|
66
|
-
|
67
|
-
command = klass.build(users_relation)
|
68
|
-
|
69
|
-
expect(command).to be_kind_of(ROM::Memory::Commands::Update)
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'returns delete command when type is set to :delete' do
|
73
|
-
klass = Class.new(ROM::Commands::Delete[:memory]) do
|
74
|
-
relation :users
|
75
|
-
end
|
76
|
-
|
77
|
-
command = klass.build(users_relation)
|
78
|
-
|
79
|
-
expect(command).to be_kind_of(ROM::Memory::Commands::Delete)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
describe '#>>' do
|
84
|
-
let(:users) { double('users', schema: nil) }
|
85
|
-
let(:tasks) { double('tasks', schema: nil) }
|
86
|
-
let(:logs) { double('logs', schema: nil) }
|
87
|
-
|
88
|
-
it 'composes two commands' do
|
89
|
-
user_input = { name: 'Jane' }
|
90
|
-
user_tuple = { user_id: 1, name: 'Jane' }
|
91
|
-
|
92
|
-
task_input = { title: 'Task One' }
|
93
|
-
task_tuple = { user_id: 1, title: 'Task One' }
|
94
|
-
|
95
|
-
create_user = Class.new(ROM::Commands::Create) {
|
96
|
-
def execute(user_input)
|
97
|
-
relation.insert(user_input)
|
98
|
-
end
|
99
|
-
}.build(users)
|
100
|
-
|
101
|
-
create_task = Class.new(ROM::Commands::Create) {
|
102
|
-
before :associate
|
103
|
-
|
104
|
-
def associate(task_input, user_tuple)
|
105
|
-
task_input.merge(user_id: user_tuple[:user_id])
|
106
|
-
end
|
107
|
-
|
108
|
-
def execute(task_input)
|
109
|
-
relation.insert(task_input)
|
110
|
-
end
|
111
|
-
}.build(tasks)
|
112
|
-
|
113
|
-
create_log = Class.new(ROM::Commands::Create) {
|
114
|
-
result :one
|
115
|
-
|
116
|
-
def execute(task_tuple)
|
117
|
-
relation << task_tuple
|
118
|
-
end
|
119
|
-
}.build(logs)
|
120
|
-
|
121
|
-
command = create_user.curry(user_input)
|
122
|
-
command >>= create_task.curry(task_input)
|
123
|
-
command >>= create_log
|
124
|
-
|
125
|
-
expect(users).to receive(:insert).with(user_input).and_return(user_tuple)
|
126
|
-
expect(tasks).to receive(:insert).with(task_tuple).and_return(task_tuple)
|
127
|
-
expect(logs).to receive(:<<).with(task_tuple).and_return([task_tuple])
|
128
|
-
|
129
|
-
expect(command.call).to eql(task_tuple)
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'forwards methods to the left' do
|
133
|
-
user_input = { name: 'Jane' }
|
134
|
-
user_tuple = { user_id: 1, name: 'Jane' }
|
135
|
-
|
136
|
-
create_user = Class.new(ROM::Commands::Create) {
|
137
|
-
def execute(user_input)
|
138
|
-
relation.insert(user_input)
|
139
|
-
end
|
140
|
-
}.build(users)
|
141
|
-
|
142
|
-
command = create_user >> proc {}
|
143
|
-
|
144
|
-
expect(users).to receive(:insert).with(user_input).and_return(user_tuple)
|
145
|
-
|
146
|
-
command.with(user_input).call
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'short-circuits pipeline when left-side result is empty' do
|
150
|
-
command = Class.new(ROM::Commands::Update) do
|
151
|
-
result :one
|
152
|
-
|
153
|
-
def execute(*)
|
154
|
-
[]
|
155
|
-
end
|
156
|
-
end.build(users) >> -> result { result.map(&:to_a) }
|
157
|
-
|
158
|
-
expect(command.call('foo')).to be(nil)
|
159
|
-
|
160
|
-
command = Class.new(ROM::Commands::Update) do
|
161
|
-
result :many
|
162
|
-
|
163
|
-
def execute(*)
|
164
|
-
[]
|
165
|
-
end
|
166
|
-
end.build(users) >> -> result { result.map(&:to_a) }
|
167
|
-
|
168
|
-
expect(command.call('foo')).to be(ROM::EMPTY_ARRAY)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
describe '#with_opts' do
|
173
|
-
subject(:command) do
|
174
|
-
Class.new(ROM::Command::Create).build(relation, options)
|
175
|
-
end
|
176
|
-
|
177
|
-
let(:relation) { double(:relation) }
|
178
|
-
let(:options) { { result: :one } }
|
179
|
-
|
180
|
-
it 'returns a new command with updated options' do
|
181
|
-
new_command = command.with_opts(before: :test)
|
182
|
-
|
183
|
-
expect(new_command.relation).to be(relation)
|
184
|
-
expect(new_command.result).to be(:one)
|
185
|
-
expect(new_command.before_hooks).to eql([:test])
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe ROM::Configurable do
|
4
|
-
let (:klass) { Class.new { include ROM::Configurable } }
|
5
|
-
let (:object) { klass.new }
|
6
|
-
let (:config) { object.config }
|
7
|
-
|
8
|
-
it 'exposes the config property' do
|
9
|
-
expect { config }.not_to raise_error
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'is configurable via block' do
|
13
|
-
object.configure do |config|
|
14
|
-
config.sql.infer_relations = false
|
15
|
-
end
|
16
|
-
|
17
|
-
expect(config.sql.infer_relations).to be(false)
|
18
|
-
end
|
19
|
-
|
20
|
-
context ROM::Configurable::Config do
|
21
|
-
it 'can be traversed via dot syntax' do
|
22
|
-
config.sql.infer_relations = false
|
23
|
-
expect(config.sql.infer_relations).to be(false)
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'can be traversed via bracket syntax' do
|
27
|
-
config[:sql].infer_relations = false
|
28
|
-
|
29
|
-
expect(config[:sql][:infer_relations]).to be(false)
|
30
|
-
expect(config).to respond_to(:sql)
|
31
|
-
expect(config.sql.infer_relations).to be(false)
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'freezes properly' do
|
35
|
-
config.freeze
|
36
|
-
|
37
|
-
expect { config.sql.infer_relations = false }.to raise_error(NoMethodError)
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'handles unset keys when frozen' do
|
41
|
-
config.sql.infer_relations = false
|
42
|
-
config.freeze
|
43
|
-
|
44
|
-
expect(config.other).to be(nil)
|
45
|
-
expect(config.key?(:other)).to be(false)
|
46
|
-
expect(config.key?(:sql)).to be(true)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe ROM::Configuration do
|
4
|
-
it 'is configurable via settings hash' do
|
5
|
-
configuration = ROM::Configuration.new(:memory, 'something', infer_schema: false)
|
6
|
-
|
7
|
-
expect(configuration.config.gateways.default.infer_schema).to be(false)
|
8
|
-
|
9
|
-
configuration = ROM::Configuration.new(:memory, infer_schema: false)
|
10
|
-
|
11
|
-
expect(configuration.config.gateways.default.infer_schema).to be(false)
|
12
|
-
|
13
|
-
configuration = ROM::Configuration.new(default: [:memory, infer_schema: false])
|
14
|
-
|
15
|
-
expect(configuration.config.gateways.default.infer_schema).to be(false)
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '#method_missing' do
|
19
|
-
it 'returns a gateway if it is defined' do
|
20
|
-
repo = double('repo')
|
21
|
-
configuration = ROM::Configuration.new(repo: repo)
|
22
|
-
|
23
|
-
expect(configuration.repo).to be(repo)
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'raises error if repo is not defined' do
|
27
|
-
configuration = ROM::Configuration.new
|
28
|
-
|
29
|
-
expect { configuration.not_here }.to raise_error(NoMethodError, /not_here/)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '#[]' do
|
34
|
-
it 'returns a gateway if it is defined' do
|
35
|
-
repo = double('repo')
|
36
|
-
configuration = ROM::Configuration.new(repo: repo)
|
37
|
-
|
38
|
-
expect(configuration[:repo]).to be(repo)
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'raises error if repo is not defined' do
|
42
|
-
configuration = ROM::Configuration.new({})
|
43
|
-
|
44
|
-
expect { configuration[:not_here] }.to raise_error(KeyError, /not_here/)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe 'defining components when adapter was not registered' do
|
49
|
-
it 'raises error when trying to define a relation' do
|
50
|
-
expect {
|
51
|
-
Class.new(ROM::Relation[:not_here])
|
52
|
-
}.to raise_error(ROM::AdapterNotPresentError, /not_here/)
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'raises error when trying to define a command' do
|
56
|
-
expect {
|
57
|
-
Class.new(ROM::Commands::Create[:not_here])
|
58
|
-
}.to raise_error(ROM::AdapterNotPresentError, /not_here/)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|