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,109 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe ROM::Container do
4
- include_context 'container'
5
- include_context 'users and tasks'
6
-
7
- before do
8
- configuration
9
-
10
- users = Class.new(ROM::Relation[:memory]) do
11
- schema(:users) do
12
- attribute :name, ROM::Types::String
13
- attribute :email, ROM::Types::String
14
- end
15
-
16
- def by_name(name)
17
- restrict(name: name).project(:name)
18
- end
19
- end
20
-
21
- tasks = Class.new(ROM::Relation[:memory]) do
22
- schema(:tasks) do
23
- attribute :name, ROM::Types::String
24
- attribute :title, ROM::Types::String
25
- attribute :priority, ROM::Types::Int
26
- end
27
- end
28
-
29
- create_user = Class.new(ROM::Commands::Create[:memory]) do
30
- relation :users
31
- register_as :create
32
- end
33
-
34
- create_task = Class.new(ROM::Commands::Create[:memory]) do
35
- relation :tasks
36
- register_as :create
37
- end
38
-
39
- users_mapper = Class.new(ROM::Mapper) do
40
- register_as :users
41
- relation :users
42
- attribute :name
43
- attribute :email
44
- end
45
-
46
- name_list = Class.new(users_mapper) do
47
- register_as :name_list
48
- attribute :name
49
- exclude :email
50
- end
51
-
52
- configuration.register_relation(users, tasks)
53
- configuration.register_command(create_user, create_task)
54
- configuration.register_mapper(users_mapper, name_list)
55
- end
56
-
57
- describe '#command' do
58
- it 'returns registered command registry' do
59
- expect(container.command(:users)).to be_instance_of(ROM::CommandRegistry)
60
- end
61
-
62
- it 'returns registered command' do
63
- expect(container.command(:users).create).to be_kind_of(ROM::Commands::Create)
64
- end
65
-
66
- it 'accepts an array with graph options and input' do
67
- expect(container.command([:users, [:create]])).to be_kind_of(ROM::Commands::Lazy)
68
- end
69
-
70
- it 'raises ArgumentError when unsupported arg was passed' do
71
- expect { container.command(oops: 'sorry') }.to raise_error(ArgumentError)
72
- end
73
- end
74
-
75
- describe '#relation' do
76
- it 'yields selected relation to the block and returns a loaded relation' do
77
- result = container.relation(:users) { |r| r.by_name('Jane') }.as(:name_list)
78
-
79
- expect(result.call).to match_array([{ name: 'Jane' }])
80
- end
81
-
82
- it 'returns lazy-mapped relation' do
83
- by_name = container.relation(:users).as(:name_list).by_name
84
-
85
- expect(by_name['Jane']).to match_array([{ name: 'Jane' }])
86
- end
87
-
88
- it 'returns relation without mappers when mappers are not defined' do
89
- expect(container.relation(:tasks)).to be_kind_of(ROM::Relation)
90
- expect(container.relation(:tasks).mappers.elements).to be_empty
91
- end
92
-
93
- it 'returns a relation with finalized schema' do
94
- expect(container.relation(:tasks).schema.relations[:users]).to be(container.relations[:users])
95
- end
96
- end
97
-
98
- describe '#mappers' do
99
- it 'returns mappers for all relations' do
100
- expect(container.mappers.users[:name_list]).to_not be(nil)
101
- end
102
- end
103
-
104
- describe '#disconnect' do
105
- it 'does not break' do
106
- container.disconnect
107
- end
108
- end
109
- end
@@ -1,151 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe ROM::CreateContainer do
4
- describe '#finalize' do
5
- include_context 'container'
6
-
7
- context 'with gateway that supports schema inferring' do
8
- it 'builds relation from inferred schema' do
9
- repo = configuration.gateways[:default]
10
- dataset = double('dataset')
11
-
12
- allow(repo).to receive(:schema).and_return([:users])
13
- allow(repo).to receive(:dataset).with(:users).and_return(dataset)
14
-
15
- expect(container.relations.users.dataset).to be(dataset)
16
- end
17
-
18
- it 'skips inferring a relation when there is a defined one already' do
19
- repo = configuration.gateways[:default]
20
- dataset_double = double('dataset')
21
-
22
- allow(repo).to receive(:schema).and_return([:users])
23
- allow(repo).to receive(:dataset).with(:users).and_return(dataset_double)
24
-
25
- users = Class.new(ROM::Relation[:memory]) do
26
- register_as :users
27
- dataset :users
28
- end
29
-
30
- configuration.register_relation(users)
31
-
32
- expect { container }.not_to raise_error
33
-
34
- expect(container.relations.users).to be_instance_of(users)
35
- end
36
-
37
- it 'skips inferring when it is turned off for the adapter' do
38
- configuration.config.gateways.default.infer_relations = false
39
-
40
- repo = configuration.default
41
-
42
- expect(repo).not_to receive(:schema)
43
-
44
- container
45
- end
46
-
47
- it 'infers configured relations' do
48
- configuration.config.gateways.default.inferrable_relations = [:test_tasks]
49
-
50
- repo = configuration.default
51
- dataset = double('dataset')
52
-
53
- allow(repo).to receive(:schema).and_return([:test_tasks, :test_users])
54
-
55
- expect(repo).to receive(:dataset).with(:test_tasks).and_return(dataset)
56
- expect(repo).to_not receive(:dataset).with(:test_users)
57
-
58
- expect(container.relations.elements.key?(:test_users)).to be(false)
59
- expect(container.relations[:test_tasks]).to be_kind_of(ROM::Memory::Relation)
60
- expect(container.relations[:test_tasks].dataset).to be(dataset)
61
- end
62
-
63
- it 'skip inferring blacklisted relations' do
64
- configuration.config.gateways.default.not_inferrable_relations = [:test_users]
65
-
66
- repo = configuration.default
67
- dataset = double('dataset')
68
-
69
- allow(repo).to receive(:schema).and_return([:test_tasks, :test_users])
70
-
71
- expect(repo).to receive(:dataset).with(:test_tasks).and_return(dataset)
72
- expect(repo).to_not receive(:dataset).with(:test_users)
73
-
74
- expect(container.relations.elements.key?(:test_users)).to be(false)
75
- expect(container.relations[:test_tasks]).to be_kind_of(ROM::Memory::Relation)
76
- expect(container.relations[:test_tasks].dataset).to be(dataset)
77
- end
78
-
79
- it 'can register multiple relations with same dataset' do
80
- configuration
81
-
82
- apples = Class.new(ROM::Relation[:memory]) do
83
- dataset :fruits
84
- register_as :apples
85
-
86
- def apple?
87
- true
88
- end
89
- end
90
-
91
- oranges = Class.new(ROM::Relation[:memory]) do
92
- dataset :fruits
93
- register_as :oranges
94
-
95
- def orange?
96
- true
97
- end
98
- end
99
-
100
- configuration.register_relation(apples)
101
- configuration.register_relation(oranges)
102
-
103
- expect(container.relations.apples).to be_apple
104
- expect(container.relations.oranges).to be_orange
105
- expect(container.relations.apples).to_not eq(container.relations.oranges)
106
- end
107
-
108
- it "raises an error when registering relations with the same `register_as`" do
109
- configuration
110
-
111
- users = Class.new(ROM::Relation[:memory]) do
112
- dataset :guests
113
- register_as :users
114
- end
115
-
116
- users2 = Class.new(ROM::Relation[:memory]) do
117
- dataset :admins
118
- register_as :users
119
- end
120
-
121
- configuration.register_relation(users)
122
- configuration.register_relation(users2)
123
-
124
- expect { container }.to raise_error(
125
- ROM::RelationAlreadyDefinedError, /register_as :users/
126
- )
127
- end
128
- end
129
-
130
- context 'empty setup' do
131
- let(:configuration) { ROM::Configuration.new({}) }
132
- let(:container) { ROM.container(configuration) }
133
-
134
- it 'builds empty gateways' do
135
- expect(container.gateways).to eql({})
136
- end
137
-
138
- it 'builds empty relations' do
139
- expect(container.relations).to eql(ROM::RelationRegistry.new)
140
- end
141
-
142
- it 'builds empty mappers' do
143
- expect(container.mappers).to eql(ROM::Registry.new)
144
- end
145
-
146
- it 'builds empty commands' do
147
- expect(container.commands).to eql(ROM::Registry.new)
148
- end
149
- end
150
- end
151
- end
@@ -1,15 +0,0 @@
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,123 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe ROM::Environment do
4
- let(:environment) { ROM::Environment.new(*params) }
5
- let(:params) { [] }
6
- let(:gateways) { environment.gateways }
7
- let(:gateways_map) { environment.gateways_map }
8
-
9
- context 'with an adapter identifier' do
10
- let(:params) { [:memory] }
11
-
12
- it 'configures the gateways hash' do
13
- expect(gateways).to be_kind_of(Hash)
14
- expect(gateways.keys).to eq([:default])
15
- expect(gateways[:default]).to be_kind_of(ROM::Memory::Gateway)
16
- end
17
-
18
- it 'configures the gateways_map hash' do
19
- expect(gateways_map).to be_kind_of(Hash)
20
- expect(gateways_map.values).to eq([:memory])
21
- expect(gateways_map.keys.first).to be_kind_of(ROM::Memory::Gateway)
22
- expect(gateways_map.keys.first).to be(gateways[:default])
23
- end
24
- end
25
-
26
- context 'with a hash' do
27
- let(:params) { [{default: :memory}] }
28
-
29
- it 'configures the gateways hash' do
30
- expect(gateways).to be_kind_of(Hash)
31
- expect(gateways.keys).to eq([:default])
32
- expect(gateways[:default]).to be_kind_of(ROM::Memory::Gateway)
33
- end
34
-
35
- it 'configures the gateways_map hash' do
36
- expect(gateways_map).to be_kind_of(Hash)
37
- expect(gateways_map.values).to eq([:memory])
38
- expect(gateways_map.keys.first).to be_kind_of(ROM::Memory::Gateway)
39
- expect(gateways_map.keys.first).to be(gateways[:default])
40
- end
41
- end
42
-
43
- context 'with multiple gateways' do
44
- let(:params) { [{foo: :memory, default: :memory}] }
45
-
46
- it 'configures the gateways hash' do
47
- expect(gateways).to be_kind_of(Hash)
48
- expect(gateways.keys).to eq([:foo, :default])
49
- expect(gateways[:default]).to be_kind_of(ROM::Memory::Gateway)
50
- expect(gateways[:foo]).to be_kind_of(ROM::Memory::Gateway)
51
- expect(gateways[:default]).not_to be(gateways[:foo])
52
- end
53
-
54
- it 'configures the gateways_map hash' do
55
- expect(gateways_map).to be_kind_of(Hash)
56
- expect(gateways_map.values).to eq([:memory, :memory])
57
- expect(gateways_map.keys.map(&:class)).to eq([ROM::Memory::Gateway, ROM::Memory::Gateway])
58
- expect(gateways_map.keys).to match_array(gateways.values)
59
- end
60
- end
61
-
62
- context 'with settings' do
63
- before do
64
- module Test
65
- class Gateway < ROM::Gateway
66
- attr_reader :settings
67
-
68
- def initialize settings = {}
69
- @settings = settings
70
- end
71
- end
72
- end
73
-
74
- ROM.register_adapter(:test, Test)
75
- end
76
-
77
- context 'as a hash' do
78
- let(:params) { [{foo: [:test, "foo"], bar: [:test, ["bar"]]}] }
79
-
80
- it 'configures the gateway instance' do
81
- expect(gateways.values.map(&:settings)).to match_array(["foo", "bar"])
82
- end
83
- end
84
-
85
- context 'as flat args' do
86
- let(:params) { [:test, "foo"] }
87
-
88
- it 'configures the gateway instance' do
89
- expect(gateways.values.map(&:settings)).to match_array(["foo"])
90
- end
91
- end
92
- end
93
-
94
- context 'with a Gateway instance' do
95
- before do
96
- module Test
97
- class Gateway < ROM::Gateway
98
- attr_reader :settings
99
-
100
- def initialize settings = {}
101
- @settings = settings
102
- end
103
- end
104
- end
105
-
106
- ROM.register_adapter(:test, Test)
107
- end
108
-
109
- let(:gateway) { Test::Gateway.new }
110
- let(:params) { [gateway] }
111
-
112
- it 'configures the gateways hash' do
113
- expect(gateways).to be_kind_of(Hash)
114
- expect(gateways.keys).to eq([:default])
115
- expect(gateways[:default]).to be(gateway)
116
- end
117
-
118
- it 'configures the gateways_map hash' do
119
- expect(gateways_map).to be_kind_of(Hash)
120
- expect(gateways_map).to be_empty
121
- end
122
- end
123
- end
@@ -1,146 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe ROM::Gateway do
4
-
5
- subject(:gateway) { Class.new(ROM::Gateway).new }
6
-
7
- describe '.setup' do
8
- it 'sets up a gateway based on a type' do
9
- gateway_class = Class.new(ROM::Gateway) do
10
- attr_reader :args
11
-
12
- def initialize(*args)
13
- @args = args
14
- end
15
- end
16
-
17
- allow(ROM::Gateway).to receive(:class_from_symbol)
18
- .with(:wormhole).and_return(gateway_class)
19
-
20
- args = %w(hello world)
21
- gateway = ROM::Gateway.setup(:wormhole, *args)
22
-
23
- expect(gateway).to be_instance_of(gateway_class)
24
- expect(gateway.args).to eq(args)
25
- end
26
-
27
- it 'raises an exception if the type is not supported' do
28
- expect {
29
- ROM::Gateway.setup(:bogus, "memory://test")
30
- }.to raise_error(ROM::AdapterLoadError, /bogus/)
31
- end
32
-
33
- it 'accepts a gateway instance' do
34
- gateway = ROM::Gateway.new
35
- expect(ROM::Gateway.setup(gateway)).to be(gateway)
36
- end
37
-
38
- it 'raises an exception if instance and arguments are passed' do
39
- gateway = ROM::Gateway.new
40
-
41
- expect { ROM::Gateway.setup(gateway, 'foo://bar') }.to raise_error(
42
- ArgumentError,
43
- "Can't accept arguments when passing an instance"
44
- )
45
- end
46
-
47
- it 'raises an exception if a URI string is passed' do
48
- expect { ROM::Gateway.setup('memory://test') }.to raise_error(
49
- ArgumentError,
50
- /URIs without an explicit scheme are not supported anymore/
51
- )
52
- end
53
- end
54
-
55
- describe '.class_from_symbol' do
56
- context 'when adapter is already present' do
57
- before do
58
- module Test
59
- module Adapter
60
- class Gateway
61
- end
62
- end
63
- end
64
-
65
- ROM.register_adapter(:test_adapter, Test::Adapter)
66
- end
67
-
68
- it 'does not try to require an adapter if it is already present' do
69
- klass = ROM::Gateway.class_from_symbol(:test_adapter)
70
-
71
- expect(klass).to be(Test::Adapter::Gateway)
72
- end
73
- end
74
-
75
- it 'instantiates a gateway based on type' do
76
- klass = ROM::Gateway.class_from_symbol(:memory)
77
- expect(klass).to be(ROM::Memory::Gateway)
78
- end
79
-
80
- it 'raises an exception if the type is not supported' do
81
- expect { ROM::Gateway.class_from_symbol(:bogus) }
82
- .to raise_error(ROM::AdapterLoadError, /bogus/)
83
- end
84
- end
85
-
86
- describe '#disconnect' do
87
- it 'does nothing' do
88
- expect(gateway.disconnect).to be(nil)
89
- end
90
- end
91
-
92
- describe '#logger' do
93
- it 'does nothing' do
94
- expect(gateway.logger).to be(nil)
95
- end
96
- end
97
-
98
- describe '#use_logger' do
99
- it 'does nothing' do
100
- expect(gateway.use_logger).to be(nil)
101
- end
102
-
103
- it 'accepts parameters' do
104
- params = [5, "mutations", "are", "nice"]
105
-
106
- expect { gateway.use_logger(params) }.to_not raise_error
107
- end
108
- end
109
-
110
- describe '#extend_command_class' do
111
- it 'returns the class sent as 1st parameter' do
112
- klass = Class.new.freeze
113
-
114
- expect(gateway.extend_command_class(klass, "foo")).to eq(klass)
115
- end
116
- end
117
-
118
- describe '.adapter' do
119
- let(:gateway_class) { Class.new(ROM::Gateway) }
120
-
121
- it 'gets/sets the adapter' do
122
- expect { gateway_class.adapter :custom }
123
- .to change { gateway_class.adapter }
124
- .from(nil)
125
- .to(:custom)
126
- end
127
- end
128
-
129
- describe "#adapter" do
130
- before { Test::CustomGateway = Class.new(ROM::Gateway) }
131
-
132
- let(:gateway) { Test::CustomGateway.new }
133
-
134
- it 'returns class adapter' do
135
- Test::CustomGateway.adapter :custom
136
- expect(gateway.adapter).to eql :custom
137
- end
138
-
139
- it 'requires the adapter to be defined' do
140
- expect { gateway.adapter }.to raise_error(
141
- ROM::MissingAdapterIdentifierError, /Test::CustomGateway/
142
- )
143
- end
144
- end # describe #adapter
145
-
146
- end
@@ -1,25 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe ROM::MapperRegistry do
4
- subject(:registry) { ROM::MapperRegistry.new }
5
-
6
- let(:user_mapper) { double('user_mapper') }
7
- let(:index_mapper) { double('index_mapper') }
8
-
9
- before do
10
- registry[:users] = user_mapper
11
- registry[:index] = index_mapper
12
- end
13
-
14
- describe '#by_path' do
15
- it 'returns first matching mapper' do
16
- mapper = registry.by_path('users')
17
-
18
- expect(mapper).to be(user_mapper)
19
-
20
- mapper = registry.by_path('users.index')
21
-
22
- expect(mapper).to be(index_mapper)
23
- end
24
- end
25
- end
@@ -1,43 +0,0 @@
1
- require 'spec_helper'
2
- require 'rom/memory'
3
-
4
- RSpec.describe ROM::Memory::Commands do
5
- let(:relation) do
6
- Class.new(ROM::Relation[:memory]) do
7
- schema do
8
- attribute :id, ROM::Memory::Types::Int
9
- attribute :name, ROM::Memory::Types::String
10
- end
11
- end.new(ROM::Memory::Dataset.new([]))
12
- end
13
-
14
- describe 'Create' do
15
- subject(:command) { ROM::Commands::Create[:memory].build(relation) }
16
-
17
- describe '#call' do
18
- it 'uses default input handler' do
19
- result = command.call([id: 1, name: 'Jane', haha: 'oops'])
20
-
21
- expect(result).to eql([{ id: 1, name: 'Jane' }])
22
- end
23
- end
24
- end
25
-
26
- describe 'Update' do
27
- subject(:command) { ROM::Commands::Update[:memory].build(relation) }
28
-
29
- before do
30
- relation.insert(id: 1, name: 'Jane')
31
- end
32
-
33
- describe '#call' do
34
- it 'uses default input handler' do
35
- result = command
36
- .new(relation.restrict(id: 1))
37
- .call(name: 'Jane Doe', haha: 'oops')
38
-
39
- expect(result).to eql([{ id: 1, name: 'Jane Doe' }])
40
- end
41
- end
42
- end
43
- end
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
- require 'rom/lint/spec'
3
-
4
- require 'rom/memory/dataset'
5
-
6
- RSpec.describe ROM::Memory::Dataset do
7
- subject(:dataset) { ROM::Memory::Dataset.new(data) }
8
-
9
- let(:data) do
10
- [
11
- { name: 'Jane', email: 'jane@doe.org', age: 10 },
12
- { name: 'Jade', email: 'jade@doe.org', age: 11 },
13
- { name: 'Joe', email: 'joe@doe.org', age: 12 }
14
- ]
15
- end
16
-
17
- it_behaves_like "a rom enumerable dataset"
18
-
19
- describe 'subclassing' do
20
- it 'supports options' do
21
- descendant = Class.new(ROM::Memory::Dataset) do
22
- option :path
23
- end
24
-
25
- dataset = descendant.new([1, 2, 3], path: '/data')
26
-
27
- expect(dataset.to_a).to eql([1, 2, 3])
28
- expect(dataset.path).to eql('/data')
29
- end
30
- end
31
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
- require 'rom/lint/spec'
3
- require 'rom/memory'
4
-
5
- RSpec.describe ROM::Memory::Gateway do
6
- let(:gateway) { ROM::Memory::Gateway }
7
- let(:uri) { nil }
8
-
9
- it_behaves_like "a rom gateway" do
10
- let(:identifier) { :memory }
11
- end
12
- end
@@ -1,32 +0,0 @@
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