rom 3.3.3 → 4.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (241) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +2 -599
  3. data/lib/rom/version.rb +1 -1
  4. data/lib/rom.rb +3 -44
  5. metadata +19 -295
  6. data/.gitignore +0 -24
  7. data/.rspec +0 -3
  8. data/.rubocop.yml +0 -87
  9. data/.rubocop_todo.yml +0 -46
  10. data/.travis.yml +0 -24
  11. data/.yardopts +0 -2
  12. data/CODE_OF_CONDUCT.md +0 -13
  13. data/CONTRIBUTING.md +0 -1
  14. data/Gemfile +0 -54
  15. data/Guardfile +0 -24
  16. data/Rakefile +0 -28
  17. data/lib/rom/array_dataset.rb +0 -44
  18. data/lib/rom/association_set.rb +0 -49
  19. data/lib/rom/auto_curry.rb +0 -55
  20. data/lib/rom/command.rb +0 -494
  21. data/lib/rom/command_registry.rb +0 -148
  22. data/lib/rom/commands/class_interface.rb +0 -270
  23. data/lib/rom/commands/composite.rb +0 -53
  24. data/lib/rom/commands/create.rb +0 -13
  25. data/lib/rom/commands/delete.rb +0 -14
  26. data/lib/rom/commands/graph/builder.rb +0 -176
  27. data/lib/rom/commands/graph/class_interface.rb +0 -62
  28. data/lib/rom/commands/graph/input_evaluator.rb +0 -62
  29. data/lib/rom/commands/graph.rb +0 -95
  30. data/lib/rom/commands/lazy/create.rb +0 -23
  31. data/lib/rom/commands/lazy/delete.rb +0 -27
  32. data/lib/rom/commands/lazy/update.rb +0 -34
  33. data/lib/rom/commands/lazy.rb +0 -99
  34. data/lib/rom/commands/result.rb +0 -96
  35. data/lib/rom/commands/update.rb +0 -14
  36. data/lib/rom/commands.rb +0 -3
  37. data/lib/rom/configuration.rb +0 -90
  38. data/lib/rom/configuration_dsl/command.rb +0 -41
  39. data/lib/rom/configuration_dsl/command_dsl.rb +0 -35
  40. data/lib/rom/configuration_dsl/mapper.rb +0 -36
  41. data/lib/rom/configuration_dsl/mapper_dsl.rb +0 -43
  42. data/lib/rom/configuration_dsl/relation.rb +0 -26
  43. data/lib/rom/configuration_dsl.rb +0 -107
  44. data/lib/rom/configuration_plugin.rb +0 -17
  45. data/lib/rom/constants.rb +0 -36
  46. data/lib/rom/container.rb +0 -233
  47. data/lib/rom/create_container.rb +0 -60
  48. data/lib/rom/data_proxy.rb +0 -94
  49. data/lib/rom/enumerable_dataset.rb +0 -68
  50. data/lib/rom/environment.rb +0 -70
  51. data/lib/rom/gateway.rb +0 -196
  52. data/lib/rom/global/plugin_dsl.rb +0 -47
  53. data/lib/rom/global.rb +0 -58
  54. data/lib/rom/initializer.rb +0 -26
  55. data/lib/rom/lint/enumerable_dataset.rb +0 -54
  56. data/lib/rom/lint/gateway.rb +0 -120
  57. data/lib/rom/lint/linter.rb +0 -78
  58. data/lib/rom/lint/spec.rb +0 -20
  59. data/lib/rom/lint/test.rb +0 -98
  60. data/lib/rom/mapper_registry.rb +0 -35
  61. data/lib/rom/memory/commands.rb +0 -56
  62. data/lib/rom/memory/dataset.rb +0 -97
  63. data/lib/rom/memory/gateway.rb +0 -64
  64. data/lib/rom/memory/relation.rb +0 -62
  65. data/lib/rom/memory/schema.rb +0 -13
  66. data/lib/rom/memory/storage.rb +0 -59
  67. data/lib/rom/memory/types.rb +0 -9
  68. data/lib/rom/memory.rb +0 -4
  69. data/lib/rom/pipeline.rb +0 -122
  70. data/lib/rom/plugin.rb +0 -20
  71. data/lib/rom/plugin_base.rb +0 -40
  72. data/lib/rom/plugin_registry.rb +0 -173
  73. data/lib/rom/plugins/command/schema.rb +0 -37
  74. data/lib/rom/plugins/configuration/configuration_dsl.rb +0 -21
  75. data/lib/rom/plugins/relation/instrumentation.rb +0 -51
  76. data/lib/rom/plugins/relation/key_inference.rb +0 -48
  77. data/lib/rom/plugins/relation/registry_reader.rb +0 -33
  78. data/lib/rom/registry.rb +0 -50
  79. data/lib/rom/relation/class_interface.rb +0 -356
  80. data/lib/rom/relation/composite.rb +0 -46
  81. data/lib/rom/relation/curried.rb +0 -109
  82. data/lib/rom/relation/graph.rb +0 -125
  83. data/lib/rom/relation/loaded.rb +0 -127
  84. data/lib/rom/relation/materializable.rb +0 -66
  85. data/lib/rom/relation/name.rb +0 -102
  86. data/lib/rom/relation/view_dsl.rb +0 -64
  87. data/lib/rom/relation.rb +0 -250
  88. data/lib/rom/relation_registry.rb +0 -9
  89. data/lib/rom/schema/attribute.rb +0 -390
  90. data/lib/rom/schema/dsl.rb +0 -67
  91. data/lib/rom/schema.rb +0 -407
  92. data/lib/rom/setup/auto_registration.rb +0 -74
  93. data/lib/rom/setup/auto_registration_strategies/base.rb +0 -16
  94. data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +0 -63
  95. data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +0 -20
  96. data/lib/rom/setup/auto_registration_strategies/with_namespace.rb +0 -18
  97. data/lib/rom/setup/finalize/finalize_commands.rb +0 -47
  98. data/lib/rom/setup/finalize/finalize_mappers.rb +0 -36
  99. data/lib/rom/setup/finalize/finalize_relations.rb +0 -83
  100. data/lib/rom/setup/finalize.rb +0 -152
  101. data/lib/rom/setup.rb +0 -65
  102. data/lib/rom/support/configurable.rb +0 -85
  103. data/lib/rom/transaction.rb +0 -24
  104. data/lib/rom/types.rb +0 -49
  105. data/log/.gitkeep +0 -0
  106. data/rakelib/benchmark.rake +0 -15
  107. data/rakelib/mutant.rake +0 -19
  108. data/rakelib/rubocop.rake +0 -18
  109. data/rom.gemspec +0 -25
  110. data/spec/fixtures/app/commands/create_user.rb +0 -2
  111. data/spec/fixtures/app/mappers/user_list.rb +0 -2
  112. data/spec/fixtures/app/my_commands/create_user.rb +0 -2
  113. data/spec/fixtures/app/my_mappers/user_list.rb +0 -2
  114. data/spec/fixtures/app/my_relations/users.rb +0 -2
  115. data/spec/fixtures/app/relations/users.rb +0 -2
  116. data/spec/fixtures/custom/commands/create_user.rb +0 -6
  117. data/spec/fixtures/custom/mappers/user_list.rb +0 -6
  118. data/spec/fixtures/custom/relations/users.rb +0 -6
  119. data/spec/fixtures/custom_namespace/commands/create_customer.rb +0 -8
  120. data/spec/fixtures/custom_namespace/mappers/customer_list.rb +0 -8
  121. data/spec/fixtures/custom_namespace/relations/customers.rb +0 -8
  122. data/spec/fixtures/lib/persistence/commands/create_user.rb +0 -6
  123. data/spec/fixtures/lib/persistence/mappers/user_list.rb +0 -6
  124. data/spec/fixtures/lib/persistence/my_commands/create_user.rb +0 -6
  125. data/spec/fixtures/lib/persistence/my_mappers/user_list.rb +0 -6
  126. data/spec/fixtures/lib/persistence/my_relations/users.rb +0 -6
  127. data/spec/fixtures/lib/persistence/relations/users.rb +0 -6
  128. data/spec/fixtures/wrong/commands/create_customer.rb +0 -8
  129. data/spec/fixtures/wrong/mappers/customer_list.rb +0 -8
  130. data/spec/fixtures/wrong/relations/customers.rb +0 -8
  131. data/spec/integration/command_registry_spec.rb +0 -47
  132. data/spec/integration/commands/create_spec.rb +0 -157
  133. data/spec/integration/commands/delete_spec.rb +0 -67
  134. data/spec/integration/commands/error_handling_spec.rb +0 -25
  135. data/spec/integration/commands/graph_builder_spec.rb +0 -213
  136. data/spec/integration/commands/graph_spec.rb +0 -294
  137. data/spec/integration/commands/update_spec.rb +0 -86
  138. data/spec/integration/commands_spec.rb +0 -67
  139. data/spec/integration/gateways/extending_relations_spec.rb +0 -58
  140. data/spec/integration/gateways/setting_logger_spec.rb +0 -34
  141. data/spec/integration/mappers/combine_spec.rb +0 -117
  142. data/spec/integration/mappers/deep_embedded_spec.rb +0 -44
  143. data/spec/integration/mappers/definition_dsl_spec.rb +0 -206
  144. data/spec/integration/mappers/embedded_spec.rb +0 -62
  145. data/spec/integration/mappers/exclude_spec.rb +0 -27
  146. data/spec/integration/mappers/fold_spec.rb +0 -71
  147. data/spec/integration/mappers/group_spec.rb +0 -163
  148. data/spec/integration/mappers/overwrite_attributes_value_spec.rb +0 -51
  149. data/spec/integration/mappers/prefix_separator_spec.rb +0 -52
  150. data/spec/integration/mappers/prefix_spec.rb +0 -48
  151. data/spec/integration/mappers/prefixing_attributes_spec.rb +0 -37
  152. data/spec/integration/mappers/registering_custom_mappers_spec.rb +0 -28
  153. data/spec/integration/mappers/renaming_attributes_spec.rb +0 -125
  154. data/spec/integration/mappers/reusing_mappers_spec.rb +0 -43
  155. data/spec/integration/mappers/step_spec.rb +0 -119
  156. data/spec/integration/mappers/symbolizing_attributes_spec.rb +0 -77
  157. data/spec/integration/mappers/unfold_spec.rb +0 -92
  158. data/spec/integration/mappers/ungroup_spec.rb +0 -126
  159. data/spec/integration/mappers/unwrap_spec.rb +0 -93
  160. data/spec/integration/mappers/wrap_spec.rb +0 -155
  161. data/spec/integration/memory/commands/create_spec.rb +0 -23
  162. data/spec/integration/memory/commands/delete_spec.rb +0 -23
  163. data/spec/integration/memory/commands/update_spec.rb +0 -23
  164. data/spec/integration/multi_env_spec.rb +0 -69
  165. data/spec/integration/multi_repo_spec.rb +0 -46
  166. data/spec/integration/relations/default_dataset_spec.rb +0 -38
  167. data/spec/integration/relations/inheritance_spec.rb +0 -37
  168. data/spec/integration/relations/reading_spec.rb +0 -169
  169. data/spec/integration/relations/registry_dsl_spec.rb +0 -45
  170. data/spec/integration/setup_spec.rb +0 -193
  171. data/spec/shared/command_behavior.rb +0 -28
  172. data/spec/shared/command_graph.rb +0 -54
  173. data/spec/shared/container.rb +0 -9
  174. data/spec/shared/enumerable_dataset.rb +0 -52
  175. data/spec/shared/gateway_only.rb +0 -6
  176. data/spec/shared/materializable.rb +0 -36
  177. data/spec/shared/no_container.rb +0 -16
  178. data/spec/shared/one_behavior.rb +0 -26
  179. data/spec/shared/proxy.rb +0 -0
  180. data/spec/shared/users_and_tasks.rb +0 -10
  181. data/spec/spec_helper.rb +0 -59
  182. data/spec/support/constant_leak_finder.rb +0 -14
  183. data/spec/support/mutant.rb +0 -10
  184. data/spec/support/schema.rb +0 -14
  185. data/spec/support/types.rb +0 -5
  186. data/spec/test/memory_repository_lint_test.rb +0 -27
  187. data/spec/unit/rom/array_dataset_spec.rb +0 -59
  188. data/spec/unit/rom/association_set_spec.rb +0 -48
  189. data/spec/unit/rom/auto_curry_spec.rb +0 -71
  190. data/spec/unit/rom/commands/graph_spec.rb +0 -192
  191. data/spec/unit/rom/commands/lazy_spec.rb +0 -310
  192. data/spec/unit/rom/commands/pre_and_post_processors_spec.rb +0 -343
  193. data/spec/unit/rom/commands/result_spec.rb +0 -70
  194. data/spec/unit/rom/commands_spec.rb +0 -188
  195. data/spec/unit/rom/configurable_spec.rb +0 -49
  196. data/spec/unit/rom/configuration_spec.rb +0 -61
  197. data/spec/unit/rom/container_spec.rb +0 -109
  198. data/spec/unit/rom/create_container_spec.rb +0 -151
  199. data/spec/unit/rom/enumerable_dataset_spec.rb +0 -15
  200. data/spec/unit/rom/environment_spec.rb +0 -123
  201. data/spec/unit/rom/gateway_spec.rb +0 -146
  202. data/spec/unit/rom/mapper_registry_spec.rb +0 -25
  203. data/spec/unit/rom/memory/commands_spec.rb +0 -43
  204. data/spec/unit/rom/memory/dataset_spec.rb +0 -31
  205. data/spec/unit/rom/memory/gateway_spec.rb +0 -12
  206. data/spec/unit/rom/memory/inheritance_spec.rb +0 -32
  207. data/spec/unit/rom/memory/relation_spec.rb +0 -121
  208. data/spec/unit/rom/memory/storage_spec.rb +0 -45
  209. data/spec/unit/rom/plugin_spec.rb +0 -150
  210. data/spec/unit/rom/plugins/command/schema_spec.rb +0 -66
  211. data/spec/unit/rom/plugins/relation/instrumentation_spec.rb +0 -44
  212. data/spec/unit/rom/plugins/relation/key_inference_spec.rb +0 -85
  213. data/spec/unit/rom/registry_spec.rb +0 -86
  214. data/spec/unit/rom/relation/attribute_reader_spec.rb +0 -17
  215. data/spec/unit/rom/relation/call_spec.rb +0 -51
  216. data/spec/unit/rom/relation/composite_spec.rb +0 -106
  217. data/spec/unit/rom/relation/curried_spec.rb +0 -67
  218. data/spec/unit/rom/relation/graph_spec.rb +0 -106
  219. data/spec/unit/rom/relation/lazy/combine_spec.rb +0 -165
  220. data/spec/unit/rom/relation/lazy/graph_spec.rb +0 -165
  221. data/spec/unit/rom/relation/lazy_spec.rb +0 -214
  222. data/spec/unit/rom/relation/loaded_spec.rb +0 -53
  223. data/spec/unit/rom/relation/name_spec.rb +0 -58
  224. data/spec/unit/rom/relation/output_schema_spec.rb +0 -28
  225. data/spec/unit/rom/relation/schema_spec.rb +0 -259
  226. data/spec/unit/rom/relation/view_spec.rb +0 -158
  227. data/spec/unit/rom/relation_spec.rb +0 -252
  228. data/spec/unit/rom/schema/accessing_attributes_spec.rb +0 -52
  229. data/spec/unit/rom/schema/append_spec.rb +0 -17
  230. data/spec/unit/rom/schema/exclude_spec.rb +0 -15
  231. data/spec/unit/rom/schema/finalize_spec.rb +0 -59
  232. data/spec/unit/rom/schema/key_predicate_spec.rb +0 -15
  233. data/spec/unit/rom/schema/merge_spec.rb +0 -17
  234. data/spec/unit/rom/schema/prefix_spec.rb +0 -16
  235. data/spec/unit/rom/schema/project_spec.rb +0 -15
  236. data/spec/unit/rom/schema/rename_spec.rb +0 -22
  237. data/spec/unit/rom/schema/type_spec.rb +0 -49
  238. data/spec/unit/rom/schema/uniq_spec.rb +0 -21
  239. data/spec/unit/rom/schema/wrap_spec.rb +0 -18
  240. data/spec/unit/rom/schema_spec.rb +0 -10
  241. data/spec/unit/rom/setup/auto_registration_spec.rb +0 -214
