rom 2.0.2 → 3.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -4
  3. data/CHANGELOG.md +34 -1
  4. data/Gemfile +16 -2
  5. data/Rakefile +7 -2
  6. data/lib/rom/array_dataset.rb +44 -0
  7. data/lib/rom/association_set.rb +11 -5
  8. data/lib/rom/auto_curry.rb +55 -0
  9. data/lib/rom/command.rb +70 -41
  10. data/lib/rom/command_registry.rb +7 -18
  11. data/lib/rom/commands/class_interface.rb +7 -6
  12. data/lib/rom/commands/composite.rb +0 -1
  13. data/lib/rom/commands/graph.rb +7 -15
  14. data/lib/rom/commands/lazy/update.rb +1 -1
  15. data/lib/rom/configuration_dsl/command.rb +6 -8
  16. data/lib/rom/configuration_dsl/mapper.rb +2 -3
  17. data/lib/rom/configuration_dsl/mapper_dsl.rb +0 -1
  18. data/lib/rom/configuration_dsl/relation.rb +4 -4
  19. data/lib/rom/configuration_dsl.rb +0 -4
  20. data/lib/rom/constants.rb +1 -1
  21. data/lib/rom/container.rb +0 -2
  22. data/lib/rom/create_container.rb +0 -2
  23. data/lib/rom/data_proxy.rb +94 -0
  24. data/lib/rom/enumerable_dataset.rb +68 -0
  25. data/lib/rom/gateway.rb +23 -6
  26. data/lib/rom/global/plugin_dsl.rb +0 -2
  27. data/lib/rom/global.rb +0 -2
  28. data/lib/rom/initializer.rb +26 -0
  29. data/lib/rom/lint/gateway.rb +17 -0
  30. data/lib/rom/mapper_registry.rb +1 -1
  31. data/lib/rom/memory/commands.rb +0 -2
  32. data/lib/rom/memory/dataset.rb +1 -2
  33. data/lib/rom/memory/relation.rb +14 -1
  34. data/lib/rom/memory/schema.rb +13 -0
  35. data/lib/rom/plugin_registry.rb +1 -1
  36. data/lib/rom/plugins/configuration/configuration_dsl.rb +6 -2
  37. data/lib/rom/plugins/relation/key_inference.rb +4 -2
  38. data/lib/rom/plugins/relation/registry_reader.rb +5 -1
  39. data/lib/rom/registry.rb +50 -0
  40. data/lib/rom/relation/class_interface.rb +94 -26
  41. data/lib/rom/relation/curried.rb +15 -15
  42. data/lib/rom/relation/view_dsl.rb +31 -0
  43. data/lib/rom/relation.rb +49 -34
  44. data/lib/rom/schema/dsl.rb +7 -9
  45. data/lib/rom/schema/type.rb +115 -0
  46. data/lib/rom/schema.rb +218 -18
  47. data/lib/rom/setup/auto_registration.rb +20 -17
  48. data/lib/rom/setup/auto_registration_strategies/base.rb +8 -3
  49. data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +4 -3
  50. data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +5 -4
  51. data/lib/rom/setup/auto_registration_strategies/with_namespace.rb +3 -3
  52. data/lib/rom/setup/finalize/finalize_commands.rb +1 -1
  53. data/lib/rom/setup/finalize/finalize_mappers.rb +1 -1
  54. data/lib/rom/setup/finalize/finalize_relations.rb +3 -1
  55. data/lib/rom/setup/finalize.rb +1 -1
  56. data/lib/rom/transaction.rb +24 -0
  57. data/lib/rom/types.rb +9 -1
  58. data/lib/rom/version.rb +1 -1
  59. data/lib/rom.rb +4 -8
  60. data/rom.gemspec +4 -3
  61. data/spec/integration/command_registry_spec.rb +1 -14
  62. data/spec/integration/commands/create_spec.rb +5 -25
  63. data/spec/integration/commands/delete_spec.rb +1 -1
  64. data/spec/integration/commands/error_handling_spec.rb +1 -1
  65. data/spec/integration/commands/graph_spec.rb +20 -14
  66. data/spec/integration/commands/update_spec.rb +4 -27
  67. data/spec/integration/commands_spec.rb +1 -1
  68. data/spec/integration/{repositories → gateways}/extending_relations_spec.rb +1 -1
  69. data/spec/integration/{repositories → gateways}/setting_logger_spec.rb +2 -2
  70. data/spec/integration/mappers/combine_spec.rb +1 -1
  71. data/spec/integration/mappers/deep_embedded_spec.rb +1 -1
  72. data/spec/integration/mappers/definition_dsl_spec.rb +1 -1
  73. data/spec/integration/mappers/embedded_spec.rb +1 -1
  74. data/spec/integration/mappers/exclude_spec.rb +1 -1
  75. data/spec/integration/mappers/fold_spec.rb +1 -1
  76. data/spec/integration/mappers/group_spec.rb +1 -1
  77. data/spec/integration/mappers/overwrite_attributes_value_spec.rb +1 -1
  78. data/spec/integration/mappers/prefix_separator_spec.rb +1 -1
  79. data/spec/integration/mappers/prefix_spec.rb +1 -1
  80. data/spec/integration/mappers/prefixing_attributes_spec.rb +1 -1
  81. data/spec/integration/mappers/registering_custom_mappers_spec.rb +1 -1
  82. data/spec/integration/mappers/renaming_attributes_spec.rb +1 -1
  83. data/spec/integration/mappers/reusing_mappers_spec.rb +1 -1
  84. data/spec/integration/mappers/step_spec.rb +1 -1
  85. data/spec/integration/mappers/symbolizing_attributes_spec.rb +1 -1
  86. data/spec/integration/mappers/unfold_spec.rb +1 -1
  87. data/spec/integration/mappers/ungroup_spec.rb +1 -1
  88. data/spec/integration/mappers/unwrap_spec.rb +2 -2
  89. data/spec/integration/mappers/wrap_spec.rb +1 -1
  90. data/spec/integration/memory/commands/create_spec.rb +1 -1
  91. data/spec/integration/memory/commands/delete_spec.rb +1 -1
  92. data/spec/integration/memory/commands/update_spec.rb +1 -1
  93. data/spec/integration/multi_env_spec.rb +1 -1
  94. data/spec/integration/multi_repo_spec.rb +1 -1
  95. data/spec/integration/relations/default_dataset_spec.rb +1 -1
  96. data/spec/integration/relations/reading_spec.rb +1 -1
  97. data/spec/integration/relations/registry_dsl_spec.rb +1 -1
  98. data/spec/integration/setup_spec.rb +10 -4
  99. data/spec/shared/command_graph.rb +8 -4
  100. data/spec/shared/enumerable_dataset.rb +1 -1
  101. data/spec/spec_helper.rb +7 -9
  102. data/spec/support/schema.rb +14 -0
  103. data/spec/unit/rom/array_dataset_spec.rb +59 -0
  104. data/spec/unit/rom/association_set_spec.rb +4 -0
  105. data/spec/unit/rom/auto_curry_spec.rb +63 -0
  106. data/spec/unit/rom/commands/graph_spec.rb +12 -11
  107. data/spec/unit/rom/commands/lazy_spec.rb +8 -5
  108. data/spec/unit/rom/commands/pre_and_post_processors_spec.rb +269 -0
  109. data/spec/unit/rom/commands/result_spec.rb +1 -1
  110. data/spec/unit/rom/commands_spec.rb +9 -3
  111. data/spec/unit/rom/configuration_spec.rb +1 -1
  112. data/spec/unit/rom/container_spec.rb +11 -5
  113. data/spec/unit/rom/create_container_spec.rb +1 -1
  114. data/spec/unit/rom/enumerable_dataset_spec.rb +15 -0
  115. data/spec/unit/rom/gateway_spec.rb +1 -1
  116. data/spec/unit/rom/mapper_registry_spec.rb +1 -1
  117. data/spec/unit/rom/memory/commands_spec.rb +1 -1
  118. data/spec/unit/rom/memory/dataset_spec.rb +1 -1
  119. data/spec/unit/rom/memory/{repository_spec.rb → gateway_spec.rb} +1 -1
  120. data/spec/unit/rom/memory/inheritance_spec.rb +32 -0
  121. data/spec/unit/rom/memory/relation_spec.rb +15 -3
  122. data/spec/unit/rom/memory/storage_spec.rb +1 -1
  123. data/spec/unit/rom/plugin_spec.rb +1 -1
  124. data/spec/unit/rom/plugins/relation/key_inference_spec.rb +1 -1
  125. data/spec/unit/rom/registry_spec.rb +86 -0
  126. data/spec/unit/rom/relation/attribute_reader_spec.rb +17 -0
  127. data/spec/unit/rom/relation/composite_spec.rb +1 -1
  128. data/spec/unit/rom/relation/graph_spec.rb +1 -1
  129. data/spec/unit/rom/relation/lazy/combine_spec.rb +1 -1
  130. data/spec/unit/rom/relation/lazy_spec.rb +1 -1
  131. data/spec/unit/rom/relation/loaded_spec.rb +1 -1
  132. data/spec/unit/rom/relation/schema_spec.rb +10 -6
  133. data/spec/unit/rom/relation/view_spec.rb +112 -0
  134. data/spec/unit/rom/relation_spec.rb +16 -2
  135. data/spec/unit/rom/schema/accessing_attributes_spec.rb +52 -0
  136. data/spec/unit/rom/schema/exclude_spec.rb +15 -0
  137. data/spec/unit/rom/schema/finalize_spec.rb +59 -0
  138. data/spec/unit/rom/schema/key_predicate_spec.rb +15 -0
  139. data/spec/unit/rom/schema/merge_spec.rb +17 -0
  140. data/spec/unit/rom/schema/prefix_spec.rb +16 -0
  141. data/spec/unit/rom/schema/project_spec.rb +15 -0
  142. data/spec/unit/rom/schema/rename_spec.rb +22 -0
  143. data/spec/unit/rom/schema/type_spec.rb +49 -0
  144. data/spec/unit/rom/schema/wrap_spec.rb +17 -0
  145. data/spec/unit/rom/schema_spec.rb +2 -2
  146. metadata +69 -17
  147. data/lib/rom/plugins/relation/view/dsl.rb +0 -32
  148. data/lib/rom/plugins/relation/view.rb +0 -95
  149. data/spec/unit/rom/plugins/relation/view_spec.rb +0 -51
