rom 0.9.1 → 1.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/.rubocop_todo.yml +30 -12
- data/.travis.yml +1 -1
- data/CHANGELOG.md +24 -0
- data/Gemfile +7 -3
- data/README.md +24 -11
- data/lib/rom.rb +9 -26
- data/lib/rom/command.rb +113 -75
- data/lib/rom/commands/class_interface.rb +115 -0
- data/lib/rom/commands/graph.rb +17 -23
- data/lib/rom/commands/graph/builder.rb +176 -0
- data/lib/rom/commands/graph/class_interface.rb +8 -2
- data/lib/rom/commands/graph/input_evaluator.rb +13 -9
- data/lib/rom/commands/lazy.rb +23 -17
- data/lib/rom/commands/lazy/create.rb +23 -0
- data/lib/rom/commands/lazy/delete.rb +27 -0
- data/lib/rom/commands/lazy/update.rb +34 -0
- data/lib/rom/commands/result.rb +14 -0
- data/lib/rom/commands/update.rb +0 -4
- data/lib/rom/configuration.rb +86 -0
- data/lib/rom/{setup_dsl/setup.rb → configuration_dsl.rb} +9 -7
- data/lib/rom/configuration_dsl/command.rb +43 -0
- data/lib/rom/{setup_dsl → configuration_dsl}/command_dsl.rb +5 -4
- data/lib/rom/configuration_dsl/mapper.rb +37 -0
- data/lib/rom/{setup_dsl → configuration_dsl}/mapper_dsl.rb +11 -5
- data/lib/rom/configuration_dsl/relation.rb +26 -0
- data/lib/rom/configuration_plugin.rb +17 -0
- data/lib/rom/constants.rb +5 -12
- data/lib/rom/container.rb +11 -8
- data/lib/rom/create_container.rb +61 -0
- data/lib/rom/environment.rb +27 -241
- data/lib/rom/gateway.rb +18 -2
- data/lib/rom/global.rb +24 -0
- data/lib/rom/global/plugin_dsl.rb +2 -0
- data/lib/rom/lint/spec.rb +0 -12
- data/lib/rom/lint/test.rb +0 -31
- data/lib/rom/memory/commands.rb +2 -2
- data/lib/rom/memory/gateway.rb +2 -0
- data/lib/rom/pipeline.rb +1 -1
- data/lib/rom/plugin_base.rb +1 -1
- data/lib/rom/plugin_registry.rb +12 -10
- data/lib/rom/plugins/configuration/configuration_dsl.rb +16 -0
- data/lib/rom/plugins/relation/key_inference.rb +31 -0
- data/lib/rom/plugins/relation/view.rb +90 -0
- data/lib/rom/plugins/relation/view/dsl.rb +32 -0
- data/lib/rom/relation.rb +1 -11
- data/lib/rom/relation/class_interface.rb +37 -50
- data/lib/rom/setup.rb +13 -104
- data/lib/rom/setup/auto_registration.rb +55 -0
- data/lib/rom/setup/finalize.rb +113 -127
- data/lib/rom/setup/finalize/commands.rb +67 -0
- data/lib/rom/setup/finalize/mappers.rb +36 -0
- data/lib/rom/setup/finalize/relations.rb +53 -0
- data/lib/rom/support/configurable.rb +21 -7
- data/lib/rom/version.rb +1 -1
- data/rakelib/mutant.rake +4 -1
- data/rom.gemspec +3 -4
- data/spec/fixtures/app/commands/create_user.rb +2 -0
- data/spec/fixtures/app/mappers/user_list.rb +2 -0
- data/spec/fixtures/app/relations/users.rb +2 -0
- data/spec/fixtures/lib/persistence/commands/create_user.rb +6 -0
- data/spec/fixtures/lib/persistence/mappers/user_list.rb +6 -0
- data/spec/fixtures/lib/persistence/relations/users.rb +6 -0
- data/spec/{unit/rom → integration}/command_registry_spec.rb +8 -9
- data/spec/integration/commands/create_spec.rb +17 -13
- data/spec/integration/commands/delete_spec.rb +12 -11
- data/spec/integration/commands/error_handling_spec.rb +5 -4
- data/spec/integration/commands/graph_builder_spec.rb +213 -0
- data/spec/integration/commands/graph_spec.rb +112 -49
- data/spec/integration/commands/update_spec.rb +14 -11
- data/spec/integration/commands_spec.rb +60 -0
- data/spec/integration/mappers/combine_spec.rb +7 -6
- data/spec/integration/mappers/deep_embedded_spec.rb +5 -6
- data/spec/integration/mappers/definition_dsl_spec.rb +19 -18
- data/spec/integration/mappers/embedded_spec.rb +11 -12
- data/spec/integration/mappers/exclude_spec.rb +5 -6
- data/spec/integration/mappers/fold_spec.rb +8 -7
- data/spec/integration/mappers/group_spec.rb +16 -15
- data/spec/integration/mappers/overwrite_attributes_value_spec.rb +5 -5
- data/spec/integration/mappers/prefix_separator_spec.rb +5 -7
- data/spec/integration/mappers/prefix_spec.rb +5 -7
- data/spec/integration/mappers/prefixing_attributes_spec.rb +7 -7
- data/spec/integration/mappers/registering_custom_mappers_spec.rb +4 -5
- data/spec/integration/mappers/renaming_attributes_spec.rb +18 -18
- data/spec/integration/mappers/step_spec.rb +11 -12
- data/spec/integration/mappers/symbolizing_attributes_spec.rb +11 -8
- data/spec/integration/mappers/unfold_spec.rb +9 -10
- data/spec/integration/mappers/ungroup_spec.rb +10 -11
- data/spec/integration/mappers/unwrap_spec.rb +10 -15
- data/spec/integration/mappers/wrap_spec.rb +16 -15
- data/spec/{unit/rom → integration}/memory/commands/create_spec.rb +7 -5
- data/spec/{unit/rom → integration}/memory/commands/delete_spec.rb +7 -5
- data/spec/{unit/rom → integration}/memory/commands/update_spec.rb +7 -5
- data/spec/integration/multi_env_spec.rb +16 -124
- data/spec/integration/multi_repo_spec.rb +9 -9
- data/spec/integration/relations/default_dataset_spec.rb +15 -0
- data/spec/integration/relations/inheritance_spec.rb +5 -7
- data/spec/integration/relations/reading_spec.rb +32 -65
- data/spec/integration/relations/registry_dsl_spec.rb +5 -4
- data/spec/integration/repositories/extending_relations_spec.rb +6 -7
- data/spec/integration/repositories/setting_logger_spec.rb +5 -7
- data/spec/integration/setup_spec.rb +49 -61
- data/spec/shared/command_graph.rb +50 -0
- data/spec/shared/container.rb +9 -0
- data/spec/shared/gateway_only.rb +6 -0
- data/spec/shared/no_container.rb +16 -0
- data/spec/shared/one_behavior.rb +4 -4
- data/spec/shared/users_and_tasks.rb +5 -17
- data/spec/spec_helper.rb +5 -3
- data/spec/test/memory_repository_lint_test.rb +1 -1
- data/spec/unit/rom/auto_registration_spec.rb +54 -0
- data/spec/unit/rom/commands/graph_spec.rb +18 -44
- data/spec/unit/rom/commands/lazy_spec.rb +246 -35
- data/spec/unit/rom/commands/result_spec.rb +56 -0
- data/spec/unit/rom/commands_spec.rb +9 -73
- data/spec/unit/rom/configurable_spec.rb +49 -0
- data/spec/unit/rom/configuration_spec.rb +61 -0
- data/spec/unit/rom/container_spec.rb +39 -33
- data/spec/unit/rom/create_container_spec.rb +151 -0
- data/spec/unit/rom/environment_spec.rb +123 -0
- data/spec/unit/rom/gateway_spec.rb +58 -2
- data/spec/unit/rom/global_spec.rb +10 -7
- data/spec/unit/rom/plugin_spec.rb +44 -25
- data/spec/unit/rom/plugins/relation/key_inference_spec.rb +27 -0
- data/spec/unit/rom/plugins/relation/view_spec.rb +47 -0
- data/spec/unit/rom/relation/composite_spec.rb +20 -20
- data/spec/unit/rom/relation/curried_spec.rb +10 -11
- data/spec/unit/rom/relation/graph_spec.rb +27 -27
- data/spec/unit/rom/relation/lazy/combine_spec.rb +26 -20
- data/spec/unit/rom/relation/lazy_spec.rb +38 -38
- data/spec/unit/rom/relation/loaded_spec.rb +2 -3
- data/spec/unit/rom/relation_spec.rb +39 -2
- metadata +58 -66
- data/lib/rom/commands/abstract.rb +0 -184
- data/lib/rom/environment_plugin.rb +0 -17
- data/lib/rom/environment_plugins/auto_registration.rb +0 -38
- data/lib/rom/repository.rb +0 -16
- data/lib/rom/setup_dsl/command.rb +0 -36
- data/lib/rom/setup_dsl/mapper.rb +0 -32
- data/lib/rom/setup_dsl/relation.rb +0 -30
- data/spec/integration/inline_setup_spec.rb +0 -65
- data/spec/unit/rom/repository_spec.rb +0 -12
- data/spec/unit/rom/setup_spec.rb +0 -253
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'rom/plugin_base'
|
2
|
-
|
3
|
-
module ROM
|
4
|
-
# EnvironmentPlugin is a simple object used to store environment plugin configurations
|
5
|
-
#
|
6
|
-
# @private
|
7
|
-
class EnvironmentPlugin < PluginBase
|
8
|
-
# Apply this plugin to the provided environment
|
9
|
-
#
|
10
|
-
# @param [ROM::Environment] environment
|
11
|
-
#
|
12
|
-
# @api private
|
13
|
-
def apply_to(environment, options = {})
|
14
|
-
mod.apply(environment, options)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module ROM
|
2
|
-
module EnvironmentPlugins
|
3
|
-
# Automatically registers relations, mappers and commands as they are defined
|
4
|
-
#
|
5
|
-
# For now this plugin is always enabled
|
6
|
-
#
|
7
|
-
# @api public
|
8
|
-
module AutoRegistration
|
9
|
-
# Say "yes" for envs that have this plugin enabled
|
10
|
-
#
|
11
|
-
# By default it says "no" in Environment#auto_registration?
|
12
|
-
#
|
13
|
-
# @api private
|
14
|
-
def auto_registration?
|
15
|
-
true
|
16
|
-
end
|
17
|
-
|
18
|
-
# @api private
|
19
|
-
def self.apply(environment, options = {})
|
20
|
-
environment.extend(AutoRegistration)
|
21
|
-
|
22
|
-
if_proc = options.fetch(:if, ->(*args) { true })
|
23
|
-
|
24
|
-
ROM::Relation.on(:inherited) do |relation|
|
25
|
-
environment.register_relation(relation) if if_proc.call(relation)
|
26
|
-
end
|
27
|
-
|
28
|
-
ROM::Command.on(:inherited) do |command|
|
29
|
-
environment.register_command(command) if if_proc.call(command)
|
30
|
-
end
|
31
|
-
|
32
|
-
ROM::Mapper.on(:inherited) do |mapper|
|
33
|
-
environment.register_mapper(mapper) if if_proc.call(mapper)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
data/lib/rom/repository.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'rom/gateway'
|
2
|
-
|
3
|
-
module ROM
|
4
|
-
# Abstract repository class
|
5
|
-
#
|
6
|
-
# This is a transitional placeholder, deprecating the Repository class.
|
7
|
-
#
|
8
|
-
# @api public
|
9
|
-
class Repository < Gateway
|
10
|
-
def self.inherited(_klass)
|
11
|
-
ROM::Deprecations.announce "Inheriting from ROM::Repository is", <<-MSG
|
12
|
-
Please inherit from ROM::Gateway instead.
|
13
|
-
MSG
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module ROM
|
2
|
-
# Setup DSL-specific command extensions
|
3
|
-
#
|
4
|
-
# @private
|
5
|
-
class Command
|
6
|
-
# Generate a command subclass
|
7
|
-
#
|
8
|
-
# This is used by Setup#commands DSL and its `define` block
|
9
|
-
#
|
10
|
-
# @api private
|
11
|
-
def self.build_class(name, relation, options = EMPTY_HASH, &block)
|
12
|
-
type = options.fetch(:type) { name }
|
13
|
-
command_type = Inflector.classify(type)
|
14
|
-
adapter = options.fetch(:adapter)
|
15
|
-
parent = adapter_namespace(adapter).const_get(command_type)
|
16
|
-
class_name = generate_class_name(adapter, command_type, relation)
|
17
|
-
|
18
|
-
ClassBuilder.new(name: class_name, parent: parent).call do |klass|
|
19
|
-
klass.register_as(name)
|
20
|
-
klass.relation(relation)
|
21
|
-
klass.class_eval(&block) if block
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# Create a command subclass name based on adapter, type and relation
|
26
|
-
#
|
27
|
-
# @api private
|
28
|
-
def self.generate_class_name(adapter, command_type, relation)
|
29
|
-
pieces = ['ROM']
|
30
|
-
pieces << Inflector.classify(adapter)
|
31
|
-
pieces << 'Commands'
|
32
|
-
pieces << "#{command_type}[#{Inflector.classify(relation)}s]"
|
33
|
-
pieces.join('::')
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/lib/rom/setup_dsl/mapper.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
module ROM
|
2
|
-
# Setup DSL-specific mapper extensions
|
3
|
-
#
|
4
|
-
# @private
|
5
|
-
class Mapper
|
6
|
-
# Generate a mapper subclass
|
7
|
-
#
|
8
|
-
# This is used by Setup#mappers DSL
|
9
|
-
#
|
10
|
-
# @api private
|
11
|
-
def self.build_class(name, options = EMPTY_HASH, &block)
|
12
|
-
class_name = "ROM::Mapper[#{name}]"
|
13
|
-
|
14
|
-
parent = options[:parent]
|
15
|
-
inherit_header = options.fetch(:inherit_header) { Mapper.inherit_header }
|
16
|
-
|
17
|
-
parent_class =
|
18
|
-
if parent
|
19
|
-
ROM.boot.mapper_classes.detect { |klass| klass.relation == parent }
|
20
|
-
else
|
21
|
-
self
|
22
|
-
end
|
23
|
-
|
24
|
-
ClassBuilder.new(name: class_name, parent: parent_class).call do |klass|
|
25
|
-
klass.relation(name)
|
26
|
-
klass.inherit_header(inherit_header)
|
27
|
-
|
28
|
-
klass.class_eval(&block) if block
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module ROM
|
2
|
-
# Setup DSL-specific relation extensions
|
3
|
-
#
|
4
|
-
# @private
|
5
|
-
class Relation
|
6
|
-
# Generate a relation subclass
|
7
|
-
#
|
8
|
-
# This is used by Setup#relation DSL
|
9
|
-
#
|
10
|
-
# @api private
|
11
|
-
def self.build_class(name, options = EMPTY_HASH)
|
12
|
-
class_name = "ROM::Relation[#{Inflector.camelize(name)}]"
|
13
|
-
adapter = options.fetch(:adapter)
|
14
|
-
|
15
|
-
ClassBuilder.new(name: class_name, parent: self[adapter]).call do |klass|
|
16
|
-
klass.gateway(options.fetch(:gateway) {
|
17
|
-
if options.key?(:repository)
|
18
|
-
ROM::Deprecations.announce "The :repository key is", <<-MSG
|
19
|
-
Please use `gateway: :#{options.fetch(:repository)}` instead.
|
20
|
-
MSG
|
21
|
-
options.fetch(:repository)
|
22
|
-
else
|
23
|
-
:default
|
24
|
-
end
|
25
|
-
})
|
26
|
-
klass.dataset(name)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rom/memory'
|
3
|
-
|
4
|
-
RSpec.describe 'Inline setup' do
|
5
|
-
before do
|
6
|
-
module Test
|
7
|
-
module Dummy
|
8
|
-
class Gateway < ROM::Memory::Gateway
|
9
|
-
def schema
|
10
|
-
[:users, :tasks]
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class Relation < ROM::Relation
|
15
|
-
adapter :dummy
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
ROM.register_adapter :dummy, Test::Dummy
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'using global env' do
|
24
|
-
it 'auto-registers components' do
|
25
|
-
rom = ROM.setup(:dummy) do
|
26
|
-
relation(:users)
|
27
|
-
end
|
28
|
-
|
29
|
-
users = rom.relation(:users)
|
30
|
-
|
31
|
-
expect(users).to be_kind_of(Test::Dummy::Relation)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'using local env' do
|
36
|
-
it 'auto-registers components' do
|
37
|
-
env = ROM::Environment.new
|
38
|
-
|
39
|
-
rom = env.setup(:dummy) do
|
40
|
-
relation(:users)
|
41
|
-
end
|
42
|
-
|
43
|
-
users = rom.relation(:users)
|
44
|
-
|
45
|
-
expect(users).to be_kind_of(Test::Dummy::Relation)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context 'defining a relation with custom dataset name' do
|
50
|
-
it 'registers under provided name and uses custom dataset' do
|
51
|
-
env = ROM::Environment.new
|
52
|
-
|
53
|
-
rom = env.setup(:dummy) do
|
54
|
-
relation(:super_users) do
|
55
|
-
dataset :users
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
users = rom.relation(:super_users)
|
60
|
-
|
61
|
-
expect(users).to be_kind_of(Test::Dummy::Relation)
|
62
|
-
expect(users.dataset).to be(rom.gateways[:default].dataset(:users))
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
data/spec/unit/rom/setup_spec.rb
DELETED
@@ -1,253 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ROM::Setup do
|
4
|
-
it 'is configurable' do
|
5
|
-
setup = ROM::Setup.new({})
|
6
|
-
|
7
|
-
setup.configure do |config|
|
8
|
-
config.sql.infer_relations = false
|
9
|
-
end
|
10
|
-
|
11
|
-
expect(setup.config.sql.infer_relations).to be(false)
|
12
|
-
expect(setup.config[:sql][:infer_relations]).to be(false)
|
13
|
-
|
14
|
-
expect(setup.config).to respond_to(:sql)
|
15
|
-
expect(setup.config).to respond_to(:other=)
|
16
|
-
|
17
|
-
setup.config.freeze
|
18
|
-
|
19
|
-
expect(setup.config.other).to be(nil)
|
20
|
-
expect(setup.config.key?(:other)).to be(false)
|
21
|
-
expect(setup.config.key?(:sql)).to be(true)
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'is configurable via settings hash' do
|
25
|
-
setup = ROM.setup(:memory, 'something', infer_schema: false)
|
26
|
-
|
27
|
-
setup.finalize
|
28
|
-
|
29
|
-
expect(setup.config.gateways.default.infer_schema).to be(false)
|
30
|
-
|
31
|
-
setup = ROM.setup(:memory, infer_schema: false)
|
32
|
-
|
33
|
-
setup.finalize
|
34
|
-
|
35
|
-
expect(setup.config.gateways.default.infer_schema).to be(false)
|
36
|
-
|
37
|
-
setup = ROM.setup(default: [:memory, infer_schema: false])
|
38
|
-
|
39
|
-
setup.finalize
|
40
|
-
|
41
|
-
expect(setup.config.gateways.default.infer_schema).to be(false)
|
42
|
-
end
|
43
|
-
|
44
|
-
describe '#finalize' do
|
45
|
-
context 'with gateway that supports schema inferring' do
|
46
|
-
it 'builds relation from inferred schema' do
|
47
|
-
setup = ROM.setup(:memory)
|
48
|
-
repo = setup.default
|
49
|
-
dataset = double('dataset')
|
50
|
-
|
51
|
-
allow(repo).to receive(:schema).and_return([:users])
|
52
|
-
allow(repo).to receive(:dataset).with(:users).and_return(dataset)
|
53
|
-
|
54
|
-
rom = setup.finalize
|
55
|
-
|
56
|
-
expect(rom.relations.users.dataset).to be(dataset)
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'skips inferring a relation when there is a defined one already' do
|
60
|
-
setup = ROM.setup(:memory)
|
61
|
-
repo = setup.default
|
62
|
-
dataset = double('dataset')
|
63
|
-
|
64
|
-
allow(repo).to receive(:schema).and_return([:test_users])
|
65
|
-
allow(repo).to receive(:dataset).with(:test_users).and_return(dataset)
|
66
|
-
|
67
|
-
class Test::Users < ROM::Relation[:memory]; end
|
68
|
-
|
69
|
-
expect { setup.finalize }.not_to raise_error
|
70
|
-
|
71
|
-
rom = setup.env
|
72
|
-
|
73
|
-
expect(rom.relations.test_users).to be_instance_of(Test::Users)
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'skips inferring when it is turned off for the adapter' do
|
77
|
-
setup = ROM.setup(:memory)
|
78
|
-
|
79
|
-
setup.configure { |config| config.gateways.default.infer_relations = false }
|
80
|
-
|
81
|
-
repo = setup.default
|
82
|
-
|
83
|
-
expect(repo).not_to receive(:schema)
|
84
|
-
|
85
|
-
setup.finalize
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'infers configured relations' do
|
89
|
-
setup = ROM.setup(:memory)
|
90
|
-
|
91
|
-
setup.configure do |config|
|
92
|
-
config.gateways.default.inferrable_relations = [:test_tasks]
|
93
|
-
end
|
94
|
-
|
95
|
-
repo = setup.default
|
96
|
-
dataset = double('dataset')
|
97
|
-
|
98
|
-
allow(repo).to receive(:schema).and_return([:test_tasks, :test_users])
|
99
|
-
|
100
|
-
expect(repo).to receive(:dataset).with(:test_tasks).and_return(dataset)
|
101
|
-
expect(repo).to_not receive(:dataset).with(:test_users)
|
102
|
-
|
103
|
-
rom = setup.finalize
|
104
|
-
|
105
|
-
expect(rom.relations.elements.key?(:test_users)).to be(false)
|
106
|
-
expect(rom.relations[:test_tasks]).to be_kind_of(ROM::Memory::Relation)
|
107
|
-
expect(rom.relations[:test_tasks].dataset).to be(dataset)
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'skip inferring blacklisted relations' do
|
111
|
-
setup = ROM.setup(:memory)
|
112
|
-
|
113
|
-
setup.configure do |config|
|
114
|
-
config.gateways.default.not_inferrable_relations = [:test_users]
|
115
|
-
end
|
116
|
-
|
117
|
-
repo = setup.default
|
118
|
-
dataset = double('dataset')
|
119
|
-
|
120
|
-
allow(repo).to receive(:schema).and_return([:test_tasks, :test_users])
|
121
|
-
|
122
|
-
expect(repo).to receive(:dataset).with(:test_tasks).and_return(dataset)
|
123
|
-
expect(repo).to_not receive(:dataset).with(:test_users)
|
124
|
-
|
125
|
-
rom = setup.finalize
|
126
|
-
|
127
|
-
expect(rom.relations.elements.key?(:test_users)).to be(false)
|
128
|
-
expect(rom.relations[:test_tasks]).to be_kind_of(ROM::Memory::Relation)
|
129
|
-
expect(rom.relations[:test_tasks].dataset).to be(dataset)
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'can register multiple relations with same dataset' do
|
133
|
-
setup = ROM.setup(:memory)
|
134
|
-
|
135
|
-
Class.new(ROM::Relation[:memory]) do
|
136
|
-
dataset :fruits
|
137
|
-
register_as :apples
|
138
|
-
|
139
|
-
def apple?
|
140
|
-
true
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
Class.new(ROM::Relation[:memory]) do
|
145
|
-
dataset :fruits
|
146
|
-
register_as :oranges
|
147
|
-
|
148
|
-
def orange?
|
149
|
-
true
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
rom = setup.finalize
|
154
|
-
|
155
|
-
expect(rom.relations.apples).to be_apple
|
156
|
-
expect(rom.relations.oranges).to be_orange
|
157
|
-
expect(rom.relations.apples).to_not eq(rom.relations.oranges)
|
158
|
-
end
|
159
|
-
|
160
|
-
it "raises an error when registering relations with the same `register_as`" do
|
161
|
-
setup = ROM.setup(:memory)
|
162
|
-
|
163
|
-
Class.new(ROM::Relation[:memory]) do
|
164
|
-
dataset :guests
|
165
|
-
register_as :users
|
166
|
-
end
|
167
|
-
|
168
|
-
Class.new(ROM::Relation[:memory]) do
|
169
|
-
dataset :admins
|
170
|
-
register_as :users
|
171
|
-
end
|
172
|
-
|
173
|
-
expect { setup.finalize }.to raise_error(
|
174
|
-
ROM::RelationAlreadyDefinedError, /register_as :users/
|
175
|
-
)
|
176
|
-
end
|
177
|
-
|
178
|
-
it 'resets boot to nil' do
|
179
|
-
setup = ROM.setup(:memory)
|
180
|
-
|
181
|
-
allow(setup).to receive(:container).and_raise(StandardError)
|
182
|
-
|
183
|
-
expect { ROM.finalize }.to raise_error(StandardError)
|
184
|
-
expect(ROM.boot).to be(nil)
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
context 'empty setup' do
|
189
|
-
let(:setup) { ROM::Setup.new({}) }
|
190
|
-
let(:env) { setup.finalize }
|
191
|
-
|
192
|
-
it 'builds empty gateways' do
|
193
|
-
expect(env.gateways).to eql({})
|
194
|
-
end
|
195
|
-
|
196
|
-
it 'builds empty relations' do
|
197
|
-
expect(env.relations).to eql(ROM::RelationRegistry.new)
|
198
|
-
end
|
199
|
-
|
200
|
-
it 'builds empty mappers' do
|
201
|
-
expect(env.mappers).to eql(ROM::Registry.new)
|
202
|
-
end
|
203
|
-
|
204
|
-
it 'builds empty commands' do
|
205
|
-
expect(env.commands).to eql(ROM::Registry.new)
|
206
|
-
end
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
describe '#method_missing' do
|
211
|
-
it 'returns a gateway if it is defined' do
|
212
|
-
repo = double('repo')
|
213
|
-
setup = ROM::Setup.new(repo: repo)
|
214
|
-
|
215
|
-
expect(setup.repo).to be(repo)
|
216
|
-
end
|
217
|
-
|
218
|
-
it 'raises error if repo is not defined' do
|
219
|
-
setup = ROM::Setup.new({})
|
220
|
-
|
221
|
-
expect { setup.not_here }.to raise_error(NoMethodError, /not_here/)
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
describe '#[]' do
|
226
|
-
it 'returns a gateway if it is defined' do
|
227
|
-
repo = double('repo')
|
228
|
-
setup = ROM::Setup.new(repo: repo)
|
229
|
-
|
230
|
-
expect(setup[:repo]).to be(repo)
|
231
|
-
end
|
232
|
-
|
233
|
-
it 'raises error if repo is not defined' do
|
234
|
-
setup = ROM::Setup.new({})
|
235
|
-
|
236
|
-
expect { setup[:not_here] }.to raise_error(KeyError, /not_here/)
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
describe 'defining components when adapter was not registered' do
|
241
|
-
it 'raises error when trying to define a relation' do
|
242
|
-
expect {
|
243
|
-
Class.new(ROM::Relation[:not_here])
|
244
|
-
}.to raise_error(ROM::AdapterNotPresentError, /not_here/)
|
245
|
-
end
|
246
|
-
|
247
|
-
it 'raises error when trying to define a command' do
|
248
|
-
expect {
|
249
|
-
Class.new(ROM::Commands::Create[:not_here])
|
250
|
-
}.to raise_error(ROM::AdapterNotPresentError, /not_here/)
|
251
|
-
end
|
252
|
-
end
|
253
|
-
end
|