rom 2.0.2 → 3.0.0

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 (156) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -7
  3. data/.yardopts +2 -0
  4. data/CHANGELOG.md +35 -1
  5. data/Gemfile +17 -2
  6. data/Rakefile +7 -2
  7. data/lib/rom/array_dataset.rb +44 -0
  8. data/lib/rom/association_set.rb +11 -5
  9. data/lib/rom/auto_curry.rb +55 -0
  10. data/lib/rom/command.rb +331 -47
  11. data/lib/rom/command_registry.rb +7 -18
  12. data/lib/rom/commands/class_interface.rb +120 -6
  13. data/lib/rom/commands/composite.rb +0 -1
  14. data/lib/rom/commands/graph.rb +7 -15
  15. data/lib/rom/commands/lazy/update.rb +1 -1
  16. data/lib/rom/configuration.rb +2 -0
  17. data/lib/rom/configuration_dsl/command.rb +6 -8
  18. data/lib/rom/configuration_dsl/mapper.rb +2 -3
  19. data/lib/rom/configuration_dsl/mapper_dsl.rb +0 -1
  20. data/lib/rom/configuration_dsl/relation.rb +4 -4
  21. data/lib/rom/configuration_dsl.rb +0 -4
  22. data/lib/rom/constants.rb +7 -1
  23. data/lib/rom/container.rb +11 -17
  24. data/lib/rom/create_container.rb +0 -2
  25. data/lib/rom/data_proxy.rb +94 -0
  26. data/lib/rom/enumerable_dataset.rb +68 -0
  27. data/lib/rom/gateway.rb +74 -32
  28. data/lib/rom/global/plugin_dsl.rb +0 -2
  29. data/lib/rom/global.rb +0 -2
  30. data/lib/rom/initializer.rb +26 -0
  31. data/lib/rom/lint/gateway.rb +17 -0
  32. data/lib/rom/mapper_registry.rb +1 -1
  33. data/lib/rom/memory/commands.rb +0 -2
  34. data/lib/rom/memory/dataset.rb +1 -2
  35. data/lib/rom/memory/relation.rb +14 -1
  36. data/lib/rom/memory/schema.rb +13 -0
  37. data/lib/rom/plugin_registry.rb +1 -1
  38. data/lib/rom/plugins/command/schema.rb +2 -2
  39. data/lib/rom/plugins/configuration/configuration_dsl.rb +6 -2
  40. data/lib/rom/plugins/relation/key_inference.rb +4 -2
  41. data/lib/rom/plugins/relation/registry_reader.rb +5 -1
  42. data/lib/rom/registry.rb +50 -0
  43. data/lib/rom/relation/class_interface.rb +142 -30
  44. data/lib/rom/relation/curried.rb +15 -15
  45. data/lib/rom/relation/view_dsl.rb +31 -0
  46. data/lib/rom/relation.rb +101 -41
  47. data/lib/rom/schema/attribute.rb +367 -0
  48. data/lib/rom/schema/dsl.rb +14 -10
  49. data/lib/rom/schema.rb +337 -19
  50. data/lib/rom/setup/auto_registration.rb +20 -17
  51. data/lib/rom/setup/auto_registration_strategies/base.rb +8 -3
  52. data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +4 -3
  53. data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +5 -4
  54. data/lib/rom/setup/auto_registration_strategies/with_namespace.rb +3 -3
  55. data/lib/rom/setup/finalize/finalize_commands.rb +1 -1
  56. data/lib/rom/setup/finalize/finalize_mappers.rb +1 -1
  57. data/lib/rom/setup/finalize/finalize_relations.rb +4 -2
  58. data/lib/rom/setup/finalize.rb +1 -1
  59. data/lib/rom/transaction.rb +24 -0
  60. data/lib/rom/types.rb +9 -1
  61. data/lib/rom/version.rb +1 -1
  62. data/lib/rom.rb +4 -8
  63. data/rom.gemspec +5 -4
  64. data/spec/integration/command_registry_spec.rb +1 -14
  65. data/spec/integration/commands/create_spec.rb +5 -25
  66. data/spec/integration/commands/delete_spec.rb +1 -1
  67. data/spec/integration/commands/error_handling_spec.rb +1 -1
  68. data/spec/integration/commands/graph_spec.rb +20 -14
  69. data/spec/integration/commands/update_spec.rb +4 -27
  70. data/spec/integration/commands_spec.rb +1 -1
  71. data/spec/integration/{repositories → gateways}/extending_relations_spec.rb +1 -1
  72. data/spec/integration/{repositories → gateways}/setting_logger_spec.rb +2 -2
  73. data/spec/integration/mappers/combine_spec.rb +1 -1
  74. data/spec/integration/mappers/deep_embedded_spec.rb +1 -1
  75. data/spec/integration/mappers/definition_dsl_spec.rb +1 -1
  76. data/spec/integration/mappers/embedded_spec.rb +1 -1
  77. data/spec/integration/mappers/exclude_spec.rb +1 -1
  78. data/spec/integration/mappers/fold_spec.rb +1 -1
  79. data/spec/integration/mappers/group_spec.rb +1 -1
  80. data/spec/integration/mappers/overwrite_attributes_value_spec.rb +1 -1
  81. data/spec/integration/mappers/prefix_separator_spec.rb +1 -1
  82. data/spec/integration/mappers/prefix_spec.rb +1 -1
  83. data/spec/integration/mappers/prefixing_attributes_spec.rb +1 -1
  84. data/spec/integration/mappers/registering_custom_mappers_spec.rb +1 -1
  85. data/spec/integration/mappers/renaming_attributes_spec.rb +1 -1
  86. data/spec/integration/mappers/reusing_mappers_spec.rb +1 -1
  87. data/spec/integration/mappers/step_spec.rb +1 -1
  88. data/spec/integration/mappers/symbolizing_attributes_spec.rb +1 -1
  89. data/spec/integration/mappers/unfold_spec.rb +1 -1
  90. data/spec/integration/mappers/ungroup_spec.rb +2 -2
  91. data/spec/integration/mappers/unwrap_spec.rb +2 -2
  92. data/spec/integration/mappers/wrap_spec.rb +1 -1
  93. data/spec/integration/memory/commands/create_spec.rb +1 -1
  94. data/spec/integration/memory/commands/delete_spec.rb +1 -1
  95. data/spec/integration/memory/commands/update_spec.rb +1 -1
  96. data/spec/integration/multi_env_spec.rb +1 -1
  97. data/spec/integration/multi_repo_spec.rb +1 -1
  98. data/spec/integration/relations/default_dataset_spec.rb +1 -1
  99. data/spec/integration/relations/reading_spec.rb +1 -1
  100. data/spec/integration/relations/registry_dsl_spec.rb +1 -1
  101. data/spec/integration/setup_spec.rb +10 -4
  102. data/spec/shared/command_graph.rb +8 -4
  103. data/spec/shared/enumerable_dataset.rb +1 -1
  104. data/spec/spec_helper.rb +7 -9
  105. data/spec/support/schema.rb +14 -0
  106. data/spec/unit/rom/array_dataset_spec.rb +59 -0
  107. data/spec/unit/rom/association_set_spec.rb +4 -0
  108. data/spec/unit/rom/auto_curry_spec.rb +63 -0
  109. data/spec/unit/rom/commands/graph_spec.rb +12 -11
  110. data/spec/unit/rom/commands/lazy_spec.rb +8 -5
  111. data/spec/unit/rom/commands/pre_and_post_processors_spec.rb +336 -0
  112. data/spec/unit/rom/commands/result_spec.rb +1 -1
  113. data/spec/unit/rom/commands_spec.rb +26 -3
  114. data/spec/unit/rom/configuration_spec.rb +1 -1
  115. data/spec/unit/rom/container_spec.rb +15 -5
  116. data/spec/unit/rom/create_container_spec.rb +1 -1
  117. data/spec/unit/rom/enumerable_dataset_spec.rb +15 -0
  118. data/spec/unit/rom/gateway_spec.rb +1 -1
  119. data/spec/unit/rom/mapper_registry_spec.rb +1 -1
  120. data/spec/unit/rom/memory/commands_spec.rb +1 -1
  121. data/spec/unit/rom/memory/dataset_spec.rb +1 -1
  122. data/spec/unit/rom/memory/{repository_spec.rb → gateway_spec.rb} +1 -1
  123. data/spec/unit/rom/memory/inheritance_spec.rb +32 -0
  124. data/spec/unit/rom/memory/relation_spec.rb +15 -3
  125. data/spec/unit/rom/memory/storage_spec.rb +1 -1
  126. data/spec/unit/rom/plugin_spec.rb +1 -1
  127. data/spec/unit/rom/plugins/command/schema_spec.rb +5 -5
  128. data/spec/unit/rom/plugins/relation/key_inference_spec.rb +1 -1
  129. data/spec/unit/rom/registry_spec.rb +86 -0
  130. data/spec/unit/rom/relation/attribute_reader_spec.rb +17 -0
  131. data/spec/unit/rom/relation/call_spec.rb +51 -0
  132. data/spec/unit/rom/relation/composite_spec.rb +1 -1
  133. data/spec/unit/rom/relation/graph_spec.rb +1 -1
  134. data/spec/unit/rom/relation/lazy/combine_spec.rb +1 -1
  135. data/spec/unit/rom/relation/lazy_spec.rb +1 -1
  136. data/spec/unit/rom/relation/loaded_spec.rb +1 -1
  137. data/spec/unit/rom/relation/schema_spec.rb +50 -6
  138. data/spec/unit/rom/relation/view_spec.rb +122 -0
  139. data/spec/unit/rom/relation_spec.rb +20 -5
  140. data/spec/unit/rom/schema/accessing_attributes_spec.rb +52 -0
  141. data/spec/unit/rom/schema/append_spec.rb +17 -0
  142. data/spec/unit/rom/schema/exclude_spec.rb +15 -0
  143. data/spec/unit/rom/schema/finalize_spec.rb +59 -0
  144. data/spec/unit/rom/schema/key_predicate_spec.rb +15 -0
  145. data/spec/unit/rom/schema/merge_spec.rb +17 -0
  146. data/spec/unit/rom/schema/prefix_spec.rb +16 -0
  147. data/spec/unit/rom/schema/project_spec.rb +15 -0
  148. data/spec/unit/rom/schema/rename_spec.rb +22 -0
  149. data/spec/unit/rom/schema/type_spec.rb +49 -0
  150. data/spec/unit/rom/schema/uniq_spec.rb +21 -0
  151. data/spec/unit/rom/schema/wrap_spec.rb +17 -0
  152. data/spec/unit/rom/schema_spec.rb +2 -2
  153. metadata +79 -17
  154. data/lib/rom/plugins/relation/view/dsl.rb +0 -32
  155. data/lib/rom/plugins/relation/view.rb +0 -95
  156. data/spec/unit/rom/plugins/relation/view_spec.rb +0 -51
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'ROM::CommandRegistry' do
3
+ RSpec.describe 'ROM::CommandRegistry' do
4
4
  include_context 'container'
