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
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'rom/support/registry'
|
2
|
+
require 'rom/command_registry'
|
3
|
+
|
4
|
+
module ROM
|
5
|
+
class Finalize
|
6
|
+
class FinalizeCommands
|
7
|
+
# Build command registry hash for provided relations
|
8
|
+
#
|
9
|
+
# @param [RelationRegistry] relations registry
|
10
|
+
# @param [Hash] gateways
|
11
|
+
# @param [Array] command_classes a list of command subclasses
|
12
|
+
#
|
13
|
+
# @api private
|
14
|
+
def initialize(relations, gateways, command_classes)
|
15
|
+
@relations = relations
|
16
|
+
@gateways = gateways
|
17
|
+
@command_classes = command_classes
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [Hash]
|
21
|
+
#
|
22
|
+
# @api private
|
23
|
+
def run!
|
24
|
+
registry = @command_classes.each_with_object({}) do |klass, h|
|
25
|
+
rel_name = klass.relation
|
26
|
+
next unless rel_name
|
27
|
+
|
28
|
+
relation = @relations[rel_name]
|
29
|
+
name = klass.register_as || klass.default_name
|
30
|
+
|
31
|
+
gateway = @gateways[relation.class.gateway]
|
32
|
+
gateway.extend_command_class(klass, relation.dataset)
|
33
|
+
|
34
|
+
klass.send(:include, relation_methods_mod(relation.class))
|
35
|
+
|
36
|
+
(h[rel_name] ||= {})[name] = klass.build(relation)
|
37
|
+
end
|
38
|
+
|
39
|
+
commands = registry.each_with_object({}) do |(name, rel_commands), h|
|
40
|
+
h[name] = CommandRegistry.new(rel_commands)
|
41
|
+
end
|
42
|
+
|
43
|
+
Registry.new(commands)
|
44
|
+
end
|
45
|
+
|
46
|
+
# @api private
|
47
|
+
def relation_methods_mod(relation_class)
|
48
|
+
mod = Module.new
|
49
|
+
relation_class.view_methods.each do |meth|
|
50
|
+
mod.module_eval <<-RUBY
|
51
|
+
def #{meth}(*args)
|
52
|
+
response = relation.public_send(:#{meth}, *args)
|
53
|
+
|
54
|
+
if response.is_a?(relation.class)
|
55
|
+
new(response)
|
56
|
+
else
|
57
|
+
response
|
58
|
+
end
|
59
|
+
end
|
60
|
+
RUBY
|
61
|
+
end
|
62
|
+
|
63
|
+
mod
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rom/support/registry'
|
2
|
+
|
3
|
+
module ROM
|
4
|
+
class Finalize
|
5
|
+
class FinalizeMappers
|
6
|
+
# @api private
|
7
|
+
def initialize(mapper_classes, mapper_objects)
|
8
|
+
@mapper_classes = mapper_classes
|
9
|
+
@mapper_objects = mapper_objects
|
10
|
+
end
|
11
|
+
|
12
|
+
# @api private
|
13
|
+
def run!
|
14
|
+
registry = @mapper_classes.each_with_object({}) do |klass, h|
|
15
|
+
name = klass.register_as || klass.relation
|
16
|
+
(h[klass.base_relation] ||= {})[name] = klass.build
|
17
|
+
end
|
18
|
+
|
19
|
+
registry_hash = registry.each_with_object({}).each { |(relation, mappers), h|
|
20
|
+
h[relation] = MapperRegistry.new(mappers)
|
21
|
+
}
|
22
|
+
|
23
|
+
@mapper_objects.each do |relation, mappers|
|
24
|
+
if registry_hash.key?(relation)
|
25
|
+
mappers_registry = registry_hash[relation]
|
26
|
+
mappers.each { |name, mapper| mappers_registry[name] = mapper }
|
27
|
+
else
|
28
|
+
registry_hash[relation] = MapperRegistry.new(mappers)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
Registry.new(registry_hash)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rom/relation_registry'
|
2
|
+
|
3
|
+
module ROM
|
4
|
+
class Finalize
|
5
|
+
class FinalizeRelations
|
6
|
+
# Build relation registry of specified descendant classes
|
7
|
+
#
|
8
|
+
# This is used by the setup
|
9
|
+
#
|
10
|
+
# @param [Hash] gateways
|
11
|
+
# @param [Array] relation_classes a list of relation descendants
|
12
|
+
#
|
13
|
+
# @api private
|
14
|
+
def initialize(gateways, relation_classes)
|
15
|
+
@gateways = gateways
|
16
|
+
@relation_classes = relation_classes
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Hash]
|
20
|
+
#
|
21
|
+
# @api private
|
22
|
+
def run!
|
23
|
+
registry = {}
|
24
|
+
|
25
|
+
@relation_classes.each do |klass|
|
26
|
+
# TODO: raise a meaningful error here and add spec covering the case
|
27
|
+
# where klass' gateway points to non-existant repo
|
28
|
+
gateway = @gateways.fetch(klass.gateway)
|
29
|
+
ds_proc = klass.dataset_proc || -> { self }
|
30
|
+
dataset = gateway.dataset(klass.dataset).instance_exec(&ds_proc)
|
31
|
+
|
32
|
+
relation = klass.new(dataset, __registry__: registry)
|
33
|
+
|
34
|
+
name = klass.register_as
|
35
|
+
|
36
|
+
if registry.key?(name)
|
37
|
+
raise RelationAlreadyDefinedError,
|
38
|
+
"Relation with `register_as #{name.inspect}` registered more " \
|
39
|
+
"than once"
|
40
|
+
end
|
41
|
+
|
42
|
+
registry[name] = relation
|
43
|
+
end
|
44
|
+
|
45
|
+
registry.each_value do |relation|
|
46
|
+
relation.class.finalize(registry, relation)
|
47
|
+
end
|
48
|
+
|
49
|
+
RelationRegistry.new(registry)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -7,8 +7,8 @@ module ROM
|
|
7
7
|
attr_reader :settings
|
8
8
|
|
9
9
|
# @api private
|
10
|
-
def initialize
|
11
|
-
@settings =
|
10
|
+
def initialize(settings = {})
|
11
|
+
@settings = settings
|
12
12
|
end
|
13
13
|
|
14
14
|
# @api public
|
@@ -23,19 +23,33 @@ module ROM
|
|
23
23
|
|
24
24
|
# @api private
|
25
25
|
def freeze
|
26
|
-
settings.each_value
|
26
|
+
settings.each_value(&:freeze)
|
27
27
|
super
|
28
28
|
end
|
29
29
|
|
30
30
|
# @api private
|
31
|
-
def respond_to_missing?(
|
31
|
+
def respond_to_missing?(_name, _include_private = false)
|
32
32
|
true
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
|
+
def dup
|
36
|
+
self.class.new(dup_settings(settings))
|
37
|
+
end
|
38
|
+
|
35
39
|
private
|
40
|
+
|
41
|
+
def dup_settings(settings)
|
42
|
+
settings.each_with_object({}) do |(key, value), new_settings|
|
43
|
+
if value.is_a?(self.class)
|
44
|
+
new_settings[key] = value.dup
|
45
|
+
else
|
46
|
+
new_settings[key] = value
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
36
50
|
|
37
51
|
# @api private
|
38
|
-
def method_missing(meth, *args, &
|
52
|
+
def method_missing(meth, *args, &_block)
|
39
53
|
return settings.fetch(meth, nil) if frozen?
|
40
54
|
|
41
55
|
name = meth.to_s
|
@@ -50,7 +64,7 @@ module ROM
|
|
50
64
|
|
51
65
|
# @api private
|
52
66
|
def writer?(name)
|
53
|
-
!
|
67
|
+
!WRITER_REGEXP.match(name).nil?
|
54
68
|
end
|
55
69
|
end
|
56
70
|
|
data/lib/rom/version.rb
CHANGED
data/rakelib/mutant.rake
CHANGED
@@ -4,11 +4,14 @@ task :mutant do
|
|
4
4
|
if subject == 'mutant'
|
5
5
|
abort "usage: rake mutant SUBJECT\nexample: rake mutant ROM::Header"
|
6
6
|
else
|
7
|
+
sep = subject.include?('#') ? '#' : '.'
|
8
|
+
ns = subject.split(sep).first
|
9
|
+
|
7
10
|
opts = {
|
8
11
|
'include' => 'lib',
|
9
12
|
'require' => 'rom',
|
10
13
|
'use' => 'rspec',
|
11
|
-
'ignore-subject' => "#{
|
14
|
+
'ignore-subject' => "#{ns}#respond_to_missing?"
|
12
15
|
}.to_a.map { |k, v| "--#{k} #{v}" }.join(' ')
|
13
16
|
|
14
17
|
exec("bundle exec mutant #{opts} #{subject}")
|
data/rom.gemspec
CHANGED
@@ -15,10 +15,9 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.test_files = `git ls-files -- {spec}/*`.split("\n")
|
16
16
|
gem.license = 'MIT'
|
17
17
|
|
18
|
-
gem.add_runtime_dependency '
|
19
|
-
gem.add_runtime_dependency '
|
20
|
-
gem.add_runtime_dependency 'rom-
|
21
|
-
gem.add_runtime_dependency 'rom-mapper', '~> 0.2', '>= 0.2.0'
|
18
|
+
gem.add_runtime_dependency 'dry-equalizer', '~> 0.2'
|
19
|
+
gem.add_runtime_dependency 'rom-support', '~> 1.0.0.beta1'
|
20
|
+
gem.add_runtime_dependency 'rom-mapper', '~> 0.3.0.beta1'
|
22
21
|
|
23
22
|
gem.add_development_dependency 'rake', '~> 10.3'
|
24
23
|
gem.add_development_dependency 'rspec', '~> 3.3'
|
@@ -1,19 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'ROM::CommandRegistry' do
|
4
|
-
|
4
|
+
include_context 'container'
|
5
5
|
|
6
|
-
let(:
|
7
|
-
let(:users) { env.command(:users) }
|
6
|
+
let(:users) { container.command(:users) }
|
8
7
|
|
9
8
|
before do
|
10
|
-
|
9
|
+
configuration.relation(:users)
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
11
|
+
configuration.register_command(Class.new(ROM::Commands::Create[:memory]) do
|
12
|
+
register_as :create
|
13
|
+
relation :users
|
14
|
+
validator proc { |input| raise(ROM::CommandError) unless input[:name] }
|
15
|
+
end)
|
17
16
|
end
|
18
17
|
|
19
18
|
describe '#try' do
|
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'Commands / Create' do
|
4
|
+
include_context 'container'
|
4
5
|
include_context 'users and tasks'
|
5
6
|
|
6
|
-
let(:users) {
|
7
|
-
let(:tasks) {
|
7
|
+
let(:users) { container.commands.users }
|
8
|
+
let(:tasks) { container.commands.tasks }
|
8
9
|
|
9
10
|
before do
|
10
11
|
module Test
|
@@ -19,8 +20,8 @@ describe 'Commands / Create' do
|
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
22
|
-
|
23
|
-
|
23
|
+
configuration.relation(:users)
|
24
|
+
configuration.relation(:tasks)
|
24
25
|
|
25
26
|
class Test::CreateUser < ROM::Commands::Create[:memory]
|
26
27
|
relation :users
|
@@ -62,6 +63,9 @@ describe 'Commands / Create' do
|
|
62
63
|
attribute :name
|
63
64
|
attribute :title
|
64
65
|
end
|
66
|
+
|
67
|
+
configuration.register_command(Test::CreateUser, Test::CreateTask)
|
68
|
+
configuration.register_mapper(Test::UserMapper, Test::TaskMapper)
|
65
69
|
end
|
66
70
|
|
67
71
|
it 'inserts user on successful validation' do
|
@@ -87,12 +91,12 @@ describe 'Commands / Create' do
|
|
87
91
|
|
88
92
|
expect(result.error).to be_instance_of(Test::ValidationError)
|
89
93
|
expect(result.error.message).to eql(":name and :email are required")
|
90
|
-
expect(
|
94
|
+
expect(container.relations.users.count).to be(2)
|
91
95
|
end
|
92
96
|
|
93
97
|
describe '"result" option' do
|
94
98
|
it 'returns a single tuple when set to :one' do
|
95
|
-
|
99
|
+
configuration.commands(:users) do
|
96
100
|
define(:create_one, type: :create) do
|
97
101
|
result :one
|
98
102
|
end
|
@@ -109,12 +113,12 @@ describe 'Commands / Create' do
|
|
109
113
|
|
110
114
|
it 'allows only valid result types' do
|
111
115
|
expect {
|
112
|
-
|
116
|
+
configuration.commands(:users) do
|
113
117
|
define(:create_one, type: :create) do
|
114
118
|
result :invalid_type
|
115
119
|
end
|
116
120
|
end
|
117
|
-
|
121
|
+
container
|
118
122
|
}.to raise_error(ROM::Options::InvalidOptionValueError)
|
119
123
|
end
|
120
124
|
end
|
@@ -125,7 +129,7 @@ describe 'Commands / Create' do
|
|
125
129
|
end
|
126
130
|
|
127
131
|
it 'uses registered mapper to process the result for :one result' do
|
128
|
-
command =
|
132
|
+
command = container.command(:users).as(:entity).create
|
129
133
|
result = command[attributes]
|
130
134
|
|
131
135
|
expect(result).to eql(Test::User.new(attributes))
|
@@ -138,11 +142,11 @@ describe 'Commands / Create' do
|
|
138
142
|
mapper_input = tuples
|
139
143
|
end
|
140
144
|
|
141
|
-
left =
|
145
|
+
left = container.command(:users).as(:entity).create.with(
|
142
146
|
name: 'Jane', email: 'jane@doe.org'
|
143
147
|
)
|
144
148
|
|
145
|
-
right =
|
149
|
+
right = container.command(:tasks).as(:entity).create.with(
|
146
150
|
title: 'Jane task'
|
147
151
|
)
|
148
152
|
|
@@ -157,11 +161,11 @@ describe 'Commands / Create' do
|
|
157
161
|
end
|
158
162
|
|
159
163
|
it 'uses registered mapper to process the result for :many results' do
|
160
|
-
|
164
|
+
configuration.commands(:users) do
|
161
165
|
define(:create_many, type: :create)
|
162
166
|
end
|
163
167
|
|
164
|
-
command =
|
168
|
+
command = container.command(:users).as(:entity).create_many
|
165
169
|
result = command[attributes]
|
166
170
|
|
167
171
|
expect(result).to eql([Test::User.new(attributes)])
|
@@ -1,12 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'Commands / Delete' do
|
4
|
+
include_context 'container'
|
4
5
|
include_context 'users and tasks'
|
5
6
|
|
6
|
-
subject(:users) {
|
7
|
+
subject(:users) { container.commands.users }
|
7
8
|
|
8
9
|
before do
|
9
|
-
|
10
|
+
configuration.relation(:users) do
|
10
11
|
def by_name(name)
|
11
12
|
restrict(name: name)
|
12
13
|
end
|
@@ -14,7 +15,7 @@ describe 'Commands / Delete' do
|
|
14
15
|
end
|
15
16
|
|
16
17
|
it 'deletes all tuples when there is no restriction' do
|
17
|
-
|
18
|
+
configuration.commands(:users) do
|
18
19
|
define(:delete)
|
19
20
|
end
|
20
21
|
|
@@ -25,11 +26,11 @@ describe 'Commands / Delete' do
|
|
25
26
|
{ name: 'Joe', email: 'joe@doe.org' }
|
26
27
|
])
|
27
28
|
|
28
|
-
expect(
|
29
|
+
expect(container.relation(:users)).to match_array([])
|
29
30
|
end
|
30
31
|
|
31
32
|
it 'deletes tuples matching restriction' do
|
32
|
-
|
33
|
+
configuration.commands(:users) do
|
33
34
|
define(:delete)
|
34
35
|
end
|
35
36
|
|
@@ -37,13 +38,13 @@ describe 'Commands / Delete' do
|
|
37
38
|
|
38
39
|
expect(result).to match_array([{ name: 'Joe', email: 'joe@doe.org' }])
|
39
40
|
|
40
|
-
expect(
|
41
|
-
{ name: 'Jane', email: 'jane@doe.org' }
|
41
|
+
expect(container.relation(:users)).to match_array([
|
42
|
+
{ name: 'Jane', email: 'jane@doe.org' }
|
42
43
|
])
|
43
44
|
end
|
44
45
|
|
45
46
|
it 'returns untouched relation if there are no tuples to delete' do
|
46
|
-
|
47
|
+
configuration.commands(:users) do
|
47
48
|
define(:delete)
|
48
49
|
end
|
49
50
|
|
@@ -53,7 +54,7 @@ describe 'Commands / Delete' do
|
|
53
54
|
end
|
54
55
|
|
55
56
|
it 'returns deleted tuple when result is set to :one' do
|
56
|
-
|
57
|
+
configuration.commands(:users) do
|
57
58
|
define(:delete_one, type: :delete) do
|
58
59
|
result :one
|
59
60
|
end
|
@@ -65,7 +66,7 @@ describe 'Commands / Delete' do
|
|
65
66
|
end
|
66
67
|
|
67
68
|
it 'raises when result is set to :one and relation contains more tuples' do
|
68
|
-
|
69
|
+
configuration.commands(:users) do
|
69
70
|
define(:delete) do
|
70
71
|
result :one
|
71
72
|
end
|
@@ -75,7 +76,7 @@ describe 'Commands / Delete' do
|
|
75
76
|
|
76
77
|
expect(result.error).to be_instance_of(ROM::TupleCountMismatchError)
|
77
78
|
|
78
|
-
expect(
|
79
|
+
expect(container.relations.users.to_a).to match_array([
|
79
80
|
{ name: 'Jane', email: 'jane@doe.org' },
|
80
81
|
{ name: 'Joe', email: 'joe@doe.org' }
|
81
82
|
])
|