rom 2.0.2 → 5.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (203) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +122 -324
  3. data/LICENSE +17 -17
  4. data/README.md +91 -22
  5. data/lib/rom/version.rb +3 -1
  6. data/lib/rom.rb +4 -46
  7. metadata +42 -245
  8. data/.gitignore +0 -24
  9. data/.rspec +0 -3
  10. data/.rubocop.yml +0 -87
  11. data/.rubocop_todo.yml +0 -46
  12. data/.travis.yml +0 -28
  13. data/CODE_OF_CONDUCT.md +0 -13
  14. data/CONTRIBUTING.md +0 -1
  15. data/Gemfile +0 -41
  16. data/Guardfile +0 -24
  17. data/Rakefile +0 -22
  18. data/lib/rom/association_set.rb +0 -26
  19. data/lib/rom/command.rb +0 -173
  20. data/lib/rom/command_registry.rb +0 -153
  21. data/lib/rom/commands/class_interface.rb +0 -148
  22. data/lib/rom/commands/composite.rb +0 -54
  23. data/lib/rom/commands/create.rb +0 -13
  24. data/lib/rom/commands/delete.rb +0 -14
  25. data/lib/rom/commands/graph/builder.rb +0 -176
  26. data/lib/rom/commands/graph/class_interface.rb +0 -62
  27. data/lib/rom/commands/graph/input_evaluator.rb +0 -62
  28. data/lib/rom/commands/graph.rb +0 -103
  29. data/lib/rom/commands/lazy/create.rb +0 -23
  30. data/lib/rom/commands/lazy/delete.rb +0 -27
  31. data/lib/rom/commands/lazy/update.rb +0 -34
  32. data/lib/rom/commands/lazy.rb +0 -99
  33. data/lib/rom/commands/result.rb +0 -96
  34. data/lib/rom/commands/update.rb +0 -14
  35. data/lib/rom/commands.rb +0 -3
  36. data/lib/rom/configuration.rb +0 -88
  37. data/lib/rom/configuration_dsl/command.rb +0 -43
  38. data/lib/rom/configuration_dsl/command_dsl.rb +0 -35
  39. data/lib/rom/configuration_dsl/mapper.rb +0 -37
  40. data/lib/rom/configuration_dsl/mapper_dsl.rb +0 -44
  41. data/lib/rom/configuration_dsl/relation.rb +0 -26
  42. data/lib/rom/configuration_dsl.rb +0 -78
  43. data/lib/rom/configuration_plugin.rb +0 -17
  44. data/lib/rom/constants.rb +0 -30
  45. data/lib/rom/container.rb +0 -231
  46. data/lib/rom/create_container.rb +0 -61
  47. data/lib/rom/environment.rb +0 -70
  48. data/lib/rom/gateway.rb +0 -154
  49. data/lib/rom/global/plugin_dsl.rb +0 -49
  50. data/lib/rom/global.rb +0 -60
  51. data/lib/rom/lint/enumerable_dataset.rb +0 -54
  52. data/lib/rom/lint/gateway.rb +0 -94
  53. data/lib/rom/lint/linter.rb +0 -78
  54. data/lib/rom/lint/spec.rb +0 -20
  55. data/lib/rom/lint/test.rb +0 -98
  56. data/lib/rom/mapper_registry.rb +0 -35
  57. data/lib/rom/memory/commands.rb +0 -58
  58. data/lib/rom/memory/dataset.rb +0 -98
  59. data/lib/rom/memory/gateway.rb +0 -64
  60. data/lib/rom/memory/relation.rb +0 -49
  61. data/lib/rom/memory/storage.rb +0 -59
  62. data/lib/rom/memory/types.rb +0 -9
  63. data/lib/rom/memory.rb +0 -4
  64. data/lib/rom/pipeline.rb +0 -106
  65. data/lib/rom/plugin.rb +0 -17
  66. data/lib/rom/plugin_base.rb +0 -31
  67. data/lib/rom/plugin_registry.rb +0 -173
  68. data/lib/rom/plugins/command/schema.rb +0 -37
  69. data/lib/rom/plugins/configuration/configuration_dsl.rb +0 -17
  70. data/lib/rom/plugins/relation/key_inference.rb +0 -46
  71. data/lib/rom/plugins/relation/registry_reader.rb +0 -32
  72. data/lib/rom/plugins/relation/view/dsl.rb +0 -32
  73. data/lib/rom/plugins/relation/view.rb +0 -95
  74. data/lib/rom/relation/class_interface.rb +0 -230
  75. data/lib/rom/relation/composite.rb +0 -46
  76. data/lib/rom/relation/curried.rb +0 -104
  77. data/lib/rom/relation/graph.rb +0 -115
  78. data/lib/rom/relation/loaded.rb +0 -118
  79. data/lib/rom/relation/materializable.rb +0 -66
  80. data/lib/rom/relation/name.rb +0 -102
  81. data/lib/rom/relation.rb +0 -172
  82. data/lib/rom/relation_registry.rb +0 -9
  83. data/lib/rom/schema/dsl.rb +0 -58
  84. data/lib/rom/schema.rb +0 -89
  85. data/lib/rom/setup/auto_registration.rb +0 -69
  86. data/lib/rom/setup/auto_registration_strategies/base.rb +0 -11
  87. data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +0 -22
  88. data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +0 -19
  89. data/lib/rom/setup/auto_registration_strategies/with_namespace.rb +0 -18
  90. data/lib/rom/setup/finalize/finalize_commands.rb +0 -47
  91. data/lib/rom/setup/finalize/finalize_mappers.rb +0 -36
  92. data/lib/rom/setup/finalize/finalize_relations.rb +0 -60
  93. data/lib/rom/setup/finalize.rb +0 -146
  94. data/lib/rom/setup.rb +0 -55
  95. data/lib/rom/support/configurable.rb +0 -80
  96. data/lib/rom/types.rb +0 -18
  97. data/log/.gitkeep +0 -0
  98. data/rakelib/benchmark.rake +0 -15
  99. data/rakelib/mutant.rake +0 -19
  100. data/rakelib/rubocop.rake +0 -18
  101. data/rom.gemspec +0 -26
  102. data/spec/fixtures/app/commands/create_user.rb +0 -2
  103. data/spec/fixtures/app/mappers/user_list.rb +0 -2
  104. data/spec/fixtures/app/my_commands/create_user.rb +0 -2
  105. data/spec/fixtures/app/my_mappers/user_list.rb +0 -2
  106. data/spec/fixtures/app/my_relations/users.rb +0 -2
  107. data/spec/fixtures/app/relations/users.rb +0 -2
  108. data/spec/fixtures/custom/commands/create_user.rb +0 -6
  109. data/spec/fixtures/custom/mappers/user_list.rb +0 -6
  110. data/spec/fixtures/custom/relations/users.rb +0 -6
  111. data/spec/fixtures/lib/persistence/commands/create_user.rb +0 -6
  112. data/spec/fixtures/lib/persistence/mappers/user_list.rb +0 -6
  113. data/spec/fixtures/lib/persistence/my_commands/create_user.rb +0 -6
  114. data/spec/fixtures/lib/persistence/my_mappers/user_list.rb +0 -6
  115. data/spec/fixtures/lib/persistence/my_relations/users.rb +0 -6
  116. data/spec/fixtures/lib/persistence/relations/users.rb +0 -6
  117. data/spec/integration/command_registry_spec.rb +0 -60
  118. data/spec/integration/commands/create_spec.rb +0 -177
  119. data/spec/integration/commands/delete_spec.rb +0 -67
  120. data/spec/integration/commands/error_handling_spec.rb +0 -25
  121. data/spec/integration/commands/graph_builder_spec.rb +0 -213
  122. data/spec/integration/commands/graph_spec.rb +0 -288
  123. data/spec/integration/commands/update_spec.rb +0 -109
  124. data/spec/integration/commands_spec.rb +0 -67
  125. data/spec/integration/mappers/combine_spec.rb +0 -117
  126. data/spec/integration/mappers/deep_embedded_spec.rb +0 -44
  127. data/spec/integration/mappers/definition_dsl_spec.rb +0 -206
  128. data/spec/integration/mappers/embedded_spec.rb +0 -62
  129. data/spec/integration/mappers/exclude_spec.rb +0 -27
  130. data/spec/integration/mappers/fold_spec.rb +0 -71
  131. data/spec/integration/mappers/group_spec.rb +0 -163
  132. data/spec/integration/mappers/overwrite_attributes_value_spec.rb +0 -51
  133. data/spec/integration/mappers/prefix_separator_spec.rb +0 -52
  134. data/spec/integration/mappers/prefix_spec.rb +0 -48
  135. data/spec/integration/mappers/prefixing_attributes_spec.rb +0 -37
  136. data/spec/integration/mappers/registering_custom_mappers_spec.rb +0 -28
  137. data/spec/integration/mappers/renaming_attributes_spec.rb +0 -125
  138. data/spec/integration/mappers/reusing_mappers_spec.rb +0 -43
  139. data/spec/integration/mappers/step_spec.rb +0 -119
  140. data/spec/integration/mappers/symbolizing_attributes_spec.rb +0 -77
  141. data/spec/integration/mappers/unfold_spec.rb +0 -92
  142. data/spec/integration/mappers/ungroup_spec.rb +0 -126
  143. data/spec/integration/mappers/unwrap_spec.rb +0 -93
  144. data/spec/integration/mappers/wrap_spec.rb +0 -155
  145. data/spec/integration/memory/commands/create_spec.rb +0 -23
  146. data/spec/integration/memory/commands/delete_spec.rb +0 -23
  147. data/spec/integration/memory/commands/update_spec.rb +0 -23
  148. data/spec/integration/multi_env_spec.rb +0 -69
  149. data/spec/integration/multi_repo_spec.rb +0 -46
  150. data/spec/integration/relations/default_dataset_spec.rb +0 -38
  151. data/spec/integration/relations/inheritance_spec.rb +0 -37
  152. data/spec/integration/relations/reading_spec.rb +0 -169
  153. data/spec/integration/relations/registry_dsl_spec.rb +0 -45
  154. data/spec/integration/repositories/extending_relations_spec.rb +0 -58
  155. data/spec/integration/repositories/setting_logger_spec.rb +0 -34
  156. data/spec/integration/setup_spec.rb +0 -160
  157. data/spec/shared/command_behavior.rb +0 -28
  158. data/spec/shared/command_graph.rb +0 -50
  159. data/spec/shared/container.rb +0 -9
  160. data/spec/shared/enumerable_dataset.rb +0 -52
  161. data/spec/shared/gateway_only.rb +0 -6
  162. data/spec/shared/materializable.rb +0 -36
  163. data/spec/shared/no_container.rb +0 -16
  164. data/spec/shared/one_behavior.rb +0 -26
  165. data/spec/shared/proxy.rb +0 -0
  166. data/spec/shared/users_and_tasks.rb +0 -10
  167. data/spec/spec_helper.rb +0 -52
  168. data/spec/support/constant_leak_finder.rb +0 -14
  169. data/spec/support/mutant.rb +0 -10
  170. data/spec/support/types.rb +0 -5
  171. data/spec/test/memory_repository_lint_test.rb +0 -27
  172. data/spec/unit/rom/association_set_spec.rb +0 -23
  173. data/spec/unit/rom/commands/graph_spec.rb +0 -191
  174. data/spec/unit/rom/commands/lazy_spec.rb +0 -307
  175. data/spec/unit/rom/commands/result_spec.rb +0 -70
  176. data/spec/unit/rom/commands_spec.rb +0 -165
  177. data/spec/unit/rom/configurable_spec.rb +0 -49
  178. data/spec/unit/rom/configuration_spec.rb +0 -61
  179. data/spec/unit/rom/container_spec.rb +0 -99
  180. data/spec/unit/rom/create_container_spec.rb +0 -151
  181. data/spec/unit/rom/environment_spec.rb +0 -123
  182. data/spec/unit/rom/gateway_spec.rb +0 -146
  183. data/spec/unit/rom/mapper_registry_spec.rb +0 -25
  184. data/spec/unit/rom/memory/commands_spec.rb +0 -43
  185. data/spec/unit/rom/memory/dataset_spec.rb +0 -31
  186. data/spec/unit/rom/memory/relation_spec.rb +0 -109
  187. data/spec/unit/rom/memory/repository_spec.rb +0 -12
  188. data/spec/unit/rom/memory/storage_spec.rb +0 -45
  189. data/spec/unit/rom/plugin_spec.rb +0 -150
  190. data/spec/unit/rom/plugins/command/schema_spec.rb +0 -66
  191. data/spec/unit/rom/plugins/relation/key_inference_spec.rb +0 -85
  192. data/spec/unit/rom/plugins/relation/view_spec.rb +0 -51
  193. data/spec/unit/rom/relation/composite_spec.rb +0 -89
  194. data/spec/unit/rom/relation/curried_spec.rb +0 -52
  195. data/spec/unit/rom/relation/graph_spec.rb +0 -92
  196. data/spec/unit/rom/relation/lazy/combine_spec.rb +0 -165
  197. data/spec/unit/rom/relation/lazy_spec.rb +0 -214
  198. data/spec/unit/rom/relation/loaded_spec.rb +0 -53
  199. data/spec/unit/rom/relation/name_spec.rb +0 -58
  200. data/spec/unit/rom/relation/schema_spec.rb +0 -117
  201. data/spec/unit/rom/relation_spec.rb +0 -237
  202. data/spec/unit/rom/schema_spec.rb +0 -10
  203. data/spec/unit/rom/setup/auto_registration_spec.rb +0 -152