@@ -7,6 +7,10 @@ RSpec.describe ROM::AssociationSet do
7
7
  assoc_set.try(:users, &:done)
8
8
 
9
9
  expect(assoc).to have_received(:done)
10
+
11
+ assoc_set.try(:user, &:done)
12
+
13
+ expect(assoc).to have_received(:done)
10
14
  end
11
15
 
12
16
  it 'returns false when assoc is not found' do
@@ -0,0 +1,63 @@
1
+ require 'rom/auto_curry'
2
+
3
+ RSpec.describe ROM::AutoCurry do
4
+ subject(:object) { klass.new }
5
+
6
+ let(:klass) do
7
+ Class.new do
8
+ extend ROM::AutoCurry
9
+
10
+ def self.curried(*)
11
+ self
12
+ end
13
+
14
+ def initialize(*)
15
+ end
16
+
17
+ def arity_0
18
+ 0
19
+ end
20
+
21
+ def arity_1(x)
22
+ x
23
+ end
24
+
25
+ def arity_2(x, y)
26
+ [x,y]
27
+ end
28
+
29
+ def arity_many(*args)
30
+ args
31
+ end
32
+
33
+ protected
34
+
35
+ def leave_me_alone(foo)
36
+ foo
37
+ end
38
+ end
39
+ end
40
+
41
+ it 'registers auto-curried methods' do
42
+ expect(object.class.auto_curried_methods).to eql(%i[arity_1 arity_2 arity_many])
43
+ end
44
+
45
+ it 'auto-curries method with arity == 0' do
46
+ expect(object.arity_0).to be(0)
47
+ end
48
+
49
+ it 'auto-curries method with arity == 1' do
50
+ expect(object.arity_1).to be_instance_of(klass)
51
+ expect(object.arity_1(1)).to be(1)
52
+ end
53
+
54
+ it 'auto-curries method with arity > 0' do
55
+ expect(object.arity_2).to be_instance_of(klass)
56
+ expect(object.arity_2(1, 2)).to eql([1, 2])
57
+ end
58
+
59
+ it 'auto-curries method with arity < 0' do
60
+ expect(object.arity_many).to eql([])
61
+ expect(object.arity_many(1, 2)).to eql([1, 2])
62
+ end
63
+ end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'dry-struct'
3
3
 
