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,158 +0,0 @@
1
- require 'rom'
2
- require 'rom/memory'
3
-
4
- RSpec.describe ROM::Relation, '.view' do
5
- subject(:relation) { relation_class.new(ROM::Memory::Dataset.new([])) }
6
-
7
- let(:registry) do
8
- { tasks: tasks }
9
- end
10
-
11
- let(:tasks) do
12
- Class.new(ROM::Relation[:memory]) do
13
- schema do
14
- attribute :title, ROM::Types::String
15
- end
16
- end.new([])
17
- end
18
-
19
- it 'returns view method name' do
20
- klass = Class.new(ROM::Relation[:memory]) {
21
- schema { attribute :id, ROM::Types::Int }
22
- }
23
-
24
- name = klass.view(:by_id, klass.schema) { self }
25
-
26
- expect(name).to be(:by_id)
27
- end
28
-
29
- shared_context 'relation with views' do
30
- before do
31
- relation << { id: 1, name: 'Joe' }
32
- relation << { id: 2, name: 'Jane' }
33
- end
34
-
35
- it 'appends foreign attributes' do
36
- expect(relation.schemas[:foreign_attributes].map(&:name)).to eql(%i[id name title])
37
- end
38
-
39
- it 'uses projected schema for view schema' do
40
- expect(relation.schemas[:names].map(&:name)).to eql(%i[name])
41
- end
42
-
43
- it 'auto-projects the relation via schema' do
44
- new_rel = relation_class.new([{ name: 'Jane' }, { name: 'Joe' }])
45
- names_schema = relation_class.schemas[:names]
46
-
47
- expect(names_schema).to receive(:call).with(relation).and_return(new_rel)
48
- expect(relation.names).to eql(new_rel)
49
- end
50
-
51
- it 'auto-projects a restricted relation via schema' do
52
- new_rel = relation_class.new([{ id: 2 }])
53
- ids_schema = relation_class.schemas[:ids_for_names]
54
-
55
- expect(ids_schema).to receive(:call).with(relation.restrict(name: ['Jane'])).and_return(new_rel)
56
- expect(relation.ids_for_names(['Jane'])).to eql(new_rel)
57
- end
58
- end
59
-
60
- context 'with an explicit schema' do
61
- before do
62
- # this is normally called automatically during setup
63
- relation_class.finalize(registry, relation)
64
- end
65
-
66
- include_context 'relation with views' do
67
- let(:relation_class) do
68
- Class.new(ROM::Memory::Relation) do
69
- schema(:users) do
70
- attribute :id, ROM::Types::Int
71
- attribute :name, ROM::Types::String
72
- end
73
-
74
- view(:foreign_attributes) do
75
- schema do
76
- append(relations[:tasks][:title])
77
- end
78
-
79
- relation do
80
- self
81
- end
82
- end
83
-
84
- view(:names) do
85
- schema do
86
- project(:name)
87
- end
88
-
89
- relation do
90
- self
91
- end
92
- end
93
-
94
- view(:ids_for_names) do
95
- schema do
96
- project(:id)
97
- end
98
-
99
- relation do |names|
100
- restrict(name: names)
101
- end
102
- end
103
- end
104
- end
105
- end
106
- end
107
-
108
- context 'with an inferred schema' do
109
- before do
110
- # this is normally called automatically during setup
111
- relation_class.schema.finalize!
112
- relation_class.finalize(registry, relation)
113
- end
114
-
115
- include_context 'relation with views' do
116
- let(:relation_class) do
117
- Class.new(ROM::Memory::Relation) do
118
- schema_inferrer -> dataset, gateway {
119
- [[ROM::Types::Int.meta(name: :id, source: :users),
120
- ROM::Types::String.meta(name: :name, source: :users)], []]
121
- }
122
-
123
- schema(:users, infer: true)
124
-
125
- view(:foreign_attributes) do
126
- schema do
127
- append(relations[:tasks][:title])
128
- end
129
-
130
- relation do
131
- self
132
- end
133
- end
134
-
135
- view(:names) do
136
- schema do
137
- project(:name)
138
- end
139
-
140
- relation do
141
- self
142
- end
143
- end
144
-
145
- view(:ids_for_names) do
146
- schema do
147
- project(:id)
148
- end
149
-
150
- relation do |names|
151
- restrict(name: names)
152
- end
153
- end
154
- end
155
- end
156
- end
157
- end
158
- end
@@ -1,252 +0,0 @@
1
- require 'rom/memory'
2
-
3
- RSpec.describe ROM::Relation do
4
- subject(:relation) { Class.new(ROM::Relation).new(dataset) }
5
-
6
- let(:dataset) { ROM::Memory::Dataset.new([jane, joe]) }
7
-
8
- let(:jane) { { id: 1, name: 'Jane' } }
9
- let(:joe) { { id: 2, name: 'Joe' } }
10
-
11
- describe '.[]' do
12
- before do
13
- module Test::TestAdapter
14
- class Relation < ROM::Relation
15
- adapter :test
16
-
17
- def test_relation?
18
- true
19
- end
20
- end
21
- end
22
-
23
- module Test::BrokenAdapter
24
- class Relation < ROM::Relation
25
- def test_relation?
26
- true
27
- end
28
- end
29
- end
30
-
31
- ROM.register_adapter(:test, Test::TestAdapter)
32
- ROM.register_adapter(:broken, Test::BrokenAdapter)
33
- end
34
-
35
- it 'returns relation subclass from the registered adapter' do
36
- subclass = Class.new(ROM::Relation[:test])
37
-
38
- relation = subclass.new([])
39
-
40
- expect(relation).to be_test_relation
41
- end
42
-
43
- it 'raises error when adapter relation has no identifier' do
44
- expect {
45
- Class.new(ROM::Relation[:broken])
46
- }.to raise_error(ROM::MissingAdapterIdentifierError, /Test::BrokenAdapter::Relation/)
47
- end
48
- end
49
-
50
- describe ".dataset" do
51
- it 'allows setting dataset name' do
52
- rel_class = Class.new(ROM::Relation[:memory]) { dataset :users }
53
-
54
- expect(rel_class.dataset).to be(:users)
55
- end
56
- end
57
-
58
- describe ".register_as" do
59
- it "defaults to dataset with a generated class" do
60
- rel = Class.new(ROM::Relation[:memory]) { dataset :users }
61
- expect(rel.register_as).to eq(:users)
62
- rel.register_as(:guests)
63
- expect(rel.register_as).to eq(:guests)
64
- end
65
-
66
- it "defaults to dataset with a defined class that has dataset inferred" do
67
- class Test::Users < ROM::Relation[:memory]; end
68
- expect(Test::Users.register_as).to eq(:test_users)
69
- end
70
-
71
- it "defaults to dataset with a defined class that has dataset set manually" do
72
- class Test::Users < ROM::Relation[:memory]
73
- dataset :guests
74
- end
75
- expect(Test::Users.register_as).to eq(:guests)
76
- end
77
-
78
- it "defaults to :dataset of parent class" do
79
- class Test::SuperUsers < ROM::Relation[:memory]
80
- dataset :users
81
- end
82
-
83
- class Test::DescendantUsers < Test::SuperUsers; end
84
-
85
- expect(Test::DescendantUsers.register_as).to be(:users)
86
- end
87
-
88
- it "sets custom value for super and descendant classes" do
89
- class Test::SuperUsers < ROM::Relation[:memory]
90
- register_as :users
91
- end
92
-
93
- class Test::DescendantUsers < Test::SuperUsers
94
- register_as :descendant_users
95
- end
96
-
97
- expect(Test::SuperUsers.register_as).to eq(:users)
98
- expect(Test::DescendantUsers.register_as).to eq(:descendant_users)
99
- end
100
-
101
- it "sets provided value overriding inherited value" do
102
- module Test
103
- class BaseRelation < ROM::Relation[:memory]
104
- end
105
-
106
- class UsersRelation < BaseRelation
107
- register_as :users
108
- dataset :users
109
- end
110
- end
111
-
112
- expect(Test::UsersRelation.register_as).to be(:users)
113
- end
114
- end
115
-
116
- describe '#name' do
117
- context 'missing dataset' do
118
- context 'with Relation inside module' do
119
- before do
120
- module Test::Test
121
- class SuperRelation < ROM::Relation[:memory]; end
122
- end
123
- end
124
-
125
- it 'returns name based on module and class' do
126
- relation = Test::Test::SuperRelation.new([])
127
-
128
- expect(relation.name).to eql(ROM::Relation::Name.new(:test_test_super_relation))
129
- end
130
- end
131
-
132
- context 'with Relation without module' do
133
- before do
134
- class Test::SuperRelation < ROM::Relation[:memory]; end
135
- end
136
-
137
- it 'returns name based only on class' do
138
- relation = Test::SuperRelation.new([])
139
-
140
- expect(relation.name).to eql(ROM::Relation::Name.new(:test_super_relation))
141
- end
142
- end
143
-
144
- context 'with a descendant relation' do
145
- before do
146
- class Test::SuperRelation < ROM::Relation[:memory]; end
147
- class Test::DescendantRelation < Test::SuperRelation; end
148
- end
149
-
150
- it 'inherits :name from the super relation' do
151
- relation = Test::DescendantRelation.new([])
152
-
153
- expect(relation.name).to eql(ROM::Relation::Name.new(:test_super_relation))
154
- end
155
- end
156
- end
157
-
158
- context 'manualy set dataset' do
159
- before do
160
- module Test::TestAdapter
161
- class Relation < ROM::Relation[:memory]
162
- dataset :foo_bar
163
- end
164
- end
165
- end
166
-
167
- it 'returns name based on dataset' do
168
- relation = Test::TestAdapter::Relation.new([])
169
-
170
- expect(relation.name).to eql(ROM::Relation::Name.new(:foo_bar))
171
- end
172
- end
173
- end
174
-
175
- describe "#each" do
176
- it "yields all objects" do
177
- result = []
178
-
179
- relation.each do |user|
180
- result << user
181
- end
182
-
183
- expect(result).to eql([jane, joe])
184
- end
185
-
186
- it "returns an enumerator if block is not provided" do
187
- expect(relation.each).to be_instance_of(Enumerator)
188
- end
189
- end
190
-
191
- describe "#to_a" do
192
- it "materializes relation to an array" do
193
- expect(relation.to_a).to eql([jane, joe])
194
- end
195
- end
196
-
197
- describe "#with" do
198
- it "returns a new instance with the original dataset and given custom options" do
199
- relation = Class.new(ROM::Relation) { option :custom }.new([], custom: true)
200
-
201
- custom_opts = { mappers: "Custom Mapper Registry" }
202
- new_relation = relation.with(custom_opts).with(custom: true)
203
-
204
- expect(new_relation.dataset).to be(relation.dataset)
205
- expect(new_relation.options).to include(custom_opts.merge(custom: true))
206
- end
207
- end
208
-
209
- describe '#graph?' do
210
- it 'returns false' do
211
- expect(relation.graph?).to be(false)
212
- end
213
-
214
- it 'returns false when curried' do
215
- relation = Class.new(ROM::Relation[:memory]) { def by_name(_); self; end }.new([])
216
- expect(relation.by_name.graph?).to be(false)
217
- end
218
- end
219
-
220
- describe '#schema' do
221
- it 'returns an empty schema by default' do
222
- relation = Class.new(ROM::Relation) {
223
- def self.name
224
- 'Test::SomeRelation'
225
- end
226
- }.new([])
227
-
228
- expect(relation.schema).to be_empty
229
- expect(relation.schema.inferrer).to be(ROM::Schema::DEFAULT_INFERRER)
230
- expect(relation.schema.name).to be(:test_some_relation)
231
- expect(relation.schema?).to be(false)
232
- end
233
- end
234
-
235
- describe '#input_schema' do
236
- it 'returns a schema hash type' do
237
- relation = Class.new(ROM::Relation[:memory]) do
238
- schema { attribute :id, ROM::Types::Coercible::Int }
239
- end.new([])
240
-
241
- expect(relation.input_schema[id: '1']).to eql(id: 1)
242
- end
243
-
244
- it 'returns a plain Hash coercer when there is no schema' do
245
- relation = Class.new(ROM::Relation[:memory]).new([])
246
-
247
- tuple = [[:id, '1']]
248
-
249
- expect(relation.input_schema[tuple]).to eql(id: '1')
250
- end
251
- end
252
- end
@@ -1,52 +0,0 @@
1
- require 'rom/schema'
2
-
3
- RSpec.describe ROM::Schema, '#[]' do
4
- context 'with a schema' do
5
- subject(:schema) do
6
- define_schema(:users, id: :Int, name: :String, email: :String)
7
- end
8
-
9
- it 'returns an attribute identified by its canonical name' do
10
- expect(schema[:email]).to eql(define_type(:email, :String, source: :users))
11
- end
12
-
13
- it 'returns an aliased attribute identified by its canonical name' do
14
- expect(schema.rename(id: :user_id)[:id]).to eql(define_type(:id, :Int, source: :users, alias: :user_id))
15
- end
16
-
17
- it 'raises KeyError when attribute is not found' do
18
- expect { schema[:not_here] }.to raise_error(KeyError, /not_here/)
19
- end
20
- end
21
-
22
- context 'with a merged schema' do
23
- subject(:schema) do
24
- left.merge(right.__send__(:new, right.map { |attr| attr.meta(source: :tasks) }))
25
- end
26
-
27
- let(:left) do
28
- define_schema(:users, id: :Int, name: :String)
29
- end
30
-
31
- let(:right) do
32
- define_schema(:tasks, id: :Int, title: :String)
33
- end
34
-
35
- it 'returns an attribute identified by its canonical name' do
36
- expect(schema[:id]).to eql(define_type(:id, :Int, source: :users))
37
- end
38
-
39
- it 'returns an attribute identified by its canonical name when its unique' do
40
- expect(schema[:title]).to eql(define_type(:title, :String, source: :tasks))
41
- end
42
-
43
- it 'returns an attribute identified by its canonical name and its source' do
44
- expect(schema[:id, :tasks]).to eql(define_type(:id, :Int, source: :tasks))
45
- end
46
-
47
- it 'raises KeyError when attribute is not found' do
48
- expect { schema[:not_here] }.to raise_error(KeyError, /not_here/)
49
- expect { schema[:not_here, :tasks] }.to raise_error(KeyError, /not_here/)
50
- end
51
- end
52
- end
@@ -1,17 +0,0 @@
1
- require 'rom/schema'
2
-
3
- RSpec.describe ROM::Schema, '#append' do
4
- subject(:schema) { left.append(*right) }
5
-
6
- let(:left) do
7
- define_schema(:users, id: :Int, name: :String)
8
- end
9
-
10
- let(:right) do
11
- define_schema(:tasks, user_id: :Int)
12
- end
13
-
14
- it 'returns a new schema with attributes from two schemas' do
15
- expect(schema.map(&:name)).to eql(%i[id name user_id])
16
- end
17
- end
@@ -1,15 +0,0 @@
1
- require 'rom/schema'
2
-
3
- RSpec.describe ROM::Schema, '#exclude' do
4
- subject(:schema) do
5
- define_schema(:users, id: :Int, name: :String, email: :String)
6
- end
7
-
8
- let(:excluded) do
9
- schema.exclude(:id, :name)
10
- end
11
-
12
- it 'returns projected schema with renamed attributes using provided prefix' do
13
- expect(excluded.map(&:name)).to eql(%i[email])
14
- end
15
- end
@@ -1,59 +0,0 @@
1
- require 'rom/schema'
2
-
3
- RSpec.describe ROM::Schema, '#finalize!' do
4
- context 'without inferrer' do
5
- subject(:schema) do
6
- define_schema(:users, id: :Int, name: :String)
7
- end
8
-
9
- before { schema.finalize! }
10
-
11
- it 'returns a frozen canonical schema' do
12
- expect(schema).to be_frozen
13
- end
14
- end
15
-
16
- context 'with inferrer' do
17
- subject(:schema) do
18
- ROM::Schema.define(:users, attributes: attributes, inferrer: inferrer)
19
- end
20
-
21
- let(:inferrer) do
22
- proc { [[define_type(:name, :String)], [:id, :age]]}
23
- end
24
-
25
- context 'when all required attributes are present' do
26
- let(:attributes) do
27
- [define_type(:id, :Int), define_type(:age, :Int)]
28
- end
29
-
30
- it 'concats defined attributes with inferred attributes' do
31
- expect(schema.finalize!.map(&:name)).to eql(%i[id age name])
32
- end
33
- end
34
-
35
- context 'when inferred attributes are overridden' do
36
- let(:attributes) do
37
- [define_type(:id, :Int),
38
- define_type(:age, :Int),
39
- define_type(:name, :String).meta(custom: true)]
40
- end
41
-
42
- it 'respects overridden attributes' do
43
- expect(schema.finalize!.map(&:name)).to eql(%i[id age name])
44
- expect(schema[:name].meta[:custom]).to be(true)
45
- end
46
- end
47
-
48
- context 'when some attributes are missing' do
49
- let(:attributes) do
50
- []
51
- end
52
-
53
- it 'raises error' do
54
- expect { schema.finalize! }.
55
- to raise_error(ROM::Schema::MissingAttributesError, /missing attributes in :users schema: :id, :age/)
56
- end
57
- end
58
- end
59
- end
@@ -1,15 +0,0 @@
1
- require 'rom/schema'
2
-
3
- RSpec.describe ROM::Schema, '#key?' do
4
- subject(:schema) do
5
- define_schema(:users, name: :String)
6
- end
7
-
8
- it 'returns true when an attribute exists' do
9
- expect(schema.key?(:name)).to be(true)
10
- end
11
-
12
- it 'returns false when an attribute does not exist' do
13
- expect(schema.key?(:foo)).to be(false)
14
- end
15
- end
@@ -1,17 +0,0 @@
1
- require 'rom/schema'
2
-
3
- RSpec.describe ROM::Schema, '#merge' do
4
- subject(:schema) { left.merge(right) }
5
-
6
- let(:left) do
7
- define_schema(:users, id: :Int, name: :String)
8
- end
9
-
10
- let(:right) do
11
- define_schema(:tasks, user_id: :Int)
12
- end
13
-
14
- it 'returns a new schema with attributes from two schemas' do
15
- expect(schema.map(&:name)).to eql(%i[id name user_id])
16
- end
17
- end
@@ -1,16 +0,0 @@
1
- require 'rom/schema'
2
-
3
- RSpec.describe ROM::Schema, '#prefix' do
4
- subject(:schema) do
5
- define_schema(:users, id: :Int, name: :String)
6
- end
7
-
8
- let(:prefixed) do
9
- schema.prefix(:user)
10
- end
11
-
12
- it 'returns projected schema with renamed attributes using provided prefix' do
13
- expect(prefixed.map(&:alias)).to eql(%i[user_id user_name])
14
- expect(prefixed.map { |attr| attr.meta[:name] }).to eql(%i[id name])
15
- end
16
- end
@@ -1,15 +0,0 @@
1
- require 'rom/schema'
2
-
3
- RSpec.describe ROM::Schema, '#project' do
4
- subject(:schema) do
5
- define_schema(:users, id: :Int, name: :String, age: :Int)
6
- end
7
-
8
- it 'projects provided attribute names' do
9
- expect(schema.project(:name, :age).map(&:name)).to eql(%i[name age])
10
- end
11
-
12
- it 'projects provided attributes' do
13
- expect(schema.project(schema[:name], schema[:age]).map(&:name)).to eql(%i[name age])
14
- end
15
- end
@@ -1,22 +0,0 @@
1
- require 'rom/schema'
2
-
3
- RSpec.describe ROM::Schema, '#rename' do
4
- subject(:schema) do
5
- define_schema(
6
- :users,
7
- user_id: :Int, user_name: :String, user_email: :String
8
- )
9
- end
10
-
11
- let(:renamed) do
12
- schema.rename(user_id: :id, user_name: :name)
13
- end
14
-
15
- it 'returns projected schema with renamed attributes' do
16
- expect(renamed.map(&:name)).to eql(%i[user_id user_name user_email])
17
- expect(renamed.map(&:alias)).to eql([:id, :name, nil])
18
- expect(renamed.all?(&:aliased?)).to be(false)
19
- expect(renamed[:user_id]).to be_aliased
20
- expect(renamed[:user_name]).to be_aliased
21
- end
22
- end
@@ -1,49 +0,0 @@
1
- require 'rom/schema/attribute'
2
-
3
- RSpec.describe ROM::Schema::Attribute do
4
- describe '#inspect' do
5
- context 'with a primitive definition' do
6
- subject(:type) do
7
- ROM::Schema::Attribute.new(ROM::Types::Int).meta(name: :id, primary_key: true)
8
- end
9
-
10
- specify do
11
- expect(type.inspect).to eql("#<ROM::Schema::Attribute[Integer] name=:id primary_key=true>")
12
- end
13
- end
14
-
15
- context 'with a sum' do
16
- subject(:type) do
17
- ROM::Schema::Attribute.new(ROM::Types::Bool).meta(name: :admin)
18
- end
19
-
20
- specify do
21
- expect(type.inspect).to eql("#<ROM::Schema::Attribute[TrueClass | FalseClass] name=:admin>")
22
- end
23
- end
24
- end
25
-
26
- describe '#aliased' do
27
- subject(:type) do
28
- ROM::Schema::Attribute.new(ROM::Types::String).meta(name: :user_name)
29
- end
30
-
31
- specify do
32
- expect(type.as(:name).meta[:alias]).to eql(:name)
33
- end
34
- end
35
-
36
- describe '#method_missing' do
37
- subject(:type) do
38
- ROM::Schema::Attribute.new(ROM::Types::Int).meta(name: :id, primary_key: true)
39
- end
40
-
41
- specify do
42
- expect(type.meta).to eql(name: :id, primary_key: true)
43
- end
44
-
45
- specify do
46
- expect { type.not_here }.to raise_error(NoMethodError, /not_here/)
47
- end
48
- end
49
- end