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
@@ -2,12 +2,11 @@ require 'spec_helper'
|
|
2
2
|
require 'rom/memory'
|
3
3
|
|
4
4
|
describe 'Mappers / Symbolizing atributes' do
|
5
|
-
|
6
|
-
let(:rom) { setup.finalize }
|
5
|
+
include_context 'container'
|
7
6
|
|
8
7
|
before do
|
9
|
-
|
10
|
-
|
8
|
+
configuration.relation(:users)
|
9
|
+
configuration.relation(:tasks)
|
11
10
|
end
|
12
11
|
|
13
12
|
it 'automatically maps all attributes using top-level settings' do
|
@@ -30,13 +29,15 @@ describe 'Mappers / Symbolizing atributes' do
|
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
33
|
-
|
32
|
+
configuration.register_mapper(Test::UserMapper)
|
33
|
+
|
34
|
+
container.relations.users << {
|
34
35
|
'user_id' => 123,
|
35
36
|
'first_name' => 'Jane',
|
36
37
|
'email' => 'jane@doe.org'
|
37
38
|
}
|
38
39
|
|
39
|
-
jane =
|
40
|
+
jane = container.relation(:users).as(:users).first
|
40
41
|
|
41
42
|
expect(jane).to eql(
|
42
43
|
id: 123, details: { name: 'Jane' }, contact: { email: 'jane@doe.org' }
|
@@ -58,13 +59,15 @@ describe 'Mappers / Symbolizing atributes' do
|
|
58
59
|
end
|
59
60
|
end
|
60
61
|
|
61
|
-
|
62
|
+
configuration.register_mapper(Test::TaskMapper)
|
63
|
+
|
64
|
+
container.relations.tasks << {
|
62
65
|
'title' => 'Task One',
|
63
66
|
'task_priority' => 1,
|
64
67
|
'task_description' => 'It is a task'
|
65
68
|
}
|
66
69
|
|
67
|
-
task =
|
70
|
+
task = container.relation(:tasks).as(:tasks).first
|
68
71
|
|
69
72
|
expect(task).to eql(
|
70
73
|
title: 'Task One',
|
@@ -2,13 +2,12 @@ require 'spec_helper'
|
|
2
2
|
require 'rom/memory'
|
3
3
|
|
4
4
|
describe 'Mapper definition DSL' do
|
5
|
-
|
6
|
-
let(:rom) { ROM.finalize.env }
|
5
|
+
include_context 'container'
|
7
6
|
|
8
7
|
before do
|
9
|
-
|
8
|
+
configuration.relation(:users)
|
10
9
|
|
11
|
-
users =
|
10
|
+
users = configuration.default.dataset(:users)
|
12
11
|
|
13
12
|
users.insert(name: 'Joe', roles: ['admin', 'user', 'user', nil])
|
14
13
|
users.insert(name: 'Jane', roles: 'user')
|
@@ -16,10 +15,10 @@ describe 'Mapper definition DSL' do
|
|
16
15
|
end
|
17
16
|
|
18
17
|
describe 'unfold' do
|
19
|
-
let(:mapped_users) {
|
18
|
+
let(:mapped_users) { container.relation(:users).as(:users).to_a }
|
20
19
|
|
21
20
|
it 'splits the attribute' do
|
22
|
-
|
21
|
+
configuration.mappers do
|
23
22
|
define(:users) { unfold :roles }
|
24
23
|
end
|
25
24
|
|
@@ -34,7 +33,7 @@ describe 'Mapper definition DSL' do
|
|
34
33
|
end
|
35
34
|
|
36
35
|
it 'renames unfolded attribute when necessary' do
|
37
|
-
|
36
|
+
configuration.mappers do
|
38
37
|
define(:users) { unfold :role, from: :roles }
|
39
38
|
end
|
40
39
|
|
@@ -49,7 +48,7 @@ describe 'Mapper definition DSL' do
|
|
49
48
|
end
|
50
49
|
|
51
50
|
it 'rewrites the existing attribute' do
|
52
|
-
|
51
|
+
configuration.mappers do
|
53
52
|
define(:users) { unfold :name, from: :roles }
|
54
53
|
end
|
55
54
|
|
@@ -64,7 +63,7 @@ describe 'Mapper definition DSL' do
|
|
64
63
|
end
|
65
64
|
|
66
65
|
it 'ignores the absent attribute' do
|
67
|
-
|
66
|
+
configuration.mappers do
|
68
67
|
define(:users) { unfold :foo, from: :absent }
|
69
68
|
end
|
70
69
|
|
@@ -76,7 +75,7 @@ describe 'Mapper definition DSL' do
|
|
76
75
|
end
|
77
76
|
|
78
77
|
it 'accepts block' do
|
79
|
-
|
78
|
+
configuration.mappers do
|
80
79
|
define(:users) { unfold(:role, from: :roles) {} }
|
81
80
|
end
|
82
81
|
|
@@ -2,29 +2,28 @@ require 'spec_helper'
|
|
2
2
|
require 'rom/memory'
|
3
3
|
|
4
4
|
describe 'Mapper definition DSL' do
|
5
|
-
|
6
|
-
let(:rom) { ROM.finalize.env }
|
5
|
+
include_context 'container'
|
7
6
|
|
8
7
|
before do
|
9
|
-
|
8
|
+
configuration.relation(:users)
|
10
9
|
|
11
|
-
users =
|
10
|
+
users = configuration.default.dataset(:users)
|
12
11
|
users.insert(name: 'Joe', emails: [
|
13
12
|
{ address: 'joe@home.org', type: 'home' },
|
14
13
|
{ address: 'joe@job.com', type: 'job' },
|
15
14
|
{ address: 'joe@doe.com', type: 'job' },
|
16
15
|
{ address: 'joe@thor.org' },
|
17
|
-
{
|
16
|
+
{ type: 'home' },
|
18
17
|
{}
|
19
18
|
])
|
20
19
|
users.insert(name: 'Jane')
|
21
20
|
end
|
22
21
|
|
23
22
|
describe 'ungroup' do
|
24
|
-
subject(:mapped_users) {
|
23
|
+
subject(:mapped_users) { container.relation(:users).as(:users).to_a }
|
25
24
|
|
26
25
|
it 'partially ungroups attributes' do
|
27
|
-
|
26
|
+
configuration.mappers do
|
28
27
|
define(:users) { ungroup emails: [:type] }
|
29
28
|
end
|
30
29
|
|
@@ -46,7 +45,7 @@ describe 'Mapper definition DSL' do
|
|
46
45
|
end
|
47
46
|
|
48
47
|
it 'removes group when all attributes extracted' do
|
49
|
-
|
48
|
+
configuration.mappers do
|
50
49
|
define(:users) { ungroup emails: [:address, :type, :foo] }
|
51
50
|
end
|
52
51
|
|
@@ -62,7 +61,7 @@ describe 'Mapper definition DSL' do
|
|
62
61
|
end
|
63
62
|
|
64
63
|
it 'accepts block syntax' do
|
65
|
-
|
64
|
+
configuration.mappers do
|
66
65
|
define(:users) do
|
67
66
|
ungroup :emails do
|
68
67
|
attribute :address
|
@@ -83,7 +82,7 @@ describe 'Mapper definition DSL' do
|
|
83
82
|
end
|
84
83
|
|
85
84
|
it 'renames ungrouped attributes' do
|
86
|
-
|
85
|
+
configuration.mappers do
|
87
86
|
define(:users) do
|
88
87
|
ungroup :emails do
|
89
88
|
attribute :email, from: :address
|
@@ -104,7 +103,7 @@ describe 'Mapper definition DSL' do
|
|
104
103
|
end
|
105
104
|
|
106
105
|
it 'skips existing attributes' do
|
107
|
-
|
106
|
+
configuration.mappers do
|
108
107
|
define(:users) do
|
109
108
|
ungroup :emails do
|
110
109
|
attribute :name, from: :address
|
@@ -1,13 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'Mapper definition DSL' do
|
4
|
+
include_context 'container'
|
4
5
|
include_context 'users and tasks'
|
5
6
|
|
6
7
|
let(:header) { mapper.header }
|
7
8
|
|
8
9
|
describe 'unwrapping relation mapper' do
|
9
10
|
before do
|
10
|
-
|
11
|
+
configuration.relation(:tasks) do
|
11
12
|
def with_user
|
12
13
|
tuples = map { |tuple|
|
13
14
|
tuple.merge(user: users.restrict(name: tuple[:name]).first)
|
@@ -17,9 +18,9 @@ describe 'Mapper definition DSL' do
|
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
20
|
-
|
21
|
+
configuration.relation(:users)
|
21
22
|
|
22
|
-
|
23
|
+
configuration.mappers do
|
23
24
|
define(:tasks) do
|
24
25
|
model name: 'Test::Task'
|
25
26
|
|
@@ -30,7 +31,7 @@ describe 'Mapper definition DSL' do
|
|
30
31
|
end
|
31
32
|
|
32
33
|
it 'unwraps nested attributes via options hash' do
|
33
|
-
|
34
|
+
configuration.mappers do
|
34
35
|
define(:with_user, parent: :tasks) do
|
35
36
|
attribute :title
|
36
37
|
attribute :priority
|
@@ -39,9 +40,7 @@ describe 'Mapper definition DSL' do
|
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
result = rom.relation(:tasks).with_user.as(:with_user).to_a.last
|
43
|
+
result = container.relation(:tasks).with_user.as(:with_user).to_a.last
|
45
44
|
|
46
45
|
expect(result).to eql(title: 'be cool',
|
47
46
|
priority: 2,
|
@@ -50,7 +49,7 @@ describe 'Mapper definition DSL' do
|
|
50
49
|
end
|
51
50
|
|
52
51
|
it 'unwraps nested attributes via options block' do
|
53
|
-
|
52
|
+
configuration.mappers do
|
54
53
|
define(:with_user, parent: :tasks) do
|
55
54
|
attribute :title
|
56
55
|
attribute :priority
|
@@ -62,9 +61,7 @@ describe 'Mapper definition DSL' do
|
|
62
61
|
end
|
63
62
|
end
|
64
63
|
|
65
|
-
|
66
|
-
|
67
|
-
result = rom.relation(:tasks).with_user.as(:with_user).to_a.last
|
64
|
+
result = container.relation(:tasks).with_user.as(:with_user).to_a.last
|
68
65
|
|
69
66
|
expect(result).to eql(title: 'be cool',
|
70
67
|
priority: 2,
|
@@ -73,7 +70,7 @@ describe 'Mapper definition DSL' do
|
|
73
70
|
end
|
74
71
|
|
75
72
|
it 'unwraps specified attributes via options block' do
|
76
|
-
|
73
|
+
configuration.mappers do
|
77
74
|
define(:with_user, parent: :tasks) do
|
78
75
|
attribute :title
|
79
76
|
attribute :priority
|
@@ -84,9 +81,7 @@ describe 'Mapper definition DSL' do
|
|
84
81
|
end
|
85
82
|
end
|
86
83
|
|
87
|
-
|
88
|
-
|
89
|
-
result = rom.relation(:tasks).with_user.as(:with_user).to_a.last
|
84
|
+
result = container.relation(:tasks).with_user.as(:with_user).to_a.last
|
90
85
|
|
91
86
|
expect(result).to eql(title: 'be cool',
|
92
87
|
priority: 2,
|
@@ -1,21 +1,22 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'Mapper definition DSL' do
|
4
|
+
include_context 'container'
|
4
5
|
include_context 'users and tasks'
|
5
6
|
|
6
7
|
let(:header) { mapper.header }
|
7
8
|
|
8
9
|
describe 'wrapped relation mapper' do
|
9
10
|
before do
|
10
|
-
|
11
|
+
configuration.relation(:tasks) do
|
11
12
|
def with_user
|
12
13
|
join(users)
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
|
-
|
17
|
+
configuration.relation(:users)
|
17
18
|
|
18
|
-
|
19
|
+
configuration.mappers do
|
19
20
|
define(:tasks) do
|
20
21
|
model name: 'Test::Task'
|
21
22
|
|
@@ -26,7 +27,7 @@ describe 'Mapper definition DSL' do
|
|
26
27
|
end
|
27
28
|
|
28
29
|
it 'allows defining wrapped attributes via options hash' do
|
29
|
-
|
30
|
+
configuration.mappers do
|
30
31
|
define(:with_user, parent: :tasks) do
|
31
32
|
model name: 'Test::TaskWithUser'
|
32
33
|
|
@@ -37,11 +38,11 @@ describe 'Mapper definition DSL' do
|
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
40
|
-
|
41
|
+
container
|
41
42
|
|
42
43
|
Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
|
43
44
|
|
44
|
-
jane =
|
45
|
+
jane = container.relation(:tasks).with_user.as(:with_user).to_a.last
|
45
46
|
|
46
47
|
expect(jane).to eql(
|
47
48
|
Test::TaskWithUser.new(
|
@@ -53,7 +54,7 @@ describe 'Mapper definition DSL' do
|
|
53
54
|
end
|
54
55
|
|
55
56
|
it 'allows defining wrapped attributes via options block' do
|
56
|
-
|
57
|
+
configuration.mappers do
|
57
58
|
define(:with_user, parent: :tasks) do
|
58
59
|
model name: 'Test::TaskWithUser'
|
59
60
|
|
@@ -66,11 +67,11 @@ describe 'Mapper definition DSL' do
|
|
66
67
|
end
|
67
68
|
end
|
68
69
|
|
69
|
-
|
70
|
+
container
|
70
71
|
|
71
72
|
Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
|
72
73
|
|
73
|
-
jane =
|
74
|
+
jane = container.relation(:tasks).with_user.as(:with_user).to_a.last
|
74
75
|
|
75
76
|
expect(jane).to eql(
|
76
77
|
Test::TaskWithUser.new(
|
@@ -82,7 +83,7 @@ describe 'Mapper definition DSL' do
|
|
82
83
|
end
|
83
84
|
|
84
85
|
it 'allows defining nested wrapped attributes via a block' do
|
85
|
-
|
86
|
+
configuration.mappers do
|
86
87
|
define(:with_user, parent: :tasks, inherit_header: false) do
|
87
88
|
model name: 'Test::TaskWithUser'
|
88
89
|
|
@@ -101,13 +102,13 @@ describe 'Mapper definition DSL' do
|
|
101
102
|
end
|
102
103
|
end
|
103
104
|
|
104
|
-
|
105
|
+
container
|
105
106
|
|
106
107
|
Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
|
107
108
|
Test::TaskUser.send(:include, Equalizer.new(:name, :contact))
|
108
109
|
Test::Contact.send(:include, Equalizer.new(:email))
|
109
110
|
|
110
|
-
jane =
|
111
|
+
jane = container.relation(:tasks).with_user.as(:with_user).to_a.last
|
111
112
|
|
112
113
|
expect(jane).to eql(
|
113
114
|
Test::TaskWithUser.new(
|
@@ -121,7 +122,7 @@ describe 'Mapper definition DSL' do
|
|
121
122
|
end
|
122
123
|
|
123
124
|
it 'allows defining wrapped attributes mapped to a model' do
|
124
|
-
|
125
|
+
configuration.mappers do
|
125
126
|
define(:with_user, parent: :tasks) do
|
126
127
|
model name: 'Test::TaskWithUser'
|
127
128
|
|
@@ -135,12 +136,12 @@ describe 'Mapper definition DSL' do
|
|
135
136
|
end
|
136
137
|
end
|
137
138
|
|
138
|
-
|
139
|
+
container
|
139
140
|
|
140
141
|
Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
|
141
142
|
Test::User.send(:include, Equalizer.new(:email))
|
142
143
|
|
143
|
-
jane =
|
144
|
+
jane = container.relation(:tasks).with_user.as(:with_user).to_a.last
|
144
145
|
|
145
146
|
expect(jane).to eql(
|
146
147
|
Test::TaskWithUser.new(
|
@@ -3,19 +3,21 @@ require 'spec_helper'
|
|
3
3
|
require 'rom/memory'
|
4
4
|
|
5
5
|
describe ROM::Memory::Commands::Create do
|
6
|
+
include_context 'container'
|
6
7
|
include_context 'users and tasks'
|
7
8
|
|
8
|
-
subject(:command) { ROM::Memory::Commands::Create.build(users) }
|
9
|
-
|
10
|
-
let(:users) { rom.relations[:users] }
|
11
|
-
|
12
9
|
before do
|
13
|
-
|
10
|
+
configuration.relation(:users) do
|
14
11
|
def by_id(id)
|
15
12
|
restrict(id: id)
|
16
13
|
end
|
17
14
|
end
|
15
|
+
configuration.commands(:users) do
|
16
|
+
define(:create)
|
17
|
+
end
|
18
18
|
end
|
19
19
|
|
20
|
+
subject(:command) { container.command(:users).create }
|
21
|
+
|
20
22
|
it_behaves_like 'a command'
|
21
23
|
end
|
@@ -3,19 +3,21 @@ require 'spec_helper'
|
|
3
3
|
require 'rom/memory'
|
4
4
|
|
5
5
|
describe ROM::Memory::Commands::Delete do
|
6
|
+
include_context 'container'
|
6
7
|
include_context 'users and tasks'
|
7
8
|
|
8
|
-
subject(:command) { ROM::Memory::Commands::Delete.build(users) }
|
9
|
-
|
10
|
-
let(:users) { rom.relations[:users] }
|
11
|
-
|
12
9
|
before do
|
13
|
-
|
10
|
+
configuration.relation(:users) do
|
14
11
|
def by_id(id)
|
15
12
|
restrict(id: id)
|
16
13
|
end
|
17
14
|
end
|
15
|
+
configuration.commands(:users) do
|
16
|
+
define(:delete)
|
17
|
+
end
|
18
18
|
end
|
19
19
|
|
20
|
+
subject(:command) { container.command(:users).delete }
|
21
|
+
|
20
22
|
it_behaves_like 'a command'
|
21
23
|
end
|
@@ -3,19 +3,21 @@ require 'spec_helper'
|
|
3
3
|
require 'rom/memory'
|
4
4
|
|
5
5
|
describe ROM::Memory::Commands::Update do
|
6
|
+
include_context 'container'
|
6
7
|
include_context 'users and tasks'
|
7
8
|
|
8
|
-
subject(:command) { ROM::Memory::Commands::Update.build(users) }
|
9
|
-
|
10
|
-
let(:users) { rom.relations[:users] }
|
11
|
-
|
12
9
|
before do
|
13
|
-
|
10
|
+
configuration.relation(:users) do
|
14
11
|
def by_id(id)
|
15
12
|
restrict(id: id)
|
16
13
|
end
|
17
14
|
end
|
15
|
+
configuration.commands(:users) do
|
16
|
+
define(:update)
|
17
|
+
end
|
18
18
|
end
|
19
19
|
|
20
|
+
subject(:command) { container.command(:users).update }
|
21
|
+
|
20
22
|
it_behaves_like 'a command'
|
21
23
|
end
|