rom 2.0.2 → 4.2.1

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 +35 -430
  3. data/LICENSE +1 -1
  4. data/README.md +83 -11
  5. data/lib/rom/version.rb +1 -1
  6. data/lib/rom.rb +3 -46
  7. metadata +30 -236
  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,191 +0,0 @@
1
- require 'spec_helper'
2
- require 'dry-struct'
3
-
4
- describe ROM::Commands::Graph do
5
- shared_examples_for 'a persisted graph' do
6
- it 'returns nested results' do
7
- expect(command.call).to match_array([
8
- # parent users
9
- [
10
- { name: 'Jane' }
11
- ],
12
- [
13
- [
14
- # user tasks
15
- [
16
- { title: 'One', user: 'Jane' }
17
- ],
18
- [
19
- # task tags
20
- [
21
- { name: 'red', task: 'One' },
22
- { name: 'green', task: 'One' },
23
- { name: 'blue', task: 'One' }
24
- ]
25
- ]
26
- ]
27
- ]
28
- ])
29
- end
30
-
31
- context 'persisted relations' do
32
- before { command.call }
33
-
34
- it 'inserts root' do
35
- expect(container.relation(:users)).to match_array([{ name: 'Jane' }])
36
- end
37
-
38
- it 'inserts root nodes' do
39
- expect(container.relation(:tasks)).to match_array([{ user: 'Jane', title: 'One' }])
40
- end
41
-
42
- it 'inserts nested graph nodes' do
43
- expect(container.relation(:tags)).to match_array([
44
- { name: 'red', task: 'One' },
45
- { name: 'green', task: 'One' },
46
- { name: 'blue', task: 'One' }
47
- ])
48
- end
49
- end
50
- end
51
-
52
- include_context 'container'
53
-
54
- let(:create_user) { container.command(:users).create }
55
- let(:create_task) { container.command(:tasks).create }
56
-
57
- let(:create_many_tasks) { container.command(:tasks).create_many }
58
- let(:create_many_tags) { container.command(:tags).create_many }
59
-
60
- let(:user) { { name: 'Jane' } }
61
- let(:task) { { title: 'One' } }
62
- let(:tags) { [{ name: 'red' }, { name: 'green' }, { name: 'blue' }] }
63
-
64
- before do
65
- configuration.relation(:users)
66
- configuration.relation(:tasks)
67
- configuration.relation(:tags)
68
-
69
- configuration.commands(:users) do
70
- define(:create) do
71
- result :one
72
- end
73
- end
74
-
75
- configuration.commands(:tasks) do
76
- define(:create) do
77
- result :one
78
-
79
- def execute(task, user)
80
- super(task.merge(user: user[:name]))
81
- end
82
- end
83
-
84
- define(:create) do
85
- register_as :create_many
86
-
87
- def execute(tasks, user)
88
- super(tasks.map { |t| t.merge(user: user[:name]) })
89
- end
90
- end
91
- end
92
-
93
- configuration.commands(:tags) do
94
- define(:create) do
95
- register_as :create_many
96
-
97
- def execute(tags, tasks)
98
- super(
99
- Array([tasks]).flatten.map { |task|
100
- tags.map { |tag| tag.merge(task: task[:title]) }
101
- }.flatten
102
- )
103
- end
104
- end
105
- end
106
- end
107
-
108
- describe '#call' do
109
- context 'when result is :one in root and its direct children' do
110
- it_behaves_like 'a persisted graph' do
111
- subject(:command) do
112
- create_user.with(user)
113
- .combine(create_task.with(task)
114
- .combine(create_many_tags.with(tags)))
115
- end
116
- end
117
- end
118
-
119
- context 'when result is :many for root direct children' do
120
- it_behaves_like 'a persisted graph' do
121
- subject(:command) do
122
- create_user.with(user)
123
- .combine(create_many_tasks.with([task])
124
- .combine(create_many_tags.with(tags)))
125
- end
126
- end
127
- end
128
- end
129
-
130
- describe 'pipeline' do
131
- subject(:command) do
132
- container.command(:users).as(:entity).create.with(user)
133
- .combine(create_task.with(task)
134
- .combine(create_many_tags.with(tags)))
135
- end
136
-
137
- before do
138
- Test::Tag = Class.new(Dry::Struct) {
139
- attribute :name, Types::String
140
- }
141
-
142
- Test::Task = Class.new(Dry::Struct) {
143
- attribute :title, Types::String
144
- attribute :tags, Types::Array.member(Test::Tag)
145
- }
146
-
147
- Test::User = Class.new(Dry::Struct) {
148
- attribute :name, Types::String
149
- attribute :task, Test::Task
150
- }
151
-
152
- class Test::UserMapper < ROM::Mapper
153
- relation :users
154
- register_as :entity
155
- reject_keys :true
156
-
157
- model Test::User
158
-
159
- attribute :name
160
-
161
- combine :task, on: { name: :user }, type: :hash do
162
- model Test::Task
163
-
164
- attribute :title
165
-
166
- combine :tags, on: { title: :task } do
167
- model Test::Tag
168
- attribute :name
169
- end
170
- end
171
- end
172
- configuration.register_mapper(Test::UserMapper)
173
- end
174
-
175
- it 'sends data through the pipeline' do
176
- expect(command.call).to eql(
177
- Test::User.new(
178
- name: 'Jane',
179
- task: Test::Task.new(
180
- title: 'One',
181
- tags: [
182
- Test::Tag.new(name: 'red'),
183
- Test::Tag.new(name: 'green'),
184
- Test::Tag.new(name: 'blue')
185
- ]
186
- )
187
- )
188
- )
189
- end
190
- end
191
- end
@@ -1,307 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ROM::Commands::Lazy do
4
- include_context 'container'
5
-
6
- let(:create_user) { container.command(:users).create }
7
- let(:update_user) { container.command(:users).update }
8
- let(:delete_user) { container.command(:users).delete }
9
-
10
- let(:create_task) { container.command(:tasks).create }
11
- let(:create_tasks) { container.command(:tasks).create_many }
12
- let(:update_task) { container.command(:tasks).update }
13
-
14
- let(:input) { { user: { name: 'Jane', email: 'jane@doe.org' } } }
15
- let(:jane) { input[:user] }
16
- let(:evaluator) { -> input { input[:user] } }
17
-
18
- before do
19
- configuration.relation(:tasks) do
20
- def by_user_and_title(user, title)
21
- by_user(user).by_title(title)
22
- end
23
-
24
- def by_user(user)
25
- restrict(user: user)
26
- end
27
-
28
- def by_title(title)
29
- restrict(title: title)
30
- end
31
- end
32
-
33
- configuration.relation(:users) do
34
- def by_name(name)
35
- restrict(name: name)
36
- end
37
- end
38
-
39
- configuration.commands(:users) do
40
- define(:create) do
41
- result :one
42
- end
43
-
44
- define(:update) do
45
- result :one
46
- end
47
-
48
- define(:delete) do
49
- result :one
50
- end
51
- end
52
-
53
- configuration.commands(:tasks) do
54
- define(:create) do
55
- result :one
56
- end
57
-
58
- define(:create_many, type: :create) do
59
- def execute(tuples, user)
60
- super(tuples.map { |tuple| tuple.merge(user: user[:name]) })
61
- end
62
- end
63
-
64
- define(:update) do
65
- result :one
66
-
67
- def execute(tuple, user)
68
- super(tuple.merge(user: user[:name]))
69
- end
70
- end
71
- end
72
- end
73
-
74
- describe '#call' do
75
- context 'with a create command' do
76
- subject(:command) { ROM::Commands::Lazy[create_user].new(create_user, evaluator) }
77
-
78
- it 'evaluates the input and calls command' do
79
- command.call(input)
80
-
81
- expect(container.relation(:users)).to match_array([jane])
82
- end
83
- end
84
-
85
- context 'with a create command for many child tuples' do
86
- subject(:command) do
87
- ROM::Commands::Lazy[create_tasks].new(create_tasks, evaluator)
88
- end
89
-
90
- let(:evaluator) { -> input, index { input[:users][index][:tasks] } }
91
-
92
- let(:input) do
93
- { users: [
94
- {
95
- name: 'Jane',
96
- tasks: [{ title: 'Jane Task One' }, { title: 'Jane Task Two' }]
97
- },
98
- {
99
- name: 'Joe',
100
- tasks: [{ title: 'Joe Task One' }]
101
- }
102
- ]}
103
- end
104
-
105
- it 'evaluates the input and calls command' do
106
- command.call(input, input[:users])
107
-
108
- expect(container.relation(:tasks)).to match_array([
109
- { user: 'Jane', title: 'Jane Task One' },
110
- { user: 'Jane', title: 'Jane Task Two' },
111
- { user: 'Joe', title: 'Joe Task One' }
112
- ])
113
- end
114
- end
115
-
116
- context 'with an update command' do
117
- subject(:command) do
118
- ROM::Commands::Lazy[update_user].new(
119
- update_user, evaluator, -> cmd, user { cmd.by_name(user[:name]) })
120
- end
121
-
122
- before do
123
- create_user[jane]
124
- end
125
-
126
- it 'evaluates the input, restricts the relation and calls its command' do
127
- input = { user: { name: 'Jane', email: 'jane.doe@rom-rb.org' } }
128
- command.call(input)
129
-
130
- expect(container.relation(:users)).to match_array([input[:user]])
131
- end
132
- end
133
-
134
- context 'with an update command for a child tuple' do
135
- subject(:command) do
136
- ROM::Commands::Lazy[update_task].new(
137
- update_task,
138
- evaluator,
139
- -> cmd, user, task { cmd.by_user(user[:name]).by_title(task[:title]) }
140
- )
141
- end
142
-
143
- let(:evaluator) { -> input { input[:user][:task] } }
144
-
145
- let(:jane) { { name: 'Jane' } }
146
- let(:jane_task) { { user: 'Jane', title: 'Jane Task', priority: 1 } }
147
-
148
- let(:input) { { user: jane.merge(task: jane_task) } }
149
-
150
- before do
151
- create_user[jane]
152
- create_task[user: 'Jane', title: 'Jane Task', priority: 2]
153
- end
154
-
155
- it 'evaluates the input, restricts the relation and calls its command' do
156
- command.call(input, input[:user])
157
-
158
- expect(container.relation(:users)).to match_array([jane])
159
-
160
- expect(container.relation(:tasks)).to match_array([jane_task])
161
- end
162
- end
163
-
164
- context 'with an update command for child tuples' do
165
- subject(:command) do
166
- ROM::Commands::Lazy[update_task].new(
167
- update_task,
168
- evaluator,
169
- -> cmd, user, task { cmd.by_user(user[:name]).by_title(task[:title]) }
170
- )
171
- end
172
-
173
- let(:evaluator) { -> input { input[:user][:tasks] } }
174
-
175
- let(:jane) { { name: 'Jane' } }
176
- let(:jane_tasks) {
177
- [
178
- { user: 'Jane', title: 'Jane Task One', priority: 2 },
179
- { user: 'Jane', title: 'Jane Task Two', priority: 3 }
180
- ]
181
- }
182
-
183
- let(:input) { { user: jane.merge(tasks: jane_tasks) } }
184
-
185
- before do
186
- create_user[jane]
187
- create_task[user: 'Jane', title: 'Jane Task One', priority: 3]
188
- create_task[user: 'Jane', title: 'Jane Task Two', priority: 4]
189
- end
190
-
191
- it 'evaluates the input, restricts the relation and calls its command' do
192
- command.call(input, input[:user])
193
-
194
- expect(container.relation(:users)).to match_array([jane])
195
-
196
- expect(container.relation(:tasks)).to match_array(jane_tasks)
197
- end
198
- end
199
-
200
- context 'with an update command for many parents and their children' do
201
- subject(:command) do
202
- ROM::Commands::Lazy[update_task].new(
203
- update_task,
204
- evaluator,
205
- -> cmd, user, task { cmd.by_user(user[:name]).by_title(task[:title]) }
206
- )
207
- end
208
-
209
- let(:evaluator) { -> input, index { input[:users][index][:tasks] } }
210
-
211
- let(:input) do
212
- { users: [
213
- {
214
- name: 'Jane',
215
- tasks: [
216
- { title: 'Jane Task One', priority: 1 },
217
- { title: 'Jane Task Two', priority: 2 }
218
- ]
219
- },
220
- {
221
- name: 'Joe',
222
- tasks: [{ title: 'Joe Task One', priority: 1 }]
223
- }
224
- ]}
225
- end
226
-
227
- before do
228
- create_user[name: 'Jane']
229
- create_user[name: 'Joe']
230
-
231
- create_task[user: 'Jane', title: 'Jane Task One']
232
- create_task[user: 'Jane', title: 'Jane Task Two']
233
- create_task[user: 'Joe', title: 'Joe Task One']
234
- end
235
-
236
- it 'evaluates the input and calls its command' do
237
- command.call(input, input[:users])
238
-
239
- expect(container.relation(:tasks)).to match_array([
240
- { user: 'Jane', title: 'Jane Task One', priority: 1 },
241
- { user: 'Jane', title: 'Jane Task Two', priority: 2 },
242
- { user: 'Joe', title: 'Joe Task One', priority: 1 }
243
- ])
244
- end
245
- end
246
-
247
- context 'with a delete command' do
248
- subject(:command) do
249
- ROM::Commands::Lazy[delete_user].new(
250
- delete_user,
251
- evaluator,
252
- -> cmd, user { cmd.by_name(user[:name]) }
253
- )
254
- end
255
-
256
- let(:joe) { { name: 'Joe' } }
257
-
258
- before do
259
- create_user[jane]
260
- create_user[joe]
261
- end
262
-
263
- it 'restricts the relation and calls its command' do
264
- command.call(input)
265
-
266
- expect(container.relation(:users)).to match_array([joe])
267
- end
268
- end
269
- end
270
-
271
- describe '#>>' do
272
- subject(:command) { ROM::Commands::Lazy[create_user].new(create_user, evaluator) }
273
-
274
- it 'composes with another command' do
275
- expect(command >> create_task).to be_instance_of(ROM::Commands::Composite)
276
- end
277
- end
278
-
279
- describe '#combine' do
280
- subject(:command) { ROM::Commands::Lazy[create_user].new(create_user, evaluator) }
281
-
282
- it 'combines with another command' do
283
- expect(command.combine(create_task)).to be_instance_of(ROM::Commands::Graph)
284
- end
285
- end
286
-
287
- describe '#unwrap' do
288
- subject(:command) { ROM::Commands::Lazy[create_user].new(create_user, evaluator) }
289
-
290
- it 'returns wrapped command' do
291
- expect(command.unwrap).to be(create_user)
292
- end
293
- end
294
-
295
- describe '#method_missing' do
296
- subject(:command) { ROM::Commands::Lazy[update_user].new(update_user, evaluator) }
297
-
298
- it 'returns original response if it was not a command' do
299
- response = command.result
300
- expect(response).to be(:one)
301
- end
302
-
303
- it 'raises error when message is unknown' do
304
- expect { command.not_here }.to raise_error(NoMethodError, /not_here/)
305
- end
306
- end
307
- end
@@ -1,70 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ROM::Commands::Result do
4
- describe '#value' do
5
- subject(:result) { ROM::Commands::Result::Success }
6
-
7
- it 'bubble up nested values' do
8
- data = double(to_ary: ['foo'])
9
- r = result.new(result.new(result.new(data)))
10
-
11
- expect(r.value).to eq(data)
12
- end
13
- end
14
-
15
- describe '#success?' do
16
- context 'not launched command' do
17
- subject(:command) { ROM::Commands::Result }
18
-
19
- it 'returns false' do
20
- expect(command.new.success?).to eq(false)
21
- end
22
- end
23
-
24
- context 'successful command' do
25
- subject(:result) { ROM::Commands::Result::Success }
26
-
27
- it 'returns true' do
28
- data = double(to_ary: ['foo'])
29
- expect(result.new(data).success?).to eq(true)
30
- end
31
- end
32
-
33
- context 'failed command' do
34
- subject(:result) { ROM::Commands::Result::Failure }
35
-
36
- it 'returns false' do
37
- error = double(:error)
38
- expect(result.new(error).success?).to eq(false)
39
- end
40
- end
41
- end
42
-
43
- describe '#failure?' do
44
- context 'not launched command' do
45
- subject(:command) { ROM::Commands::Result }
46
-
47
- it 'returns false' do
48
- expect(command.new.success?).to eq(false)
49
- end
50
- end
51
-
52
- context 'successful command' do
53
- subject(:result) { ROM::Commands::Result::Success }
54
-
55
- it 'returns false' do
56
- data = double(to_ary: ['foo'])
57
- expect(result.new(data).failure?).to eq(false)
58
- end
59
- end
60
-
61
- context 'failed command' do
62
- subject(:result) { ROM::Commands::Result::Failure }
63
-
64
- it 'returns true' do
65
- error = double(:error)
66
- expect(result.new(error).failure?).to eq(true)
67
- end
68
- end
69
- end
70
- end