rom 3.3.3 → 4.0.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,214 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe ROM::Relation 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_name(name)
|
10
|
-
restrict(name: name)
|
11
|
-
end
|
12
|
-
|
13
|
-
def by_name_sorted(name, order_by = :name)
|
14
|
-
by_name(name).order(order_by)
|
15
|
-
end
|
16
|
-
|
17
|
-
def by_email(email)
|
18
|
-
restrict(name: email)
|
19
|
-
end
|
20
|
-
|
21
|
-
def by_name_and_email(name, email)
|
22
|
-
by_name(name).by_email(email)
|
23
|
-
end
|
24
|
-
|
25
|
-
def by_name_and_email_sorted(name, email, order_by)
|
26
|
-
by_name_and_email(name, email).order(order_by)
|
27
|
-
end
|
28
|
-
|
29
|
-
def all(*args)
|
30
|
-
if args.any?
|
31
|
-
restrict(*args)
|
32
|
-
else
|
33
|
-
self
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end.new(users_dataset)
|
37
|
-
end
|
38
|
-
|
39
|
-
let(:tasks_relation) do
|
40
|
-
Class.new(ROM::Memory::Relation) do
|
41
|
-
def for_users(users)
|
42
|
-
names = users.map { |u| u[:name] }
|
43
|
-
restrict { |t| names.include?(t[:name]) }
|
44
|
-
end
|
45
|
-
end.new(tasks_dataset)
|
46
|
-
end
|
47
|
-
|
48
|
-
it_behaves_like 'a relation that returns one tuple' do
|
49
|
-
let(:relation) { users_relation }
|
50
|
-
end
|
51
|
-
|
52
|
-
describe '#map_with' do
|
53
|
-
it 'raises error when unknown mapper was selected' do
|
54
|
-
expect {
|
55
|
-
users_relation.as(:not_here)
|
56
|
-
}.to raise_error(ROM::MapperMissingError, /not_here/)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe '#method_missing' do
|
61
|
-
it 'forwards to relation and auto-curries' do
|
62
|
-
relation = users_relation.by_name_and_email_sorted('Jane')
|
63
|
-
|
64
|
-
expect(relation.name).to eql(ROM::Relation::Name[:by_name_and_email_sorted])
|
65
|
-
expect(relation.curry_args).to eql(['Jane'])
|
66
|
-
|
67
|
-
relation = relation['jane@doe.org']
|
68
|
-
|
69
|
-
expect(relation.name).to eql(ROM::Relation::Name[:by_name_and_email_sorted])
|
70
|
-
expect(relation.curry_args).to eql(['Jane', 'jane@doe.org'])
|
71
|
-
|
72
|
-
expect(relation[:email]).to match_array(
|
73
|
-
users_relation.by_name_and_email_sorted('Jane', 'jane@doe.org', :email)
|
74
|
-
)
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'forwards to relation and does not auto-curry when it is not needed' do
|
78
|
-
relation = users_relation.by_name('Jane')
|
79
|
-
|
80
|
-
expect(relation).to_not be_curried
|
81
|
-
expect(relation).to match_array(users_relation.by_name('Jane'))
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'forwards to relation and return lazy when arity is unknown' do
|
85
|
-
relation = users_relation.all(name: 'Jane')
|
86
|
-
expect(relation).to_not be_curried
|
87
|
-
expect(relation).to match_array(users_relation.by_name('Jane').to_a)
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'returns original response if it is not a relation' do
|
91
|
-
expect(users_relation.gateway).to be(:default)
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'raises NoMethodError when relation does not respond to a method' do
|
95
|
-
expect { users_relation.not_here }.to raise_error(NoMethodError, /not_here/)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe '#call' do
|
100
|
-
it 'auto-curries' do
|
101
|
-
relation = users_relation.by_name
|
102
|
-
|
103
|
-
expect(relation.name).to eql(ROM::Relation::Name[:by_name])
|
104
|
-
expect(relation['Jane'].to_a).to eql(users_relation.by_name('Jane').to_a)
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'returns relation' do
|
108
|
-
expect(users_relation.call.to_a).to eql(users_relation.to_a)
|
109
|
-
end
|
110
|
-
|
111
|
-
describe 'using mappers' do
|
112
|
-
subject(:users) { users_relation.with(mappers: mappers) }
|
113
|
-
|
114
|
-
let(:name_list) { proc { |r| r.map { |t| t[:name] } } }
|
115
|
-
let(:upcaser) { proc { |r| r.map(&:upcase) } }
|
116
|
-
let(:mappers) { { name_list: name_list, upcaser: upcaser } }
|
117
|
-
|
118
|
-
it 'sends relation through mappers' do
|
119
|
-
relation = users.map_with(:name_list, :upcaser).by_name('Jane')
|
120
|
-
|
121
|
-
expect(relation.call.to_a).to eql(['JANE'])
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe '#first' do
|
127
|
-
it 'return first tuple' do
|
128
|
-
expect(users_relation.first).to eql(name: 'Joe', email: 'joe@doe.org')
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'raises when relation is curried and arity does not match' do
|
132
|
-
expect { users_relation.by_name.first }.to raise_error(
|
133
|
-
ArgumentError, "#{users_relation.class.to_s}#by_name arity is 1 (0 args given)"
|
134
|
-
)
|
135
|
-
end
|
136
|
-
|
137
|
-
it 'does not raise when relation is curried and arity matches' do
|
138
|
-
expect { users_relation.by_name_sorted('Joe').first }.to_not raise_error
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
describe '#each' do
|
143
|
-
it 'yields relation tuples' do
|
144
|
-
result = []
|
145
|
-
users_relation.each do |tuple|
|
146
|
-
result << tuple
|
147
|
-
end
|
148
|
-
expect(result).to match_array([
|
149
|
-
{ name: 'Jane', email: 'jane@doe.org' },
|
150
|
-
{ name: 'Joe', email: 'joe@doe.org' }
|
151
|
-
])
|
152
|
-
end
|
153
|
-
|
154
|
-
it 'returns an enumerator if block is not provided' do
|
155
|
-
expect(users_relation.each.to_a).to match_array([
|
156
|
-
{ name: 'Jane', email: 'jane@doe.org' },
|
157
|
-
{ name: 'Joe', email: 'joe@doe.org' }
|
158
|
-
])
|
159
|
-
end
|
160
|
-
|
161
|
-
it 'raises when relation is curried and arity does not match' do
|
162
|
-
expect { users_relation.by_name.each {} }.to raise_error(
|
163
|
-
ArgumentError, "#{users_relation.class.to_s}#by_name arity is 1 (0 args given)"
|
164
|
-
)
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'does not raise when relation is curried and arity matches' do
|
168
|
-
expect { users_relation.by_name_sorted('Jane').first }.to_not raise_error
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
describe '#to_ary' do
|
173
|
-
it 'returns an array with relation tuples' do
|
174
|
-
expect(users_relation.to_ary).to match_array([
|
175
|
-
{ name: 'Jane', email: 'jane@doe.org' },
|
176
|
-
{ name: 'Joe', email: 'joe@doe.org' }
|
177
|
-
])
|
178
|
-
end
|
179
|
-
|
180
|
-
it 'raises when relation is curried and arity does not match' do
|
181
|
-
expect { users_relation.by_name.to_ary }.to raise_error(
|
182
|
-
ArgumentError, "#{users_relation.class.to_s}#by_name arity is 1 (0 args given)"
|
183
|
-
)
|
184
|
-
end
|
185
|
-
|
186
|
-
it 'does not raise when relation is curried and arity matches' do
|
187
|
-
expect { users_relation.by_name_sorted('Jane').first }.to_not raise_error
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
describe '#>>' do
|
192
|
-
it 'composes two relations' do
|
193
|
-
other = users_relation.by_name('Jane') >> tasks_relation.for_users
|
194
|
-
|
195
|
-
expect(other).to match_array([
|
196
|
-
{ name: 'Jane', title: 'be cool', priority: 2 }
|
197
|
-
])
|
198
|
-
end
|
199
|
-
|
200
|
-
it_behaves_like 'a relation that returns one tuple' do
|
201
|
-
let(:relation) { users_relation >> proc { |r| r } }
|
202
|
-
|
203
|
-
describe 'using a mapper' do
|
204
|
-
it 'returns one mapped tuple' do
|
205
|
-
mapper = proc { |r| r.map { |t| t[:name].upcase } }
|
206
|
-
relation = users_relation.by_name('Jane') >> mapper
|
207
|
-
|
208
|
-
expect(relation.one).to eql('JANE')
|
209
|
-
expect(relation.one!).to eql('JANE')
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe ROM::Relation::Loaded do
|
4
|
-
include_context 'no container'
|
5
|
-
include_context 'users and tasks'
|
6
|
-
|
7
|
-
subject(:users) { ROM::Relation::Loaded.new(users_relation) }
|
8
|
-
|
9
|
-
describe '#each' do
|
10
|
-
it 'yields tuples from relation' do
|
11
|
-
result = []
|
12
|
-
|
13
|
-
users.each do |tuple|
|
14
|
-
result << tuple
|
15
|
-
end
|
16
|
-
|
17
|
-
expect(result).to match_array([
|
18
|
-
{ name: 'Jane', email: 'jane@doe.org' },
|
19
|
-
{ name: 'Joe', email: 'joe@doe.org' }
|
20
|
-
])
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'returns enumerator when block is not provided' do
|
24
|
-
expect(users.each.to_a).to eql(users.collection.to_a)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#to_ary' do
|
29
|
-
it 'coerces to an array' do
|
30
|
-
expect(users.to_ary).to match_array([
|
31
|
-
{ name: 'Jane', email: 'jane@doe.org' },
|
32
|
-
{ name: 'Joe', email: 'joe@doe.org' }
|
33
|
-
])
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe '#pluck' do
|
38
|
-
it 'returns a list of values under provided key' do
|
39
|
-
expect(users.pluck(:email)).to eql(%w(joe@doe.org jane@doe.org))
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe '#primary_keys' do
|
44
|
-
it 'returns a list of primary key values' do
|
45
|
-
expect(users.source).to receive(:primary_key).and_return(:name)
|
46
|
-
expect(users.primary_keys).to eql(%w(Joe Jane))
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
it_behaves_like 'a relation that returns one tuple' do
|
51
|
-
let(:relation) { users }
|
52
|
-
end
|
53
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'rom/relation/name'
|
2
|
-
|
3
|
-
RSpec.describe ROM::Relation::Name do
|
4
|
-
describe '.[]' do
|
5
|
-
it 'returns a new name from args' do
|
6
|
-
expect(ROM::Relation::Name[:users]).to eql(
|
7
|
-
ROM::Relation::Name.new(:users)
|
8
|
-
)
|
9
|
-
|
10
|
-
expect(ROM::Relation::Name[:authors, :users]).to eql(
|
11
|
-
ROM::Relation::Name.new(:authors, :users)
|
12
|
-
)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'returns name object when it was passed in as arg' do
|
16
|
-
name = ROM::Relation::Name[:users]
|
17
|
-
expect(ROM::Relation::Name[name]).to be(name)
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'caches name instances' do
|
21
|
-
name = ROM::Relation::Name[:users]
|
22
|
-
expect(ROM::Relation::Name[:users]).to be(name)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe '#inspect' do
|
27
|
-
it 'provides relation name' do
|
28
|
-
name = ROM::Relation::Name.new(:users)
|
29
|
-
expect(name.inspect).to eql("ROM::Relation::Name(users)")
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'provides dataset and relation names' do
|
33
|
-
name = ROM::Relation::Name.new(:authors, :users)
|
34
|
-
expect(name.inspect).to eql("ROM::Relation::Name(authors on users)")
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe '#with' do
|
39
|
-
it 'returns a new name with the same dataset but for a different relation name' do
|
40
|
-
name = ROM::Relation::Name[:users]
|
41
|
-
expect(name.with(:people)).to be(ROM::Relation::Name[:people, :users])
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe '#to_sym' do
|
46
|
-
it 'returns relation name' do
|
47
|
-
expect(ROM::Relation::Name.new(:users).to_sym).to be(:users)
|
48
|
-
expect(ROM::Relation::Name.new(:authors, :users).to_sym).to be(:authors)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe '#to_s' do
|
53
|
-
it 'returns stringified relation name' do
|
54
|
-
expect(ROM::Relation::Name.new(:users).to_s).to eql('users')
|
55
|
-
expect(ROM::Relation::Name.new(:authors, :users).to_s).to eql('authors on users')
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'rom/memory'
|
2
|
-
|
3
|
-
RSpec.describe ROM::Relation, '#output_schema' do
|
4
|
-
subject(:relation) do
|
5
|
-
Class.new(ROM::Relation[:memory]) do
|
6
|
-
schema do
|
7
|
-
attribute :id, ROM::Types::String, read: ROM::Types::Int
|
8
|
-
attribute :name, ROM::Types::String
|
9
|
-
end
|
10
|
-
end.new(ROM::Memory::Dataset.new([]))
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:schema) do
|
14
|
-
relation.schema
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'returns output_schema based on canonical schema' do
|
18
|
-
expect(relation.output_schema).
|
19
|
-
to eql(ROM::Types::Coercible::Hash.schema(id: schema[:id].to_read_type, name: schema[:name].type))
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'returns output_schema based on projected schema' do
|
23
|
-
projected = relation.project(schema[:id].aliased(:user_id))
|
24
|
-
|
25
|
-
expect(projected.output_schema).
|
26
|
-
to eql(ROM::Types::Coercible::Hash.schema(user_id: projected.schema[:id].to_read_type))
|
27
|
-
end
|
28
|
-
end
|
@@ -1,259 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rom/memory'
|
3
|
-
|
4
|
-
RSpec.describe ROM::Relation, '.schema' do
|
5
|
-
it 'defines a canonical schema for a relation' do
|
6
|
-
class Test::Users < ROM::Relation[:memory]
|
7
|
-
schema do
|
8
|
-
attribute :id, Types::Int.meta(primary_key: true)
|
9
|
-
attribute :name, Types::String
|
10
|
-
attribute :admin, Types::Bool
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
Test::Users.schema.finalize!
|
15
|
-
|
16
|
-
relation_name = ROM::Relation::Name[:test_users]
|
17
|
-
|
18
|
-
schema = ROM::Memory::Schema.define(
|
19
|
-
ROM::Relation::Name.new(:test_users),
|
20
|
-
attributes: [
|
21
|
-
ROM::Memory::Types::Int.meta(primary_key: true, name: :id, source: relation_name),
|
22
|
-
ROM::Memory::Types::String.meta(name: :name, source: relation_name),
|
23
|
-
ROM::Memory::Types::Bool.meta(name: :admin, source: relation_name)
|
24
|
-
]
|
25
|
-
).finalize!
|
26
|
-
|
27
|
-
expect(Test::Users.schema.primary_key).to eql([Test::Users.schema[:id]])
|
28
|
-
|
29
|
-
expect(Test::Users.schema).to eql(schema)
|
30
|
-
|
31
|
-
expect(Test::Users.schema.relations).to be_empty
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'allows defining types for reading tuples' do
|
35
|
-
module Test
|
36
|
-
module Types
|
37
|
-
CoercibleDate = ROM::Types::Date.constructor(Date.method(:parse))
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
class Test::Users < ROM::Relation[:memory]
|
42
|
-
schema do
|
43
|
-
attribute :id, Types::Int
|
44
|
-
attribute :date, Types::Coercible::String, read: Test::Types::CoercibleDate
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
schema = Test::Users.schema
|
49
|
-
|
50
|
-
expect(schema.to_output_hash).
|
51
|
-
to eql(ROM::Types::Coercible::Hash.schema(id: schema[:id].type, date: schema[:date].meta[:read]))
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'allows setting composite primary key' do
|
55
|
-
class Test::Users < ROM::Relation[:memory]
|
56
|
-
schema do
|
57
|
-
attribute :name, Types::String
|
58
|
-
attribute :email, Types::String
|
59
|
-
|
60
|
-
primary_key :name, :email
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
schema = Test::Users.schema.finalize!
|
65
|
-
|
66
|
-
expect(schema.primary_key).to eql([schema[:name], schema[:email]])
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'allows setting foreign keys' do
|
70
|
-
class Test::Posts < ROM::Relation[:memory]
|
71
|
-
schema do
|
72
|
-
attribute :author_id, Types::ForeignKey(:users)
|
73
|
-
attribute :title, Types::String
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
schema = Test::Posts.schema
|
78
|
-
|
79
|
-
expect(schema[:author_id].primitive).to be(Integer)
|
80
|
-
|
81
|
-
expect(schema.foreign_key(:users)).to be(schema[:author_id])
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'allows JSON read/write coersion', aggregate_failures: true do
|
85
|
-
class Test::Posts < ROM::Relation[:memory]
|
86
|
-
schema do
|
87
|
-
attribute :payload, Types::Coercible::JSON
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
schema = Test::Posts.schema
|
92
|
-
json_payload = '{"foo":"bar"}'
|
93
|
-
hash_payload = { "foo" => "bar" }
|
94
|
-
|
95
|
-
expect(schema[:payload][hash_payload]).to eq(json_payload)
|
96
|
-
expect(schema[:payload].meta[:read][json_payload]).to eq(hash_payload)
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'allows JSON/Hash read/write coersion using symbols as keys', aggregate_failures: true do
|
100
|
-
class Test::Posts < ROM::Relation[:memory]
|
101
|
-
schema do
|
102
|
-
attribute :payload, Types::Coercible::JSON(symbol_keys: true)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
schema = Test::Posts.schema
|
107
|
-
json_payload = '{"foo":"bar"}'
|
108
|
-
hash_payload = { foo: "bar" }
|
109
|
-
|
110
|
-
expect(schema[:payload][hash_payload]).to eq(json_payload)
|
111
|
-
expect(schema[:payload].meta[:read][json_payload]).to eq(hash_payload)
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'allows JSON to Hash coersion only' do
|
115
|
-
class Test::Posts < ROM::Relation[:memory]
|
116
|
-
schema do
|
117
|
-
attribute :payload, Types::Coercible::JSONHash
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
schema = Test::Posts.schema
|
122
|
-
json_payload = '{"foo":"bar"}'
|
123
|
-
hash_payload = { "foo" => "bar" }
|
124
|
-
|
125
|
-
expect(schema[:payload][json_payload]).to eq(hash_payload)
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'returns original payload in JSON to Hash coersion when json is invalid' do
|
129
|
-
class Test::Posts < ROM::Relation[:memory]
|
130
|
-
schema do
|
131
|
-
attribute :payload, Types::Coercible::JSONHash
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
schema = Test::Posts.schema
|
136
|
-
json_payload = 'invalid: json'
|
137
|
-
|
138
|
-
expect(schema[:payload][json_payload]).to eq(json_payload)
|
139
|
-
end
|
140
|
-
|
141
|
-
it 'allows JSON to Hash coersion only using symbols as keys' do
|
142
|
-
class Test::Posts < ROM::Relation[:memory]
|
143
|
-
schema do
|
144
|
-
attribute :payload, Types::Coercible::JSONHash(symbol_keys: true)
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
schema = Test::Posts.schema
|
149
|
-
json_payload = '{"foo":"bar"}'
|
150
|
-
hash_payload = { foo: "bar" }
|
151
|
-
|
152
|
-
expect(schema[:payload][json_payload]).to eq(hash_payload)
|
153
|
-
end
|
154
|
-
|
155
|
-
it 'allows Hash to JSON coersion only' do
|
156
|
-
class Test::Posts < ROM::Relation[:memory]
|
157
|
-
schema do
|
158
|
-
attribute :payload, Types::Coercible::HashJSON
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
schema = Test::Posts.schema
|
163
|
-
json_payload = '{"foo":"bar"}'
|
164
|
-
hash_payload = { "foo" => "bar" }
|
165
|
-
|
166
|
-
expect(schema[:payload][hash_payload]).to eq(json_payload)
|
167
|
-
end
|
168
|
-
|
169
|
-
it 'sets register_as and dataset' do
|
170
|
-
class Test::Users < ROM::Relation[:memory]
|
171
|
-
schema(:users) do
|
172
|
-
attribute :id, Types::Int
|
173
|
-
attribute :name, Types::String
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
expect(Test::Users.dataset).to be(:users)
|
178
|
-
expect(Test::Users.register_as).to be(:users)
|
179
|
-
end
|
180
|
-
|
181
|
-
it 'sets dataset and respects custom register_as' do
|
182
|
-
class Test::Users < ROM::Relation[:memory]
|
183
|
-
register_as :test_users
|
184
|
-
|
185
|
-
schema(:users) do
|
186
|
-
attribute :id, Types::Int
|
187
|
-
attribute :name, Types::String
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
expect(Test::Users.dataset).to be(:users)
|
192
|
-
expect(Test::Users.register_as).to be(:test_users)
|
193
|
-
end
|
194
|
-
|
195
|
-
it 'allows setting both dataset and relation alias' do
|
196
|
-
class Test::Users < ROM::Relation[:memory]
|
197
|
-
schema(:test_users, as: :users) { }
|
198
|
-
end
|
199
|
-
|
200
|
-
expect(Test::Users.register_as).to be(:users)
|
201
|
-
expect(Test::Users.dataset).to be(:test_users)
|
202
|
-
end
|
203
|
-
|
204
|
-
it 'raises error when schema_class is missing' do
|
205
|
-
class Test::Users < ROM::Relation[:memory]
|
206
|
-
schema_class nil
|
207
|
-
end
|
208
|
-
|
209
|
-
expect { Test::Users.schema(:test) { } }.
|
210
|
-
to raise_error(ROM::MissingSchemaClassError, "Test::Users relation is missing schema_class")
|
211
|
-
end
|
212
|
-
|
213
|
-
describe '#schema' do
|
214
|
-
it 'returns defined schema' do
|
215
|
-
class Test::Users < ROM::Relation[:memory]
|
216
|
-
schema do
|
217
|
-
attribute :id, Types::Int.meta(primary_key: true)
|
218
|
-
attribute :name, Types::String
|
219
|
-
attribute :admin, Types::Bool
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
users = Test::Users.new([])
|
224
|
-
|
225
|
-
expect(users.schema).to be(Test::Users.schema)
|
226
|
-
end
|
227
|
-
|
228
|
-
it 'uses custom schema dsl' do
|
229
|
-
class Test::SchemaDSL < ROM::Schema::DSL
|
230
|
-
def bool(name)
|
231
|
-
attribute(name, ::ROM::Types::Bool)
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
class Test::Users < ROM::Relation[:memory]
|
236
|
-
schema_dsl Test::SchemaDSL
|
237
|
-
|
238
|
-
schema do
|
239
|
-
bool :admin
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
expect(Test::Users.schema[:admin]).to eql(ROM::Types::Bool.meta(name: :admin, source: ROM::Relation::Name[:test_users]))
|
244
|
-
end
|
245
|
-
|
246
|
-
it 'raises an error on double definition' do
|
247
|
-
expect {
|
248
|
-
class Test::Users < ROM::Relation[:memory]
|
249
|
-
schema do
|
250
|
-
attribute :id, Types::Int.meta(primary_key: true)
|
251
|
-
attribute :name, Types::String
|
252
|
-
attribute :id, Types::Int
|
253
|
-
end
|
254
|
-
end
|
255
|
-
}.to raise_error(ROM::Schema::AttributeAlreadyDefinedError,
|
256
|
-
/:id already defined/)
|
257
|
-
end
|
258
|
-
end
|
259
|
-
end
|