rom 3.3.3 → 4.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (241) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +2 -599
  3. data/lib/rom/version.rb +1 -1
  4. data/lib/rom.rb +3 -44
  5. metadata +19 -295
  6. data/.gitignore +0 -24
  7. data/.rspec +0 -3
  8. data/.rubocop.yml +0 -87
  9. data/.rubocop_todo.yml +0 -46
  10. data/.travis.yml +0 -24
  11. data/.yardopts +0 -2
  12. data/CODE_OF_CONDUCT.md +0 -13
  13. data/CONTRIBUTING.md +0 -1
  14. data/Gemfile +0 -54
  15. data/Guardfile +0 -24
  16. data/Rakefile +0 -28
  17. data/lib/rom/array_dataset.rb +0 -44
  18. data/lib/rom/association_set.rb +0 -49
  19. data/lib/rom/auto_curry.rb +0 -55
  20. data/lib/rom/command.rb +0 -494
  21. data/lib/rom/command_registry.rb +0 -148
  22. data/lib/rom/commands/class_interface.rb +0 -270
  23. data/lib/rom/commands/composite.rb +0 -53
  24. data/lib/rom/commands/create.rb +0 -13
  25. data/lib/rom/commands/delete.rb +0 -14
  26. data/lib/rom/commands/graph/builder.rb +0 -176
  27. data/lib/rom/commands/graph/class_interface.rb +0 -62
  28. data/lib/rom/commands/graph/input_evaluator.rb +0 -62
  29. data/lib/rom/commands/graph.rb +0 -95
  30. data/lib/rom/commands/lazy/create.rb +0 -23
  31. data/lib/rom/commands/lazy/delete.rb +0 -27
  32. data/lib/rom/commands/lazy/update.rb +0 -34
  33. data/lib/rom/commands/lazy.rb +0 -99
  34. data/lib/rom/commands/result.rb +0 -96
  35. data/lib/rom/commands/update.rb +0 -14
  36. data/lib/rom/commands.rb +0 -3
  37. data/lib/rom/configuration.rb +0 -90
  38. data/lib/rom/configuration_dsl/command.rb +0 -41
  39. data/lib/rom/configuration_dsl/command_dsl.rb +0 -35
  40. data/lib/rom/configuration_dsl/mapper.rb +0 -36
  41. data/lib/rom/configuration_dsl/mapper_dsl.rb +0 -43
  42. data/lib/rom/configuration_dsl/relation.rb +0 -26
  43. data/lib/rom/configuration_dsl.rb +0 -107
  44. data/lib/rom/configuration_plugin.rb +0 -17
  45. data/lib/rom/constants.rb +0 -36
  46. data/lib/rom/container.rb +0 -233
  47. data/lib/rom/create_container.rb +0 -60
  48. data/lib/rom/data_proxy.rb +0 -94
  49. data/lib/rom/enumerable_dataset.rb +0 -68
  50. data/lib/rom/environment.rb +0 -70
  51. data/lib/rom/gateway.rb +0 -196
  52. data/lib/rom/global/plugin_dsl.rb +0 -47
  53. data/lib/rom/global.rb +0 -58
  54. data/lib/rom/initializer.rb +0 -26
  55. data/lib/rom/lint/enumerable_dataset.rb +0 -54
  56. data/lib/rom/lint/gateway.rb +0 -120
  57. data/lib/rom/lint/linter.rb +0 -78
  58. data/lib/rom/lint/spec.rb +0 -20
  59. data/lib/rom/lint/test.rb +0 -98
  60. data/lib/rom/mapper_registry.rb +0 -35
  61. data/lib/rom/memory/commands.rb +0 -56
  62. data/lib/rom/memory/dataset.rb +0 -97
  63. data/lib/rom/memory/gateway.rb +0 -64
  64. data/lib/rom/memory/relation.rb +0 -62
  65. data/lib/rom/memory/schema.rb +0 -13
  66. data/lib/rom/memory/storage.rb +0 -59
  67. data/lib/rom/memory/types.rb +0 -9
  68. data/lib/rom/memory.rb +0 -4
  69. data/lib/rom/pipeline.rb +0 -122
  70. data/lib/rom/plugin.rb +0 -20
  71. data/lib/rom/plugin_base.rb +0 -40
  72. data/lib/rom/plugin_registry.rb +0 -173
  73. data/lib/rom/plugins/command/schema.rb +0 -37
  74. data/lib/rom/plugins/configuration/configuration_dsl.rb +0 -21
  75. data/lib/rom/plugins/relation/instrumentation.rb +0 -51
  76. data/lib/rom/plugins/relation/key_inference.rb +0 -48
  77. data/lib/rom/plugins/relation/registry_reader.rb +0 -33
  78. data/lib/rom/registry.rb +0 -50
  79. data/lib/rom/relation/class_interface.rb +0 -356
  80. data/lib/rom/relation/composite.rb +0 -46
  81. data/lib/rom/relation/curried.rb +0 -109
  82. data/lib/rom/relation/graph.rb +0 -125
  83. data/lib/rom/relation/loaded.rb +0 -127
  84. data/lib/rom/relation/materializable.rb +0 -66
  85. data/lib/rom/relation/name.rb +0 -102
  86. data/lib/rom/relation/view_dsl.rb +0 -64
  87. data/lib/rom/relation.rb +0 -250
  88. data/lib/rom/relation_registry.rb +0 -9
  89. data/lib/rom/schema/attribute.rb +0 -390
  90. data/lib/rom/schema/dsl.rb +0 -67
  91. data/lib/rom/schema.rb +0 -407
  92. data/lib/rom/setup/auto_registration.rb +0 -74
  93. data/lib/rom/setup/auto_registration_strategies/base.rb +0 -16
  94. data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +0 -63
  95. data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +0 -20
  96. data/lib/rom/setup/auto_registration_strategies/with_namespace.rb +0 -18
  97. data/lib/rom/setup/finalize/finalize_commands.rb +0 -47
  98. data/lib/rom/setup/finalize/finalize_mappers.rb +0 -36
  99. data/lib/rom/setup/finalize/finalize_relations.rb +0 -83
  100. data/lib/rom/setup/finalize.rb +0 -152
  101. data/lib/rom/setup.rb +0 -65
  102. data/lib/rom/support/configurable.rb +0 -85
  103. data/lib/rom/transaction.rb +0 -24
  104. data/lib/rom/types.rb +0 -49
  105. data/log/.gitkeep +0 -0
  106. data/rakelib/benchmark.rake +0 -15
  107. data/rakelib/mutant.rake +0 -19
  108. data/rakelib/rubocop.rake +0 -18
  109. data/rom.gemspec +0 -25
  110. data/spec/fixtures/app/commands/create_user.rb +0 -2
  111. data/spec/fixtures/app/mappers/user_list.rb +0 -2
  112. data/spec/fixtures/app/my_commands/create_user.rb +0 -2
  113. data/spec/fixtures/app/my_mappers/user_list.rb +0 -2
  114. data/spec/fixtures/app/my_relations/users.rb +0 -2
  115. data/spec/fixtures/app/relations/users.rb +0 -2
  116. data/spec/fixtures/custom/commands/create_user.rb +0 -6
  117. data/spec/fixtures/custom/mappers/user_list.rb +0 -6
  118. data/spec/fixtures/custom/relations/users.rb +0 -6
  119. data/spec/fixtures/custom_namespace/commands/create_customer.rb +0 -8
  120. data/spec/fixtures/custom_namespace/mappers/customer_list.rb +0 -8
  121. data/spec/fixtures/custom_namespace/relations/customers.rb +0 -8
  122. data/spec/fixtures/lib/persistence/commands/create_user.rb +0 -6
  123. data/spec/fixtures/lib/persistence/mappers/user_list.rb +0 -6
  124. data/spec/fixtures/lib/persistence/my_commands/create_user.rb +0 -6
  125. data/spec/fixtures/lib/persistence/my_mappers/user_list.rb +0 -6
  126. data/spec/fixtures/lib/persistence/my_relations/users.rb +0 -6
  127. data/spec/fixtures/lib/persistence/relations/users.rb +0 -6
  128. data/spec/fixtures/wrong/commands/create_customer.rb +0 -8
  129. data/spec/fixtures/wrong/mappers/customer_list.rb +0 -8
  130. data/spec/fixtures/wrong/relations/customers.rb +0 -8
  131. data/spec/integration/command_registry_spec.rb +0 -47
  132. data/spec/integration/commands/create_spec.rb +0 -157
  133. data/spec/integration/commands/delete_spec.rb +0 -67
  134. data/spec/integration/commands/error_handling_spec.rb +0 -25
  135. data/spec/integration/commands/graph_builder_spec.rb +0 -213
  136. data/spec/integration/commands/graph_spec.rb +0 -294
  137. data/spec/integration/commands/update_spec.rb +0 -86
  138. data/spec/integration/commands_spec.rb +0 -67
  139. data/spec/integration/gateways/extending_relations_spec.rb +0 -58
  140. data/spec/integration/gateways/setting_logger_spec.rb +0 -34
  141. data/spec/integration/mappers/combine_spec.rb +0 -117
  142. data/spec/integration/mappers/deep_embedded_spec.rb +0 -44
  143. data/spec/integration/mappers/definition_dsl_spec.rb +0 -206
  144. data/spec/integration/mappers/embedded_spec.rb +0 -62
  145. data/spec/integration/mappers/exclude_spec.rb +0 -27
  146. data/spec/integration/mappers/fold_spec.rb +0 -71
  147. data/spec/integration/mappers/group_spec.rb +0 -163
  148. data/spec/integration/mappers/overwrite_attributes_value_spec.rb +0 -51
  149. data/spec/integration/mappers/prefix_separator_spec.rb +0 -52
  150. data/spec/integration/mappers/prefix_spec.rb +0 -48
  151. data/spec/integration/mappers/prefixing_attributes_spec.rb +0 -37
  152. data/spec/integration/mappers/registering_custom_mappers_spec.rb +0 -28
  153. data/spec/integration/mappers/renaming_attributes_spec.rb +0 -125
  154. data/spec/integration/mappers/reusing_mappers_spec.rb +0 -43
  155. data/spec/integration/mappers/step_spec.rb +0 -119
  156. data/spec/integration/mappers/symbolizing_attributes_spec.rb +0 -77
  157. data/spec/integration/mappers/unfold_spec.rb +0 -92
  158. data/spec/integration/mappers/ungroup_spec.rb +0 -126
  159. data/spec/integration/mappers/unwrap_spec.rb +0 -93
  160. data/spec/integration/mappers/wrap_spec.rb +0 -155
  161. data/spec/integration/memory/commands/create_spec.rb +0 -23
  162. data/spec/integration/memory/commands/delete_spec.rb +0 -23
  163. data/spec/integration/memory/commands/update_spec.rb +0 -23
  164. data/spec/integration/multi_env_spec.rb +0 -69
  165. data/spec/integration/multi_repo_spec.rb +0 -46
  166. data/spec/integration/relations/default_dataset_spec.rb +0 -38
  167. data/spec/integration/relations/inheritance_spec.rb +0 -37
  168. data/spec/integration/relations/reading_spec.rb +0 -169
  169. data/spec/integration/relations/registry_dsl_spec.rb +0 -45
  170. data/spec/integration/setup_spec.rb +0 -193
  171. data/spec/shared/command_behavior.rb +0 -28
  172. data/spec/shared/command_graph.rb +0 -54
  173. data/spec/shared/container.rb +0 -9
  174. data/spec/shared/enumerable_dataset.rb +0 -52
  175. data/spec/shared/gateway_only.rb +0 -6
  176. data/spec/shared/materializable.rb +0 -36
  177. data/spec/shared/no_container.rb +0 -16
  178. data/spec/shared/one_behavior.rb +0 -26
  179. data/spec/shared/proxy.rb +0 -0
  180. data/spec/shared/users_and_tasks.rb +0 -10
  181. data/spec/spec_helper.rb +0 -59
  182. data/spec/support/constant_leak_finder.rb +0 -14
  183. data/spec/support/mutant.rb +0 -10
  184. data/spec/support/schema.rb +0 -14
  185. data/spec/support/types.rb +0 -5
  186. data/spec/test/memory_repository_lint_test.rb +0 -27
  187. data/spec/unit/rom/array_dataset_spec.rb +0 -59
  188. data/spec/unit/rom/association_set_spec.rb +0 -48
  189. data/spec/unit/rom/auto_curry_spec.rb +0 -71
  190. data/spec/unit/rom/commands/graph_spec.rb +0 -192
  191. data/spec/unit/rom/commands/lazy_spec.rb +0 -310
  192. data/spec/unit/rom/commands/pre_and_post_processors_spec.rb +0 -343
  193. data/spec/unit/rom/commands/result_spec.rb +0 -70
  194. data/spec/unit/rom/commands_spec.rb +0 -188
  195. data/spec/unit/rom/configurable_spec.rb +0 -49
  196. data/spec/unit/rom/configuration_spec.rb +0 -61
  197. data/spec/unit/rom/container_spec.rb +0 -109
  198. data/spec/unit/rom/create_container_spec.rb +0 -151
  199. data/spec/unit/rom/enumerable_dataset_spec.rb +0 -15
  200. data/spec/unit/rom/environment_spec.rb +0 -123
  201. data/spec/unit/rom/gateway_spec.rb +0 -146
  202. data/spec/unit/rom/mapper_registry_spec.rb +0 -25
  203. data/spec/unit/rom/memory/commands_spec.rb +0 -43
  204. data/spec/unit/rom/memory/dataset_spec.rb +0 -31
  205. data/spec/unit/rom/memory/gateway_spec.rb +0 -12
  206. data/spec/unit/rom/memory/inheritance_spec.rb +0 -32
  207. data/spec/unit/rom/memory/relation_spec.rb +0 -121
  208. data/spec/unit/rom/memory/storage_spec.rb +0 -45
  209. data/spec/unit/rom/plugin_spec.rb +0 -150
  210. data/spec/unit/rom/plugins/command/schema_spec.rb +0 -66
  211. data/spec/unit/rom/plugins/relation/instrumentation_spec.rb +0 -44
  212. data/spec/unit/rom/plugins/relation/key_inference_spec.rb +0 -85
  213. data/spec/unit/rom/registry_spec.rb +0 -86
  214. data/spec/unit/rom/relation/attribute_reader_spec.rb +0 -17
  215. data/spec/unit/rom/relation/call_spec.rb +0 -51
  216. data/spec/unit/rom/relation/composite_spec.rb +0 -106
  217. data/spec/unit/rom/relation/curried_spec.rb +0 -67
  218. data/spec/unit/rom/relation/graph_spec.rb +0 -106
  219. data/spec/unit/rom/relation/lazy/combine_spec.rb +0 -165
  220. data/spec/unit/rom/relation/lazy/graph_spec.rb +0 -165
  221. data/spec/unit/rom/relation/lazy_spec.rb +0 -214
  222. data/spec/unit/rom/relation/loaded_spec.rb +0 -53
  223. data/spec/unit/rom/relation/name_spec.rb +0 -58
  224. data/spec/unit/rom/relation/output_schema_spec.rb +0 -28
  225. data/spec/unit/rom/relation/schema_spec.rb +0 -259
  226. data/spec/unit/rom/relation/view_spec.rb +0 -158
  227. data/spec/unit/rom/relation_spec.rb +0 -252
  228. data/spec/unit/rom/schema/accessing_attributes_spec.rb +0 -52
  229. data/spec/unit/rom/schema/append_spec.rb +0 -17
  230. data/spec/unit/rom/schema/exclude_spec.rb +0 -15
  231. data/spec/unit/rom/schema/finalize_spec.rb +0 -59
  232. data/spec/unit/rom/schema/key_predicate_spec.rb +0 -15
  233. data/spec/unit/rom/schema/merge_spec.rb +0 -17
  234. data/spec/unit/rom/schema/prefix_spec.rb +0 -16
  235. data/spec/unit/rom/schema/project_spec.rb +0 -15
  236. data/spec/unit/rom/schema/rename_spec.rb +0 -22
  237. data/spec/unit/rom/schema/type_spec.rb +0 -49
  238. data/spec/unit/rom/schema/uniq_spec.rb +0 -21
  239. data/spec/unit/rom/schema/wrap_spec.rb +0 -18
  240. data/spec/unit/rom/schema_spec.rb +0 -10
  241. data/spec/unit/rom/setup/auto_registration_spec.rb +0 -214
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe 'Relation registration DSL' do
4
- include_context 'container'
5
- include_context 'users and tasks'
6
-
7
- it 'allows to expose chainable relations' do
8
- configuration.relation(:tasks) do
9
- def high_priority
10
- restrict { |tuple| tuple[:priority] < 2 }
11
- end
12
-
13
- def by_title(title)
14
- restrict(title: title)
15
- end
16
- end
17
-
18
- configuration.relation(:users) do
19
- def with_tasks
20
- join(tasks)
21
- end
22
- end
23
-
24
- tasks = container.relations.tasks
25
-
26
- expect(tasks.class.name).to eql("ROM::Relation[Tasks]")
27
- expect(tasks.high_priority.inspect).to include("#<ROM::Relation[Tasks]")
28
-
29
- expect(tasks.high_priority.by_title("be nice")).to match_array(
30
- [name: "Joe", title: "be nice", priority: 1]
31
- )
32
-
33
- expect(tasks.by_title("be cool")).to match_array(
34
- [name: "Jane", title: "be cool", priority: 2]
35
- )
36
-
37
- users = container.relations.users
38
-
39
- expect(users.with_tasks).to match_array(
40
- [{ name: "Joe", email: "joe@doe.org", title: "be nice", priority: 1 },
41
- { name: "Joe", email: "joe@doe.org", title: "sleep well", priority: 2 },
42
- { name: "Jane", email: "jane@doe.org", title: "be cool", priority: 2 }]
43
- )
44
- end
45
- end
@@ -1,193 +0,0 @@
1
- require 'spec_helper'
2
- require 'rom/plugins/relation/key_inference'
3
- require 'dry-struct'
4
-
5
- RSpec.describe 'Configuring ROM' do
6
- context 'with existing schema' do
7
- include_context 'container'
8
- include_context 'users and tasks'
9
-
10
- let(:jane) { { name: 'Jane', email: 'jane@doe.org' } }
11
- let(:joe) { { name: 'Joe', email: 'joe@doe.org' } }
12
-
13
- before do
14
- configuration.relation(:users)
15
- configuration.relation(:tasks)
16
- end
17
-
18
- it 'configures schema relations' do
19
- expect(container.gateways[:default][:users]).to match_array([joe, jane])
20
- end
21
-
22
- it 'configures rom relations' do
23
- users = container.relations.users
24
-
25
- expect(users).to be_kind_of(ROM::Relation)
26
- expect(users).to respond_to(:tasks)
27
-
28
- tasks = users.tasks
29
-
30
- expect(tasks).to be_kind_of(ROM::Relation)
31
- expect(tasks).to respond_to(:users)
32
- expect(tasks.users).to be(users)
33
- end
34
- end
35
-
36
- context 'without schema' do
37
- it 'builds empty registries if there is no schema' do
38
- container = ROM.container(:memory)
39
- expect(container.relations).to eql(ROM::RelationRegistry.new)
40
- expect(container.mappers).to eql(ROM::Registry.new)
41
- end
42
- end
43
-
44
- describe 'defining classes' do
45
- let(:container) do
46
- ROM.container(:memory) do |config|
47
- class Test::UserRelation < ROM::Relation[:memory]
48
- dataset :users
49
-
50
- def by_name(name)
51
- restrict(name: name)
52
- end
53
- end
54
-
55
- class Test::TaskRelation < ROM::Relation[:memory]
56
- dataset :tasks
57
- end
58
-
59
- class Test::CreateUser < ROM::Commands::Update[:memory]
60
- relation :users
61
- register_as :create
62
- end
63
-
64
- config.register_relation(Test::UserRelation, Test::TaskRelation)
65
- config.register_command(Test::CreateUser)
66
- end
67
- end
68
-
69
- it 'sets up registries based on class definitions' do
70
- expect(container.relations.users).to be_kind_of(Test::UserRelation)
71
- expect(container.relations.users.tasks).to be(container.relations.tasks)
72
-
73
- expect(container.commands.users[:create]).to be_kind_of(Test::CreateUser)
74
-
75
- expect(container.relations.tasks).to be_kind_of(Test::TaskRelation)
76
- expect(container.relations.tasks.users).to be(container.relations.users)
77
- end
78
-
79
- it 'sets empty schemas by default' do
80
- expect(container.relations[:users].schema).to be_empty
81
- expect(container.relations[:tasks].schema).to be_empty
82
- end
83
- end
84
-
85
- describe 'quick setup' do
86
- # NOTE: move to DSL tests
87
- it 'exposes boot DSL inside the setup block via `macros` plugin' do
88
- module Test
89
- User = Class.new(Dry::Struct) do
90
- attribute :name, Types::String
91
- end
92
- end
93
-
94
- container = ROM.container(:memory) do |rom|
95
- rom.relation(:users) do
96
- def by_name(name)
97
- restrict(name: name)
98
- end
99
- end
100
-
101
- rom.commands(:users) do
102
- define(:create)
103
- end
104
-
105
- rom.mappers do
106
- define(:users) do
107
- model Test::User
108
- end
109
- end
110
- end
111
-
112
- container.commands.users.create.call(name: 'Jane')
113
-
114
- expect(container.relation(:users).by_name('Jane').as(:users).to_a)
115
- .to eql([Test::User.new(name: 'Jane')])
116
-
117
- expect(container.relations[:users].map_with(:users).to_a)
118
- .to eql([Test::User.new(name: 'Jane')])
119
- end
120
- end
121
-
122
- describe 'multi-step setup' do
123
- it 'exposes boot DSL that can be invoked multiple times' do
124
- module Test
125
- User = Class.new(Dry::Struct) do
126
- attribute :name, Types::String
127
- end
128
- end
129
-
130
- configuration = ROM::Configuration.new(:memory)
131
-
132
- configuration.relation(:users) do
133
- def by_name(name)
134
- restrict(name: name)
135
- end
136
- end
137
-
138
- configuration.commands(:users) do
139
- define(:create)
140
- end
141
-
142
- configuration.mappers do
143
- define(:users) do
144
- model Test::User
145
- end
146
- end
147
-
148
- container = ROM.container(configuration)
149
-
150
- container.command(:users).create.call(name: 'Jane')
151
-
152
- expect(container.relation(:users).by_name('Jane').as(:users).to_a)
153
- .to eql([Test::User.new(name: 'Jane')])
154
- end
155
- end
156
-
157
- it 'allows to use a relation with a schema in multiple containers' do
158
- class Test::UserRelation < ROM::Relation[:memory]
159
- dataset :users
160
-
161
- schema do
162
- attribute :id, Types::Int.meta(primary_key: true)
163
- end
164
- end
165
-
166
- 2.times do
167
- ROM.container(:memory) { |c| c.register_relation(Test::UserRelation) }
168
- end
169
- end
170
-
171
- describe 'configuring plugins for all relations' do
172
- it 'allows setting instrumentation for relations' do
173
- Test::Notifications = double(:notifications)
174
-
175
- configuration = ROM::Configuration.new(:memory)
176
-
177
- configuration.plugin(:memory, relations: :instrumentation) do |p|
178
- p.notifications = Test::Notifications
179
- end
180
-
181
- configuration.plugin(:memory, relations: :key_inference)
182
-
183
- configuration.relation(:users)
184
-
185
- container = ROM.container(configuration)
186
-
187
- users = container.relations[:users]
188
-
189
- expect(users.notifications).to be(Test::Notifications)
190
- expect(users).to respond_to(:foreign_key)
191
- end
192
- end
193
- end
@@ -1,28 +0,0 @@
1
- shared_examples_for 'a command' do
2
- describe '#name' do
3
- it 'returns relation name' do
4
- expect(command.name).to eql(command.relation.name)
5
- end
6
- end
7
-
8
- describe '#gateway' do
9
- it 'returns relation gateway' do
10
- expect(command.gateway).to eql(command.relation.gateway)
11
- end
12
- end
13
-
14
- describe '#method_missing' do
15
- it 'forwards to relation and wraps response if it returned another relation' do
16
- if command.class.restrictable
17
- new_command = command.by_id(1)
18
-
19
- expect(new_command).to be_instance_of(command.class)
20
- expect(new_command.relation).to eql(command.by_id(1).relation)
21
- end
22
- end
23
-
24
- it 'raises error when message is not known' do
25
- expect { command.not_here }.to raise_error(NoMethodError, /not_here/)
26
- end
27
- end
28
- end
@@ -1,54 +0,0 @@
1
- shared_context 'command graph' do
2
- include_context 'container'
3
-
4
- before do
5
- configuration.relation :users do
6
- def by_name(name)
7
- restrict(name: name)
8
- end
9
- end
10
-
11
- configuration.relation :tasks do
12
- def by_user_and_title(user, title)
13
- by_user(user).by_title(title)
14
- end
15
-
16
- def by_user(user)
17
- restrict(user: user)
18
- end
19
-
20
- def by_title(title)
21
- restrict(title: title)
22
- end
23
- end
24
-
25
- configuration.relation :books
26
- configuration.relation :tags
27
-
28
- configuration.commands(:users) do
29
- define(:create) do
30
- result :one
31
- end
32
- end
33
-
34
- configuration.commands(:books) do
35
- define(:create) do
36
- before :associate
37
-
38
- def associate(tuples, user)
39
- tuples.map { |t| t.merge(user: user.fetch(:name)) }
40
- end
41
- end
42
- end
43
-
44
- configuration.commands(:tags) do
45
- define(:create) do
46
- before :associate
47
-
48
- def associate(tuples, task)
49
- tuples.map { |t| t.merge(task: task.fetch(:title)) }
50
- end
51
- end
52
- end
53
- end
54
- end
@@ -1,9 +0,0 @@
1
- RSpec.shared_context 'container' do
2
- let(:container) { ROM.container(configuration) }
3
- let!(:configuration) { ROM::Configuration.new(:memory) }
4
- let(:gateway) { configuration.gateways[:default] }
5
- let(:users_relation) { container.relation(:users) }
6
- let(:tasks_relation) { container.relation(:tasks) }
7
- let(:users_dataset) { gateway.dataset(:users) }
8
- let(:tasks_dataset) { gateway.dataset(:tasks) }
9
- end
@@ -1,52 +0,0 @@
1
- RSpec.shared_examples_for "an enumerable dataset" do
2
- subject(:dataset) { klass.new(data) }
3
-
4
- let(:data) do
5
- [{ 'name' => 'Jane' }, { 'name' => 'Joe' }]
6
- end
7
-
8
- describe '#each' do
9
- it 'yields tuples through row_proc' do
10
- result = []
11
-
12
- dataset.each do |tuple|
13
- result << tuple
14
- end
15
-
16
- expect(result).to match_array([{ name: 'Jane' }, { name: 'Joe' }])
17
- end
18
- end
19
-
20
- describe '#to_a' do
21
- it 'casts dataset to an array' do
22
- expect(dataset.to_a).to eql([{ name: 'Jane' }, { name: 'Joe' }])
23
- end
24
- end
25
-
26
- describe '#find_all' do
27
- it 'yields tuples through row_proc' do
28
- result = dataset.find_all { |tuple| tuple[:name] == 'Jane' }
29
-
30
- expect(result).to be_instance_of(klass)
31
- expect(result).to match_array([{ name: 'Jane' }])
32
- end
33
- end
34
-
35
- describe '#kind_of?' do
36
- it 'does not forward to data object' do
37
- expect(dataset).to be_kind_of(klass)
38
- end
39
- end
40
-
41
- describe '#instance_of?' do
42
- it 'does not forward to data object' do
43
- expect(dataset).to be_instance_of(klass)
44
- end
45
- end
46
-
47
- describe '#is_a?' do
48
- it 'does not forward to data object' do
49
- expect(dataset.is_a?(klass)).to be(true)
50
- end
51
- end
52
- end
@@ -1,6 +0,0 @@
1
- RSpec.shared_context 'gateway only' do
2
- let(:gateway) { ROM::Memory::Gateway.new }
3
-
4
- let(:users_dataset) { gateway.dataset(:users) }
5
- let(:tasks_dataset) { gateway.dataset(:tasks) }
6
- end
@@ -1,36 +0,0 @@
1
- shared_examples_for 'materializable relation' do
2
- describe '#each' do
3
- it 'yields objects' do
4
- count = relation.to_a.size
5
- result = []
6
-
7
- relation.each do |object|
8
- result << object
9
- end
10
-
11
- expect(result.count).to eql(count)
12
- end
13
-
14
- it 'returns enumerator when block is not provided' do
15
- expect(relation.each.to_a).to eql(relation.to_a)
16
- end
17
- end
18
-
19
- describe '#one' do
20
- it 'returns one tuple' do
21
- expect(relation.one).to be_instance_of(Hash)
22
- end
23
- end
24
-
25
- describe '#first' do
26
- it 'returns first tuple' do
27
- expect(relation.first).to be_instance_of(Hash)
28
- end
29
- end
30
-
31
- describe '#call' do
32
- it 'materializes relation' do
33
- expect(relation.call).to be_instance_of(ROM::Relation::Loaded)
34
- end
35
- end
36
- end
@@ -1,16 +0,0 @@
1
- require 'rom/memory'
2
-
3
- RSpec.shared_context 'no container' do
4
- let(:gateway) { ROM::Memory::Gateway.new }
5
-
6
- let(:users_dataset) { gateway.dataset(:users) }
7
- let(:tasks_dataset) { gateway.dataset(:tasks) }
8
-
9
- let(:users_relation) do
10
- Class.new(ROM::Memory::Relation).new(users_dataset)
11
- end
12
-
13
- let(:tasks_relation) do
14
- Class.new(ROM::Memory::Relation).new(tasks_dataset)
15
- end
16
- end
@@ -1,26 +0,0 @@
1
- shared_examples_for 'a relation that returns one tuple' do
2
- describe '#one' do
3
- it 'returns first tuple' do
4
- users_relation.delete(name: 'Joe', email: 'joe@doe.org')
5
- expect(relation.one).to eql(name: 'Jane', email: 'jane@doe.org')
6
- end
7
-
8
- it 'raises error when there is more than one tuple' do
9
- expect { relation.one }.to raise_error(ROM::TupleCountMismatchError)
10
- end
11
- end
12
-
13
- describe '#one!' do
14
- it 'returns first tuple' do
15
- users_relation.delete(name: 'Joe', email: 'joe@doe.org')
16
- expect(relation.one!).to eql(name: 'Jane', email: 'jane@doe.org')
17
- end
18
-
19
- it 'raises error when there is no tuples' do
20
- users_relation.delete(name: 'Jane', email: 'jane@doe.org')
21
- users_relation.delete(name: 'Joe', email: 'joe@doe.org')
22
-
23
- expect { relation.one! }.to raise_error(ROM::TupleCountMismatchError)
24
- end
25
- end
26
- end
data/spec/shared/proxy.rb DELETED
File without changes
@@ -1,10 +0,0 @@
1
- RSpec.shared_context 'users and tasks' do
2
- before do
3
- users_dataset.insert(name: "Joe", email: "joe@doe.org")
4
- users_dataset.insert(name: "Jane", email: "jane@doe.org")
5
-
6
- tasks_dataset.insert(name: "Joe", title: "be nice", priority: 1)
7
- tasks_dataset.insert(name: "Joe", title: "sleep well", priority: 2)
8
- tasks_dataset.insert(name: "Jane", title: "be cool", priority: 2)
9
- end
10
- end
data/spec/spec_helper.rb DELETED
@@ -1,59 +0,0 @@
1
- require 'pathname'
2
-
3
- if RUBY_ENGINE == 'ruby' && ENV['COVERAGE'] == 'true'
4
- require 'yaml'
5
- rubies = YAML.load(File.read(File.join(__dir__, '..', '.travis.yml')))['rvm']
6
- latest_mri = rubies.select { |v| v =~ /\A\d+\.\d+.\d+\z/ }.max
7
-
8
- if RUBY_VERSION == latest_mri
9
- require 'simplecov'
10
- SimpleCov.start do
11
- add_filter '/spec/'
12
- end
13
- end
14
- end
15
-
16
- SPEC_ROOT = root = Pathname(__FILE__).dirname
17
-
18
- require 'dry/core/deprecations'
19
- Dry::Core::Deprecations.set_logger!(SPEC_ROOT.join('../log/deprecations.log'))
20
-
21
- require 'rom'
22
-
23
- begin
24
- require 'byebug'
25
- rescue LoadError
26
- end
27
-
28
- Dir[root.join('support/*.rb').to_s].each do |f|
29
- require f
30
- end
31
- Dir[root.join('shared/*.rb').to_s].each do |f|
32
- require f
33
- end
34
-
35
- # Namespace holding all objects created during specs
36
- module Test
37
- def self.remove_constants
38
- constants.each(&method(:remove_const))
39
- end
40
- end
41
-
42
- def T(*args)
43
- ROM::Processor::Transproc::Functions[*args]
44
- end
45
-
46
- RSpec.configure do |config|
47
- config.include(SchemaHelpers)
48
-
49
- config.after do
50
- Test.remove_constants
51
- end
52
-
53
- config.around do |example|
54
- ConstantLeakFinder.find(example)
55
- end
56
-
57
- config.disable_monkey_patching!
58
- config.warnings = true
59
- end
@@ -1,14 +0,0 @@
1
- # Finds leaking constants created during ROM specs
2
- module ConstantLeakFinder
3
- def self.find(example)
4
- constants = Object.constants
5
-
6
- example.run
7
-
8
- added_constants = (Object.constants - constants)
9
- added = added_constants.map(&Object.method(:const_get))
10
- if added.any? { |mod| mod.ancestors.map(&:name).grep(/\AROM/).any? }
11
- raise "Leaking constants: #{added_constants.inspect}"
12
- end
13
- end
14
- end
@@ -1,10 +0,0 @@
1
- module Mutant
2
- class Selector
3
- # Expression based test selector
4
- class Expression < self
5
- def call(_subject)
6
- integration.all_tests
7
- end
8
- end # Expression
9
- end # Selector
10
- end # Mutant
@@ -1,14 +0,0 @@
1
- require 'dry-types'
2
-
3
- module SchemaHelpers
4
- def define_schema(source, attrs)
5
- ROM::Schema.define(
6
- source,
7
- attributes: attrs.map { |name, type| define_type(name, type, source: source) }
8
- )
9
- end
10
-
11
- def define_type(name, id, **opts)
12
- ROM::Types.const_get(id).meta(name: name, **opts)
13
- end
14
- end
@@ -1,5 +0,0 @@
1
- require 'dry-types'
2
-
3
- module Types
4
- include Dry::Types.module
5
- end
@@ -1,27 +0,0 @@
1
- require 'rom'
2
- require 'rom/memory'
3
- require 'rom/lint/test'
4
-
5
- require 'minitest/autorun'
6
-
7
- class MemoryRepositoryLintTest < Minitest::Test
8
- include ROM::Lint::TestGateway
9
-
10
- def setup
11
- @gateway = ROM::Memory::Gateway
12
- @identifier = :memory
13
- end
14
-
15
- def gateway_instance
16
- ROM::Memory::Gateway.new
17
- end
18
- end
19
-
20
- class MemoryDatasetLintTest < Minitest::Test
21
- include ROM::Lint::TestEnumerableDataset
22
-
23
- def setup
24
- @data = [{ name: 'Jane', age: 24 }, { name: 'Joe', age: 25 }]
25
- @dataset = ROM::Memory::Dataset.new(@data)
26
- end
27
- end
@@ -1,59 +0,0 @@
1
- require 'rom/array_dataset'
2
-
3
- RSpec.describe ROM::ArrayDataset do
4
- let(:klass) do
5
- Class.new do
6
- include ROM::ArrayDataset
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' do
15
- describe '#flatten' do
16
- let(:data) { [[{ 'name' => 'Jane' }], [{ 'name' => 'Joe' }]] }
17
-
18
- it 'returns a new dataset with flattened data' do
19
- result = dataset.flatten
20
-
21
- expect(result).to match_array([{ name: 'Jane' }, { name: 'Joe' }])
22
- end
23
- end
24
-
25
- describe '#map!' do
26
- context 'with a block' do
27
- it 'returns a new dataset with mapped data' do
28
- dataset.map! do |row|
29
- row.merge(age: 21)
30
- end
31
-
32
- expect(dataset).to match_array([
33
- { name: 'Jane', age: 21 }, { name: 'Joe', age: 21 }
34
- ])
35
- end
36
- end
37
-
38
- context 'without a block' do
39
- it 'returns an enumerator' do
40
- result = dataset.map!
41
-
42
- expect(result).to be_instance_of(Enumerator)
43
-
44
- expect(result).to match_array([
45
- { name: 'Jane' }, { name: 'Joe' }
46
- ])
47
- end
48
- end
49
- end
50
-
51
- describe '#values_at' do
52
- it 'returns a new dataset with rows at given indices' do
53
- result = dataset.values_at(1)
54
-
55
- expect(result).to match_array([{ name: 'Joe' }])
56
- end
57
- end
58
- end
59
- end