5
5
 
6
6
  let(:users) { container.command(:users) }
@@ -11,7 +11,6 @@ describe 'ROM::CommandRegistry' do
11
11
  configuration.register_command(Class.new(ROM::Commands::Create[:memory]) do
12
12
  register_as :create
13
13
  relation :users
14
- validator proc { |input| raise(ROM::CommandError) unless input[:name] }
15
14
  end)
16
15
  end
17
16
 
@@ -41,18 +40,6 @@ describe 'ROM::CommandRegistry' do
41
40
  expect(result).to match_array([{ name: 'Jane' }])
42
41
  end
43
42
 
44
- it 'returns a failure result object on failed execution' do
45
- result = users.try { users.create.call({}) }
46
-
47
- expect(result.value).to be(nil)
48
- end
49
-
50
- it 'returns a failure result on unsuccessful curried-command execution' do
51
- result = users.try { users.create.curry({}) }
52
-
53
- expect(result.value).to be(nil)
54
- end
55
-
56
43
  it 'allows checking if a command is available using respond_to?' do
57
44
  expect(users).to respond_to(:create)
58
45
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'dry-struct'
3
3
 
4
- describe 'Commands / Create' do
4
+ RSpec.describe 'Commands / Create' do
5
5
  include_context 'container'
6
6
  include_context 'users and tasks'
