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,93 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe 'Mapper definition DSL' do
|
4
|
-
include_context 'container'
|
5
|
-
include_context 'users and tasks'
|
6
|
-
|
7
|
-
let(:header) { mapper.header }
|
8
|
-
|
9
|
-
describe 'unwrapping relation mapper' do
|
10
|
-
before do
|
11
|
-
configuration.relation(:tasks) do
|
12
|
-
def with_user
|
13
|
-
tuples = map { |tuple|
|
14
|
-
tuple.merge(user: users.restrict(name: tuple[:name]).first)
|
15
|
-
}
|
16
|
-
|
17
|
-
new(tuples)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
configuration.relation(:users)
|
22
|
-
|
23
|
-
configuration.mappers do
|
24
|
-
define(:tasks) do
|
25
|
-
model name: 'Test::Task'
|
26
|
-
|
27
|
-
attribute :title
|
28
|
-
attribute :priority
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'unwraps nested attributes via options hash' do
|
34
|
-
configuration.mappers do
|
35
|
-
define(:with_user, parent: :tasks) do
|
36
|
-
attribute :title
|
37
|
-
attribute :priority
|
38
|
-
|
39
|
-
unwrap user: [:email, :name]
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
result = container.relation(:tasks).with_user.as(:with_user).to_a.last
|
44
|
-
|
45
|
-
expect(result).to eql(title: 'be cool',
|
46
|
-
priority: 2,
|
47
|
-
name: 'Jane',
|
48
|
-
email: 'jane@doe.org')
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'unwraps nested attributes via options block' do
|
52
|
-
configuration.mappers do
|
53
|
-
define(:with_user, parent: :tasks) do
|
54
|
-
attribute :title
|
55
|
-
attribute :priority
|
56
|
-
|
57
|
-
unwrap :user do
|
58
|
-
attribute :name
|
59
|
-
attribute :user_email, from: :email
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
result = container.relation(:tasks).with_user.as(:with_user).to_a.last
|
65
|
-
|
66
|
-
expect(result).to eql(title: 'be cool',
|
67
|
-
priority: 2,
|
68
|
-
name: 'Jane',
|
69
|
-
user_email: 'jane@doe.org')
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'unwraps specified attributes via options block' do
|
73
|
-
configuration.mappers do
|
74
|
-
define(:with_user, parent: :tasks) do
|
75
|
-
attribute :title
|
76
|
-
attribute :priority
|
77
|
-
|
78
|
-
unwrap :contact, from: :user do
|
79
|
-
attribute :task_user_name, from: :name
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
result = container.relation(:tasks).with_user.as(:with_user).to_a.last
|
85
|
-
|
86
|
-
expect(result).to eql(title: 'be cool',
|
87
|
-
priority: 2,
|
88
|
-
name: 'Jane',
|
89
|
-
task_user_name: 'Jane',
|
90
|
-
contact: { email: 'jane@doe.org' })
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
@@ -1,155 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe 'Mapper definition DSL' do
|
4
|
-
include_context 'container'
|
5
|
-
include_context 'users and tasks'
|
6
|
-
|
7
|
-
let(:header) { mapper.header }
|
8
|
-
|
9
|
-
describe 'wrapped relation mapper' do
|
10
|
-
before do
|
11
|
-
configuration.relation(:tasks) do
|
12
|
-
def with_user
|
13
|
-
join(users)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
configuration.relation(:users)
|
18
|
-
|
19
|
-
configuration.mappers do
|
20
|
-
define(:tasks) do
|
21
|
-
model name: 'Test::Task'
|
22
|
-
|
23
|
-
attribute :title
|
24
|
-
attribute :priority
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'allows defining wrapped attributes via options hash' do
|
30
|
-
configuration.mappers do
|
31
|
-
define(:with_user, parent: :tasks) do
|
32
|
-
model name: 'Test::TaskWithUser'
|
33
|
-
|
34
|
-
attribute :title
|
35
|
-
attribute :priority
|
36
|
-
|
37
|
-
wrap user: [:email]
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
container
|
42
|
-
|
43
|
-
Test::TaskWithUser.send(:include, Dry::Equalizer(:title, :priority, :user))
|
44
|
-
|
45
|
-
jane = container.relation(:tasks).with_user.as(:with_user).to_a.last
|
46
|
-
|
47
|
-
expect(jane).to eql(
|
48
|
-
Test::TaskWithUser.new(
|
49
|
-
title: 'be cool',
|
50
|
-
priority: 2,
|
51
|
-
user: { email: 'jane@doe.org' }
|
52
|
-
)
|
53
|
-
)
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'allows defining wrapped attributes via options block' do
|
57
|
-
configuration.mappers do
|
58
|
-
define(:with_user, parent: :tasks) do
|
59
|
-
model name: 'Test::TaskWithUser'
|
60
|
-
|
61
|
-
attribute :title
|
62
|
-
attribute :priority
|
63
|
-
|
64
|
-
wrap :user do
|
65
|
-
attribute :email
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
container
|
71
|
-
|
72
|
-
Test::TaskWithUser.send(:include, Dry::Equalizer(:title, :priority, :user))
|
73
|
-
|
74
|
-
jane = container.relation(:tasks).with_user.as(:with_user).to_a.last
|
75
|
-
|
76
|
-
expect(jane).to eql(
|
77
|
-
Test::TaskWithUser.new(
|
78
|
-
title: 'be cool',
|
79
|
-
priority: 2,
|
80
|
-
user: { email: 'jane@doe.org' }
|
81
|
-
)
|
82
|
-
)
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'allows defining nested wrapped attributes via a block' do
|
86
|
-
configuration.mappers do
|
87
|
-
define(:with_user, parent: :tasks, inherit_header: false) do
|
88
|
-
model name: 'Test::TaskWithUser'
|
89
|
-
|
90
|
-
attribute :title
|
91
|
-
attribute :priority
|
92
|
-
|
93
|
-
wrap :user do
|
94
|
-
model name: 'Test::TaskUser'
|
95
|
-
attribute :name
|
96
|
-
|
97
|
-
wrap :contact do
|
98
|
-
model name: 'Test::Contact'
|
99
|
-
attribute :email
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
container
|
106
|
-
|
107
|
-
Test::TaskWithUser.send(:include, Dry::Equalizer(:title, :priority, :user))
|
108
|
-
Test::TaskUser.send(:include, Dry::Equalizer(:name, :contact))
|
109
|
-
Test::Contact.send(:include, Dry::Equalizer(:email))
|
110
|
-
|
111
|
-
jane = container.relation(:tasks).with_user.as(:with_user).to_a.last
|
112
|
-
|
113
|
-
expect(jane).to eql(
|
114
|
-
Test::TaskWithUser.new(
|
115
|
-
title: 'be cool',
|
116
|
-
priority: 2,
|
117
|
-
user: Test::TaskUser.new(
|
118
|
-
name: 'Jane', contact: Test::Contact.new(email: 'jane@doe.org')
|
119
|
-
)
|
120
|
-
)
|
121
|
-
)
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'allows defining wrapped attributes mapped to a model' do
|
125
|
-
configuration.mappers do
|
126
|
-
define(:with_user, parent: :tasks) do
|
127
|
-
model name: 'Test::TaskWithUser'
|
128
|
-
|
129
|
-
attribute :title
|
130
|
-
attribute :priority
|
131
|
-
|
132
|
-
wrap :user do
|
133
|
-
model name: 'Test::User'
|
134
|
-
attribute :email
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
container
|
140
|
-
|
141
|
-
Test::TaskWithUser.send(:include, Dry::Equalizer(:title, :priority, :user))
|
142
|
-
Test::User.send(:include, Dry::Equalizer(:email))
|
143
|
-
|
144
|
-
jane = container.relation(:tasks).with_user.as(:with_user).to_a.last
|
145
|
-
|
146
|
-
expect(jane).to eql(
|
147
|
-
Test::TaskWithUser.new(
|
148
|
-
title: 'be cool',
|
149
|
-
priority: 2,
|
150
|
-
user: Test::User.new(email: 'jane@doe.org')
|
151
|
-
)
|
152
|
-
)
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'rom/memory'
|
4
|
-
|
5
|
-
RSpec.describe ROM::Memory::Commands::Create do
|
6
|
-
include_context 'container'
|
7
|
-
include_context 'users and tasks'
|
8
|
-
|
9
|
-
before do
|
10
|
-
configuration.relation(:users) do
|
11
|
-
def by_id(id)
|
12
|
-
restrict(id: id)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
configuration.commands(:users) do
|
16
|
-
define(:create)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
subject(:command) { container.command(:users).create }
|
21
|
-
|
22
|
-
it_behaves_like 'a command'
|
23
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'rom/memory'
|
4
|
-
|
5
|
-
RSpec.describe ROM::Memory::Commands::Delete do
|
6
|
-
include_context 'container'
|
7
|
-
include_context 'users and tasks'
|
8
|
-
|
9
|
-
before do
|
10
|
-
configuration.relation(:users) do
|
11
|
-
def by_id(id)
|
12
|
-
restrict(id: id)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
configuration.commands(:users) do
|
16
|
-
define(:delete)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
subject(:command) { container.command(:users).delete }
|
21
|
-
|
22
|
-
it_behaves_like 'a command'
|
23
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'rom/memory'
|
4
|
-
|
5
|
-
RSpec.describe ROM::Memory::Commands::Update do
|
6
|
-
include_context 'container'
|
7
|
-
include_context 'users and tasks'
|
8
|
-
|
9
|
-
before do
|
10
|
-
configuration.relation(:users) do
|
11
|
-
def by_id(id)
|
12
|
-
restrict(id: id)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
configuration.commands(:users) do
|
16
|
-
define(:update)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
subject(:command) { container.command(:users).update }
|
21
|
-
|
22
|
-
it_behaves_like 'a command'
|
23
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rom/memory'
|
3
|
-
|
4
|
-
RSpec.describe 'Setting up ROM with multiple environments' do
|
5
|
-
let(:configuration) do
|
6
|
-
{
|
7
|
-
one: ROM::Configuration.new(:memory),
|
8
|
-
two: ROM::Configuration.new(:memory)
|
9
|
-
}
|
10
|
-
end
|
11
|
-
|
12
|
-
let(:container) do
|
13
|
-
{
|
14
|
-
one: ROM.container(configuration[:one]),
|
15
|
-
two: ROM.container(configuration[:two]),
|
16
|
-
}
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'without :auto_registration plugin' do
|
20
|
-
before do
|
21
|
-
module Test
|
22
|
-
class Users < ROM::Relation[:memory]
|
23
|
-
dataset :users
|
24
|
-
end
|
25
|
-
|
26
|
-
class CreateUser < ROM::Commands::Create[:memory]
|
27
|
-
register_as :create
|
28
|
-
relation :users
|
29
|
-
result :one
|
30
|
-
end
|
31
|
-
|
32
|
-
class UserMapper < ROM::Mapper
|
33
|
-
relation :users
|
34
|
-
register_as :entity
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'registers items independently of other environments' do
|
40
|
-
configuration[:one].register_relation(Test::Users)
|
41
|
-
configuration[:one].register_command(Test::CreateUser)
|
42
|
-
configuration[:one].register_mapper(Test::UserMapper)
|
43
|
-
|
44
|
-
expect(container[:one].relations[:users]).to be_kind_of Test::Users
|
45
|
-
expect(container[:one].commands[:users].create).to be_kind_of Test::CreateUser
|
46
|
-
expect(container[:one].mappers[:users].entity).to be_kind_of Test::UserMapper
|
47
|
-
|
48
|
-
expect { container[:two].relations[:users] }.to raise_error(
|
49
|
-
ROM::Registry::ElementNotFoundError
|
50
|
-
)
|
51
|
-
expect { container[:two].commands[:users].create }.to raise_error(
|
52
|
-
ROM::Registry::ElementNotFoundError
|
53
|
-
)
|
54
|
-
expect { container[:two].commands[:users].create }.to raise_error(
|
55
|
-
ROM::Registry::ElementNotFoundError
|
56
|
-
)
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'allows use of the same identifiers in different environments' do
|
60
|
-
configuration[:one].register_relation(Test::Users)
|
61
|
-
configuration[:one].register_command(Test::CreateUser)
|
62
|
-
configuration[:one].register_mapper(Test::UserMapper)
|
63
|
-
|
64
|
-
expect { configuration[:two].register_relation(Test::Users) }.to_not raise_error
|
65
|
-
expect { configuration[:two].register_command(Test::CreateUser) }.to_not raise_error
|
66
|
-
expect { configuration[:two].register_mapper(Test::UserMapper) }.to_not raise_error
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rom/memory'
|
3
|
-
|
4
|
-
RSpec.describe 'Using in-memory gateways for cross-repo access' do
|
5
|
-
let(:configuration) do
|
6
|
-
ROM::Configuration.new(left: :memory, right: :memory, main: :memory)
|
7
|
-
end
|
8
|
-
|
9
|
-
let(:container) { ROM.container(configuration) }
|
10
|
-
let(:gateways) { container.gateways }
|
11
|
-
|
12
|
-
it 'works' do
|
13
|
-
configuration.relation(:users, gateway: :left) do
|
14
|
-
def by_name(name)
|
15
|
-
restrict(name: name)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
configuration.relation(:tasks, gateway: :right)
|
20
|
-
|
21
|
-
configuration.relation(:users_and_tasks, gateway: :main) do
|
22
|
-
def by_user(name)
|
23
|
-
join(users.by_name(name), tasks)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
configuration.mappers do
|
28
|
-
define(:users_and_tasks) do
|
29
|
-
group tasks: [:title]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
gateways[:left][:users] << { user_id: 1, name: 'Joe' }
|
34
|
-
gateways[:left][:users] << { user_id: 2, name: 'Jane' }
|
35
|
-
gateways[:right][:tasks] << { user_id: 1, title: 'Have fun' }
|
36
|
-
gateways[:right][:tasks] << { user_id: 2, title: 'Have fun' }
|
37
|
-
|
38
|
-
user_and_tasks = container.relation(:users_and_tasks)
|
39
|
-
.by_user('Jane')
|
40
|
-
.as(:users_and_tasks)
|
41
|
-
|
42
|
-
expect(user_and_tasks).to match_array([
|
43
|
-
{ user_id: 2, name: 'Jane', tasks: [{ title: 'Have fun' }] }
|
44
|
-
])
|
45
|
-
end
|
46
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe ROM::Relation, '.dataset' do
|
4
|
-
include_context 'container'
|
5
|
-
|
6
|
-
it 'injects configured dataset when block was provided' do
|
7
|
-
configuration.relation(:users) do
|
8
|
-
dataset do
|
9
|
-
insert(id: 2, name: 'Joe')
|
10
|
-
insert(id: 1, name: 'Jane')
|
11
|
-
|
12
|
-
restrict(name: 'Jane')
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
expect(container.relation(:users).to_a).to eql([{ id: 1, name: 'Jane' }])
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'yields relation class for setting custom dataset proc' do
|
20
|
-
configuration.relation(:users) do
|
21
|
-
schema do
|
22
|
-
attribute :id, ROM::Memory::Types::Int.meta(primary_key: true)
|
23
|
-
attribute :name, ROM::Memory::Types::String
|
24
|
-
end
|
25
|
-
|
26
|
-
dataset do |rel_klass|
|
27
|
-
insert(id: 2, name: 'Joe')
|
28
|
-
insert(id: 1, name: 'Jane')
|
29
|
-
|
30
|
-
order(*rel_klass.schema.primary_key.map { |t| t.meta[:name] })
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
expect(container.relation(:users).to_a).to eql([
|
35
|
-
{ id: 1, name: 'Jane' }, { id: 2, name: 'Joe' }
|
36
|
-
])
|
37
|
-
end
|
38
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe 'Inheritance relation hierarchy' do
|
4
|
-
include_context 'container'
|
5
|
-
|
6
|
-
before do
|
7
|
-
module Test
|
8
|
-
class Users < ROM::Relation[:memory]
|
9
|
-
dataset :users
|
10
|
-
|
11
|
-
def by_email(email)
|
12
|
-
restrict(email: email)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
class OtherUsers < Users
|
17
|
-
register_as :other_users
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
configuration.register_relation(Test::Users, Test::OtherUsers)
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'registers parent and descendant relations' do
|
25
|
-
users = container.relation(:users)
|
26
|
-
other_users = container.relation(:other_users)
|
27
|
-
|
28
|
-
expect(users).to be_instance_of(Test::Users)
|
29
|
-
expect(other_users).to be_instance_of(Test::OtherUsers)
|
30
|
-
|
31
|
-
jane = { name: 'Jane', email: 'jane@doe.org' }
|
32
|
-
|
33
|
-
other_users.insert(jane)
|
34
|
-
|
35
|
-
expect(other_users.by_email('jane@doe.org').one).to eql(jane)
|
36
|
-
end
|
37
|
-
end
|
@@ -1,169 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe 'Reading relations' do
|
4
|
-
include_context 'container'
|
5
|
-
include_context 'users and tasks'
|
6
|
-
|
7
|
-
before do
|
8
|
-
configuration.relation(:tasks)
|
9
|
-
|
10
|
-
configuration.relation(:users) do
|
11
|
-
def by_name(name)
|
12
|
-
restrict(name: name)
|
13
|
-
end
|
14
|
-
|
15
|
-
def with_task
|
16
|
-
join(tasks)
|
17
|
-
end
|
18
|
-
|
19
|
-
def with_tasks
|
20
|
-
join(tasks)
|
21
|
-
end
|
22
|
-
|
23
|
-
def sorted
|
24
|
-
order(:name, :email)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
it 'exposes a relation reader' do
|
31
|
-
configuration.mappers do
|
32
|
-
define(:users) do
|
33
|
-
model name: 'Test::User'
|
34
|
-
|
35
|
-
attribute :name
|
36
|
-
attribute :email
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
users = users_relation.sorted.by_name('Jane').as(:users)
|
41
|
-
user = users.first
|
42
|
-
|
43
|
-
expect(user).to be_an_instance_of(Test::User)
|
44
|
-
expect(user.name).to eql 'Jane'
|
45
|
-
expect(user.email).to eql 'jane@doe.org'
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'maps grouped relations' do
|
49
|
-
configuration.mappers do
|
50
|
-
define(:users) do
|
51
|
-
model name: 'Test::User'
|
52
|
-
|
53
|
-
attribute :name
|
54
|
-
attribute :email
|
55
|
-
end
|
56
|
-
|
57
|
-
define(:with_tasks, parent: :users) do
|
58
|
-
model name: 'Test::UserWithTasks'
|
59
|
-
|
60
|
-
group tasks: [:title, :priority]
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
container
|
65
|
-
|
66
|
-
Test::User.send(:include, Dry::Equalizer(:name, :email))
|
67
|
-
Test::UserWithTasks.send(:include, Dry::Equalizer(:name, :email, :tasks))
|
68
|
-
|
69
|
-
user = container.relation(:users).sorted.as(:users).first
|
70
|
-
|
71
|
-
expect(user).to eql(
|
72
|
-
Test::User.new(name: "Jane", email: "jane@doe.org")
|
73
|
-
)
|
74
|
-
|
75
|
-
user = container.relation(:users).with_tasks.sorted.as(:with_tasks).first
|
76
|
-
|
77
|
-
expect(user).to eql(
|
78
|
-
Test::UserWithTasks.new(
|
79
|
-
name: "Jane",
|
80
|
-
email: "jane@doe.org",
|
81
|
-
tasks: [{ title: "be cool", priority: 2 }])
|
82
|
-
)
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'maps wrapped relations' do
|
86
|
-
configuration.mappers do
|
87
|
-
define(:users) do
|
88
|
-
model name: 'Test::User'
|
89
|
-
|
90
|
-
attribute :name
|
91
|
-
attribute :email
|
92
|
-
end
|
93
|
-
|
94
|
-
define(:with_task, parent: :users) do
|
95
|
-
model name: 'Test::UserWithTask'
|
96
|
-
|
97
|
-
wrap task: [:title, :priority]
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
container
|
102
|
-
|
103
|
-
Test::User.send(:include, Dry::Equalizer(:name, :email))
|
104
|
-
Test::UserWithTask.send(:include, Dry::Equalizer(:name, :email, :task))
|
105
|
-
|
106
|
-
user = container.relation(:users).sorted.with_task.as(:with_task).first
|
107
|
-
|
108
|
-
expect(user).to eql(
|
109
|
-
Test::UserWithTask.new(name: "Jane", email: "jane@doe.org",
|
110
|
-
task: { title: "be cool", priority: 2 })
|
111
|
-
)
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'maps hashes' do
|
115
|
-
configuration.mappers do
|
116
|
-
define(:users)
|
117
|
-
end
|
118
|
-
|
119
|
-
user = container.relation(:users).by_name("Jane").as(:users).first
|
120
|
-
|
121
|
-
expect(user).to eql(name: "Jane", email: "jane@doe.org")
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'allows cherry-picking of a mapper' do
|
125
|
-
configuration.mappers do
|
126
|
-
define(:users) do
|
127
|
-
attribute :name
|
128
|
-
attribute :email
|
129
|
-
end
|
130
|
-
|
131
|
-
define(:prefixer, parent: :users) do
|
132
|
-
attribute :user_name, from: :name
|
133
|
-
attribute :user_email, from: :email
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
user = container.relation(:users).map_with(:prefixer).first
|
138
|
-
|
139
|
-
expect(user).to eql(user_name: 'Joe', user_email: "joe@doe.org")
|
140
|
-
end
|
141
|
-
|
142
|
-
it 'allows passing a block to retrieve relations for mapping' do
|
143
|
-
configuration.mappers do
|
144
|
-
define(:users) do
|
145
|
-
attribute :name
|
146
|
-
attribute :email
|
147
|
-
end
|
148
|
-
|
149
|
-
define(:prefixer, parent: :users) do
|
150
|
-
attribute :user_name, from: :name
|
151
|
-
attribute :user_email, from: :email
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
expect {
|
156
|
-
container.relation(:users, &:not_here)
|
157
|
-
}.to raise_error(NoMethodError, /not_here/)
|
158
|
-
|
159
|
-
expect {
|
160
|
-
container.relation(:users) { |users| users.by_name('Joe') }.as(:not_here)
|
161
|
-
}.to raise_error(ROM::MapperMissingError, /not_here/)
|
162
|
-
|
163
|
-
user = container.relation(:users) { |users|
|
164
|
-
users.by_name('Joe')
|
165
|
-
}.map_with(:prefixer).call.first
|
166
|
-
|
167
|
-
expect(user).to eql(user_name: 'Joe', user_email: "joe@doe.org")
|
168
|
-
end
|
169
|
-
end
|