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,121 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rom/lint/spec'
|
3
|
-
|
4
|
-
require 'rom/memory/dataset'
|
5
|
-
require 'rom/memory/relation'
|
6
|
-
|
7
|
-
RSpec.describe ROM::Memory::Relation do
|
8
|
-
subject(:relation) do
|
9
|
-
Class.new(ROM::Memory::Relation) do
|
10
|
-
schema do
|
11
|
-
attribute :name, ROM::Types::String
|
12
|
-
attribute :email, ROM::Types::String
|
13
|
-
attribute :age, ROM::Types::Int
|
14
|
-
end
|
15
|
-
end.new(dataset)
|
16
|
-
end
|
17
|
-
|
18
|
-
let(:dataset) do
|
19
|
-
ROM::Memory::Dataset.new([
|
20
|
-
{ name: 'Jane', email: 'jane@doe.org', age: 10 },
|
21
|
-
{ name: 'Jade', email: 'jade@doe.org', age: 11 },
|
22
|
-
{ name: 'Joe', email: 'joe@doe.org', age: 12 },
|
23
|
-
{ name: 'Jack', age: 11 },
|
24
|
-
{ name: 'Jill', email: 'jill@doe.org' },
|
25
|
-
{ name: 'John' },
|
26
|
-
{ name: 'Judy', email: 'judy@doe.org', age: 11 }
|
27
|
-
])
|
28
|
-
end
|
29
|
-
|
30
|
-
describe '#take' do
|
31
|
-
it 'takes given number of tuples' do
|
32
|
-
expect(relation.take(2)).to match_array([
|
33
|
-
{ name: 'Jane', email: 'jane@doe.org', age: 10 },
|
34
|
-
{ name: 'Jade', email: 'jade@doe.org', age: 11 }
|
35
|
-
])
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe '#project' do
|
40
|
-
it 'projects tuples with the provided keys' do
|
41
|
-
projected = relation.project(:name, :age)
|
42
|
-
|
43
|
-
expect(projected.schema).to eql(relation.schema.project(:name, :age))
|
44
|
-
|
45
|
-
expect(projected).to match_array([
|
46
|
-
{ name: 'Jane', age: 10 },
|
47
|
-
{ name: 'Jade', age: 11 },
|
48
|
-
{ name: 'Joe', age: 12 },
|
49
|
-
{ name: 'Jack', age: 11 },
|
50
|
-
{ name: 'Jill' },
|
51
|
-
{ name: 'John' },
|
52
|
-
{ name: 'Judy', age: 11 }
|
53
|
-
])
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe '#restrict' do
|
58
|
-
it 'restricts data using criteria hash' do
|
59
|
-
expect(relation.restrict(age: 10)).to match_array([
|
60
|
-
{ name: 'Jane', email: 'jane@doe.org', age: 10 }
|
61
|
-
])
|
62
|
-
|
63
|
-
expect(relation.restrict(age: 10.0)).to match_array([])
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'restricts data using block' do
|
67
|
-
expect(relation.restrict { |tuple| tuple[:age].to_i > 10 }).to match_array([
|
68
|
-
{ name: 'Jade', email: 'jade@doe.org', age: 11 },
|
69
|
-
{ name: 'Joe', email: 'joe@doe.org', age: 12 },
|
70
|
-
{ name: 'Jack', age: 11 },
|
71
|
-
{ name: 'Judy', email: 'judy@doe.org', age: 11 }
|
72
|
-
])
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'allows to use array as a value' do
|
76
|
-
expect(relation.restrict(age: [10, 11])).to match_array([
|
77
|
-
{ name: 'Jane', email: 'jane@doe.org', age: 10 },
|
78
|
-
{ name: 'Jade', email: 'jade@doe.org', age: 11 },
|
79
|
-
{ name: 'Jack', age: 11 },
|
80
|
-
{ name: 'Judy', email: 'judy@doe.org', age: 11 }
|
81
|
-
])
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'allows to use regexp as a value' do
|
85
|
-
expect(relation.restrict(name: /\w{4}/)).to match_array([
|
86
|
-
{ name: 'Jane', email: 'jane@doe.org', age: 10 },
|
87
|
-
{ name: 'Jade', email: 'jade@doe.org', age: 11 },
|
88
|
-
{ name: 'Jack', age: 11 },
|
89
|
-
{ name: 'Jill', email: 'jill@doe.org' },
|
90
|
-
{ name: 'John' },
|
91
|
-
{ name: 'Judy', email: 'judy@doe.org', age: 11 }
|
92
|
-
])
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe '#order' do
|
97
|
-
it 'sorts data using provided attribute names' do
|
98
|
-
expect(relation.order(:age, :email).to_a).to eq([
|
99
|
-
{ name: 'Jane', age: 10, email: 'jane@doe.org' },
|
100
|
-
{ name: 'Jade', age: 11, email: 'jade@doe.org' },
|
101
|
-
{ name: 'Judy', age: 11, email: 'judy@doe.org' },
|
102
|
-
{ name: 'Jack', age: 11 },
|
103
|
-
{ name: 'Joe', age: 12, email: 'joe@doe.org' },
|
104
|
-
{ name: 'Jill', email: 'jill@doe.org' },
|
105
|
-
{ name: 'John' }
|
106
|
-
])
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'places nil before other values when required' do
|
110
|
-
expect(relation.order(:age, :email, nils_first: true).to_a).to eq([
|
111
|
-
{ name: 'John' },
|
112
|
-
{ name: 'Jill', email: 'jill@doe.org' },
|
113
|
-
{ name: 'Jane', age: 10, email: 'jane@doe.org' },
|
114
|
-
{ name: 'Jack', age: 11 },
|
115
|
-
{ name: 'Jade', age: 11, email: 'jade@doe.org' },
|
116
|
-
{ name: 'Judy', age: 11, email: 'judy@doe.org' },
|
117
|
-
{ name: 'Joe', age: 12, email: 'joe@doe.org' }
|
118
|
-
])
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rom/memory/storage'
|
3
|
-
|
4
|
-
RSpec.describe ROM::Memory::Storage do
|
5
|
-
describe 'thread safe' do
|
6
|
-
let(:threads) { 4 }
|
7
|
-
let(:operations) { 5000 }
|
8
|
-
|
9
|
-
describe 'data' do
|
10
|
-
it 'create datasets properly' do
|
11
|
-
storage = ROM::Memory::Storage.new
|
12
|
-
|
13
|
-
threaded_operations do |thread, operation|
|
14
|
-
key = "#{thread}:#{operation}"
|
15
|
-
storage.create_dataset(key)
|
16
|
-
end
|
17
|
-
|
18
|
-
expect(storage.size).to eql(threads * operations)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe 'dataset' do
|
23
|
-
it 'inserts data in proper order' do
|
24
|
-
storage = ROM::Memory::Storage.new
|
25
|
-
dataset = storage.create_dataset(:ary)
|
26
|
-
|
27
|
-
threaded_operations do
|
28
|
-
dataset << :data
|
29
|
-
end
|
30
|
-
|
31
|
-
expect(dataset.size).to eql(threads * operations)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def threaded_operations
|
36
|
-
threads.times.map { |thread|
|
37
|
-
Thread.new do
|
38
|
-
operations.times do |operation|
|
39
|
-
yield thread, operation
|
40
|
-
end
|
41
|
-
end
|
42
|
-
}.each(&:join)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,150 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe "ROM::PluginRegistry" do
|
4
|
-
include_context 'container'
|
5
|
-
|
6
|
-
before do
|
7
|
-
Test::ConfigurationPlugin = Module.new
|
8
|
-
Test::CommandPlugin = Module.new
|
9
|
-
Test::MapperPlugin = Module.new
|
10
|
-
Test::RelationPlugin = Module.new do
|
11
|
-
def plugged_in
|
12
|
-
"a relation"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
ROM.plugins do
|
17
|
-
register :registration, Test::ConfigurationPlugin, type: :configuration
|
18
|
-
register :publisher, Test::CommandPlugin, type: :command
|
19
|
-
register :pager, Test::RelationPlugin, type: :relation
|
20
|
-
register :translater, Test::MapperPlugin, type: :mapper
|
21
|
-
end
|
22
|
-
|
23
|
-
configuration
|
24
|
-
end
|
25
|
-
|
26
|
-
around do |example|
|
27
|
-
orig_plugins = ROM.plugin_registry
|
28
|
-
example.run
|
29
|
-
ROM.instance_variable_set('@plugin_registry', orig_plugins)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "makes configuration plugins available" do
|
33
|
-
expect(ROM.plugin_registry.configuration[:registration].mod).to eq Test::ConfigurationPlugin
|
34
|
-
end
|
35
|
-
|
36
|
-
it "includes relation plugins" do
|
37
|
-
users = Class.new(ROM::Relation[:memory]) do
|
38
|
-
register_as :users
|
39
|
-
use :pager
|
40
|
-
end
|
41
|
-
configuration.register_relation(users)
|
42
|
-
|
43
|
-
expect(container.relation(:users).plugged_in).to eq "a relation"
|
44
|
-
end
|
45
|
-
|
46
|
-
it "makes command plugins available" do
|
47
|
-
users = Class.new(ROM::Relation[:memory]) do
|
48
|
-
register_as :users
|
49
|
-
end
|
50
|
-
|
51
|
-
create_user = Class.new(ROM::Commands::Create[:memory]) do
|
52
|
-
relation :users
|
53
|
-
register_as :create
|
54
|
-
use :publisher
|
55
|
-
end
|
56
|
-
|
57
|
-
configuration.register_relation(users)
|
58
|
-
configuration.register_command(create_user)
|
59
|
-
|
60
|
-
expect(container.command(:users).create).to be_kind_of Test::CommandPlugin
|
61
|
-
end
|
62
|
-
|
63
|
-
it "inclues plugins in mappers" do
|
64
|
-
users = Class.new(ROM::Relation[:memory]) do
|
65
|
-
register_as :users
|
66
|
-
end
|
67
|
-
translator = Class.new(ROM::Mapper) do
|
68
|
-
relation :users
|
69
|
-
register_as :translator
|
70
|
-
use :translater
|
71
|
-
end
|
72
|
-
|
73
|
-
configuration.register_relation(users)
|
74
|
-
configuration.register_mapper(translator)
|
75
|
-
|
76
|
-
expect(container.mappers[:users][:translator]).to be_kind_of Test::MapperPlugin
|
77
|
-
end
|
78
|
-
|
79
|
-
it "restricts plugins to defined type" do
|
80
|
-
expect {
|
81
|
-
configuration.relation(:users) do
|
82
|
-
use :publisher
|
83
|
-
end
|
84
|
-
}.to raise_error ROM::UnknownPluginError
|
85
|
-
end
|
86
|
-
|
87
|
-
it "allows definition of adapter restricted plugins" do
|
88
|
-
Test::LazyPlugin = Module.new do
|
89
|
-
def lazy?
|
90
|
-
true
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
ROM.plugins do
|
95
|
-
adapter :memory do
|
96
|
-
register :lazy, Test::LazyPlugin, type: :relation
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
users = Class.new(ROM::Relation[:memory]) do
|
101
|
-
register_as :users
|
102
|
-
use :lazy
|
103
|
-
end
|
104
|
-
configuration.register_relation(users)
|
105
|
-
|
106
|
-
expect(container.relation(:users)).to be_lazy
|
107
|
-
end
|
108
|
-
|
109
|
-
it "respects adapter restrictions" do
|
110
|
-
Test::LazyPlugin = Module.new
|
111
|
-
Test::LazyMemoryPlugin = Module.new
|
112
|
-
Test::LazySQLPlugin = Module.new
|
113
|
-
|
114
|
-
ROM.plugins do
|
115
|
-
register :lazy, Test::LazyPlugin, type: :command
|
116
|
-
|
117
|
-
adapter :memory do
|
118
|
-
register :lazy_command, Test::LazyMemoryPlugin, type: :command
|
119
|
-
end
|
120
|
-
|
121
|
-
adapter :sql do
|
122
|
-
register :lazy, Test::LazySQLPlugin, type: :command
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
users = Class.new(ROM::Relation[:memory]) do
|
127
|
-
register_as :users
|
128
|
-
end
|
129
|
-
|
130
|
-
create_user = Class.new(ROM::Commands::Create[:memory]) do
|
131
|
-
relation :users
|
132
|
-
register_as :create
|
133
|
-
use :lazy
|
134
|
-
end
|
135
|
-
|
136
|
-
update_user = Class.new(ROM::Commands::Update[:memory]) do
|
137
|
-
relation :users
|
138
|
-
register_as :update
|
139
|
-
use :lazy_command
|
140
|
-
end
|
141
|
-
|
142
|
-
configuration.register_relation(users)
|
143
|
-
configuration.register_command(create_user)
|
144
|
-
configuration.register_command(update_user)
|
145
|
-
|
146
|
-
expect(container.command(:users).create).not_to be_kind_of Test::LazySQLPlugin
|
147
|
-
expect(container.command(:users).create).to be_kind_of Test::LazyPlugin
|
148
|
-
expect(container.command(:users).update).to be_kind_of Test::LazyMemoryPlugin
|
149
|
-
end
|
150
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'rom/relation'
|
2
|
-
require 'rom/command'
|
3
|
-
require 'rom/plugins/command/schema'
|
4
|
-
|
5
|
-
RSpec.describe ROM::Plugins::Command::Schema do
|
6
|
-
describe '.build' do
|
7
|
-
let(:command_class) do
|
8
|
-
Class.new(ROM::Command) { use :schema }
|
9
|
-
end
|
10
|
-
|
11
|
-
context 'when relation has no schema defined' do
|
12
|
-
let(:relation) do
|
13
|
-
instance_double(ROM::Relation, schema?: false)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'sets default input handler when command does not have a custom one' do
|
17
|
-
command = Class.new(command_class).build(relation)
|
18
|
-
|
19
|
-
expect(command.input).to be(ROM::Command.input)
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'sets custom input handler when command defines it' do
|
23
|
-
my_handler = double(:my_handler)
|
24
|
-
|
25
|
-
command = Class.new(command_class) { input my_handler }.build(relation)
|
26
|
-
|
27
|
-
expect(command.input).to be(my_handler)
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'sets custom input handler when it is passed as an option' do
|
31
|
-
my_handler = double(:my_handler)
|
32
|
-
|
33
|
-
command = Class.new(command_class).build(relation, input: my_handler)
|
34
|
-
|
35
|
-
expect(command.input).to be(my_handler)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'when relation has a schema' do
|
40
|
-
let(:relation) do
|
41
|
-
instance_double(ROM::Relation, schema?: true, input_schema: input_schema)
|
42
|
-
end
|
43
|
-
|
44
|
-
let(:input_schema) do
|
45
|
-
double(:input_schema)
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'sets schema hash as input handler' do
|
49
|
-
command = Class.new(command_class).build(relation)
|
50
|
-
|
51
|
-
expect(command.input).to be(input_schema)
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'sets a composed input handler with schema hash and a custom one' do
|
55
|
-
my_handler = double(:my_handler)
|
56
|
-
|
57
|
-
command = Class.new(command_class) { input my_handler }.build(relation)
|
58
|
-
|
59
|
-
expect(my_handler).to receive(:[]).with('some value').and_return('my handler')
|
60
|
-
expect(input_schema).to receive(:[]).with('my handler').and_return('a tuple')
|
61
|
-
|
62
|
-
expect(command.input['some value']).to eql('a tuple')
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'rom'
|
2
|
-
require 'rom/memory'
|
3
|
-
|
4
|
-
RSpec.describe ROM::Plugins::Relation::Instrumentation do
|
5
|
-
before do
|
6
|
-
described_class.mixin Module.new
|
7
|
-
end
|
8
|
-
|
9
|
-
subject(:relation) do
|
10
|
-
relation_class.new(dataset, notifications: notifications)
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:dataset) do
|
14
|
-
double(:dataset)
|
15
|
-
end
|
16
|
-
|
17
|
-
let(:relation_class) do
|
18
|
-
Class.new(ROM::Memory::Relation) do
|
19
|
-
schema(:users) do
|
20
|
-
attribute :name, ROM::Types::String
|
21
|
-
end
|
22
|
-
|
23
|
-
use :instrumentation
|
24
|
-
|
25
|
-
instrument def all
|
26
|
-
self
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
let(:notifications) { spy(:notifications) }
|
32
|
-
|
33
|
-
it 'uses notifications API when materializing a relation' do
|
34
|
-
relation.to_a
|
35
|
-
|
36
|
-
expect(notifications).to have_received(:instrument).with(:memory, name: :users)
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'instruments custom methods' do
|
40
|
-
relation.all
|
41
|
-
|
42
|
-
expect(notifications).to have_received(:instrument).with(:memory, name: :users)
|
43
|
-
end
|
44
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'rom'
|
2
|
-
require 'rom/memory'
|
3
|
-
require 'rom/plugins/relation/key_inference'
|
4
|
-
|
5
|
-
RSpec.describe ROM::Plugins::Relation::KeyInference do
|
6
|
-
subject(:relation) do
|
7
|
-
relation_class.new(
|
8
|
-
[],
|
9
|
-
__registry__: ROM::RelationRegistry.new(posts: posts, users: users, tags: tags)
|
10
|
-
)
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:posts) { double(foreign_key: :post_id) }
|
14
|
-
let(:tags_name) { ROM::Relation::Name[:tags] }
|
15
|
-
let(:tags) { double(foreign_key: :tag_id) }
|
16
|
-
let(:users_name) { ROM::Relation::Name[:users] }
|
17
|
-
let(:users) { double(base_name: users_name) }
|
18
|
-
|
19
|
-
describe 'without a schema' do
|
20
|
-
let(:relation_class) do
|
21
|
-
Class.new(ROM::Memory::Relation) do
|
22
|
-
use :key_inference
|
23
|
-
|
24
|
-
dataset :users
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#base_name' do
|
29
|
-
it 'returns dataset name by default' do
|
30
|
-
expect(relation.base_name).to eql(ROM::Relation::Name[:users])
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe '#foreign_key' do
|
35
|
-
it 'returns default value' do
|
36
|
-
expect(relation.foreign_key).to be(:user_id)
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'returns default value for another relation' do
|
40
|
-
expect(relation.foreign_key(:posts)).to be(:post_id)
|
41
|
-
expect(relation.foreign_key(posts)).to be(:post_id)
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'returns default value for Relation::Name' do
|
45
|
-
expect(relation.foreign_key(ROM::Relation::Name[:posts])).to be(:post_id)
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'supports objects responding to to_sym' do
|
49
|
-
external_name = double(to_sym: :tags)
|
50
|
-
expect(relation.foreign_key(external_name)).to be(:tag_id)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe 'with a schema' do
|
56
|
-
let(:relation_class) do
|
57
|
-
Class.new(ROM::Memory::Relation) do
|
58
|
-
use :key_inference
|
59
|
-
|
60
|
-
schema :posts do
|
61
|
-
attribute :author_id, ROM::Types::Int.meta(foreign_key: true, target: :users)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe '#foreign_key' do
|
67
|
-
it 'returns configured value' do
|
68
|
-
expect(relation.foreign_key(ROM::Relation::Name[:users])).to be(:author_id)
|
69
|
-
expect(relation.foreign_key(:users)).to be(:author_id)
|
70
|
-
expect(relation.foreign_key(users)).to be(:author_id)
|
71
|
-
expect(relation.foreign_key(users_name)).to be(:author_id)
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'falls back to default when schema has no fk specified' do
|
75
|
-
expect(relation.foreign_key(:tags)).to be(:tag_id)
|
76
|
-
expect(relation.foreign_key(tags_name)).to be(:tag_id)
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'supports objects responding to to_sym' do
|
80
|
-
external_name = double(to_sym: :tags)
|
81
|
-
expect(relation.foreign_key(external_name)).to be(:tag_id)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'rom/registry'
|
2
|
-
|
3
|
-
RSpec.shared_examples_for 'registry fetch' do
|
4
|
-
it 'raises an ArgumentError when nil is used as a key' do
|
5
|
-
expect {
|
6
|
-
registry.public_send(fetch_method, nil)
|
7
|
-
}.to raise_error(ArgumentError, "key cannot be nil")
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'returns registered element identified by name' do
|
11
|
-
expect(registry.public_send(fetch_method, :mars)).to be(mars)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'raises error when element is not found' do
|
15
|
-
expect { registry.public_send(fetch_method, :twix) }.to raise_error(
|
16
|
-
ROM::Registry::ElementNotFoundError,
|
17
|
-
":twix doesn't exist in Candy registry"
|
18
|
-
)
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'returns the value from an optional block when key is not found' do
|
22
|
-
value = registry.public_send(fetch_method, :candy) { :twix }
|
23
|
-
|
24
|
-
expect(value).to eq(:twix)
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'calls #to_sym on a key before fetching' do
|
28
|
-
expect(registry.public_send(fetch_method, double(to_sym: :mars))).to be(mars)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
RSpec.describe ROM::Registry do
|
33
|
-
subject(:registry) { registry_class.new(mars: mars) }
|
34
|
-
|
35
|
-
let(:mars) { double('mars') }
|
36
|
-
|
37
|
-
let(:registry_class) do
|
38
|
-
Class.new(ROM::Registry) do
|
39
|
-
def self.name
|
40
|
-
'Candy'
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe '#fetch' do
|
46
|
-
let(:fetch_method) { :fetch }
|
47
|
-
|
48
|
-
it_behaves_like 'registry fetch'
|
49
|
-
end
|
50
|
-
|
51
|
-
describe '#[]' do
|
52
|
-
let(:fetch_method) { :[] }
|
53
|
-
|
54
|
-
it_behaves_like 'registry fetch'
|
55
|
-
end
|
56
|
-
|
57
|
-
describe '#method_missing' do
|
58
|
-
it 'returns registered element identified by name' do
|
59
|
-
expect(registry.mars).to be(mars)
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'raises no-method error when element is not there' do
|
63
|
-
expect { registry.twix }.to raise_error(NoMethodError)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe '#key?' do
|
68
|
-
let(:mars) { double(to_sym: :mars) }
|
69
|
-
|
70
|
-
it 'calls #to_sym on a key before checking if it exists' do
|
71
|
-
registry.key?(:mars)
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'returns true for an existing key' do
|
75
|
-
expect(registry.key?(:mars)).to be(true)
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'returns false for a non-existing key' do
|
79
|
-
expect(registry.key?(:twix)).to be(false)
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'returns false for a nil key' do
|
83
|
-
expect(registry.key?(nil)).to be(false)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'rom/memory'
|
2
|
-
|
3
|
-
RSpec.describe ROM::Relation, '#[]' do
|
4
|
-
it 'defines a canonical schema for a relation' do
|
5
|
-
class Test::Users < ROM::Relation[:memory]
|
6
|
-
schema do
|
7
|
-
attribute :id, Types::Int
|
8
|
-
attribute :name, Types::String
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
relation = Test::Users.new([])
|
13
|
-
|
14
|
-
expect(relation[:id]).to be(Test::Users.schema[:id])
|
15
|
-
expect(relation[:name]).to be(Test::Users.schema[:name])
|
16
|
-
end
|
17
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'rom/relation'
|
2
|
-
|
3
|
-
RSpec.describe ROM::Relation, '#call' do
|
4
|
-
subject(:relation) do
|
5
|
-
relation_class.new(data)
|
6
|
-
end
|
7
|
-
|
8
|
-
context 'without read types in schema' do
|
9
|
-
let(:relation_class) do
|
10
|
-
Class.new(ROM::Relation[:memory]) do
|
11
|
-
schema do
|
12
|
-
attribute :id, ROM::Types::Int
|
13
|
-
attribute :name, ROM::Types::String
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
let(:data) do
|
19
|
-
[{ id: '1', name: 'Jane' }, { id: '2', name: 'John'} ]
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'has noop output_schema' do
|
23
|
-
expect(relation.output_schema).to be(ROM::Relation::NOOP_OUTPUT_SCHEMA)
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'returns loaded relation with data' do
|
27
|
-
expect(relation.call.collection).
|
28
|
-
to eql(data)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'with read types in schema' do
|
33
|
-
let(:relation_class) do
|
34
|
-
Class.new(ROM::Relation[:memory]) do
|
35
|
-
schema do
|
36
|
-
attribute :id, ROM::Types::String, read: ROM::Types::Coercible::Int
|
37
|
-
attribute :name, ROM::Types::String
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
let(:data) do
|
43
|
-
[{ id: '1', name: 'Jane' }, { id: '2', name: 'John'} ]
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'returns loaded relation with coerced data' do
|
47
|
-
expect(relation.call.collection).
|
48
|
-
to eql([{ id: 1, name: 'Jane' }, { id: 2, name: 'John'} ])
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|