7
7
 
@@ -9,18 +9,6 @@ describe 'Commands / Create' do
9
9
  let(:tasks) { container.commands.tasks }
10
10
 
11
11
  before do
12
- module Test
13
- UserValidator = Class.new do
14
- ValidationError = Class.new(ROM::CommandError)
15
-
16
- def self.call(params)
17
- unless params[:name] && params[:email]
18
- raise ValidationError, ":name and :email are required"
19
- end
20
- end
21
- end
22
- end
23
-
24
12
  configuration.relation(:users)
25
13
  configuration.relation(:tasks)
26
14
 
@@ -28,16 +16,16 @@ describe 'Commands / Create' do
28
16
  relation :users
29
17
  register_as :create
30
18
  result :one
31
- validator Test::UserValidator
32
19
  end
33
20
 
34
21
  class Test::CreateTask < ROM::Commands::Create[:memory]
35
22
  relation :tasks
36
23
  register_as :create
37
24
  result :one
25
+ before :associate
38
26
 
39
- def execute(task, user)
40
- super(task.merge(name: user.to_h[:name]))
27
+ def associate(task, user)
28
+ task.merge(name: user.to_h[:name])
41
29
  end
42
30
  end
43
31
 
@@ -89,14 +77,6 @@ describe 'Commands / Create' do
89
77
  expect(result.value).to eql(name: 'Piotr', title: 'Finish command-api')