@@ -1,165 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Commands' do
4
- include_context 'gateway only'
5
- include_context 'users and tasks'
6
-
7
- let(:users_relation) do
8
- Class.new(ROM::Memory::Relation) do
9
- def by_id(id)
10
- restrict(id: id)
11
- end
12
- end.new(users_dataset)
13
- end
14
-
15
- describe '.build_class' do
16
- it 'creates a command class constant' do
17
- klass = ROM::ConfigurationDSL::Command.build_class(:create, :users, adapter: :memory) {
18
- def super?
19
- true
20
- end
21
- }
22
-
23
- expect(klass.name).to eql('ROM::Memory::Commands::Create[Users]')
24
- expect(klass.register_as).to eql(:create)
25
-
26
- command = klass.build(users_relation)
27
-
28
- expect(command).to be_a(ROM::Memory::Commands::Create)
29
- expect(command).to be_super
30
- end
31
- end
32
-
33
- describe '.create_class' do
34
- it 'builds a class' do
35
- klass = ROM::Command.create_class(:create, ROM::Memory::Commands::Create)
36
-
37
- expect(klass.name).to eql('ROM::Memory::Commands::Create[:create]')
38
- end
39
-
40
- it 'builds a class and yields it' do
41
- klass = ROM::Command.create_class(:create, ROM::Memory::Commands::Create) do |k|
42
- k.result :one
43
- k
44
- end
45
-
46
- expect(klass.name).to eql('ROM::Memory::Commands::Create[:create]')
47
- expect(klass.result).to be(:one)
48
- end
49
- end
50
-
51
- describe '.build' do
52
- it 'returns create command when type is set to :create' do
53
- klass = Class.new(ROM::Commands::Create[:memory]) do
54
- relation :users
55
- end
56
-
57
- command = klass.build(users_relation)
58
-
59
- expect(command).to be_kind_of(ROM::Memory::Commands::Create)
60
- end
61
-
62
- it 'returns update command when type is set to :update' do
63
- klass = Class.new(ROM::Commands::Update[:memory]) do
64
- relation :users
65
- end
66
-
67
- command = klass.build(users_relation)
68
-
69
- expect(command).to be_kind_of(ROM::Memory::Commands::Update)
70
- end
71
-
72
- it 'returns delete command when type is set to :delete' do
73
- klass = Class.new(ROM::Commands::Delete[:memory]) do
74
- relation :users
75
- end
76
-
77
- command = klass.build(users_relation)
78
-
79
- expect(command).to be_kind_of(ROM::Memory::Commands::Delete)
80
- end
81
- end
82
-
83
- describe '#>>' do
84
- let(:users) { double('users', schema: nil) }
85
- let(:tasks) { double('tasks', schema: nil) }
86
- let(:logs) { double('logs', schema: nil) }
87
-
88
- it 'composes two commands' do
89
- user_input = { name: 'Jane' }
90
- user_tuple = { user_id: 1, name: 'Jane' }
91
-
92
- task_input = { title: 'Task One' }
93
- task_tuple = { user_id: 1, title: 'Task One' }
94
-
95
- create_user = Class.new(ROM::Commands::Create) {
96
- def execute(user_input)
97
- relation.insert(user_input)
98
- end
99
- }.build(users)
100
-
101
- create_task = Class.new(ROM::Commands::Create) {
102
- def execute(task_input, user_tuple)
103
- relation.insert(task_input.merge(user_id: user_tuple[:user_id]))
104
- end
105
- }.build(tasks)
106
-
107
- create_log = Class.new(ROM::Commands::Create) {
108
- result :one
109
-
110
- def execute(task_tuple)
111
- relation << task_tuple
112
- end
113
- }.build(logs)
114
-
115
- command = create_user.curry(user_input)
116
- command >>= create_task.curry(task_input)
117
- command >>= create_log
118
-
119
- expect(users).to receive(:insert).with(user_input).and_return(user_tuple)
120
- expect(tasks).to receive(:insert).with(task_tuple).and_return(task_tuple)
121
- expect(logs).to receive(:<<).with(task_tuple).and_return([task_tuple])
122
-
123
- expect(command.call).to eql(task_tuple)
124
- end
125
-
126
- it 'forwards methods to the left' do
127
- user_input = { name: 'Jane' }
128
- user_tuple = { user_id: 1, name: 'Jane' }
129
-
130
- create_user = Class.new(ROM::Commands::Create) {
131
- def execute(user_input)
132
- relation.insert(user_input)
133
- end
134
- }.build(users)
135
-
136
- command = create_user >> proc {}
137
-
138
- expect(users).to receive(:insert).with(user_input).and_return(user_tuple)
139
-
140
- command.with(user_input).call
141
- end
142
-
143
- it 'short-circuits pipeline when left-side result is empty' do
144
- command = Class.new(ROM::Commands::Update) do
145
- result :one
146
-
147
- def execute(*)
148
- []
149
- end
150
- end.build(users) >> -> result { result.map(&:to_a) }
151
-
152
- expect(command.call('foo')).to be(nil)
153
-
154
- command = Class.new(ROM::Commands::Update) do
155
- result :many
156
-
157
- def execute(*)
158
- []
159
- end
160
- end.build(users) >> -> result { result.map(&:to_a) }
161
-
162
- expect(command.call('foo')).to be(ROM::EMPTY_ARRAY)
163
- end
164
- end
165
- end
@@ -1,49 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe ROM::Configurable do
4
- let (:klass) { Class.new { include ROM::Configurable } }
5
- let (:object) { klass.new }
6
- let (:config) { object.config }
7
-
8
- it 'exposes the config property' do
9
- expect { config }.not_to raise_error
10
- end
11
-
12
- it 'is configurable via block' do
13
- object.configure do |config|
14
- config.sql.infer_relations = false
15
- end
16
-
17
- expect(config.sql.infer_relations).to be(false)
18
- end
19
-
20
- context ROM::Configurable::Config do
21
- it 'can be traversed via dot syntax' do
22
- config.sql.infer_relations = false
23
- expect(config.sql.infer_relations).to be(false)
24
- end
25
-
26
- it 'can be traversed via bracket syntax' do
27
- config[:sql].infer_relations = false
28
-
29
- expect(config[:sql][:infer_relations]).to be(false)
30
- expect(config).to respond_to(:sql)
31
- expect(config.sql.infer_relations).to be(false)
32
- end
33
-
34
- it 'freezes properly' do
35
- config.freeze
36
-
37
- expect { config.sql.infer_relations = false }.to raise_error(NoMethodError)
38
- end
39
-
40
- it 'handles unset keys when frozen' do
41
- config.sql.infer_relations = false
42
- config.freeze
43
-
44
- expect(config.other).to be(nil)
45
- expect(config.key?(:other)).to be(false)
46
- expect(config.key?(:sql)).to be(true)
47
- end
48
- end
49
- end
@@ -1,61 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ROM::Configuration do
4
- it 'is configurable via settings hash' do
5
- configuration = ROM::Configuration.new(:memory, 'something', infer_schema: false)
6
-
7
- expect(configuration.config.gateways.default.infer_schema).to be(false)
8
-
9
- configuration = ROM::Configuration.new(:memory, infer_schema: false)
10
-
11
- expect(configuration.config.gateways.default.infer_schema).to be(false)
12
-
13
- configuration = ROM::Configuration.new(default: [:memory, infer_schema: false])
14
-
15
- expect(configuration.config.gateways.default.infer_schema).to be(false)
16
- end
17
-
18
- describe '#method_missing' do
19
- it 'returns a gateway if it is defined' do
20
- repo = double('repo')
21
- configuration = ROM::Configuration.new(repo: repo)
22
-
23
- expect(configuration.repo).to be(repo)
24
- end
25
-
26
- it 'raises error if repo is not defined' do
27
- configuration = ROM::Configuration.new
28
-
29
- expect { configuration.not_here }.to raise_error(NoMethodError, /not_here/)
30
- end
31
- end
32
-
33
- describe '#[]' do
34
- it 'returns a gateway if it is defined' do
35
- repo = double('repo')
36
- configuration = ROM::Configuration.new(repo: repo)
37
-
38
- expect(configuration[:repo]).to be(repo)
39
- end
40
-
41
- it 'raises error if repo is not defined' do
42
- configuration = ROM::Configuration.new({})
43
-
44
- expect { configuration[:not_here] }.to raise_error(KeyError, /not_here/)
45
- end
46
- end
47
-
48
- describe 'defining components when adapter was not registered' do
49
- it 'raises error when trying to define a relation' do
50
- expect {
51
- Class.new(ROM::Relation[:not_here])
52
- }.to raise_error(ROM::AdapterNotPresentError, /not_here/)
53
- end
54
-
55
- it 'raises error when trying to define a command' do
56
- expect {
57
- Class.new(ROM::Commands::Create[:not_here])
58
- }.to raise_error(ROM::AdapterNotPresentError, /not_here/)
59
- end
60
- end
61
- end
@@ -1,99 +0,0 @@
1
- require 'spec_helper'
2
-
3
- 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
- register_as :users
12
- dataset :users
13
- def by_name(name)
14
- restrict(name: name).project(:name)
15
- end
16
- end
17
-
18
- tasks = Class.new(ROM::Relation[:memory]) do
19
- register_as :tasks
20
- dataset :tasks
21
- end
22
-
23
- create_user = Class.new(ROM::Commands::Create[:memory]) do
24
- relation :users
25
- register_as :create
26
- end
27
-
28
- create_task = Class.new(ROM::Commands::Create[:memory]) do
29
- relation :tasks
30
- register_as :create
31
- end
32
-
33
- users_mapper = Class.new(ROM::Mapper) do
34
- register_as :users
35
- relation :users
36
- attribute :name
37
- attribute :email
38
- end
39
-
40
- name_list = Class.new(users_mapper) do
41
- register_as :name_list
42
- attribute :name
43
- exclude :email
44
- end
45
-
46
- configuration.register_relation(users, tasks)
47
- configuration.register_command(create_user, create_task)
48
- configuration.register_mapper(users_mapper, name_list)
49
- end
50
-
51
- describe '#command' do
52
- it 'returns registered command registry' do
53
- expect(container.command(:users)).to be_instance_of(ROM::CommandRegistry)
54
- end
55
-
56
- it 'returns registered command' do
57
- expect(container.command(:users).create).to be_kind_of(ROM::Commands::Create)
58
- end
59
-
60
- it 'accepts an array with graph options and input' do
61
- expect(container.command([:users, [:create]])).to be_kind_of(ROM::Commands::Lazy)
62
- end
63
-
64
- it 'raises ArgumentError when unsupported arg was passed' do
65
- expect { container.command(oops: 'sorry') }.to raise_error(ArgumentError)
66
- end
67
- end
68
-
69
- describe '#relation' do
70
- it 'yields selected relation to the block and returns a loaded relation' do
71
- result = container.relation(:users) { |r| r.by_name('Jane') }.as(:name_list)
72
-
73
- expect(result.call).to match_array([{ name: 'Jane' }])
74
- end
75
-
76
- it 'returns lazy-mapped relation' do
77
- by_name = container.relation(:users).as(:name_list).by_name
78
-
79
- expect(by_name['Jane']).to match_array([{ name: 'Jane' }])
80
- end
81
-
82
- it 'returns relation without mappers when mappers are not defined' do
83
- expect(container.relation(:tasks)).to be_kind_of(ROM::Relation)
84
- expect(container.relation(:tasks).mappers.elements).to be_empty
85
- end
86
- end
87
-
88
- describe '#mappers' do
89
- it 'returns mappers for all relations' do
90
- expect(container.mappers.users[:name_list]).to_not be(nil)
91
- end
92
- end
93
-
94
- describe '#disconnect' do
95
- it 'does not break' do
96
- container.disconnect
97
- end
98
- end
99
- end
@@ -1,151 +0,0 @@
1
- require 'spec_helper'
2
-
3
- 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,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