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,121 +0,0 @@
1
- require 'spec_helper'
2
- require 'rom/lint/spec'
3
-
4
- require 'rom/memory/dataset'
5
- require 'rom/memory/relation'
6
-
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
17
-
18
- let(:dataset) do
19
- ROM::Memory::Dataset.new([
20
- { name: 'Jane', email: 'jane@doe.org', age: 10 },
21
- { name: 'Jade', email: 'jade@doe.org', age: 11 },
22
- { name: 'Joe', email: 'joe@doe.org', age: 12 },
23
- { name: 'Jack', age: 11 },
24
- { name: 'Jill', email: 'jill@doe.org' },
25
- { name: 'John' },
26
- { name: 'Judy', email: 'judy@doe.org', age: 11 }
27
- ])
28
- end
29
-
30
- describe '#take' do
31
- it 'takes given number of tuples' do
32
- expect(relation.take(2)).to match_array([
33
- { name: 'Jane', email: 'jane@doe.org', age: 10 },
34
- { name: 'Jade', email: 'jade@doe.org', age: 11 }
35
- ])
36
- end
37
- end
38
-
39
- describe '#project' do
40
- it 'projects tuples with the provided keys' do
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([
46
- { name: 'Jane', age: 10 },
47
- { name: 'Jade', age: 11 },
48
- { name: 'Joe', age: 12 },
49
- { name: 'Jack', age: 11 },
50
- { name: 'Jill' },
51
- { name: 'John' },
52
- { name: 'Judy', age: 11 }
53
- ])
54
- end
55
- end
56
-
57
- describe '#restrict' do
58
- it 'restricts data using criteria hash' do
59
- expect(relation.restrict(age: 10)).to match_array([
60
- { name: 'Jane', email: 'jane@doe.org', age: 10 }
61
- ])
62
-
63
- expect(relation.restrict(age: 10.0)).to match_array([])
64
- end
65
-
66
- it 'restricts data using block' do
67
- expect(relation.restrict { |tuple| tuple[:age].to_i > 10 }).to match_array([
68
- { name: 'Jade', email: 'jade@doe.org', age: 11 },
69
- { name: 'Joe', email: 'joe@doe.org', age: 12 },
70
- { name: 'Jack', age: 11 },
71
- { name: 'Judy', email: 'judy@doe.org', age: 11 }
72
- ])
73
- end
74
-
75
- it 'allows to use array as a value' do
76
- expect(relation.restrict(age: [10, 11])).to match_array([
77
- { name: 'Jane', email: 'jane@doe.org', age: 10 },
78
- { name: 'Jade', email: 'jade@doe.org', age: 11 },
79
- { name: 'Jack', age: 11 },
80
- { name: 'Judy', email: 'judy@doe.org', age: 11 }
81
- ])
82
- end
83
-
84
- it 'allows to use regexp as a value' do
85
- expect(relation.restrict(name: /\w{4}/)).to match_array([
86
- { name: 'Jane', email: 'jane@doe.org', age: 10 },
87
- { name: 'Jade', email: 'jade@doe.org', age: 11 },
88
- { name: 'Jack', age: 11 },
89
- { name: 'Jill', email: 'jill@doe.org' },
90
- { name: 'John' },
91
- { name: 'Judy', email: 'judy@doe.org', age: 11 }
92
- ])
93
- end
94
- end
95
-
96
- describe '#order' do
97
- it 'sorts data using provided attribute names' do
98
- expect(relation.order(:age, :email).to_a).to eq([
99
- { name: 'Jane', age: 10, email: 'jane@doe.org' },
100
- { name: 'Jade', age: 11, email: 'jade@doe.org' },
101
- { name: 'Judy', age: 11, email: 'judy@doe.org' },
102
- { name: 'Jack', age: 11 },
103
- { name: 'Joe', age: 12, email: 'joe@doe.org' },
104
- { name: 'Jill', email: 'jill@doe.org' },
105
- { name: 'John' }
106
- ])
107
- end
108
-
109
- it 'places nil before other values when required' do
110
- expect(relation.order(:age, :email, nils_first: true).to_a).to eq([
111
- { name: 'John' },
112
- { name: 'Jill', email: 'jill@doe.org' },
113
- { name: 'Jane', age: 10, email: 'jane@doe.org' },
114
- { name: 'Jack', age: 11 },
115
- { name: 'Jade', age: 11, email: 'jade@doe.org' },
116
- { name: 'Judy', age: 11, email: 'judy@doe.org' },
117
- { name: 'Joe', age: 12, email: 'joe@doe.org' }
118
- ])
119
- end
120
- end
121
- end
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
- require 'rom/memory/storage'
3
-
4
- RSpec.describe ROM::Memory::Storage do
5
- describe 'thread safe' do
6
- let(:threads) { 4 }
7
- let(:operations) { 5000 }
8
-
9
- describe 'data' do
10
- it 'create datasets properly' do
11
- storage = ROM::Memory::Storage.new
12
-
13
- threaded_operations do |thread, operation|
14
- key = "#{thread}:#{operation}"
15
- storage.create_dataset(key)
16
- end
17
-
18
- expect(storage.size).to eql(threads * operations)
19
- end
20
- end
21
-
22
- describe 'dataset' do
23
- it 'inserts data in proper order' do
24
- storage = ROM::Memory::Storage.new
25
- dataset = storage.create_dataset(:ary)
26
-
27
- threaded_operations do
28
- dataset << :data
29
- end
30
-
31
- expect(dataset.size).to eql(threads * operations)
32
- end
33
- end
34
-
35
- def threaded_operations
36
- threads.times.map { |thread|
37
- Thread.new do
38
- operations.times do |operation|
39
- yield thread, operation
40
- end
41
- end
42
- }.each(&:join)
43
- end
44
- end
45
- end
@@ -1,150 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe "ROM::PluginRegistry" do
4
- include_context 'container'
5
-
6
- before do
7
- Test::ConfigurationPlugin = Module.new
8
- Test::CommandPlugin = Module.new
9
- Test::MapperPlugin = Module.new
10
- Test::RelationPlugin = Module.new do
11
- def plugged_in
12
- "a relation"
13
- end
14
- end
15
-
16
- ROM.plugins do
17
- register :registration, Test::ConfigurationPlugin, type: :configuration
18
- register :publisher, Test::CommandPlugin, type: :command
19
- register :pager, Test::RelationPlugin, type: :relation
20
- register :translater, Test::MapperPlugin, type: :mapper
21
- end
22
-
23
- configuration
24
- end
25
-
26
- around do |example|
27
- orig_plugins = ROM.plugin_registry
28
- example.run
29
- ROM.instance_variable_set('@plugin_registry', orig_plugins)
30
- end
31
-
32
- it "makes configuration plugins available" do
33
- expect(ROM.plugin_registry.configuration[:registration].mod).to eq Test::ConfigurationPlugin
34
- end
35
-
36
- it "includes relation plugins" do
37
- users = Class.new(ROM::Relation[:memory]) do
38
- register_as :users
39
- use :pager
40
- end
41
- configuration.register_relation(users)
42
-
43
- expect(container.relation(:users).plugged_in).to eq "a relation"
44
- end
45
-
46
- it "makes command plugins available" do
47
- users = Class.new(ROM::Relation[:memory]) do
48
- register_as :users
49
- end
50
-
51
- create_user = Class.new(ROM::Commands::Create[:memory]) do
52
- relation :users
53
- register_as :create
54
- use :publisher
55
- end
56
-
57
- configuration.register_relation(users)
58
- configuration.register_command(create_user)
59
-
60
- expect(container.command(:users).create).to be_kind_of Test::CommandPlugin
61
- end
62
-
63
- it "inclues plugins in mappers" do
64
- users = Class.new(ROM::Relation[:memory]) do
65
- register_as :users
66
- end
67
- translator = Class.new(ROM::Mapper) do
68
- relation :users
69
- register_as :translator
70
- use :translater
71
- end
72
-
73
- configuration.register_relation(users)
74
- configuration.register_mapper(translator)
75
-
76
- expect(container.mappers[:users][:translator]).to be_kind_of Test::MapperPlugin
77
- end
78
-
79
- it "restricts plugins to defined type" do
80
- expect {
81
- configuration.relation(:users) do
82
- use :publisher
83
- end
84
- }.to raise_error ROM::UnknownPluginError
85
- end
86
-
87
- it "allows definition of adapter restricted plugins" do
88
- Test::LazyPlugin = Module.new do
89
- def lazy?
90
- true
91
- end
92
- end
93
-
94
- ROM.plugins do
95
- adapter :memory do
96
- register :lazy, Test::LazyPlugin, type: :relation
97
- end
98
- end
99
-
100
- users = Class.new(ROM::Relation[:memory]) do
101
- register_as :users
102
- use :lazy
103
- end
104
- configuration.register_relation(users)
105
-
106
- expect(container.relation(:users)).to be_lazy
107
- end
108
-
109
- it "respects adapter restrictions" do
110
- Test::LazyPlugin = Module.new
111
- Test::LazyMemoryPlugin = Module.new
112
- Test::LazySQLPlugin = Module.new
113
-
114
- ROM.plugins do
115
- register :lazy, Test::LazyPlugin, type: :command
116
-
117
- adapter :memory do
118
- register :lazy_command, Test::LazyMemoryPlugin, type: :command
119
- end
120
-
121
- adapter :sql do
122
- register :lazy, Test::LazySQLPlugin, type: :command
123
- end
124
- end
125
-
126
- users = Class.new(ROM::Relation[:memory]) do
127
- register_as :users
128
- end
129
-
130
- create_user = Class.new(ROM::Commands::Create[:memory]) do
131
- relation :users
132
- register_as :create
133
- use :lazy
134
- end
135
-
136
- update_user = Class.new(ROM::Commands::Update[:memory]) do
137
- relation :users
138
- register_as :update
139
- use :lazy_command
140
- end
141
-
142
- configuration.register_relation(users)
143
- configuration.register_command(create_user)
144
- configuration.register_command(update_user)
145
-
146
- expect(container.command(:users).create).not_to be_kind_of Test::LazySQLPlugin
147
- expect(container.command(:users).create).to be_kind_of Test::LazyPlugin
148
- expect(container.command(:users).update).to be_kind_of Test::LazyMemoryPlugin
149
- end
150
- end
@@ -1,66 +0,0 @@
1
- require 'rom/relation'
2
- require 'rom/command'
3
- require 'rom/plugins/command/schema'
4
-
5
- RSpec.describe ROM::Plugins::Command::Schema do
6
- describe '.build' do
7
- let(:command_class) do
8
- Class.new(ROM::Command) { use :schema }
9
- end
10
-
11
- context 'when relation has no schema defined' do
12
- let(:relation) do
13
- instance_double(ROM::Relation, schema?: false)
14
- end
15
-
16
- it 'sets default input handler when command does not have a custom one' do
17
- command = Class.new(command_class).build(relation)
18
-
19
- expect(command.input).to be(ROM::Command.input)
20
- end
21
-
22
- it 'sets custom input handler when command defines it' do
23
- my_handler = double(:my_handler)
24
-
25
- command = Class.new(command_class) { input my_handler }.build(relation)
26
-
27
- expect(command.input).to be(my_handler)
28
- end
29
-
30
- it 'sets custom input handler when it is passed as an option' do
31
- my_handler = double(:my_handler)
32
-
33
- command = Class.new(command_class).build(relation, input: my_handler)
34
-
35
- expect(command.input).to be(my_handler)
36
- end
37
- end
38
-
39
- context 'when relation has a schema' do
40
- let(:relation) do
41
- instance_double(ROM::Relation, schema?: true, input_schema: input_schema)
42
- end
43
-
44
- let(:input_schema) do
45
- double(:input_schema)
46
- end
47
-
48
- it 'sets schema hash as input handler' do
49
- command = Class.new(command_class).build(relation)
50
-
51
- expect(command.input).to be(input_schema)
52
- end
53
-
54
- it 'sets a composed input handler with schema hash and a custom one' do
55
- my_handler = double(:my_handler)
56
-
57
- command = Class.new(command_class) { input my_handler }.build(relation)
58
-
59
- expect(my_handler).to receive(:[]).with('some value').and_return('my handler')
60
- expect(input_schema).to receive(:[]).with('my handler').and_return('a tuple')
61
-
62
- expect(command.input['some value']).to eql('a tuple')
63
- end
64
- end
65
- end
66
- end
@@ -1,44 +0,0 @@
1
- require 'rom'
2
- require 'rom/memory'
3
-
4
- RSpec.describe ROM::Plugins::Relation::Instrumentation do
5
- before do
6
- described_class.mixin Module.new
7
- end
8
-
9
- subject(:relation) do
10
- relation_class.new(dataset, notifications: notifications)
11
- end
12
-
13
- let(:dataset) do
14
- double(:dataset)
15
- end
16
-
17
- let(:relation_class) do
18
- Class.new(ROM::Memory::Relation) do
19
- schema(:users) do
20
- attribute :name, ROM::Types::String
21
- end
22
-
23
- use :instrumentation
24
-
25
- instrument def all
26
- self
27
- end
28
- end
29
- end
30
-
31
- let(:notifications) { spy(:notifications) }
32
-
33
- it 'uses notifications API when materializing a relation' do
34
- relation.to_a
35
-
36
- expect(notifications).to have_received(:instrument).with(:memory, name: :users)
37
- end
38
-
39
- it 'instruments custom methods' do
40
- relation.all
41
-
42
- expect(notifications).to have_received(:instrument).with(:memory, name: :users)
43
- end
44
- end
@@ -1,85 +0,0 @@
1
- require 'rom'
2
- require 'rom/memory'
3
- require 'rom/plugins/relation/key_inference'
4
-
5
- RSpec.describe ROM::Plugins::Relation::KeyInference do
6
- subject(:relation) do
7
- relation_class.new(
8
- [],
9
- __registry__: ROM::RelationRegistry.new(posts: posts, users: users, tags: tags)
10
- )
11
- end
12
-
13
- let(:posts) { double(foreign_key: :post_id) }
14
- let(:tags_name) { ROM::Relation::Name[:tags] }
15
- let(:tags) { double(foreign_key: :tag_id) }
16
- let(:users_name) { ROM::Relation::Name[:users] }
17
- let(:users) { double(base_name: users_name) }
18
-
19
- describe 'without a schema' do
20
- let(:relation_class) do
21
- Class.new(ROM::Memory::Relation) do
22
- use :key_inference
23
-
24
- dataset :users
25
- end
26
- end
27
-
28
- describe '#base_name' do
29
- it 'returns dataset name by default' do
30
- expect(relation.base_name).to eql(ROM::Relation::Name[:users])
31
- end
32
- end
33
-
34
- describe '#foreign_key' do
35
- it 'returns default value' do
36
- expect(relation.foreign_key).to be(:user_id)
37
- end
38
-
39
- it 'returns default value for another relation' do
40
- expect(relation.foreign_key(:posts)).to be(:post_id)
41
- expect(relation.foreign_key(posts)).to be(:post_id)
42
- end
43
-
44
- it 'returns default value for Relation::Name' do
45
- expect(relation.foreign_key(ROM::Relation::Name[:posts])).to be(:post_id)
46
- end
47
-
48
- it 'supports objects responding to to_sym' do
49
- external_name = double(to_sym: :tags)
50
- expect(relation.foreign_key(external_name)).to be(:tag_id)
51
- end
52
- end
53
- end
54
-
55
- describe 'with a schema' do
56
- let(:relation_class) do
57
- Class.new(ROM::Memory::Relation) do
58
- use :key_inference
59
-
60
- schema :posts do
61
- attribute :author_id, ROM::Types::Int.meta(foreign_key: true, target: :users)
62
- end
63
- end
64
- end
65
-
66
- describe '#foreign_key' do
67
- it 'returns configured value' do
68
- expect(relation.foreign_key(ROM::Relation::Name[:users])).to be(:author_id)
69
- expect(relation.foreign_key(:users)).to be(:author_id)
70
- expect(relation.foreign_key(users)).to be(:author_id)
71
- expect(relation.foreign_key(users_name)).to be(:author_id)
72
- end
73
-
74
- it 'falls back to default when schema has no fk specified' do
75
- expect(relation.foreign_key(:tags)).to be(:tag_id)
76
- expect(relation.foreign_key(tags_name)).to be(:tag_id)
77
- end
78
-
79
- it 'supports objects responding to to_sym' do
80
- external_name = double(to_sym: :tags)
81
- expect(relation.foreign_key(external_name)).to be(:tag_id)
82
- end
83
- end
84
- end
85
- end
@@ -1,86 +0,0 @@
1
- require 'rom/registry'
2
-
3
- RSpec.shared_examples_for 'registry fetch' do
4
- it 'raises an ArgumentError when nil is used as a key' do
5
- expect {
6
- registry.public_send(fetch_method, nil)
7
- }.to raise_error(ArgumentError, "key cannot be nil")
8
- end
9
-
10
- it 'returns registered element identified by name' do
11
- expect(registry.public_send(fetch_method, :mars)).to be(mars)
12
- end
13
-
14
- it 'raises error when element is not found' do
15
- expect { registry.public_send(fetch_method, :twix) }.to raise_error(
16
- ROM::Registry::ElementNotFoundError,
17
- ":twix doesn't exist in Candy registry"
18
- )
19
- end
20
-
21
- it 'returns the value from an optional block when key is not found' do
22
- value = registry.public_send(fetch_method, :candy) { :twix }
23
-
24
- expect(value).to eq(:twix)
25
- end
26
-
27
- it 'calls #to_sym on a key before fetching' do
28
- expect(registry.public_send(fetch_method, double(to_sym: :mars))).to be(mars)
29
- end
30
- end
31
-
32
- RSpec.describe ROM::Registry do
33
- subject(:registry) { registry_class.new(mars: mars) }
34
-
35
- let(:mars) { double('mars') }
36
-
37
- let(:registry_class) do
38
- Class.new(ROM::Registry) do
39
- def self.name
40
- 'Candy'
41
- end
42
- end
43
- end
44
-
45
- describe '#fetch' do
46
- let(:fetch_method) { :fetch }
47
-
48
- it_behaves_like 'registry fetch'
49
- end
50
-
51
- describe '#[]' do
52
- let(:fetch_method) { :[] }
53
-
54
- it_behaves_like 'registry fetch'
55
- end
56
-
57
- describe '#method_missing' do
58
- it 'returns registered element identified by name' do
59
- expect(registry.mars).to be(mars)
60
- end
61
-
62
- it 'raises no-method error when element is not there' do
63
- expect { registry.twix }.to raise_error(NoMethodError)
64
- end
65
- end
66
-
67
- describe '#key?' do
68
- let(:mars) { double(to_sym: :mars) }
69
-
70
- it 'calls #to_sym on a key before checking if it exists' do
71
- registry.key?(:mars)
72
- end
73
-
74
- it 'returns true for an existing key' do
75
- expect(registry.key?(:mars)).to be(true)
76
- end
77
-
78
- it 'returns false for a non-existing key' do
79
- expect(registry.key?(:twix)).to be(false)
80
- end
81
-
82
- it 'returns false for a nil key' do
83
- expect(registry.key?(nil)).to be(false)
84
- end
85
- end
86
- end
@@ -1,17 +0,0 @@
1
- require 'rom/memory'
2
-
3
- RSpec.describe ROM::Relation, '#[]' do
4
- it 'defines a canonical schema for a relation' do
5
- class Test::Users < ROM::Relation[:memory]
6
- schema do
7
- attribute :id, Types::Int
8
- attribute :name, Types::String
9
- end
10
- end
11
-
12
- relation = Test::Users.new([])
13
-
14
- expect(relation[:id]).to be(Test::Users.schema[:id])
15
- expect(relation[:name]).to be(Test::Users.schema[:name])
16
- end
17
- end
@@ -1,51 +0,0 @@
1
- require 'rom/relation'
2
-
3
- RSpec.describe ROM::Relation, '#call' do
4
- subject(:relation) do
5
- relation_class.new(data)
6
- end
7
-
8
- context 'without read types in schema' do
9
- let(:relation_class) do
10
- Class.new(ROM::Relation[:memory]) do
11
- schema do
12
- attribute :id, ROM::Types::Int
13
- attribute :name, ROM::Types::String
14
- end
15
- end
16
- end
17
-
18
- let(:data) do
19
- [{ id: '1', name: 'Jane' }, { id: '2', name: 'John'} ]
20
- end
21
-
22
- it 'has noop output_schema' do
23
- expect(relation.output_schema).to be(ROM::Relation::NOOP_OUTPUT_SCHEMA)
24
- end
25
-
26
- it 'returns loaded relation with data' do
27
- expect(relation.call.collection).
28
- to eql(data)
29
- end
30
- end
31
-
32
- context 'with read types in schema' do
33
- let(:relation_class) do
34
- Class.new(ROM::Relation[:memory]) do
35
- schema do
36
- attribute :id, ROM::Types::String, read: ROM::Types::Coercible::Int
37
- attribute :name, ROM::Types::String
38
- end
39
- end
40
- end
41
-
42
- let(:data) do
43
- [{ id: '1', name: 'Jane' }, { id: '2', name: 'John'} ]
44
- end
45
-
46
- it 'returns loaded relation with coerced data' do
47
- expect(relation.call.collection).
48
- to eql([{ id: 1, name: 'Jane' }, { id: 2, name: 'John'} ])
49
- end
50
- end
51
- end