@@ -1,294 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe 'Building up a command graph for nested input' do
4
- include_context 'command graph'
5
-
6
- it 'creates a command graph for nested input :one result as root' do
7
- configuration.commands(:tasks) do
8
- define(:create) do
9
- result :one
10
- before :associate
11
-
12
- def associate(tuple, user)
13
- tuple.merge(user: user.fetch(:name))
14
- end
15
- end
16
- end
17
-
18
- input = {
19
- user: {
20
- name: 'Jane',
21
- task: {
22
- title: 'Task One',
23
- tags: [
24
- { name: 'red' }, { name: 'green' }, { name: 'blue' }
25
- ]
26
- },
27
- books: [
28
- { title: 'Book One' },
29
- { title: 'Book Two' }
30
- ]
31
- }
32
- }
33
-
34
- options = [
35
- { user: :users }, [
36
- :create, [
37
- [{ task: :tasks }, [:create, [:tags, [:create]]]],
38
- [:books, [:create]]
39
- ]
40
- ]
41
- ]
42
-
43
- command = container.command(options)
44
-
45
- command.call(input)
46
-
47
- expect(container.relation(:users)).to match_array([
48
- { name: 'Jane' }
49
- ])
50
-
51
- expect(container.relation(:tasks)).to match_array([
52
- { title: 'Task One', user: 'Jane' }
53
- ])
54
-
55
- expect(container.relation(:books)).to match_array([
56
- { title: 'Book One', user: 'Jane' },
57
- { title: 'Book Two', user: 'Jane' }
58
- ])
59
-
60
- expect(container.relation(:tags)).to match_array([
61
- { name: 'red', task: 'Task One' },
62
- { name: 'green', task: 'Task One' },
63
- { name: 'blue', task: 'Task One' }
64
- ])
65
- end
66
-
67
- it 'creates a command graph for nested input with :many results as root' do
68
- configuration.commands(:tasks) do
69
- define(:create) do
70
- before :associate
71
-
72
- def associate(tuples, user)
73
- tuples.map { |t| t.merge(user: user.fetch(:name)) }
74
- end
75
- end
76
- end
77
-
78
- input = {
79
- user: {
80
- name: 'Jane',
81
- tasks: [
82
- {
83
- title: 'Task One',
84
- tags: [{ name: 'red' }, { name: 'green' }]
85
- },
86
- {
87
- title: 'Task Two',
88
- tags: [{ name: 'blue' }]
89
- }
90
- ]
91
- }
92
- }
93
-
94
- options = [
95
- { user: :users }, [
96
- :create, [
97
- [:tasks, [:create, [:tags, [:create]]]]
98
- ]
99
- ]
100
- ]
101
-
102
- command = container.command(options)
103
-
104
- command.call(input)
105
-
106
- expect(container.relation(:users)).to match_array([
107
- { name: 'Jane' }
108
- ])
109
-
110
- expect(container.relation(:tasks)).to match_array([
111
- { title: 'Task One', user: 'Jane' },
112
- { title: 'Task Two', user: 'Jane' }
113
- ])
114
-
115
- expect(container.relation(:tags)).to match_array([
116
- { name: 'red', task: 'Task One' },
117
- { name: 'green', task: 'Task One' },
118
- { name: 'blue', task: 'Task Two' }
119
- ])
120
- end
121
-
122
-
123
- it 'updates graph elements cleanly' do
124
- configuration.commands(:tasks) do
125
- define(:create) do
126
- before :associate
127
-
128
- def associate(tuples, user)
129
- tuples.map { |t| t.merge(user: user.fetch(:name)) }
130
- end
131
- end
132
-
133
- define(:update) do
134
- result :one
135
- before :associate
136
-
137
- def associate(tuple, user)
138
- tuple.merge(user: user.fetch(:name))
139
- end
140
- end
141
-
142
- define(:delete) do
143
- register_as :complete
144
- result :one
145
- end
146
- end
147
-
148
- configuration.commands(:users) do
149
- define(:update) do
150
- result :one
151
- end
152
- end
153
-
154
- initial = {
155
- user: {
156
- name: 'Johnny',
157
- email: 'johnny@doe.org',
158
- tasks: [
159
- { title: 'Change Name' },
160
- { title: 'Finish that novel' }
161
- ]
162
- }
163
- }
164
-
165
- updated = {
166
- user: {
167
- name: 'Johnny',
168
- email: 'johnathan@doe.org',
169
- completed: [{ title: 'Change Name' }],
170
- tasks: [{ title: 'Finish that novel', priority: 1 }]
171
- }
172
- }
173
-
174
- create = container.command([{ user: :users }, [:create, [:tasks, [:create]]]])
175
-
176
- update = container.command([
177
- { user: :users },
178
- [
179
- { update: -> cmd, user { cmd.by_name(user[:name]) } },
180
- [
181
- [
182
- { completed: :tasks },
183
- [{ complete: -> cmd, user, task { cmd.by_user_and_title(user[:name], task[:title]) } }]
184
- ],
185
- [
186
- :tasks,
187
- [{ update: -> cmd, user, task { cmd.by_user_and_title(user[:name], task[:title]) } }]
188
- ]
189
- ]
190
- ]
191
- ])
192
-
193
- create.call(initial)
194
-
195
- container.command(:tasks).create.with([{ title: 'Task One'}]).(name: 'Jane')
196
-
197
- expect(container.relation(:tasks)).to match_array([
198
- { title: 'Change Name', user: 'Johnny' },
199
- { title: 'Finish that novel', user: 'Johnny' },
200
- { title: 'Task One', user: 'Jane' }
201
- ])
202
-
203
- update.call(updated)
204
-
205
- expect(container.relation(:users)).to match_array([
206
- { name: 'Johnny', email: 'johnathan@doe.org' }
207
- ])
208
-
209
- expect(container.relation(:tasks)).to match_array([
210
- { title: 'Task One', user: 'Jane' },
211
- { title: 'Finish that novel', priority: 1, user: 'Johnny' }
212
- ])
213
- end
214
-
215
-
216
- it 'works with auto-mapping' do
217
- configuration.mappers do
218
- define(:users) do
219
- register_as :entity
220
- reject_keys true
221
-
222
- model name: 'Test::User'
223
-
224
- attribute :name
225
-
226
- combine :tasks, on: { name: :user } do
227
- model name: 'Test::Task'
228
- attribute :title
229
-
230
- combine :tags, on: { title: :task } do
231
- model name: 'Test::Tag'
232
- attribute :name
233
- end
234
- end
235
- end
236
- end
237
-
238
- configuration.commands(:tasks) do
239
- define(:create) do
240
- before :associate
241
-
242
- def associate(tuples, user)
243
- tuples.map { |t| t.merge(user: user.fetch(:name)) }
244
- end
245
- end
246
- end
247
-
248
- input = {
249
- user: {
250
- name: 'Jane',
251
- tasks: [
252
- {
253
- title: 'Task One',
254
- tags: [{ name: 'red' }, { name: 'green' }]
255
- },
256
- {
257
- title: 'Task Two',
258
- tags: [{ name: 'blue' }]
259
- }
260
- ]
261
- }
262
- }
263
-
264
- options = [
265
- { user: :users }, [
266
- :create, [
267
- [:tasks, [:create, [:tags, [:create]]]]
268
- ]
269
- ]
270
- ]
271
-
272
- command = container.command(options).as(:entity)
273
-
274
- result = command.call(input)
275
-
276
- expect(result).to be_instance_of(Test::User)
277
- expect(result.tasks.first).to be_instance_of(Test::Task)
278
- expect(result.tasks.first.tags.first).to be_instance_of(Test::Tag)
279
- end
280
-
281
- it 'raises a proper error when the input has invalid structure' do
282
- input = { user: { name: 'Jane' } }
283
-
284
- options = [
285
- { user: :users }, [:create, [{ book: :books }, [:create]]]
286
- ]
287
-
288
- command = container.command(options)
289
-
290
- expect {
291
- command.call(input)
292
- }.to raise_error(ROM::KeyMissing, /book/)
293
- end
294
- end
@@ -1,86 +0,0 @@
1
- require 'spec_helper'
2
- require 'dry-struct'
3
-
4
- RSpec.describe 'Commands / Update' do
5
- include_context 'container'
6
- include_context 'users and tasks'
7
-
8
- subject(:users) { container.commands.users }
9
-
10
- before do
11
- configuration.relation(:users) do
12
- register_as :users
13
-
14
- def all(criteria)
15
- restrict(criteria)
16
- end
17
-
18
- def by_name(name)
19
- restrict(name: name)
20
- end
21
- end
22
-
23
- configuration.commands(:users) do
24
- define(:update)
25
- end
26
- end
27
-
28
- it 'update tuples' do
29
- result = users.try {
30
- users.update.all(name: 'Jane').call(email: 'jane.doe@test.com')
31
- }
32
-
33
- expect(result)
34
- .to match_array([{ name: 'Jane', email: 'jane.doe@test.com' }])
35
- end
36
-
37
- describe '"result" option' do
38
- it 'returns a single tuple when set to :one' do
39
- configuration.commands(:users) do
40
- define(:update_one, type: :update) do
41
- result :one
42
- end
43
- end
44
-
45
- result = users.try {
46
- users.update_one.by_name('Jane').call(email: 'jane.doe@test.com')
47
- }
48
-
49
- expect(result.value).to eql(name: 'Jane', email: 'jane.doe@test.com')
50
- end
51
-
52
- it 'allows only valid result types' do
53
- expect {
54
- configuration.commands(:users) do
55
- define(:create_one, type: :create) do
56
- result :invalid_type
57
- end
58
- end
59
- container
60
- }.to raise_error(Dry::Types::ConstraintError)
61
- end
62
- end
63
-
64
- describe 'piping results through mappers' do
65
- it 'allows scoping to a virtual relation' do
66
- user_model = Class.new(Dry::Struct) {
67
- attribute :name, Types::String
68
- attribute :email, Types::String
69
- }
70
-
71
- configuration.mappers do
72
- define(:users) do
73
- model user_model
74
- register_as :entity
75
- end
76
- end
77
-
78
- command = container.command(:users).as(:entity).update.by_name('Jane')
79
-
80
- attributes = { name: 'Jane Doe', email: 'jane@doe.org' }
81
- result = command[attributes]
82
-
83
- expect(result).to eql([user_model.new(attributes)])
84
- end
85
- end
86
- end
@@ -1,67 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe 'Commands' do
4
- include_context 'container'
5
- include_context 'users and tasks'
6
-
7
- before do
8
- configuration.relation(:users) do
9
- def by_id(id)
10
- restrict(id: id)
11
- end
12
- end
13
-
14
- configuration.commands(:users) do
15
- define(:update)
16
- define(:create)
17
- end
18
- end
19
-
20
- let(:create) { container.command(:users)[:create] }
21
- let(:update) { container.command(:users)[:update] }
22
-
23
- describe '#method_missing' do
24
- it 'forwards known relation view methods' do
25
- expect(update.by_id(1).relation).to eql(users_relation.by_id(1))
26
- end
27
-
28
- it 'raises no-method error when a non-view relation method was sent' do
29
- expect { update.as(:foo) }.to raise_error(NoMethodError, /as/)
30
- end
31
-
32
- it 'does not forward relation view methods to non-restrictable commands' do
33
- expect { create.by_id(1) }.to raise_error(NoMethodError, /by_id/)
34
- end
35
- end
36
-
37
- describe 'extending command with a db-specific behavior' do
38
- before do
39
- gateway.instance_exec do
40
- def extend_command_class(klass, _)
41
- klass.class_eval do
42
- def super_command?
43
- true
44
- end
45
- end
46
- klass
47
- end
48
- end
49
- end
50
-
51
- it 'applies to defined classes' do
52
- klass = Class.new(ROM::Commands::Create[:memory]) { relation :users }
53
- configuration.register_command(klass)
54
- container
55
- command = klass.build(users_relation)
56
- expect(command).to be_super_command
57
- end
58
-
59
- it 'applies to generated classes' do
60
- klass = ROM::ConfigurationDSL::Command.build_class(:create, :users, adapter: :memory)
61
- configuration.register_command(klass)
62
- container
63
- command = klass.build(users_relation)
64
- expect(command).to be_super_command
65
- end
66
- end
67
- end
@@ -1,58 +0,0 @@
1
- require 'spec_helper'
2
- require 'rom/memory'
3
-
4
- RSpec.describe 'Gateways / Extending Relations' do
5
- include_context 'container'
6
- include_context 'users and tasks'
7
-
8
- before do
9
- module ROM
10
- module Memory
11
- class Relation < ROM::Relation
12
- def self.freaking_awesome?
13
- true
14
- end
15
-
16
- def freaking_cool?
17
- true
18
- end
19
- end
20
- end
21
- end
22
- end
23
-
24
- after do
25
- ROM::Memory::Relation.class_eval do
26
- undef_method :freaking_cool?
27
- class << self
28
- undef_method :freaking_awesome?
29
- end
30
- end
31
- end
32
-
33
- shared_examples_for 'extended relation' do
34
- it 'can extend relation class' do
35
- expect(container.relations.users.class).to be_freaking_awesome
36
- end
37
-
38
- it 'can extend relation instance' do
39
- expect(container.relations.users).to be_freaking_cool
40
- end
41
- end
42
-
43
- context 'using DSL' do
44
- it_behaves_like 'extended relation' do
45
- before do
46
- configuration.relation(:users)
47
- end
48
- end
49
- end
50
-
51
- context 'using class definition' do
52
- it_behaves_like 'extended relation' do
53
- before do
54
- configuration.register_relation(Class.new(ROM::Relation[:memory]) { dataset :users })
55
- end
56
- end
57
- end
58
- end
@@ -1,34 +0,0 @@
1
- require 'spec_helper'
2
- require 'rom/memory'
3
-
4
- require 'logger'
5
-
6
- RSpec.describe 'Gateways / Setting logger' do
7
- let(:logger_class) do
8
- Class.new do
9
- attr_reader :messages
10
-
11
- def initialize
12
- @messages = []
13
- end
14
-
15
- def info(msg)
16
- @messages << msg
17
- end
18
- end
19
- end
20
-
21
- let(:logger) do
22
- logger_class.new
23
- end
24
-
25
- it 'sets up a logger for a given gateway' do
26
- container = ROM.container(:memory) do |config|
27
- config.gateways[:default].use_logger(logger)
28
- end
29
-
30
- container.gateways[:default].logger.info("test")
31
-
32
- expect(logger.messages).to eql(["test"])
33
- end
34
- end
@@ -1,117 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe 'Mapper definition DSL' do
4
- include_context 'container'
5
- include_context 'users and tasks'
6
-
7
- describe 'combine' do
8
- before do
9
- configuration.relation(:tasks) do
10
- def for_users(users)
11
- names = users.map { |user| user[:name] }
12
- restrict { |task| names.include?(task[:name]) }
13
- end
14
-
15
- def tags(_tasks)
16
- [{ name: 'blue', task: 'be cool' }]
17
- end
18
- end
19
-
20
- configuration.relation(:users) do
21
- def addresses(_users)
22
- [{ city: 'NYC', user: 'Jane' }, { city: 'Boston', user: 'Joe' }]
23
- end
24
-
25
- def books(_users)
26
- [{ title: 'Book One', user: 'Jane' }, { title: 'Book Two', user: 'Joe' }]
27
- end
28
- end
29
-
30
- configuration.mappers do
31
- define(:users) do
32
- register_as :entity
33
-
34
- model name: 'Test::User'
35
-
36
- attribute :name
37
- attribute :email
38
-
39
- combine :tasks, on: { name: :name } do
40
- model name: 'Test::Task'
41
-
42
- attribute :title
43
-
44
- wrap :meta do
45
- attribute :user, from: :name
46
- attribute :priority
47
- end
48
-
49
- combine :tags, on: { title: :task } do
50
- model name: 'Test::Tag'
51
-
52
- attribute :name
53
- end
54
- end
55
-
56
- combine :address, on: { name: :user }, type: :hash do
57
- model name: 'Test::Address'
58
-
59
- attribute :city
60
- end
61
-
62
- combine :book, on: { name: :user }, type: :hash
63
- end
64
- end
65
- end
66
-
67
- let(:users) { container.relation(:users) }
68
- let(:tasks) { container.relation(:tasks) }
69
-
70
- let(:joe) {
71
- Test::User.new(
72
- name: 'Joe',
73
- email: 'joe@doe.org',
74
- tasks: [
75
- Test::Task.new(title: 'be nice', meta: { user: 'Joe', priority: 1 },
76
- tags: []),
77
- Test::Task.new(title: 'sleep well', meta: { user: 'Joe', priority: 2 },
78
- tags: [])
79
- ],
80
- address: Test::Address.new(city: 'Boston'),
81
- book: { title: 'Book Two', user: 'Joe' }
82
- )
83
- }
84
-
85
- let(:jane) {
86
- Test::User.new(
87
- name: 'Jane',
88
- email: 'jane@doe.org',
89
- tasks: [
90
- Test::Task.new(
91
- title: 'be cool',
92
- meta: { user: 'Jane', priority: 2 },
93
- tags: [Test::Tag.new(name: 'blue')]
94
- )
95
- ],
96
- address: Test::Address.new(city: 'NYC'),
97
- book: { title: 'Book One', user: 'Jane' }
98
- )
99
- }
100
-
101
- it 'works' do
102
- container
103
-
104
- Test::User.send(:include, Dry::Equalizer(:name, :email, :tasks, :address, :book))
105
- Test::Task.send(:include, Dry::Equalizer(:title, :meta))
106
- Test::Address.send(:include, Dry::Equalizer(:city))
107
-
108
- result = users.combine(
109
- tasks.for_users.combine(tasks.tags),
110
- users.addresses,
111
- users.books
112
- ).as(:entity)
113
-
114
- expect(result).to match_array([joe, jane])
115
- end
116
- end
117
- end
@@ -1,44 +0,0 @@
1
- require 'spec_helper'
2
- require 'rom/memory'
3
-
4
- RSpec.describe 'Mappers / deeply embedded tuples' do
5
- include_context 'container'
6
-
7
- it 'allows mapping embedded tuples' do
8
- configuration.relation(:users)
9
-
10
- configuration.mappers do
11
- define(:users) do
12
- model name: 'Test::User'
13
-
14
- attribute :name, from: 'name'
15
-
16
- embedded :tasks, from: 'tasks' do
17
- attribute :title, from: 'title'
18
-
19
- embedded :priority, from: 'priority', type: :hash do
20
- attribute :value, from: 'value'
21
- attribute :desc, from: 'desc'
22
- end
23
- end
24
- end
25
- end
26
-
27
- container.relations.users << {
28
- 'name' => 'Jane',
29
- 'tasks' => [
30
- { 'title' => 'Task One', 'priority' => { 'value' => 1, 'desc' => 'high' } },
31
- { 'title' => 'Task Two', 'priority' => { 'value' => 3, 'desc' => 'low' } }
32
- ]
33
- }
34
-
35
- jane = container.relation(:users).as(:users).first
36
-
37
- expect(jane.name).to eql('Jane')
38
-
39
- expect(jane.tasks).to eql([
40
- { title: 'Task One', priority: { value: 1, desc: 'high' } },
41
- { title: 'Task Two', priority: { value: 3, desc: 'low' } }
42
- ])
43
- end
44
- end