90
78
  end
91
79
 
92
- it 'returns validation object with errors on failed validation' do
93
- result = users.try { users.create.call(name: 'Piotr') }
94
-
95
- expect(result.error).to be_instance_of(Test::ValidationError)
96
- expect(result.error.message).to eql(":name and :email are required")
97
- expect(container.relations.users.count).to be(2)
98
- end
99
-
100
80
  describe '"result" option' do
101
81
  it 'returns a single tuple when set to :one' do
102
82
  configuration.commands(:users) do
@@ -122,7 +102,7 @@ describe 'Commands / Create' do
122
102
  end
123
103
  end
124
104
  container
125
- }.to raise_error(ROM::Options::InvalidOptionValueError)
105
+ }.to raise_error(Dry::Types::ConstraintError)
126
106
  end
127
107
  end
128
108
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Commands / Delete' do
3
+ RSpec.describe 'Commands / Delete' do
4
4
  include_context 'container'
5
5
  include_context 'users and tasks'
6
6
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Commands / Error handling' do
3
+ RSpec.describe 'Commands / Error handling' do
4
4
  include_context 'container'
5
5
  include_context 'users and tasks'
6
6
 
@@ -1,15 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Building up a command graph for nested input' do
3
+ RSpec.describe 'Building up a command graph for nested input' do
4
4
  include_context 'command graph'
5
5
 
6
6
  it 'creates a command graph for nested input :one result as root' do
7
7
  configuration.commands(:tasks) do
8
8
  define(:create) do
9
9
  result :one
10
+ before :associate
10
11
 
