rom 2.0.2 → 3.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 (149) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -4
  3. data/CHANGELOG.md +34 -1
  4. data/Gemfile +16 -2
  5. data/Rakefile +7 -2
  6. data/lib/rom/array_dataset.rb +44 -0
  7. data/lib/rom/association_set.rb +11 -5
  8. data/lib/rom/auto_curry.rb +55 -0
  9. data/lib/rom/command.rb +70 -41
  10. data/lib/rom/command_registry.rb +7 -18
  11. data/lib/rom/commands/class_interface.rb +7 -6
  12. data/lib/rom/commands/composite.rb +0 -1
  13. data/lib/rom/commands/graph.rb +7 -15
  14. data/lib/rom/commands/lazy/update.rb +1 -1
  15. data/lib/rom/configuration_dsl/command.rb +6 -8
  16. data/lib/rom/configuration_dsl/mapper.rb +2 -3
  17. data/lib/rom/configuration_dsl/mapper_dsl.rb +0 -1
  18. data/lib/rom/configuration_dsl/relation.rb +4 -4
  19. data/lib/rom/configuration_dsl.rb +0 -4
  20. data/lib/rom/constants.rb +1 -1
  21. data/lib/rom/container.rb +0 -2
  22. data/lib/rom/create_container.rb +0 -2
  23. data/lib/rom/data_proxy.rb +94 -0
  24. data/lib/rom/enumerable_dataset.rb +68 -0
  25. data/lib/rom/gateway.rb +23 -6
  26. data/lib/rom/global/plugin_dsl.rb +0 -2
  27. data/lib/rom/global.rb +0 -2
  28. data/lib/rom/initializer.rb +26 -0
  29. data/lib/rom/lint/gateway.rb +17 -0
  30. data/lib/rom/mapper_registry.rb +1 -1
  31. data/lib/rom/memory/commands.rb +0 -2
  32. data/lib/rom/memory/dataset.rb +1 -2
  33. data/lib/rom/memory/relation.rb +14 -1
  34. data/lib/rom/memory/schema.rb +13 -0
  35. data/lib/rom/plugin_registry.rb +1 -1
  36. data/lib/rom/plugins/configuration/configuration_dsl.rb +6 -2
  37. data/lib/rom/plugins/relation/key_inference.rb +4 -2
  38. data/lib/rom/plugins/relation/registry_reader.rb +5 -1
  39. data/lib/rom/registry.rb +50 -0
  40. data/lib/rom/relation/class_interface.rb +94 -26
  41. data/lib/rom/relation/curried.rb +15 -15
  42. data/lib/rom/relation/view_dsl.rb +31 -0
  43. data/lib/rom/relation.rb +49 -34
  44. data/lib/rom/schema/dsl.rb +7 -9
  45. data/lib/rom/schema/type.rb +115 -0
  46. data/lib/rom/schema.rb +218 -18
  47. data/lib/rom/setup/auto_registration.rb +20 -17
  48. data/lib/rom/setup/auto_registration_strategies/base.rb +8 -3
  49. data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +4 -3
  50. data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +5 -4
  51. data/lib/rom/setup/auto_registration_strategies/with_namespace.rb +3 -3
  52. data/lib/rom/setup/finalize/finalize_commands.rb +1 -1
  53. data/lib/rom/setup/finalize/finalize_mappers.rb +1 -1
  54. data/lib/rom/setup/finalize/finalize_relations.rb +3 -1
  55. data/lib/rom/setup/finalize.rb +1 -1
  56. data/lib/rom/transaction.rb +24 -0
  57. data/lib/rom/types.rb +9 -1
  58. data/lib/rom/version.rb +1 -1
  59. data/lib/rom.rb +4 -8
  60. data/rom.gemspec +4 -3
  61. data/spec/integration/command_registry_spec.rb +1 -14
  62. data/spec/integration/commands/create_spec.rb +5 -25
  63. data/spec/integration/commands/delete_spec.rb +1 -1
  64. data/spec/integration/commands/error_handling_spec.rb +1 -1
  65. data/spec/integration/commands/graph_spec.rb +20 -14
  66. data/spec/integration/commands/update_spec.rb +4 -27
  67. data/spec/integration/commands_spec.rb +1 -1
  68. data/spec/integration/{repositories → gateways}/extending_relations_spec.rb +1 -1
  69. data/spec/integration/{repositories → gateways}/setting_logger_spec.rb +2 -2
  70. data/spec/integration/mappers/combine_spec.rb +1 -1
  71. data/spec/integration/mappers/deep_embedded_spec.rb +1 -1
  72. data/spec/integration/mappers/definition_dsl_spec.rb +1 -1
  73. data/spec/integration/mappers/embedded_spec.rb +1 -1
  74. data/spec/integration/mappers/exclude_spec.rb +1 -1
  75. data/spec/integration/mappers/fold_spec.rb +1 -1
  76. data/spec/integration/mappers/group_spec.rb +1 -1
  77. data/spec/integration/mappers/overwrite_attributes_value_spec.rb +1 -1
  78. data/spec/integration/mappers/prefix_separator_spec.rb +1 -1
  79. data/spec/integration/mappers/prefix_spec.rb +1 -1
  80. data/spec/integration/mappers/prefixing_attributes_spec.rb +1 -1
  81. data/spec/integration/mappers/registering_custom_mappers_spec.rb +1 -1
  82. data/spec/integration/mappers/renaming_attributes_spec.rb +1 -1
  83. data/spec/integration/mappers/reusing_mappers_spec.rb +1 -1
  84. data/spec/integration/mappers/step_spec.rb +1 -1
  85. data/spec/integration/mappers/symbolizing_attributes_spec.rb +1 -1
  86. data/spec/integration/mappers/unfold_spec.rb +1 -1
  87. data/spec/integration/mappers/ungroup_spec.rb +1 -1
  88. data/spec/integration/mappers/unwrap_spec.rb +2 -2
  89. data/spec/integration/mappers/wrap_spec.rb +1 -1
  90. data/spec/integration/memory/commands/create_spec.rb +1 -1
  91. data/spec/integration/memory/commands/delete_spec.rb +1 -1
  92. data/spec/integration/memory/commands/update_spec.rb +1 -1
  93. data/spec/integration/multi_env_spec.rb +1 -1
  94. data/spec/integration/multi_repo_spec.rb +1 -1
  95. data/spec/integration/relations/default_dataset_spec.rb +1 -1
  96. data/spec/integration/relations/reading_spec.rb +1 -1
  97. data/spec/integration/relations/registry_dsl_spec.rb +1 -1
  98. data/spec/integration/setup_spec.rb +10 -4
  99. data/spec/shared/command_graph.rb +8 -4
  100. data/spec/shared/enumerable_dataset.rb +1 -1
  101. data/spec/spec_helper.rb +7 -9
  102. data/spec/support/schema.rb +14 -0
  103. data/spec/unit/rom/array_dataset_spec.rb +59 -0
  104. data/spec/unit/rom/association_set_spec.rb +4 -0
  105. data/spec/unit/rom/auto_curry_spec.rb +63 -0
  106. data/spec/unit/rom/commands/graph_spec.rb +12 -11
  107. data/spec/unit/rom/commands/lazy_spec.rb +8 -5
  108. data/spec/unit/rom/commands/pre_and_post_processors_spec.rb +269 -0
  109. data/spec/unit/rom/commands/result_spec.rb +1 -1
  110. data/spec/unit/rom/commands_spec.rb +9 -3
  111. data/spec/unit/rom/configuration_spec.rb +1 -1
  112. data/spec/unit/rom/container_spec.rb +11 -5
  113. data/spec/unit/rom/create_container_spec.rb +1 -1
  114. data/spec/unit/rom/enumerable_dataset_spec.rb +15 -0
  115. data/spec/unit/rom/gateway_spec.rb +1 -1
  116. data/spec/unit/rom/mapper_registry_spec.rb +1 -1
  117. data/spec/unit/rom/memory/commands_spec.rb +1 -1
  118. data/spec/unit/rom/memory/dataset_spec.rb +1 -1
  119. data/spec/unit/rom/memory/{repository_spec.rb → gateway_spec.rb} +1 -1
  120. data/spec/unit/rom/memory/inheritance_spec.rb +32 -0
  121. data/spec/unit/rom/memory/relation_spec.rb +15 -3
  122. data/spec/unit/rom/memory/storage_spec.rb +1 -1
  123. data/spec/unit/rom/plugin_spec.rb +1 -1
  124. data/spec/unit/rom/plugins/relation/key_inference_spec.rb +1 -1
  125. data/spec/unit/rom/registry_spec.rb +86 -0
  126. data/spec/unit/rom/relation/attribute_reader_spec.rb +17 -0
  127. data/spec/unit/rom/relation/composite_spec.rb +1 -1
  128. data/spec/unit/rom/relation/graph_spec.rb +1 -1
  129. data/spec/unit/rom/relation/lazy/combine_spec.rb +1 -1
  130. data/spec/unit/rom/relation/lazy_spec.rb +1 -1
  131. data/spec/unit/rom/relation/loaded_spec.rb +1 -1
  132. data/spec/unit/rom/relation/schema_spec.rb +10 -6
  133. data/spec/unit/rom/relation/view_spec.rb +112 -0
  134. data/spec/unit/rom/relation_spec.rb +16 -2
  135. data/spec/unit/rom/schema/accessing_attributes_spec.rb +52 -0
  136. data/spec/unit/rom/schema/exclude_spec.rb +15 -0
  137. data/spec/unit/rom/schema/finalize_spec.rb +59 -0
  138. data/spec/unit/rom/schema/key_predicate_spec.rb +15 -0
  139. data/spec/unit/rom/schema/merge_spec.rb +17 -0
  140. data/spec/unit/rom/schema/prefix_spec.rb +16 -0
  141. data/spec/unit/rom/schema/project_spec.rb +15 -0
  142. data/spec/unit/rom/schema/rename_spec.rb +22 -0
  143. data/spec/unit/rom/schema/type_spec.rb +49 -0
  144. data/spec/unit/rom/schema/wrap_spec.rb +17 -0
  145. data/spec/unit/rom/schema_spec.rb +2 -2
  146. metadata +69 -17
  147. data/lib/rom/plugins/relation/view/dsl.rb +0 -32
  148. data/lib/rom/plugins/relation/view.rb +0 -95
  149. data/spec/unit/rom/plugins/relation/view_spec.rb +0 -51
