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,10 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'Relation registration DSL' do
|
4
|
+
include_context 'container'
|
4
5
|
include_context 'users and tasks'
|
5
6
|
|
6
7
|
it 'allows to expose chainable relations' do
|
7
|
-
|
8
|
+
configuration.relation(:tasks) do
|
8
9
|
def high_priority
|
9
10
|
restrict { |tuple| tuple[:priority] < 2 }
|
10
11
|
end
|
@@ -14,13 +15,13 @@ describe 'Relation registration DSL' do
|
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
|
-
|
18
|
+
configuration.relation(:users) do
|
18
19
|
def with_tasks
|
19
20
|
join(tasks)
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
23
|
-
tasks =
|
24
|
+
tasks = container.relations.tasks
|
24
25
|
|
25
26
|
expect(tasks.class.name).to eql("ROM::Relation[Tasks]")
|
26
27
|
expect(tasks.high_priority.inspect).to include("#<ROM::Relation[Tasks]")
|
@@ -33,7 +34,7 @@ describe 'Relation registration DSL' do
|
|
33
34
|
[name: "Jane", title: "be cool", priority: 2]
|
34
35
|
)
|
35
36
|
|
36
|
-
users =
|
37
|
+
users = container.relations.users
|
37
38
|
|
38
39
|
expect(users.with_tasks).to match_array(
|
39
40
|
[{ name: "Joe", email: "joe@doe.org", title: "be nice", priority: 1 },
|
@@ -2,9 +2,8 @@ require 'spec_helper'
|
|
2
2
|
require 'rom/memory'
|
3
3
|
|
4
4
|
describe 'Repository' do
|
5
|
-
|
6
|
-
|
7
|
-
let(:rom) { setup.finalize }
|
5
|
+
include_context 'container'
|
6
|
+
include_context 'users and tasks'
|
8
7
|
|
9
8
|
before do
|
10
9
|
module ROM
|
@@ -33,18 +32,18 @@ describe 'Repository' do
|
|
33
32
|
|
34
33
|
shared_examples_for 'extended relation' do
|
35
34
|
it 'can extend relation class' do
|
36
|
-
expect(
|
35
|
+
expect(container.relations.users.class).to be_freaking_awesome
|
37
36
|
end
|
38
37
|
|
39
38
|
it 'can extend relation instance' do
|
40
|
-
expect(
|
39
|
+
expect(container.relations.users).to be_freaking_cool
|
41
40
|
end
|
42
41
|
end
|
43
42
|
|
44
43
|
context 'using DSL' do
|
45
44
|
it_behaves_like 'extended relation' do
|
46
45
|
before do
|
47
|
-
|
46
|
+
configuration.relation(:users)
|
48
47
|
end
|
49
48
|
end
|
50
49
|
end
|
@@ -52,7 +51,7 @@ describe 'Repository' do
|
|
52
51
|
context 'using class definition' do
|
53
52
|
it_behaves_like 'extended relation' do
|
54
53
|
before do
|
55
|
-
Class.new(ROM::Relation[:memory]) { dataset :users }
|
54
|
+
configuration.register_relation(Class.new(ROM::Relation[:memory]) { dataset :users })
|
56
55
|
end
|
57
56
|
end
|
58
57
|
end
|
@@ -23,13 +23,11 @@ describe 'Repositories / Setting logger' do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'sets up a logger for a given gateway' do
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
rom.gateways[:default].logger.info("test")
|
26
|
+
container = ROM.container(:memory) do |config|
|
27
|
+
config.gateways[:default].use_logger(logger)
|
28
|
+
end
|
29
|
+
|
30
|
+
container.gateways[:default].logger.info("test")
|
33
31
|
|
34
32
|
expect(logger.messages).to eql(["test"])
|
35
33
|
end
|
@@ -1,24 +1,25 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'virtus'
|
3
3
|
|
4
|
-
describe '
|
4
|
+
describe 'Configuring ROM' do
|
5
5
|
context 'with existing schema' do
|
6
|
+
include_context 'container'
|
6
7
|
include_context 'users and tasks'
|
7
8
|
|
8
9
|
let(:jane) { { name: 'Jane', email: 'jane@doe.org' } }
|
9
10
|
let(:joe) { { name: 'Joe', email: 'joe@doe.org' } }
|
10
11
|
|
11
12
|
before do
|
12
|
-
|
13
|
-
|
13
|
+
configuration.relation(:users)
|
14
|
+
configuration.relation(:tasks)
|
14
15
|
end
|
15
16
|
|
16
17
|
it 'configures schema relations' do
|
17
|
-
expect(
|
18
|
+
expect(container.gateways[:default][:users]).to match_array([joe, jane])
|
18
19
|
end
|
19
20
|
|
20
21
|
it 'configures rom relations' do
|
21
|
-
users =
|
22
|
+
users = container.relations.users
|
22
23
|
|
23
24
|
expect(users).to be_kind_of(ROM::Relation)
|
24
25
|
expect(users).to respond_to(:tasks)
|
@@ -29,70 +30,55 @@ describe 'Setting up ROM' do
|
|
29
30
|
expect(tasks).to respond_to(:users)
|
30
31
|
expect(tasks.users).to be(users)
|
31
32
|
end
|
32
|
-
|
33
|
-
it 'raises on double-finalize' do
|
34
|
-
expect {
|
35
|
-
2.times { setup.finalize }
|
36
|
-
}.to raise_error(ROM::EnvAlreadyFinalizedError)
|
37
|
-
end
|
38
33
|
end
|
39
34
|
|
40
35
|
context 'without schema' do
|
41
36
|
it 'builds empty registries if there is no schema' do
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
expect(rom.relations).to eql(ROM::RelationRegistry.new)
|
47
|
-
expect(rom.mappers).to eql(ROM::Registry.new)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context 'with old syntax' do
|
52
|
-
it 'warns when old repository key is used' do
|
53
|
-
setup = ROM.setup(data: :memory)
|
54
|
-
|
55
|
-
expect {
|
56
|
-
setup.relation(:users, repository: :data)
|
57
|
-
}.to output(/use `gateway: :data`/).to_stderr
|
37
|
+
container = ROM.container(:memory)
|
38
|
+
expect(container.relations).to eql(ROM::RelationRegistry.new)
|
39
|
+
expect(container.mappers).to eql(ROM::Registry.new)
|
58
40
|
end
|
59
41
|
end
|
60
42
|
|
61
43
|
describe 'defining classes' do
|
62
44
|
it 'sets up registries based on class definitions' do
|
63
|
-
ROM.
|
45
|
+
container = ROM.container(:memory) do |config|
|
46
|
+
config.use(:macros)
|
64
47
|
|
65
|
-
|
66
|
-
|
48
|
+
class Test::UserRelation < ROM::Relation[:memory]
|
49
|
+
dataset :users
|
67
50
|
|
68
|
-
|
69
|
-
|
51
|
+
def by_name(name)
|
52
|
+
restrict(name: name)
|
53
|
+
end
|
70
54
|
end
|
71
|
-
end
|
72
55
|
|
73
|
-
|
74
|
-
|
75
|
-
|
56
|
+
class Test::TaskRelation < ROM::Relation[:memory]
|
57
|
+
dataset :tasks
|
58
|
+
end
|
76
59
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
60
|
+
class Test::CreateUser < ROM::Commands::Update[:memory]
|
61
|
+
relation :users
|
62
|
+
register_as :create
|
63
|
+
end
|
81
64
|
|
82
|
-
|
65
|
+
config.register_relation(Test::UserRelation, Test::TaskRelation)
|
66
|
+
config.register_command(Test::CreateUser)
|
67
|
+
end
|
83
68
|
|
84
|
-
expect(
|
85
|
-
expect(
|
69
|
+
expect(container.relations.users).to be_kind_of(Test::UserRelation)
|
70
|
+
expect(container.relations.users.tasks).to be(container.relations.tasks)
|
86
71
|
|
87
|
-
expect(
|
72
|
+
expect(container.commands.users[:create]).to be_kind_of(Test::CreateUser)
|
88
73
|
|
89
|
-
expect(
|
90
|
-
expect(
|
74
|
+
expect(container.relations.tasks).to be_kind_of(Test::TaskRelation)
|
75
|
+
expect(container.relations.tasks.users).to be(container.relations.users)
|
91
76
|
end
|
92
77
|
end
|
93
78
|
|
94
79
|
describe 'quick setup' do
|
95
|
-
|
80
|
+
# NOTE: move to DSL tests
|
81
|
+
it 'exposes boot DSL inside the setup block via `macros` plugin' do
|
96
82
|
module Test
|
97
83
|
User = Class.new do
|
98
84
|
include Virtus.value_object
|
@@ -100,27 +86,29 @@ describe 'Setting up ROM' do
|
|
100
86
|
end
|
101
87
|
end
|
102
88
|
|
103
|
-
|
104
|
-
|
89
|
+
container = ROM.container(:memory) do |rom|
|
90
|
+
rom.use(:macros)
|
91
|
+
|
92
|
+
rom.relation(:users) do
|
105
93
|
def by_name(name)
|
106
94
|
restrict(name: name)
|
107
95
|
end
|
108
96
|
end
|
109
97
|
|
110
|
-
commands(:users) do
|
98
|
+
rom.commands(:users) do
|
111
99
|
define(:create)
|
112
100
|
end
|
113
101
|
|
114
|
-
mappers do
|
102
|
+
rom.mappers do
|
115
103
|
define(:users) do
|
116
104
|
model Test::User
|
117
105
|
end
|
118
106
|
end
|
119
|
-
|
107
|
+
end
|
120
108
|
|
121
|
-
|
109
|
+
container.commands.users.create.call(name: 'Jane')
|
122
110
|
|
123
|
-
expect(
|
111
|
+
expect(container.relation(:users).by_name('Jane').as(:users).to_a)
|
124
112
|
.to eql([Test::User.new(name: 'Jane')])
|
125
113
|
end
|
126
114
|
end
|
@@ -134,29 +122,29 @@ describe 'Setting up ROM' do
|
|
134
122
|
end
|
135
123
|
end
|
136
124
|
|
137
|
-
ROM.
|
125
|
+
configuration = ROM::Configuration.new(:memory).use(:macros)
|
138
126
|
|
139
|
-
|
127
|
+
configuration.relation(:users) do
|
140
128
|
def by_name(name)
|
141
129
|
restrict(name: name)
|
142
130
|
end
|
143
131
|
end
|
144
132
|
|
145
|
-
|
133
|
+
configuration.commands(:users) do
|
146
134
|
define(:create)
|
147
135
|
end
|
148
136
|
|
149
|
-
|
137
|
+
configuration.mappers do
|
150
138
|
define(:users) do
|
151
139
|
model Test::User
|
152
140
|
end
|
153
141
|
end
|
154
142
|
|
155
|
-
|
143
|
+
container = ROM.container(configuration)
|
156
144
|
|
157
|
-
|
145
|
+
container.command(:users).create.call(name: 'Jane')
|
158
146
|
|
159
|
-
expect(
|
147
|
+
expect(container.relation(:users).by_name('Jane').as(:users).to_a)
|
160
148
|
.to eql([Test::User.new(name: 'Jane')])
|
161
149
|
end
|
162
150
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
shared_context 'command graph' do
|
2
|
+
include_context 'container'
|
3
|
+
|
4
|
+
before do
|
5
|
+
configuration.relation :users do
|
6
|
+
def by_name(name)
|
7
|
+
restrict(name: name)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
configuration.relation :tasks do
|
12
|
+
def by_user_and_title(user, title)
|
13
|
+
by_user(user).by_title(title)
|
14
|
+
end
|
15
|
+
|
16
|
+
def by_user(user)
|
17
|
+
restrict(user: user)
|
18
|
+
end
|
19
|
+
|
20
|
+
def by_title(title)
|
21
|
+
restrict(title: title)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
configuration.relation :books
|
26
|
+
configuration.relation :tags
|
27
|
+
|
28
|
+
configuration.commands(:users) do
|
29
|
+
define(:create) do
|
30
|
+
result :one
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
configuration.commands(:books) do
|
35
|
+
define(:create) do
|
36
|
+
def execute(tuples, user)
|
37
|
+
super(tuples.map { |t| t.merge(user: user.fetch(:name)) })
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
configuration.commands(:tags) do
|
43
|
+
define(:create) do
|
44
|
+
def execute(tuples, task)
|
45
|
+
super(tuples.map { |t| t.merge(task: task.fetch(:title)) })
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
RSpec.shared_context 'container' do
|
2
|
+
let(:container) { ROM.container(configuration) }
|
3
|
+
let!(:configuration) { ROM::Configuration.new(:memory).use(:macros) }
|
4
|
+
let(:gateway) { configuration.gateways[:default] }
|
5
|
+
let(:users_relation) { container.relation(:users) }
|
6
|
+
let(:tasks_relation) { container.relation(:tasks) }
|
7
|
+
let(:users_dataset) { gateway.dataset(:users) }
|
8
|
+
let(:tasks_dataset) { gateway.dataset(:tasks) }
|
9
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rom/memory'
|
2
|
+
|
3
|
+
RSpec.shared_context 'no container' do
|
4
|
+
let(:gateway) { ROM::Memory::Gateway.new }
|
5
|
+
|
6
|
+
let(:users_dataset) { gateway.dataset(:users) }
|
7
|
+
let(:tasks_dataset) { gateway.dataset(:tasks) }
|
8
|
+
|
9
|
+
let(:users_relation) do
|
10
|
+
Class.new(ROM::Memory::Relation).new(users_dataset)
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:tasks_relation) do
|
14
|
+
Class.new(ROM::Memory::Relation).new(tasks_dataset)
|
15
|
+
end
|
16
|
+
end
|
data/spec/shared/one_behavior.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
shared_examples_for 'a relation that returns one tuple' do
|
2
2
|
describe '#one' do
|
3
3
|
it 'returns first tuple' do
|
4
|
-
|
4
|
+
users_relation.delete(name: 'Joe', email: 'joe@doe.org')
|
5
5
|
expect(relation.one).to eql(name: 'Jane', email: 'jane@doe.org')
|
6
6
|
end
|
7
7
|
|
@@ -12,13 +12,13 @@ shared_examples_for 'a relation that returns one tuple' do
|
|
12
12
|
|
13
13
|
describe '#one!' do
|
14
14
|
it 'returns first tuple' do
|
15
|
-
|
15
|
+
users_relation.delete(name: 'Joe', email: 'joe@doe.org')
|
16
16
|
expect(relation.one!).to eql(name: 'Jane', email: 'jane@doe.org')
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'raises error when there is no tuples' do
|
20
|
-
|
21
|
-
|
20
|
+
users_relation.delete(name: 'Jane', email: 'jane@doe.org')
|
21
|
+
users_relation.delete(name: 'Joe', email: 'joe@doe.org')
|
22
22
|
|
23
23
|
expect { relation.one! }.to raise_error(ROM::TupleCountMismatchError)
|
24
24
|
end
|
@@ -1,22 +1,10 @@
|
|
1
1
|
RSpec.shared_context 'users and tasks' do
|
2
|
-
require 'rom/memory'
|
3
|
-
|
4
|
-
subject(:rom) { setup.finalize }
|
5
|
-
|
6
|
-
let(:setup) { ROM.setup(:memory) }
|
7
|
-
|
8
2
|
before do
|
9
|
-
|
10
|
-
|
11
|
-
users = gateway.dataset(:users)
|
12
|
-
tasks = gateway.dataset(:tasks)
|
13
|
-
|
14
|
-
users.insert(name: "Joe", email: "joe@doe.org")
|
15
|
-
users.insert(name: "Jane", email: "jane@doe.org")
|
16
|
-
|
17
|
-
tasks.insert(name: "Joe", title: "be nice", priority: 1)
|
18
|
-
tasks.insert(name: "Joe", title: "sleep well", priority: 2)
|
3
|
+
users_dataset.insert(name: "Joe", email: "joe@doe.org")
|
4
|
+
users_dataset.insert(name: "Jane", email: "jane@doe.org")
|
19
5
|
|
20
|
-
|
6
|
+
tasks_dataset.insert(name: "Joe", title: "be nice", priority: 1)
|
7
|
+
tasks_dataset.insert(name: "Joe", title: "sleep well", priority: 2)
|
8
|
+
tasks_dataset.insert(name: "Jane", title: "be cool", priority: 2)
|
21
9
|
end
|
22
10
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -17,7 +17,7 @@ begin
|
|
17
17
|
rescue LoadError
|
18
18
|
end
|
19
19
|
|
20
|
-
root = Pathname(__FILE__).dirname
|
20
|
+
SPEC_ROOT = root = Pathname(__FILE__).dirname
|
21
21
|
|
22
22
|
Dir[root.join('support/*.rb').to_s].each do |f|
|
23
23
|
require f
|
@@ -38,6 +38,10 @@ def T(*args)
|
|
38
38
|
end
|
39
39
|
|
40
40
|
RSpec.configure do |config|
|
41
|
+
config.before do
|
42
|
+
ROM.env = nil
|
43
|
+
end
|
44
|
+
|
41
45
|
config.after do
|
42
46
|
Test.remove_constants
|
43
47
|
end
|
@@ -46,5 +50,3 @@ RSpec.configure do |config|
|
|
46
50
|
ConstantLeakFinder.find(example)
|
47
51
|
end
|
48
52
|
end
|
49
|
-
|
50
|
-
ROM.use :auto_registration
|