11
- def execute(tuple, user)
12
- super(tuple.merge(user: user.fetch(:name)))
12
+ def associate(tuple, user)
13
+ tuple.merge(user: user.fetch(:name))
13
14
  end
14
15
  end
15
16
  end
@@ -66,8 +67,10 @@ describe 'Building up a command graph for nested input' do
66
67
  it 'creates a command graph for nested input with :many results as root' do
67
68
  configuration.commands(:tasks) do
68
69
  define(:create) do
69
- def execute(tuples, user)
70
- super(tuples.map { |t| t.merge(user: user.fetch(:name)) })
70
+ before :associate
71
+
72
+ def associate(tuples, user)
73
+ tuples.map { |t| t.merge(user: user.fetch(:name)) }
71
74
  end
72
75
  end
73
76
  end
@@ -120,16 +123,19 @@ describe 'Building up a command graph for nested input' do
120
123
  it 'updates graph elements cleanly' do
121
124
  configuration.commands(:tasks) do
122
125
  define(:create) do
123
- def execute(tuples, user)
124
- super(tuples.map { |t| t.merge(user: user.fetch(:name)) })
126
+ before :associate
127
+
128
+ def associate(tuples, user)
129
+ tuples.map { |t| t.merge(user: user.fetch(:name)) }
125
130
  end
126
131
  end
127
132
 
128
133
  define(:update) do
129
134
  result :one
135
+ before :associate
130
136
 
131
- def execute(tuple, user)
132
- super(tuple.merge(user: user.fetch(:name)))
137
+ def associate(tuple, user)
138
+ tuple.merge(user: user.fetch(:name))
133
139
  end
134
140
  end
135
141
 
@@ -186,9 +192,7 @@ describe 'Building up a command graph for nested input' do
186
192
 
187
193
  create.call(initial)
188
194
 
189
- container.command(:tasks).create.call(
190
- [{ title: 'Task One'}], { name: 'Jane' }
191
- )
195
+ container.command(:tasks).create.with([{ title: 'Task One'}]).(name: 'Jane')
192
196
 
193
197
  expect(container.relation(:tasks)).to match_array([
194
198
  { title: 'Change Name', user: 'Johnny' },
@@ -233,8 +237,10 @@ describe 'Building up a command graph for nested input' do
233
237
 
234
238
  configuration.commands(:tasks) do
235
239
  define(:create) do
236
- def execute(tuples, user)
237
- super(tuples.map { |t| t.merge(user: user.fetch(:name)) })
240
+ before :associate
241
+
242
+ def associate(tuples, user)
243
+ tuples.map { |t| t.merge(user: user.fetch(:name)) }
238
244
  end
239
245
  end
240
246
  end
@@ -1,23 +1,13 @@
1
1
  require 'spec_helper'
2
2
  require 'dry-struct'
3
3
 
4
- describe 'Commands / Update' do
4
+ RSpec.describe 'Commands / Update' do
5
5
  include_context 'container'
6
6
  include_context 'users and tasks'
7
7
 
8
8
  subject(:users) { container.commands.users }
9
9
 
10
10
  before do
11
- module Test
12
- UserValidator = Class.new do
13
- ValidationError = Class.new(ROM::CommandError)
14
-
15
- def self.call(params)
16
- raise ValidationError, ":email is required" unless params[:email]
17
- end
18
- end
19
- end
20
-
21
11
  configuration.relation(:users) do
22
12
  register_as :users
23
13
 
@@ -31,13 +21,11 @@ describe 'Commands / Update' do
31
21
  end
32
22
 
33
23
  configuration.commands(:users) do
34
- define(:update) do
35
- validator Test::UserValidator
36
- end
24
+ define(:update)
37
25
  end
38
26
  end
39
27
 
40
- it 'update tuples on successful validation' do
28
+ it 'update tuples' do
41
29
  result = users.try {
42
30
  users.update.all(name: 'Jane').call(email: 'jane.doe@test.com')
43
31
  }
@@ -46,17 +34,6 @@ describe 'Commands / Update' do
46
34
  .to match_array([{ name: 'Jane', email: 'jane.doe@test.com' }])
47
35
  end
48
36
 
49
- it 'returns validation object with errors on failed validation' do
50
- result = users.try { users.update.all(name: 'Jane').call(email: nil) }
51
-
52
- expect(result.error).to be_instance_of(Test::ValidationError)
53
- expect(result.error.message).to eql(':email is required')
54
-
55
- expect(container.relations.users.restrict(name: 'Jane')).to match_array([
56
- { name: 'Jane', email: 'jane@doe.org' }
57
- ])
58
- end
59
-
60
37
  describe '"result" option' do
61
38
  it 'returns a single tuple when set to :one' do
62
39
  configuration.commands(:users) do
@@ -80,7 +57,7 @@ describe 'Commands / Update' do
80
57
  end
81
58
  end
82
59
  container
83
- }.to raise_error(ROM::Options::InvalidOptionValueError)
60
+ }.to raise_error(Dry::Types::ConstraintError)
84
61
  end