@@ -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
@@ -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
@@ -1,4 +1,4 @@
1
- shared_examples_for "an enumerable dataset" do
1
+ RSpec.shared_examples_for "an enumerable dataset" do
2
2
  subject(:dataset) { klass.new(data) }
3
3
 
4
4
  let(:data) do
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,4 @@
1
- # encoding: utf-8
2
-
3
- # this is needed for guard to work, not sure why :(
4
- require "bundler"
5
- Bundler.setup
6
-
7
- if ENV['COVERAGE'] == 'true' && RUBY_ENGINE == 'ruby' && RUBY_VERSION='2.3.1'
1
+ if ENV['COVERAGE'] == 'true' && RUBY_ENGINE == 'ruby' && RUBY_VERSION == '2.3.1'
8
2
  require "simplecov"
9
3
  SimpleCov.start do
10
4
  add_filter '/spec/'
@@ -13,8 +7,8 @@ end
13
7
 
14
8
  SPEC_ROOT = root = Pathname(__FILE__).dirname
15
9
 
16
- require 'rom/support/deprecations'
17
- ROM::Deprecations.set_logger!(SPEC_ROOT.join('../log/deprecations.log'))
10
+ require 'dry/core/deprecations'
11
+ Dry::Core::Deprecations.set_logger!(SPEC_ROOT.join('../log/deprecations.log'))
18
12
 