4
- describe ROM::Commands::Graph do
4
+ RSpec.describe ROM::Commands::Graph do
5
5
  shared_examples_for 'a persisted graph' do
6
6
  it 'returns nested results' do
7
7
  expect(command.call).to match_array([
@@ -75,17 +75,19 @@ describe ROM::Commands::Graph do
75
75
  configuration.commands(:tasks) do
76
76
  define(:create) do
77
77
  result :one
78
+ before :associate
78
79
 
79
- def execute(task, user)
80
- super(task.merge(user: user[:name]))
80
+ def associate(task, user)
81
+ task.merge(user: user[:name])
81
82
  end
82
83
  end
83
84
 
84
85
  define(:create) do
85
86
  register_as :create_many
87
+ before :associate
86
88
 
87
- def execute(tasks, user)
88
- super(tasks.map { |t| t.merge(user: user[:name]) })
89
+ def associate(tasks, user)
90
+ tasks.map { |t| t.merge(user: user[:name]) }
89
91
  end
90
92
  end
91
93
  end
@@ -93,13 +95,12 @@ describe ROM::Commands::Graph do
93
95
  configuration.commands(:tags) do
94
96
  define(:create) do
95
97
  register_as :create_many
98
+ before :associate
96
99
 
97
- def execute(tags, tasks)
98
- super(
99
- Array([tasks]).flatten.map { |task|
100
- tags.map { |tag| tag.merge(task: task[:title]) }
101
- }.flatten
102
- )
100
+ def associate(tags, tasks)
101
+ Array([tasks]).flatten.map { |task|
102
+ tags.map { |tag| tag.merge(task: task[:title]) }
103
+ }.flatten
103
104
  end
104
105
  end
105
106
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ROM::Commands::Lazy do
3
+ RSpec.describe ROM::Commands::Lazy do
4
4
  include_context 'container'
5
5
 
6
6
  let(:create_user) { container.command(:users).create }
@@ -56,16 +56,19 @@ describe ROM::Commands::Lazy do
56
56
  end
57
57
 
58
58
  define(:create_many, type: :create) do
59
- def execute(tuples, user)
60
- super(tuples.map { |tuple| tuple.merge(user: user[:name]) })
59
+ before :associate
60
+
61
+ def associate(tuples, user)
62
+ tuples.map { |tuple| tuple.merge(user: user[:name]) }
61
63
  end
62
64
  end
63
65
 
64
66
  define(:update) do
65
67
  result :one
68
+ before :associate
66
69
 
67
- def execute(tuple, user)
68
- super(tuple.merge(user: user[:name]))
70
+ def associate(tuple, user)
71
+ tuple.merge(user: user[:name])
69
72
  end
70
73
  end
71
74
  end
@@ -0,0 +1,269 @@
1
+ require 'rom/command'
2
+
3
+ RSpec.describe ROM::Command, 'before/after hooks' do
4
+ let(:relation) do
5
+ spy(:relation)
6
+ end
7
+
8
+ describe '#before' do
9
+ subject(:command) do
10
+ Class.new(ROM::Command) do
11
+ def prepare(*)
12
+ end
13
+ end.build(relation)
14
+ end
15
+
16
+ it 'returns a new command with configured before hooks' do
17
+ expect(command.before(:prepare).before_hooks).to include(:prepare)
18
+ end
19
+ end
20
+
21
+ describe '#after' do
22
+ subject(:command) do
23
+ Class.new(ROM::Command) do
24
+ def prepare(*)
25
+ end
26
+ end.build(relation)
27
+ end
28
+
29
+ it 'returns a new command with configured after hooks' do
30
+ expect(command.after(:prepare).after_hooks).to include(:prepare)
31
+ end
32
+ end
33
+
34
+ context 'without curried args' do
35
+ subject(:command) do
36
+ Class.new(ROM::Command) do
37
+ result :many
38
+ before :prepare
39
+ after :finalize
40
+
41
+ def execute(tuples)
42
+ input = tuples.map.with_index { |tuple, idx| tuple.merge(id: idx + 1) }
43
+ relation.insert(input)
44
+ input
45
+ end
46
+
47
+ def prepare(tuples)
48
+ tuples.map { |tuple| tuple.merge(prepared: true) }
49
+ end
50
+
51
+ def finalize(tuples)
52
+ tuples.map { |tuple| tuple.merge(finalized: true) }
53
+ end
54
+ end.build(relation)
55
+ end
56
+
57
+ let(:tuples) do
58
+ [{ name: 'Jane' }, { name: 'Joe' }]
59
+ end
60
+
61
+ it 'applies before/after hooks' do
62
+ insert_tuples = [
63
+ { id: 1, name: 'Jane', prepared: true },
64
+ { id: 2, name: 'Joe', prepared: true }
65
+ ]
66
+
67
+ result = [
68
+ { id: 1, name: 'Jane', prepared: true, finalized: true },
69
+ { id: 2, name: 'Joe', prepared: true, finalized: true }
70
+ ]
71
+
72
+ expect(command.call(tuples)).to eql(result)
73
+
74
+ expect(relation).to have_received(:insert).with(insert_tuples)
75
+ end
76
+ end
77
+
78
+ context 'with curried args' do
79
+ subject(:command) do
80
+ Class.new(ROM::Command) do
81
+ result :many
82
+ before :prepare
83
+ after :finalize
84
+
85
+ def execute(tuples)
86
+ input = tuples.map.with_index { |tuple, idx| tuple.merge(id: idx + 1) }
87
+ relation.insert(input)
88
+ input
89
+ end
90
+
91
+ def prepare(tuples, name)
92
+ tuples.map.with_index { |tuple, idx| tuple.merge(name: "#{name} #{idx + 1}") }
93
+ end
94
+
95
+ def finalize(tuples, *)
96
+ tuples.map { |tuple| tuple.merge(finalized: true) }
97
+ end
98
+ end.build(relation)
99
+ end
100
+
101
+ let(:tuples) do
102
+ [{ email: 'user-1@test.com' }, { email: 'user-2@test.com' }]
103
+ end
104
+
105
+ let(:relation) do
106
+ spy(:relation)
107
+ end
108
+
109
+ it 'applies before/after hooks' do
110
+ insert_tuples = [
111
+ { id: 1, email: 'user-1@test.com', name: 'User 1' },
112
+ { id: 2, email: 'user-2@test.com', name: 'User 2' }
113
+ ]
114
+
115
+ result = [
116
+ { id: 1, email: 'user-1@test.com', name: 'User 1', finalized: true },
117
+ { id: 2, email: 'user-2@test.com', name: 'User 2', finalized: true }
118
+ ]
119
+
120
+ expect(command.with(tuples).call('User')).to eql(result)
121
+
122
+ expect(relation).to have_received(:insert).with(insert_tuples)
123
+ end
124
+ end
125
+
126
+ context 'with pre-set opts' do
127
+ subject(:command) do
128
+ Class.new(ROM::Command) do
129
+ result :many
130
+ before [prepare: { prepared: true }]
131
+ after [finalize: { finalized: true }]
132
+
133
+ def execute(tuples)
134
+ input = tuples.map.with_index { |tuple, idx| tuple.merge(id: idx + 1) }
135
+ relation.insert(input)
136
+ input
137
+ end
138
+
139
+ def prepare(tuples, opts)
140
+ tuples.map { |tuple| tuple.merge(opts) }
141
+ end
142
+
143
+ def finalize(tuples, opts)
144
+ tuples.map { |tuple| tuple.merge(opts) }
145
+ end
146
+ end.build(relation)
147
+ end
148
+
149
+ let(:tuples) do
150
+ [{ name: 'Jane' }, { name: 'Joe' }]
151
+ end
152
+
153
+ let(:relation) do
154
+ spy(:relation)
155
+ end
156
+
157
+ it 'applies before/after hooks' do
158
+ insert_tuples = [
159
+ { id: 1, name: 'Jane', prepared: true },
160
+ { id: 2, name: 'Joe', prepared: true }
161
+ ]
162
+
163
+ result = [
164
+ { id: 1, name: 'Jane', prepared: true, finalized: true },
165
+ { id: 2, name: 'Joe', prepared: true, finalized: true }
166
+ ]
167
+
168
+ expect(command.call(tuples)).to eql(result)
169
+
170
+ expect(relation).to have_received(:insert).with(insert_tuples)
171
+ end
172
+ end
173
+
174
+ context 'with pre-set opts for a curried command' do
175
+ subject(:command) do
176
+ Class.new(ROM::Command) do
177
+ result :many
178
+ before [prepare: { prepared: true }]
179
+ after [finalize: { finalized: true }]
180
+
181
+ def execute(tuples)
182
+ input = tuples.map.with_index { |tuple, idx| tuple.merge(id: idx + 1) }
183
+ relation.insert(input)
184
+ input
185
+ end
186
+
187
+ def prepare(tuples, parent, opts)
188
+ tuples.map { |tuple| tuple.merge(opts).merge(parent_size: parent.size) }
189
+ end
190
+
191
+ def finalize(tuples, parent, opts)
192
+ tuples.map { |tuple| tuple.merge(opts).merge(user_id: parent[:id]) }
193
+ end
194
+ end.build(relation)
195
+ end
196
+
197
+ let(:tuples) do
198
+ [{ name: 'Jane' }, { name: 'Joe' }]
199
+ end
200
+
201
+ let(:relation) do
202
+ spy(:relation)
203
+ end
204
+
205
+ it 'applies before/after hooks' do
206
+ insert_tuples = [
207
+ { id: 1, name: 'Jane', parent_size: 1, prepared: true },
208
+ { id: 2, name: 'Joe', parent_size: 1, prepared: true }
209
+ ]
210
+
211
+ result = [
212
+ { id: 1, name: 'Jane', parent_size: 1, user_id: 1, prepared: true, finalized: true },
213
+ { id: 2, name: 'Joe', parent_size: 1, user_id: 1, prepared: true, finalized: true }
214
+ ]
215
+
216
+ expect(command.with(tuples).call(id: 1)).to eql(result)
217
+
218
+ expect(relation).to have_received(:insert).with(insert_tuples)
219
+ end
220
+ end
221
+
222
+ context 'calling with multiple args' do
223
+ subject(:command) do
224
+ Class.new(ROM::Command) do
225
+ result :many
226
+ before [prepare: { prepared: true }]
227
+ after [finalize: { finalized: true }]
228
+
229
+ def execute(tuples)
230
+ input = tuples.map.with_index { |tuple, idx| tuple.merge(id: idx + 1) }
231
+ relation.insert(input)
232
+ input
233
+ end
234
+
235
+ def prepare(tuples, parent, opts)
236
+ tuples.map { |tuple| tuple.merge(opts).merge(parent_size: parent.size) }
237
+ end
238
+
239
+ def finalize(tuples, parent, opts)
240
+ tuples.map { |tuple| tuple.merge(opts).merge(user_id: parent[:id]) }
241
+ end
242
+ end.build(relation)
243
+ end
244
+
245
+ let(:tuples) do
246
+ [{ name: 'Jane' }, { name: 'Joe' }]
247
+ end
248
+
249
+ let(:relation) do
250
+ spy(:relation)
251
+ end
252
+
253
+ it 'applies before/after hooks' do
254
+ insert_tuples = [
255
+ { id: 1, name: 'Jane', parent_size: 1, prepared: true },
256
+ { id: 2, name: 'Joe', parent_size: 1, prepared: true }
257
+ ]
258
+
259
+ result = [
260
+ { id: 1, name: 'Jane', parent_size: 1, user_id: 1, prepared: true, finalized: true },
261
+ { id: 2, name: 'Joe', parent_size: 1, user_id: 1, prepared: true, finalized: true }
262
+ ]
263
+
264
+ expect(command.call(tuples, id: 1)).to eql(result)
265
+
266
+ expect(relation).to have_received(:insert).with(insert_tuples)
267
+ end
268
+ end
269
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ROM::Commands::Result do
3
+ RSpec.describe ROM::Commands::Result do
4
4
  describe '#value' do
5
5
  subject(:result) { ROM::Commands::Result::Success }
6
6
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Commands' do
3
+ RSpec.describe 'Commands' do
4
4
  include_context 'gateway only'
5
5
  include_context 'users and tasks'
6
6
 
@@ -99,8 +99,14 @@ describe 'Commands' do
99
99
  }.build(users)
100
100
 
101
101
  create_task = Class.new(ROM::Commands::Create) {
102
- def execute(task_input, user_tuple)
103
- relation.insert(task_input.merge(user_id: user_tuple[:user_id]))
102
+ before :associate
103
+
104
+ def associate(task_input, user_tuple)
105
+ task_input.merge(user_id: user_tuple[:user_id])
106
+ end
107
+
108
+ def execute(task_input)
109
+ relation.insert(task_input)
104
110
  end
105
111
  }.build(tasks)
106
112
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ROM::Configuration do
3
+ RSpec.describe ROM::Configuration do
4
4
  it 'is configurable via settings hash' do
5
5
  configuration = ROM::Configuration.new(:memory, 'something', infer_schema: false)
6
6
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ROM::Container do
3
+ RSpec.describe ROM::Container do
4
4
  include_context 'container'
5
5
  include_context 'users and tasks'
6
6
 
@@ -8,16 +8,22 @@ describe ROM::Container do
8
8
  configuration
9
9
 
10
10
  users = Class.new(ROM::Relation[:memory]) do
11
- register_as :users
12
- dataset :users
11
+ schema(:users) do
12
+ attribute :name, ROM::Types::String
13
+ attribute :email, ROM::Types::String
14
+ end
15
+
13
16
  def by_name(name)
14
17
  restrict(name: name).project(:name)
15
18
  end
16
19
  end
17
20
 
18
21
  tasks = Class.new(ROM::Relation[:memory]) do
19
- register_as :tasks
20
- dataset :tasks
22
+ schema(:tasks) do
23
+ attribute :name, ROM::Types::String
24
+ attribute :title, ROM::Types::String
25
+ attribute :priority, ROM::Types::Int
26
+ end
21
27
  end
22
28
 
23
29
  create_user = Class.new(ROM::Commands::Create[:memory]) do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ROM::CreateContainer do
3
+ RSpec.describe ROM::CreateContainer do
4
4
  describe '#finalize' do
5
5
  include_context 'container'
6
6
 
@@ -0,0 +1,15 @@
1
+ require 'rom/enumerable_dataset'
2
+
3
+ RSpec.describe ROM::EnumerableDataset do
4
+ let(:klass) do
5
+ Class.new do
6
+ include ROM::EnumerableDataset
7
+
8
+ def self.row_proc
9
+ -> i { i.each_with_object({}) { |(k,v),h| h[k.to_sym] = v } }
10
+ end
11
+ end
12
+ end
13
+
14
+ it_behaves_like 'an enumerable dataset'
15
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ROM::Gateway do
3
+ RSpec.describe ROM::Gateway do
4
4
 
5
5
  subject(:gateway) { Class.new(ROM::Gateway).new }
6
6
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ROM::MapperRegistry do
3
+ RSpec.describe ROM::MapperRegistry do
4
4
  subject(:registry) { ROM::MapperRegistry.new }
5
5
 
6
6
  let(:user_mapper) { double('user_mapper') }
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'rom/memory'
3
3
 
4
- describe ROM::Memory::Commands do
4
+ RSpec.describe ROM::Memory::Commands do
5
5
  let(:relation) do
6
6
  Class.new(ROM::Relation[:memory]) do
7
7
  schema do
@@ -3,7 +3,7 @@ require 'rom/lint/spec'
3
3
 
4
4
  require 'rom/memory/dataset'
5
5
 
6
- describe ROM::Memory::Dataset do
6
+ RSpec.describe ROM::Memory::Dataset do
7
7
  subject(:dataset) { ROM::Memory::Dataset.new(data) }
8
8
 
9
9
  let(:data) do
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
  require 'rom/lint/spec'
3
3
  require 'rom/memory'
4
4
 
5
- describe ROM::Memory::Gateway do
5
+ RSpec.describe ROM::Memory::Gateway do
6
6
  let(:gateway) { ROM::Memory::Gateway }
7
7
  let(:uri) { nil }
8
8
 
@@ -0,0 +1,32 @@
1
+ require 'rom/memory'
2
+
3
+ RSpec.describe ROM::Memory::Relation, '.inherited' do
4
+ subject(:relation) do
5
+ Class.new(ROM::Relation[:test]) do
6
+ schema(:users) do
7
+ attribute :name, ROM::Types::String
8
+ end
9
+ end.new([])
10
+ end
11
+
12
+ before do
13
+ module Test
14
+ module AnotherAdapter
15
+ class Relation < ROM::Memory::Relation
16
+ adapter :test
17
+ end
18
+ end
19
+ end
20
+
21
+ ROM.register_adapter(:test, Test::AnotherAdapter)
22
+ end
23
+
24
+ after do
25
+ ROM.adapters.delete(:test)
26
+ end
27
+
28
+ it 'extends subclass with core methods' do
29
+ expect(relation.name.to_sym).to be(:users)
30
+ expect(relation.schema.map(&:name)).to eql(%i[name])
31
+ end
32
+ end
@@ -4,8 +4,16 @@ require 'rom/lint/spec'
4
4
  require 'rom/memory/dataset'
5
5
  require 'rom/memory/relation'
6
6
 
7
- describe ROM::Memory::Relation do
8
- subject(:relation) { ROM::Memory::Relation.new(dataset) }
7
+ RSpec.describe ROM::Memory::Relation do
8
+ subject(:relation) do
9
+ Class.new(ROM::Memory::Relation) do
10
+ schema do
11
+ attribute :name, ROM::Types::String
12
+ attribute :email, ROM::Types::String
13
+ attribute :age, ROM::Types::Int
14
+ end
15
+ end.new(dataset)
16
+ end
9
17
 
10
18
  let(:dataset) do
11
19
  ROM::Memory::Dataset.new([
@@ -30,7 +38,11 @@ describe ROM::Memory::Relation do
30
38
 
31
39
  describe '#project' do
32
40
  it 'projects tuples with the provided keys' do
33
- expect(relation.project(:name, :age)).to match_array([
41
+ projected = relation.project(:name, :age)
42
+
43
+ expect(projected.schema).to eql(relation.schema.project(:name, :age))
44
+
45
+ expect(projected).to match_array([
34
46
  { name: 'Jane', age: 10 },
35
47
  { name: 'Jade', age: 11 },
36
48
  { name: 'Joe', age: 12 },
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'rom/memory/storage'
3
3
 
4
- describe ROM::Memory::Storage do
4
+ RSpec.describe ROM::Memory::Storage do
5
5
  describe 'thread safe' do
6
6
  let(:threads) { 4 }
7
7
  let(:operations) { 5000 }
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "ROM::PluginRegistry" do
3
+ RSpec.describe "ROM::PluginRegistry" do
4
4
  include_context 'container'
5
5
 
6
6
  before do
@@ -58,7 +58,7 @@ RSpec.describe ROM::Plugins::Relation::KeyInference do
58
58
  use :key_inference
59
59
 
60
60
  schema :posts do
61
- attribute :author_id, ROM::Types::Int.meta(foreign_key: true, relation: :users)
61
+ attribute :author_id, ROM::Types::Int.meta(foreign_key: true, target: :users)
62
62
  end
63
63
  end
64
64
  end