85
62
  end
86
63
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Commands' do
3
+ RSpec.describe 'Commands' do
4
4
  include_context 'container'
5
5
  include_context 'users and tasks'
6
6
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'rom/memory'
3
3
 
4
- describe 'Repository' do
4
+ RSpec.describe 'Gateways / Extending Relations' do
5
5
  include_context 'container'
6
6
  include_context 'users and tasks'
7
7
 
@@ -3,7 +3,7 @@ require 'rom/memory'
3
3
 
4
4
  require 'logger'
5
5
 
6
- describe 'Repositories / Setting logger' do
6
+ RSpec.describe 'Gateways / Setting logger' do
7
7
  let(:logger_class) do
8
8
  Class.new do
9
9
  attr_reader :messages
@@ -26,7 +26,7 @@ describe 'Repositories / Setting logger' do
26
26
  container = ROM.container(:memory) do |config|
27
27
  config.gateways[:default].use_logger(logger)
28
28
  end
29
-
29
+
30
30
  container.gateways[:default].logger.info("test")
31
31
 
32
32
  expect(logger.messages).to eql(["test"])
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Mapper definition DSL' do
3
+ RSpec.describe 'Mapper definition DSL' do
4
4
  include_context 'container'
5
5
  include_context 'users and tasks'
6
6
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'rom/memory'
3
3
 
4
- describe 'Mappers / deeply embedded tuples' do
4
+ RSpec.describe 'Mappers / deeply embedded tuples' do
5
5
  include_context 'container'
6
6
 
7
7
  it 'allows mapping embedded tuples' do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Mapper definition DSL' do
3
+ RSpec.describe 'Mapper definition DSL' do
4
4
  include_context 'container'
5
5
  include_context 'users and tasks'
6
6
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'rom/memory'
3
3
 
4
- describe 'Mappers / embedded' do
4
+ RSpec.describe 'Mappers / embedded' do
5
5
  include_context 'container'
6
6
 
7
7
  before do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'rom/memory'
3
3
 
4
- describe 'Mapper definition DSL' do
4
+ RSpec.describe 'Mapper definition DSL' do
5
5
  include_context 'container'
6
6
 
7
7
  before do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Mapper definition DSL' do
3
+ RSpec.describe 'Mapper definition DSL' do
4
4
  include_context 'container'
5
5
  include_context 'users and tasks'
6
6
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Mapper definition DSL' do
3
+ RSpec.describe 'Mapper definition DSL' do
4
4
  include_context 'container'
5
5
  include_context 'users and tasks'
6
6
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'rom/memory'
3
3
 
4
- describe 'Mappers / Attributes value' do
4
+ RSpec.describe 'Mappers / Attributes value' do
5
5
  include_context 'container'
