rom 2.0.2 → 5.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +122 -324
- data/LICENSE +17 -17
- data/README.md +91 -22
- data/lib/rom/version.rb +3 -1
- data/lib/rom.rb +4 -46
- metadata +42 -245
- data/.gitignore +0 -24
- data/.rspec +0 -3
- data/.rubocop.yml +0 -87
- data/.rubocop_todo.yml +0 -46
- data/.travis.yml +0 -28
- data/CODE_OF_CONDUCT.md +0 -13
- data/CONTRIBUTING.md +0 -1
- data/Gemfile +0 -41
- data/Guardfile +0 -24
- data/Rakefile +0 -22
- data/lib/rom/association_set.rb +0 -26
- data/lib/rom/command.rb +0 -173
- data/lib/rom/command_registry.rb +0 -153
- data/lib/rom/commands/class_interface.rb +0 -148
- data/lib/rom/commands/composite.rb +0 -54
- 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 -103
- 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 -88
- data/lib/rom/configuration_dsl/command.rb +0 -43
- data/lib/rom/configuration_dsl/command_dsl.rb +0 -35
- data/lib/rom/configuration_dsl/mapper.rb +0 -37
- data/lib/rom/configuration_dsl/mapper_dsl.rb +0 -44
- data/lib/rom/configuration_dsl/relation.rb +0 -26
- data/lib/rom/configuration_dsl.rb +0 -78
- data/lib/rom/configuration_plugin.rb +0 -17
- data/lib/rom/constants.rb +0 -30
- data/lib/rom/container.rb +0 -231
- data/lib/rom/create_container.rb +0 -61
- data/lib/rom/environment.rb +0 -70
- data/lib/rom/gateway.rb +0 -154
- data/lib/rom/global/plugin_dsl.rb +0 -49
- data/lib/rom/global.rb +0 -60
- data/lib/rom/lint/enumerable_dataset.rb +0 -54
- data/lib/rom/lint/gateway.rb +0 -94
- 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 -58
- data/lib/rom/memory/dataset.rb +0 -98
- data/lib/rom/memory/gateway.rb +0 -64
- data/lib/rom/memory/relation.rb +0 -49
- 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 -106
- data/lib/rom/plugin.rb +0 -17
- data/lib/rom/plugin_base.rb +0 -31
- 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 -17
- data/lib/rom/plugins/relation/key_inference.rb +0 -46
- data/lib/rom/plugins/relation/registry_reader.rb +0 -32
- data/lib/rom/plugins/relation/view/dsl.rb +0 -32
- data/lib/rom/plugins/relation/view.rb +0 -95
- data/lib/rom/relation/class_interface.rb +0 -230
- data/lib/rom/relation/composite.rb +0 -46
- data/lib/rom/relation/curried.rb +0 -104
- data/lib/rom/relation/graph.rb +0 -115
- data/lib/rom/relation/loaded.rb +0 -118
- data/lib/rom/relation/materializable.rb +0 -66
- data/lib/rom/relation/name.rb +0 -102
- data/lib/rom/relation.rb +0 -172
- data/lib/rom/relation_registry.rb +0 -9
- data/lib/rom/schema/dsl.rb +0 -58
- data/lib/rom/schema.rb +0 -89
- data/lib/rom/setup/auto_registration.rb +0 -69
- data/lib/rom/setup/auto_registration_strategies/base.rb +0 -11
- data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +0 -22
- data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +0 -19
- 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 -60
- data/lib/rom/setup/finalize.rb +0 -146
- data/lib/rom/setup.rb +0 -55
- data/lib/rom/support/configurable.rb +0 -80
- data/lib/rom/types.rb +0 -18
- 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 -26
- 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/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/integration/command_registry_spec.rb +0 -60
- data/spec/integration/commands/create_spec.rb +0 -177
- 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 -288
- data/spec/integration/commands/update_spec.rb +0 -109
- data/spec/integration/commands_spec.rb +0 -67
- 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/repositories/extending_relations_spec.rb +0 -58
- data/spec/integration/repositories/setting_logger_spec.rb +0 -34
- data/spec/integration/setup_spec.rb +0 -160
- data/spec/shared/command_behavior.rb +0 -28
- data/spec/shared/command_graph.rb +0 -50
- 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 -52
- data/spec/support/constant_leak_finder.rb +0 -14
- data/spec/support/mutant.rb +0 -10
- data/spec/support/types.rb +0 -5
- data/spec/test/memory_repository_lint_test.rb +0 -27
- data/spec/unit/rom/association_set_spec.rb +0 -23
- data/spec/unit/rom/commands/graph_spec.rb +0 -191
- data/spec/unit/rom/commands/lazy_spec.rb +0 -307
- data/spec/unit/rom/commands/result_spec.rb +0 -70
- data/spec/unit/rom/commands_spec.rb +0 -165
- 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 -99
- data/spec/unit/rom/create_container_spec.rb +0 -151
- 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/relation_spec.rb +0 -109
- data/spec/unit/rom/memory/repository_spec.rb +0 -12
- 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/key_inference_spec.rb +0 -85
- data/spec/unit/rom/plugins/relation/view_spec.rb +0 -51
- data/spec/unit/rom/relation/composite_spec.rb +0 -89
- data/spec/unit/rom/relation/curried_spec.rb +0 -52
- data/spec/unit/rom/relation/graph_spec.rb +0 -92
- data/spec/unit/rom/relation/lazy/combine_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/schema_spec.rb +0 -117
- data/spec/unit/rom/relation_spec.rb +0 -237
- data/spec/unit/rom/schema_spec.rb +0 -10
- data/spec/unit/rom/setup/auto_registration_spec.rb +0 -152
@@ -1,146 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ROM::Gateway do
|
4
|
-
|
5
|
-
subject(:gateway) { Class.new(ROM::Gateway).new }
|
6
|
-
|
7
|
-
describe '.setup' do
|
8
|
-
it 'sets up a gateway based on a type' do
|
9
|
-
gateway_class = Class.new(ROM::Gateway) do
|
10
|
-
attr_reader :args
|
11
|
-
|
12
|
-
def initialize(*args)
|
13
|
-
@args = args
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
allow(ROM::Gateway).to receive(:class_from_symbol)
|
18
|
-
.with(:wormhole).and_return(gateway_class)
|
19
|
-
|
20
|
-
args = %w(hello world)
|
21
|
-
gateway = ROM::Gateway.setup(:wormhole, *args)
|
22
|
-
|
23
|
-
expect(gateway).to be_instance_of(gateway_class)
|
24
|
-
expect(gateway.args).to eq(args)
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'raises an exception if the type is not supported' do
|
28
|
-
expect {
|
29
|
-
ROM::Gateway.setup(:bogus, "memory://test")
|
30
|
-
}.to raise_error(ROM::AdapterLoadError, /bogus/)
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'accepts a gateway instance' do
|
34
|
-
gateway = ROM::Gateway.new
|
35
|
-
expect(ROM::Gateway.setup(gateway)).to be(gateway)
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'raises an exception if instance and arguments are passed' do
|
39
|
-
gateway = ROM::Gateway.new
|
40
|
-
|
41
|
-
expect { ROM::Gateway.setup(gateway, 'foo://bar') }.to raise_error(
|
42
|
-
ArgumentError,
|
43
|
-
"Can't accept arguments when passing an instance"
|
44
|
-
)
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'raises an exception if a URI string is passed' do
|
48
|
-
expect { ROM::Gateway.setup('memory://test') }.to raise_error(
|
49
|
-
ArgumentError,
|
50
|
-
/URIs without an explicit scheme are not supported anymore/
|
51
|
-
)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe '.class_from_symbol' do
|
56
|
-
context 'when adapter is already present' do
|
57
|
-
before do
|
58
|
-
module Test
|
59
|
-
module Adapter
|
60
|
-
class Gateway
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
ROM.register_adapter(:test_adapter, Test::Adapter)
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'does not try to require an adapter if it is already present' do
|
69
|
-
klass = ROM::Gateway.class_from_symbol(:test_adapter)
|
70
|
-
|
71
|
-
expect(klass).to be(Test::Adapter::Gateway)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'instantiates a gateway based on type' do
|
76
|
-
klass = ROM::Gateway.class_from_symbol(:memory)
|
77
|
-
expect(klass).to be(ROM::Memory::Gateway)
|
78
|
-
end
|
79
|
-
|
80
|
-
it 'raises an exception if the type is not supported' do
|
81
|
-
expect { ROM::Gateway.class_from_symbol(:bogus) }
|
82
|
-
.to raise_error(ROM::AdapterLoadError, /bogus/)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
describe '#disconnect' do
|
87
|
-
it 'does nothing' do
|
88
|
-
expect(gateway.disconnect).to be(nil)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
describe '#logger' do
|
93
|
-
it 'does nothing' do
|
94
|
-
expect(gateway.logger).to be(nil)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe '#use_logger' do
|
99
|
-
it 'does nothing' do
|
100
|
-
expect(gateway.use_logger).to be(nil)
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'accepts parameters' do
|
104
|
-
params = [5, "mutations", "are", "nice"]
|
105
|
-
|
106
|
-
expect { gateway.use_logger(params) }.to_not raise_error
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
describe '#extend_command_class' do
|
111
|
-
it 'returns the class sent as 1st parameter' do
|
112
|
-
klass = Class.new.freeze
|
113
|
-
|
114
|
-
expect(gateway.extend_command_class(klass, "foo")).to eq(klass)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
describe '.adapter' do
|
119
|
-
let(:gateway_class) { Class.new(ROM::Gateway) }
|
120
|
-
|
121
|
-
it 'gets/sets the adapter' do
|
122
|
-
expect { gateway_class.adapter :custom }
|
123
|
-
.to change { gateway_class.adapter }
|
124
|
-
.from(nil)
|
125
|
-
.to(:custom)
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
describe "#adapter" do
|
130
|
-
before { Test::CustomGateway = Class.new(ROM::Gateway) }
|
131
|
-
|
132
|
-
let(:gateway) { Test::CustomGateway.new }
|
133
|
-
|
134
|
-
it 'returns class adapter' do
|
135
|
-
Test::CustomGateway.adapter :custom
|
136
|
-
expect(gateway.adapter).to eql :custom
|
137
|
-
end
|
138
|
-
|
139
|
-
it 'requires the adapter to be defined' do
|
140
|
-
expect { gateway.adapter }.to raise_error(
|
141
|
-
ROM::MissingAdapterIdentifierError, /Test::CustomGateway/
|
142
|
-
)
|
143
|
-
end
|
144
|
-
end # describe #adapter
|
145
|
-
|
146
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ROM::MapperRegistry do
|
4
|
-
subject(:registry) { ROM::MapperRegistry.new }
|
5
|
-
|
6
|
-
let(:user_mapper) { double('user_mapper') }
|
7
|
-
let(:index_mapper) { double('index_mapper') }
|
8
|
-
|
9
|
-
before do
|
10
|
-
registry[:users] = user_mapper
|
11
|
-
registry[:index] = index_mapper
|
12
|
-
end
|
13
|
-
|
14
|
-
describe '#by_path' do
|
15
|
-
it 'returns first matching mapper' do
|
16
|
-
mapper = registry.by_path('users')
|
17
|
-
|
18
|
-
expect(mapper).to be(user_mapper)
|
19
|
-
|
20
|
-
mapper = registry.by_path('users.index')
|
21
|
-
|
22
|
-
expect(mapper).to be(index_mapper)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rom/memory'
|
3
|
-
|
4
|
-
describe ROM::Memory::Commands do
|
5
|
-
let(:relation) do
|
6
|
-
Class.new(ROM::Relation[:memory]) do
|
7
|
-
schema do
|
8
|
-
attribute :id, ROM::Memory::Types::Int
|
9
|
-
attribute :name, ROM::Memory::Types::String
|
10
|
-
end
|
11
|
-
end.new(ROM::Memory::Dataset.new([]))
|
12
|
-
end
|
13
|
-
|
14
|
-
describe 'Create' do
|
15
|
-
subject(:command) { ROM::Commands::Create[:memory].build(relation) }
|
16
|
-
|
17
|
-
describe '#call' do
|
18
|
-
it 'uses default input handler' do
|
19
|
-
result = command.call([id: 1, name: 'Jane', haha: 'oops'])
|
20
|
-
|
21
|
-
expect(result).to eql([{ id: 1, name: 'Jane' }])
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe 'Update' do
|
27
|
-
subject(:command) { ROM::Commands::Update[:memory].build(relation) }
|
28
|
-
|
29
|
-
before do
|
30
|
-
relation.insert(id: 1, name: 'Jane')
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '#call' do
|
34
|
-
it 'uses default input handler' do
|
35
|
-
result = command
|
36
|
-
.new(relation.restrict(id: 1))
|
37
|
-
.call(name: 'Jane Doe', haha: 'oops')
|
38
|
-
|
39
|
-
expect(result).to eql([{ id: 1, name: 'Jane Doe' }])
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rom/lint/spec'
|
3
|
-
|
4
|
-
require 'rom/memory/dataset'
|
5
|
-
|
6
|
-
describe ROM::Memory::Dataset do
|
7
|
-
subject(:dataset) { ROM::Memory::Dataset.new(data) }
|
8
|
-
|
9
|
-
let(:data) do
|
10
|
-
[
|
11
|
-
{ name: 'Jane', email: 'jane@doe.org', age: 10 },
|
12
|
-
{ name: 'Jade', email: 'jade@doe.org', age: 11 },
|
13
|
-
{ name: 'Joe', email: 'joe@doe.org', age: 12 }
|
14
|
-
]
|
15
|
-
end
|
16
|
-
|
17
|
-
it_behaves_like "a rom enumerable dataset"
|
18
|
-
|
19
|
-
describe 'subclassing' do
|
20
|
-
it 'supports options' do
|
21
|
-
descendant = Class.new(ROM::Memory::Dataset) do
|
22
|
-
option :path, reader: true
|
23
|
-
end
|
24
|
-
|
25
|
-
dataset = descendant.new([1, 2, 3], path: '/data')
|
26
|
-
|
27
|
-
expect(dataset.to_a).to eql([1, 2, 3])
|
28
|
-
expect(dataset.path).to eql('/data')
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,109 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rom/lint/spec'
|
3
|
-
|
4
|
-
require 'rom/memory/dataset'
|
5
|
-
require 'rom/memory/relation'
|
6
|
-
|
7
|
-
describe ROM::Memory::Relation do
|
8
|
-
subject(:relation) { ROM::Memory::Relation.new(dataset) }
|
9
|
-
|
10
|
-
let(:dataset) do
|
11
|
-
ROM::Memory::Dataset.new([
|
12
|
-
{ name: 'Jane', email: 'jane@doe.org', age: 10 },
|
13
|
-
{ name: 'Jade', email: 'jade@doe.org', age: 11 },
|
14
|
-
{ name: 'Joe', email: 'joe@doe.org', age: 12 },
|
15
|
-
{ name: 'Jack', age: 11 },
|
16
|
-
{ name: 'Jill', email: 'jill@doe.org' },
|
17
|
-
{ name: 'John' },
|
18
|
-
{ name: 'Judy', email: 'judy@doe.org', age: 11 }
|
19
|
-
])
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '#take' do
|
23
|
-
it 'takes given number of tuples' do
|
24
|
-
expect(relation.take(2)).to match_array([
|
25
|
-
{ name: 'Jane', email: 'jane@doe.org', age: 10 },
|
26
|
-
{ name: 'Jade', email: 'jade@doe.org', age: 11 }
|
27
|
-
])
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe '#project' do
|
32
|
-
it 'projects tuples with the provided keys' do
|
33
|
-
expect(relation.project(:name, :age)).to match_array([
|
34
|
-
{ name: 'Jane', age: 10 },
|
35
|
-
{ name: 'Jade', age: 11 },
|
36
|
-
{ name: 'Joe', age: 12 },
|
37
|
-
{ name: 'Jack', age: 11 },
|
38
|
-
{ name: 'Jill' },
|
39
|
-
{ name: 'John' },
|
40
|
-
{ name: 'Judy', age: 11 }
|
41
|
-
])
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe '#restrict' do
|
46
|
-
it 'restricts data using criteria hash' do
|
47
|
-
expect(relation.restrict(age: 10)).to match_array([
|
48
|
-
{ name: 'Jane', email: 'jane@doe.org', age: 10 }
|
49
|
-
])
|
50
|
-
|
51
|
-
expect(relation.restrict(age: 10.0)).to match_array([])
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'restricts data using block' do
|
55
|
-
expect(relation.restrict { |tuple| tuple[:age].to_i > 10 }).to match_array([
|
56
|
-
{ name: 'Jade', email: 'jade@doe.org', age: 11 },
|
57
|
-
{ name: 'Joe', email: 'joe@doe.org', age: 12 },
|
58
|
-
{ name: 'Jack', age: 11 },
|
59
|
-
{ name: 'Judy', email: 'judy@doe.org', age: 11 }
|
60
|
-
])
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'allows to use array as a value' do
|
64
|
-
expect(relation.restrict(age: [10, 11])).to match_array([
|
65
|
-
{ name: 'Jane', email: 'jane@doe.org', age: 10 },
|
66
|
-
{ name: 'Jade', email: 'jade@doe.org', age: 11 },
|
67
|
-
{ name: 'Jack', age: 11 },
|
68
|
-
{ name: 'Judy', email: 'judy@doe.org', age: 11 }
|
69
|
-
])
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'allows to use regexp as a value' do
|
73
|
-
expect(relation.restrict(name: /\w{4}/)).to match_array([
|
74
|
-
{ name: 'Jane', email: 'jane@doe.org', age: 10 },
|
75
|
-
{ name: 'Jade', email: 'jade@doe.org', age: 11 },
|
76
|
-
{ name: 'Jack', age: 11 },
|
77
|
-
{ name: 'Jill', email: 'jill@doe.org' },
|
78
|
-
{ name: 'John' },
|
79
|
-
{ name: 'Judy', email: 'judy@doe.org', age: 11 }
|
80
|
-
])
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe '#order' do
|
85
|
-
it 'sorts data using provided attribute names' do
|
86
|
-
expect(relation.order(:age, :email).to_a).to eq([
|
87
|
-
{ name: 'Jane', age: 10, email: 'jane@doe.org' },
|
88
|
-
{ name: 'Jade', age: 11, email: 'jade@doe.org' },
|
89
|
-
{ name: 'Judy', age: 11, email: 'judy@doe.org' },
|
90
|
-
{ name: 'Jack', age: 11 },
|
91
|
-
{ name: 'Joe', age: 12, email: 'joe@doe.org' },
|
92
|
-
{ name: 'Jill', email: 'jill@doe.org' },
|
93
|
-
{ name: 'John' }
|
94
|
-
])
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'places nil before other values when required' do
|
98
|
-
expect(relation.order(:age, :email, nils_first: true).to_a).to eq([
|
99
|
-
{ name: 'John' },
|
100
|
-
{ name: 'Jill', email: 'jill@doe.org' },
|
101
|
-
{ name: 'Jane', age: 10, email: 'jane@doe.org' },
|
102
|
-
{ name: 'Jack', age: 11 },
|
103
|
-
{ name: 'Jade', age: 11, email: 'jade@doe.org' },
|
104
|
-
{ name: 'Judy', age: 11, email: 'judy@doe.org' },
|
105
|
-
{ name: 'Joe', age: 12, email: 'joe@doe.org' }
|
106
|
-
])
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rom/memory/storage'
|
3
|
-
|
4
|
-
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
|
-
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, schema_hash: schema_hash)
|
42
|
-
end
|
43
|
-
|
44
|
-
let(:schema_hash) do
|
45
|
-
double(:schema_hash)
|
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(schema_hash)
|
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(schema_hash).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
|