rom 3.3.3 → 4.0.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,106 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe ROM::Relation::Composite do
4
- include_context 'gateway only'
5
- include_context 'users and tasks'
6
-
7
- let(:users_relation) do
8
- Class.new(ROM::Memory::Relation) do
9
- schema do
10
- attribute :name, ROM::Types::String
11
- attribute :email, ROM::Types::String
12
- end
13
-
14
- def by_name(name)
15
- restrict(name: name)
16
- end
17
-
18
- def sorted(other)
19
- other.source.order(:name)
20
- end
21
-
22
- def select(key)
23
- project(key)
24
- end
25
- end.new(users_dataset)
26
- end
27
-
28
- let(:tasks_relation) do
29
- Class.new(ROM::Memory::Relation) do
30
- def for_users(users)
31
- restrict(name: users.map { |u| u[:name] })
32
- end
33
- end.new(tasks_dataset)
34
- end
35
-
36
- let(:name_list) { proc { |r| r.map { |t| t[:name] } } }
37
- let(:upcaser) { proc { |r| r.map(&:upcase) } }
38
-
39
- describe '#call' do
40
- it 'sends a relation through mappers' do
41
- relation = users_relation >> name_list >> upcaser
42
- loaded = relation.call
43
-
44
- expect(loaded.source).to eql(users_relation)
45
-
46
- expect(loaded).to match_array(%w(JANE JOE))
47
- end
48
-
49
- it 'sends a relation through another relation' do
50
- relation = users_relation >> users_relation.sorted
51
- loaded = relation.call
52
-
53
- expect(loaded.source).to eql(users_relation.sorted(users_relation.call))
54
-
55
- expect(loaded).to match_array([
56
- { name: 'Jane', email: 'jane@doe.org' },
57
- { name: 'Joe', email: 'joe@doe.org' }
58
- ])
59
- end
60
-
61
- it 'sends a relation through another composite relation' do
62
- task_mapper = -> tasks_relation { tasks_relation }
63
- relation = users_relation.by_name('Jane') >> (tasks_relation.for_users >> task_mapper)
64
-
65
- loaded = relation.call
66
-
67
- expect(loaded.source).to eql(tasks_relation.for_users(users_relation.by_name('Jane')))
68
-
69
- expect(loaded).to match_array([
70
- { name: 'Jane', title: 'be cool', priority: 2 }
71
- ])
72
- end
73
- end
74
-
75
- describe '#each' do
76
- let(:relation) { users_relation >> name_list >> upcaser }
77
-
78
- it 'calls and iterates' do
79
- result = []
80
- relation.each do |object|
81
- result << object
82
- end
83
- expect(result).to match_array(%w(JANE JOE))
84
- end
85
-
86
- it 'returns enumerator if block is not provided' do
87
- expect(relation.each.to_a).to match_array(%w(JANE JOE))
88
- end
89
- end
90
-
91
- describe '#first' do
92
- let(:relation) { users_relation >> name_list >> upcaser }
93
-
94
- it 'calls and returns the first object' do
95
- expect(relation.first).to eql('JOE')
96
- end
97
- end
98
-
99
- describe '#__send__' do
100
- it 'proxies Kernel methods' do
101
- relation = (users_relation >> name_list >> upcaser).__send__(:select, :name)
102
-
103
- expect(relation.call).to match_array(%w(JANE JOE))
104
- end
105
- end
106
- end
@@ -1,67 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe ROM::Relation::Curried do
4
- include_context 'gateway only'
5
- include_context 'users and tasks'
6
-
7
- let(:users_relation) do
8
- Class.new(ROM::Memory::Relation) do
9
- def by_name(name)
10
- restrict(name: name)
11
- end
12
-
13
- def by_name_and_age(name, age)
14
- restrict(name: name, age: age)
15
- end
16
-
17
- def find(criteria)
18
- restrict(criteria)
19
- end
20
- end.new(users_dataset)
21
- end
22
-
23
- describe '#call' do
24
- let(:relation) { users_relation.by_name }
25
-
26
- it 'materializes a relation' do
27
- expect(relation.('Jane').to_a).to eql([name: 'Jane', email: 'jane@doe.org'])
28
- end
29
-
30
- it 'returns a loaded relation' do
31
- expect(relation.('Jane').source).to eql(users_relation.by_name('Jane'))
32
- end
33
-
34
- it 'raises argument error if no arguments were provided' do
35
- expect { relation.() }.
36
- to raise_error(
37
- ArgumentError,
38
- "curried #{users_relation.class}#by_name relation was called without any arguments")
39
- end
40
-
41
- it 'returns self when has curried args and no additional args were provided' do
42
- curried = users_relation.by_name_and_age.('Jane')
43
-
44
- expect(curried.().__id__).to be(curried.__id__)
45
- end
46
- end
47
-
48
- describe '#respond_to?' do
49
- it 'returns true if wrapped relation responds to a method' do
50
- expect(users_relation.by_name).to respond_to(:dataset)
51
- end
52
-
53
- it 'returns false if wrapped relation does not respond to a method' do
54
- expect(users_relation.by_name).not_to respond_to(:not_here)
55
- end
56
- end
57
-
58
- describe '#method_missing' do
59
- it 'forwards to the relation' do
60
- expect(users_relation.by_name.dataset).to eql(users_relation.dataset)
61
- end
62
-
63
- it 'does not forward to the relation when method is auto-curried' do
64
- expect { users_relation.by_name.find }.to raise_error(NoMethodError, /find/)
65
- end
66
- end
67
- end
@@ -1,106 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe ROM::Relation::Graph do
4
- include_context 'gateway only'
5
- include_context 'users and tasks'
6
-
7
- let(:users_relation) do
8
- Class.new(ROM::Memory::Relation) do
9
- def by_name(name)
10
- restrict(name: name)
11
- end
12
- end.new(users_dataset)
13
- end
14
-
15
- let(:tasks_relation) do
16
- Class.new(ROM::Memory::Relation) do
17
- def for_users(_users)
18
- self
19
- end
20
-
21
- def by_title(title)
22
- restrict(title: title)
23
- end
24
- end.new(tasks_dataset)
25
- end
26
-
27
- subject(:graph) { ROM::Relation::Graph.new(users_relation, [tasks_relation.for_users]) }
28
-
29
- describe '#graph?' do
30
- it 'returns true' do
31
- expect(graph.graph?).to be(true)
32
- end
33
-
34
- it 'returns true when curried' do
35
- expect(graph.by_name.graph?).to be(true)
36
- end
37
- end
38
-
39
- it_behaves_like 'materializable relation' do
40
- let(:mapper) do
41
- T(:combine, [[:tasks, name: :name]])
42
- end
43
-
44
- let(:relation) do
45
- ROM::Relation::Graph.new(users_relation.by_name('Jane'), [tasks_relation.for_users]) >> mapper
46
- end
47
- end
48
-
49
- describe '#method_missing' do
50
- it 'responds to the root methods' do
51
- expect(graph).to respond_to(:by_name)
52
- end
53
-
54
- it 'forwards methods to the root and decorates response' do
55
- expect(graph.by_name('Jane')).to be_instance_of(ROM::Relation::Graph)
56
- end
57
-
58
- it 'forwards methods to the root and decorates curried response' do
59
- expect((users_relation.combine(tasks_relation.for_users)).by_name).to be_instance_of(ROM::Relation::Graph)
60
- end
61
-
62
- it 'returns original response from the root' do
63
- expect(graph.mappers).to eql(users_relation.mappers)
64
- end
65
-
66
- it 'raises method error' do
67
- expect { graph.not_here }.to raise_error(NoMethodError, /not_here/)
68
- end
69
- end
70
-
71
- describe '#with_nodes' do
72
- it 'returns a new graph with new nodes' do
73
- new_tasks = tasks_relation.by_title('foo')
74
- new_graph = graph.with_nodes([new_tasks])
75
-
76
- expect(new_graph.nodes[0]).to be(new_tasks)
77
- end
78
- end
79
-
80
- describe '#call' do
81
- it 'materializes relations' do
82
- root, nodes = graph.call.to_a
83
-
84
- expect(root.to_a).to eql(users_relation.to_a)
85
- expect(nodes.flatten).to eql(tasks_relation.to_a)
86
- end
87
- end
88
-
89
- describe '#to_a' do
90
- it 'coerces to an array' do
91
- root, nodes = graph.to_a
92
-
93
- expect(root.to_a).to eql(users_relation.to_a)
94
- expect(nodes.flatten).to eql(tasks_relation.for_users(users_relation).to_a)
95
- end
96
-
97
- it 'returns empty arrays when left was empty' do
98
- graph = ROM::Relation::Graph.new(users_relation.by_name('Not here'), [tasks_relation.for_users])
99
-
100
- root, nodes = graph.to_a
101
-
102
- expect(root).to be_empty
103
- expect(nodes.flatten).to be_empty
104
- end
105
- end
106
- end
@@ -1,165 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe ROM::Relation, '#combine' do
4
- include_context 'gateway only'
5
- include_context 'users and tasks'
6
-
7
- let(:tags_dataset) { gateway.dataset(:tags) }
8
-
9
- let(:users_relation) do
10
- Class.new(ROM::Memory::Relation) do
11
- def by_name(name)
12
- restrict(name: name)
13
- end
14
- end.new(users_dataset)
15
- end
16
-
17
- let(:tasks_relation) do
18
- Class.new(ROM::Memory::Relation) do
19
- def for_users(users)
20
- names = users.map { |user| user[:name] }
21
- restrict { |task| names.include?(task[:name]) }
22
- end
23
- end.new(tasks_dataset)
24
- end
25
-
26
- let(:tags_relation) do
27
- Class.new(ROM::Memory::Relation) do
28
- attr_accessor :tasks
29
- forward :map
30
-
31
- def for_tasks(tasks)
32
- titles = tasks.map { |task| task[:title] }
33
- restrict { |tag| titles.include?(tag[:task]) }
34
- end
35
-
36
- def for_users(users)
37
- user_tasks = tasks.for_users(users)
38
-
39
- for_tasks(user_tasks).map { |tag|
40
- tag.merge(user: user_tasks.detect { |task|
41
- task[:title] == tag[:task]
42
- } [:name])
43
- }
44
- end
45
- end.new(tags_dataset).tap { |r| r.tasks = tasks_relation }
46
- end
47
-
48
- before do
49
- tags_dataset.insert(task: 'be cool', name: 'red')
50
- tags_dataset.insert(task: 'be cool', name: 'green')
51
- end
52
-
53
- let(:map_users) {
54
- proc { |users, tasks|
55
- users.map { |user|
56
- user.merge(tasks: tasks.select { |task| task[:name] == user[:name] })
57
- }
58
- }
59
- }
60
-
61
- let(:map_tasks) {
62
- proc { |(tasks, children)|
63
- tags = children.first
64
-
65
- tasks.map { |task|
66
- task.merge(tags: tags.select { |tag| tag[:task] == task[:title] })
67
- }
68
- }
69
- }
70
-
71
- let(:map_user_with_tasks_and_tags) {
72
- proc { |users, (tasks, tags)|
73
- users.map { |user|
74
- user_tasks = tasks.select { |task| task[:name] == user[:name] }
75
-
76
- user_tags = tasks.flat_map { |task|
77
- tags.select { |tag| tag[:task] == task[:title] }
78
- }
79
-
80
- user.merge(
81
- tasks: user_tasks,
82
- tags: user_tags
83
- )
84
- }
85
- }
86
- }
87
-
88
- let(:map_user_with_tasks) {
89
- proc { |users, children|
90
- map_users[users, map_tasks[children.first]]
91
- }
92
- }
93
-
94
- it 'raises error when composite relation is passed as a node' do
95
- expect {
96
- users_relation.combine(tasks_relation >> proc {})
97
- }.to raise_error(ROM::UnsupportedRelationError)
98
- end
99
-
100
- it 'supports more than one eagerly-loaded relation' do
101
- expected = [
102
- {
103
- name: 'Jane',
104
- email: 'jane@doe.org',
105
- tasks: [
106
- { name: 'Jane', title: 'be cool', priority: 2 }
107
- ],
108
- tags: [
109
- { task: 'be cool', name: 'red', user: 'Jane' },
110
- { task: 'be cool', name: 'green', user: 'Jane' }
111
- ]
112
- }
113
- ]
114
-
115
- user_with_tasks_and_tags = users_relation.by_name('Jane')
116
- .combine(tasks_relation.for_users, tags_relation.for_users)
117
-
118
- result = user_with_tasks_and_tags >> map_user_with_tasks_and_tags
119
-
120
- expect(result.to_a).to eql(expected)
121
- end
122
-
123
- it 'supports more than one eagerly-loaded relation via chaining' do
124
- expected = [
125
- {
126
- name: 'Jane',
127
- email: 'jane@doe.org',
128
- tasks: [
129
- { name: 'Jane', title: 'be cool', priority: 2 }
130
- ],
131
- tags: [
132
- { task: 'be cool', name: 'red', user: 'Jane' },
133
- { task: 'be cool', name: 'green', user: 'Jane' }
134
- ]
135
- }
136
- ]
137
-
138
- user_with_tasks_and_tags = users_relation.by_name('Jane')
139
- .combine(tasks_relation.for_users).combine(tags_relation.for_users)
140
-
141
- result = user_with_tasks_and_tags >> map_user_with_tasks_and_tags
142
-
143
- expect(result).to match_array(expected)
144
- end
145
-
146
- it 'supports nested eager-loading' do
147
- expected = [
148
- {
149
- name: 'Jane', email: 'jane@doe.org', tasks: [
150
- { name: 'Jane', title: 'be cool', priority: 2, tags: [
151
- { task: 'be cool', name: 'red' },
152
- { task: 'be cool', name: 'green' }
153
- ] }
154
- ]
155
- }
156
- ]
157
-
158
- user_with_tasks = users_relation.by_name('Jane')
159
- .combine(tasks_relation.for_users.combine(tags_relation.for_tasks))
160
-
161
- result = user_with_tasks >> map_user_with_tasks
162
-
163
- expect(result).to match_array(expected)
164
- end
165
- end
@@ -1,165 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe ROM::Relation, '#graph' do
4
- include_context 'gateway only'
5
- include_context 'users and tasks'
6
-
7
- let(:tags_dataset) { gateway.dataset(:tags) }
8
-
9
- let(:users_relation) do
10
- Class.new(ROM::Memory::Relation) do
11
- def by_name(name)
12
- restrict(name: name)
13
- end
14
- end.new(users_dataset)
15
- end
16
-
17
- let(:tasks_relation) do
18
- Class.new(ROM::Memory::Relation) do
19
- def for_users(users)
20
- names = users.map { |user| user[:name] }
21
- restrict { |task| names.include?(task[:name]) }
22
- end
23
- end.new(tasks_dataset)
24
- end
25
-
26
- let(:tags_relation) do
27
- Class.new(ROM::Memory::Relation) do
28
- attr_accessor :tasks
29
- forward :map
30
-
31
- def for_tasks(tasks)
32
- titles = tasks.map { |task| task[:title] }
33
- restrict { |tag| titles.include?(tag[:task]) }
34
- end
35
-
36
- def for_users(users)
37
- user_tasks = tasks.for_users(users)
38
-
39
- for_tasks(user_tasks).map { |tag|
40
- tag.merge(user: user_tasks.detect { |task|
41
- task[:title] == tag[:task]
42
- } [:name])
43
- }
44
- end
45
- end.new(tags_dataset).tap { |r| r.tasks = tasks_relation }
46
- end
47
-
48
- before do
49
- tags_dataset.insert(task: 'be cool', name: 'red')
50
- tags_dataset.insert(task: 'be cool', name: 'green')
51
- end
52
-
53
- let(:map_users) {
54
- proc { |users, tasks|
55
- users.map { |user|
56
- user.merge(tasks: tasks.select { |task| task[:name] == user[:name] })
57
- }
58
- }
59
- }
60
-
61
- let(:map_tasks) {
62
- proc { |(tasks, children)|
63
- tags = children.first
64
-
65
- tasks.map { |task|
66
- task.merge(tags: tags.select { |tag| tag[:task] == task[:title] })
67
- }
68
- }
69
- }
70
-
71
- let(:map_user_with_tasks_and_tags) {
72
- proc { |users, (tasks, tags)|
73
- users.map { |user|
74
- user_tasks = tasks.select { |task| task[:name] == user[:name] }
75
-
76
- user_tags = tasks.flat_map { |task|
77
- tags.select { |tag| tag[:task] == task[:title] }
78
- }
79
-
80
- user.merge(
81
- tasks: user_tasks,
82
- tags: user_tags
83
- )
84
- }
85
- }
86
- }
87
-
88
- let(:map_user_with_tasks) {
89
- proc { |users, children|
90
- map_users[users, map_tasks[children.first]]
91
- }
92
- }
93
-
94
- it 'raises error when composite relation is passed as a node' do
95
- expect {
96
- users_relation.graph(tasks_relation >> proc {})
97
- }.to raise_error(ROM::UnsupportedRelationError)
98
- end
99
-
100
- it 'supports more than one eagerly-loaded relation' do
101
- expected = [
102
- {
103
- name: 'Jane',
104
- email: 'jane@doe.org',
105
- tasks: [
106
- { name: 'Jane', title: 'be cool', priority: 2 }
107
- ],
108
- tags: [
109
- { task: 'be cool', name: 'red', user: 'Jane' },
110
- { task: 'be cool', name: 'green', user: 'Jane' }
111
- ]
112
- }
113
- ]
114
-
115
- user_with_tasks_and_tags = users_relation.by_name('Jane')
116
- .graph(tasks_relation.for_users, tags_relation.for_users)
117
-
118
- result = user_with_tasks_and_tags >> map_user_with_tasks_and_tags
119
-
120
- expect(result.to_a).to eql(expected)
121
- end
122
-
123
- it 'supports more than one eagerly-loaded relation via chaining' do
124
- expected = [
125
- {
126
- name: 'Jane',
127
- email: 'jane@doe.org',
128
- tasks: [
129
- { name: 'Jane', title: 'be cool', priority: 2 }
130
- ],
131
- tags: [
132
- { task: 'be cool', name: 'red', user: 'Jane' },
133
- { task: 'be cool', name: 'green', user: 'Jane' }
134
- ]
135
- }
136
- ]
137
-
138
- user_with_tasks_and_tags = users_relation.by_name('Jane')
139
- .graph(tasks_relation.for_users).graph(tags_relation.for_users)
140
-
141
- result = user_with_tasks_and_tags >> map_user_with_tasks_and_tags
142
-
143
- expect(result).to match_array(expected)
144
- end
145
-
146
- it 'supports nested eager-loading' do
147
- expected = [
148
- {
149
- name: 'Jane', email: 'jane@doe.org', tasks: [
150
- { name: 'Jane', title: 'be cool', priority: 2, tags: [
151
- { task: 'be cool', name: 'red' },
152
- { task: 'be cool', name: 'green' }
153
- ] }
154
- ]
155
- }
156
- ]
157
-
158
- user_with_tasks = users_relation.by_name('Jane')
159
- .graph(tasks_relation.for_users.graph(tags_relation.for_tasks))
160
-
161
- result = user_with_tasks >> map_user_with_tasks
162
-
163
- expect(result).to match_array(expected)
164
- end
165
- end