6
6
 
7
7
  before do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'rom/memory'
3
3
 
4
- describe 'Mapper definition DSL' do
4
+ RSpec.describe 'Mapper definition DSL' do
5
5
  include_context 'container'
6
6
 
7
7
  before do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'rom/memory'
3
3
 
4
- describe 'Mapper definition DSL' do
4
+ RSpec.describe 'Mapper definition DSL' do
5
5
  include_context 'container'
6
6
 
7
7
  before do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'rom/memory'
3
3
 
4
- describe 'Mappers / Prefixing attributes' do
4
+ RSpec.describe 'Mappers / Prefixing attributes' do
5
5
  include_context 'container'
6
6
 
7
7
  before do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Registering Custom Mappers' do
3
+ RSpec.describe 'Registering Custom Mappers' do
4
4
  include_context 'container'
5
5
  include_context 'users and tasks'
6
6
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'rom/memory'
3
3
 
4
- describe 'Mappers / Renaming attributes' do
4
+ RSpec.describe 'Mappers / Renaming attributes' do
5
5
  include_context 'container'
6
6
 
7
7
  before do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Reusing mappers' do
3
+ RSpec.describe 'Reusing mappers' do
4
4
  it 'allows using another mapper in mapping definitions' do
5
5
  class Test::TaskMapper < ROM::Mapper
6
6
  attribute :title
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Mapper definition DSL' do
3
+ RSpec.describe 'Mapper definition DSL' do
4
4
  include_context 'container'
5
5
  include_context 'users and tasks'
6
6
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'rom/memory'
3
3
 
4
- describe 'Mappers / Symbolizing atributes' do
4
+ RSpec.describe 'Mappers / Symbolizing atributes' do
5
5
  include_context 'container'
6
6
 
7
7
  before do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'rom/memory'
3
3
 
4
- describe 'Mapper definition DSL' do
4
+ RSpec.describe 'Mapper definition DSL' do
5
5
  include_context 'container'
6
6
 
7
7
  before do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'rom/memory'
3
3
 
4
- describe 'Mapper definition DSL' do
4
+ RSpec.describe 'Mapper definition DSL' do
5
5
  include_context 'container'
6
6
 
7
7
  before do
@@ -16,7 +16,7 @@ describe 'Mapper definition DSL' do
16
16
  { type: 'home' },
17
17
  {}
18
18
  ])
19
- users.insert(name: 'Jane')
19
+ users.insert(name: 'Jane', emails: [])
20
20
  end
21
21
 
22
22
  describe 'ungroup' do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Mapper definition DSL' do
3
+ RSpec.describe 'Mapper definition DSL' do
4
4
  include_context 'container'
5
5
  include_context 'users and tasks'
6
6
 
@@ -14,7 +14,7 @@ describe 'Mapper definition DSL' do
14
14
  tuple.merge(user: users.restrict(name: tuple[:name]).first)
15
15
  }
16
16
 
17
- __new__(tuples)
17
+ new(tuples)
18
18
  end
19
19
  end
20
20
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Mapper definition DSL' do
3
+ RSpec.describe 'Mapper definition DSL' do
4
4
  include_context 'container'
5
5
  include_context 'users and tasks'
6
6
 
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  require 'rom/memory'
4
4
 
5
- describe ROM::Memory::Commands::Create do
5
+ RSpec.describe ROM::Memory::Commands::Create do
6
6
  include_context 'container'
7
7
  include_context 'users and tasks'
8
8
 
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  require 'rom/memory'
4
4
 
5
- describe ROM::Memory::Commands::Delete do
5
+ RSpec.describe ROM::Memory::Commands::Delete do
6
6
  include_context 'container'
7
7
  include_context 'users and tasks'
8
8
 
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  require 'rom/memory'
4
4
 
5
- describe ROM::Memory::Commands::Update do
5
+ RSpec.describe ROM::Memory::Commands::Update do
6
6
  include_context 'container'