19
13
  require 'rom'
20
14
 
@@ -42,6 +36,8 @@ def T(*args)
42
36
  end
43
37
 
44
38
  RSpec.configure do |config|
39
+ config.include(SchemaHelpers)
40
+
45
41
  config.after do
46
42
  Test.remove_constants
47
43
  end
@@ -49,4 +45,6 @@ RSpec.configure do |config|
49
45
  config.around do |example|
50
46
  ConstantLeakFinder.find(example)
51
47
  end
48
+
49
+ config.disable_monkey_patching!
52
50
  end
@@ -0,0 +1,14 @@
1
+ require 'dry-types'
2
+
3
+ module SchemaHelpers
4
+ def define_schema(source, attrs)
5
+ ROM::Schema.define(
6
+ source,
7
+ attributes: attrs.map { |name, type| define_type(name, type, source: source) }
8
+ )
9
+ end
10
+
11
+ def define_type(name, id, **opts)
12
+ ROM::Types.const_get(id).meta(name: name, **opts)
13
+ end
14
+ end
@@ -0,0 +1,59 @@
1
+ require 'rom/array_dataset'
2
+
3
+ RSpec.describe ROM::ArrayDataset do
4
+ let(:klass) do
5
+ Class.new do
6
+ include ROM::ArrayDataset
7
+
8
+ def self.row_proc
9
+ -> i { i.each_with_object({}) { |(k,v),h| h[k.to_sym] = v } }
10
+ end
11
+ end
12
+ end
13
+
14
+ it_behaves_like 'an enumerable dataset' do
15
+ describe '#flatten' do
16
+ let(:data) { [[{ 'name' => 'Jane' }], [{ 'name' => 'Joe' }]] }
17
+
18
+ it 'returns a new dataset with flattened data' do
19
+ result = dataset.flatten
20
+
21
+ expect(result).to match_array([{ name: 'Jane' }, { name: 'Joe' }])
22
+ end
23
+ end
24
+
25
+ describe '#map!' do
26
+ context 'with a block' do
27
+ it 'returns a new dataset with mapped data' do
28
+ dataset.map! do |row|
29
+ row.merge(age: 21)
30
+ end
31
+
32
+ expect(dataset).to match_array([
33
+ { name: 'Jane', age: 21 }, { name: 'Joe', age: 21 }
34
+ ])
35
+ end
36
+ end
37
+
38
+ context 'without a block' do
39
+ it 'returns an enumerator' do
40
+ result = dataset.map!
41
+
42
+ expect(result).to be_instance_of(Enumerator)
43
+
44
+ expect(result).to match_array([
45
+ { name: 'Jane' }, { name: 'Joe' }
46
+ ])
47
+ end
48
+ end
49
+ end
50
+
51
+ describe '#values_at' do
52
+ it 'returns a new dataset with rows at given indices' do
53
+ result = dataset.values_at(1)
54
+
55
+ expect(result).to match_array([{ name: 'Joe' }])
56
+ end
57
+ end
58
+ end
59
+ end