7
7
  include_context 'users and tasks'
8
8
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'rom/memory'
3
3
 
4
- describe 'Setting up ROM with multiple environments' do
4
+ RSpec.describe 'Setting up ROM with multiple environments' do
5
5
  let(:configuration) do
6
6
  {
7
7
  one: ROM::Configuration.new(:memory),
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'rom/memory'
3
3
 
4
- describe 'Using in-memory gateways for cross-repo access' do
4
+ RSpec.describe 'Using in-memory gateways for cross-repo access' do
5
5
  let(:configuration) do
6
6
  ROM::Configuration.new(left: :memory, right: :memory, main: :memory)
7
7
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ROM::Relation, '.dataset' do
3
+ RSpec.describe ROM::Relation, '.dataset' do
4
4
  include_context 'container'
5
5
 
6
6
  it 'injects configured dataset when block was provided' do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Reading relations' do
3
+ RSpec.describe 'Reading relations' do
4
4
  include_context 'container'
5
5
  include_context 'users and tasks'
6
6
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Relation registration DSL' do
3
+ RSpec.describe 'Relation registration DSL' do
4
4
  include_context 'container'
5
5
  include_context 'users and tasks'
6
6
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'dry-struct'
3
3
 
4
- describe 'Configuring ROM' do
4
+ RSpec.describe 'Configuring ROM' do
5
5
  context 'with existing schema' do
6
6
  include_context 'container'
7
7
  include_context 'users and tasks'
@@ -41,9 +41,8 @@ describe 'Configuring ROM' do
41
41
  end
42
42
 
43
43
  describe 'defining classes' do
44
- it 'sets up registries based on class definitions' do
45
- container = ROM.container(:memory) do |config|
46
-
44
+ let(:container) do
45
+ ROM.container(:memory) do |config|
47
46
  class Test::UserRelation < ROM::Relation[:memory]
48
47
  dataset :users
49
48
 
@@ -64,7 +63,9 @@ describe 'Configuring ROM' do
64
63
  config.register_relation(Test::UserRelation, Test::TaskRelation)
65
64
  config.register_command(Test::CreateUser)
66
65
  end
66
+ end
67
67
 
68
+ it 'sets up registries based on class definitions' do
68
69
  expect(container.relations.users).to be_kind_of(Test::UserRelation)
69
70
  expect(container.relations.users.tasks).to be(container.relations.tasks)
70
71
 
@@ -73,6 +74,11 @@ describe 'Configuring ROM' do
73
74
  expect(container.relations.tasks).to be_kind_of(Test::TaskRelation)
74
75
  expect(container.relations.tasks.users).to be(container.relations.users)
75
76
  end
77
+
78
+ it 'sets empty schemas by default' do
79
+ expect(container.relations[:users].schema).to be_empty
80
+ expect(container.relations[:tasks].schema).to be_empty
81
+ end
76
82
  end
77
83
 
78
84
  describe 'quick setup' do
@@ -33,16 +33,20 @@ shared_context 'command graph' do
33
33
 
34
34
  configuration.commands(:books) do
35
35
  define(:create) do
36
- def execute(tuples, user)
37
- super(tuples.map { |t| t.merge(user: user.fetch(:name)) })
36
+ before :associate
37
+
38
+ def associate(tuples, user)
39
+ tuples.map { |t| t.merge(user: user.fetch(:name)) }
38
40
  end
39
41
  end
40
42
  end
41
43
 
42
44
  configuration.commands(:tags) do
43
45
  define(:create) do
44
- def execute(tuples, task)
45
- super(tuples.map { |t| t.merge(task: task.fetch(:title)) })
46
+ before :associate
47
+
48
+ def associate(tuples, task)
49
+ tuples.map { |t| t.merge(task: task.fetch(:title)) }
46
50
  end
47
51
  end
48
52
  end