rom 0.9.1 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +30 -12
  3. data/.travis.yml +1 -1
  4. data/CHANGELOG.md +24 -0
  5. data/Gemfile +7 -3
  6. data/README.md +24 -11
  7. data/lib/rom.rb +9 -26
  8. data/lib/rom/command.rb +113 -75
  9. data/lib/rom/commands/class_interface.rb +115 -0
  10. data/lib/rom/commands/graph.rb +17 -23
  11. data/lib/rom/commands/graph/builder.rb +176 -0
  12. data/lib/rom/commands/graph/class_interface.rb +8 -2
  13. data/lib/rom/commands/graph/input_evaluator.rb +13 -9
  14. data/lib/rom/commands/lazy.rb +23 -17
  15. data/lib/rom/commands/lazy/create.rb +23 -0
  16. data/lib/rom/commands/lazy/delete.rb +27 -0
  17. data/lib/rom/commands/lazy/update.rb +34 -0
  18. data/lib/rom/commands/result.rb +14 -0
  19. data/lib/rom/commands/update.rb +0 -4
  20. data/lib/rom/configuration.rb +86 -0
  21. data/lib/rom/{setup_dsl/setup.rb → configuration_dsl.rb} +9 -7
  22. data/lib/rom/configuration_dsl/command.rb +43 -0
  23. data/lib/rom/{setup_dsl → configuration_dsl}/command_dsl.rb +5 -4
  24. data/lib/rom/configuration_dsl/mapper.rb +37 -0
  25. data/lib/rom/{setup_dsl → configuration_dsl}/mapper_dsl.rb +11 -5
  26. data/lib/rom/configuration_dsl/relation.rb +26 -0
  27. data/lib/rom/configuration_plugin.rb +17 -0
  28. data/lib/rom/constants.rb +5 -12
  29. data/lib/rom/container.rb +11 -8
  30. data/lib/rom/create_container.rb +61 -0
  31. data/lib/rom/environment.rb +27 -241
  32. data/lib/rom/gateway.rb +18 -2
  33. data/lib/rom/global.rb +24 -0
  34. data/lib/rom/global/plugin_dsl.rb +2 -0
  35. data/lib/rom/lint/spec.rb +0 -12
  36. data/lib/rom/lint/test.rb +0 -31
  37. data/lib/rom/memory/commands.rb +2 -2
  38. data/lib/rom/memory/gateway.rb +2 -0
  39. data/lib/rom/pipeline.rb +1 -1
  40. data/lib/rom/plugin_base.rb +1 -1
  41. data/lib/rom/plugin_registry.rb +12 -10
  42. data/lib/rom/plugins/configuration/configuration_dsl.rb +16 -0
  43. data/lib/rom/plugins/relation/key_inference.rb +31 -0
  44. data/lib/rom/plugins/relation/view.rb +90 -0
  45. data/lib/rom/plugins/relation/view/dsl.rb +32 -0
  46. data/lib/rom/relation.rb +1 -11
  47. data/lib/rom/relation/class_interface.rb +37 -50
  48. data/lib/rom/setup.rb +13 -104
  49. data/lib/rom/setup/auto_registration.rb +55 -0
  50. data/lib/rom/setup/finalize.rb +113 -127
  51. data/lib/rom/setup/finalize/commands.rb +67 -0
  52. data/lib/rom/setup/finalize/mappers.rb +36 -0
  53. data/lib/rom/setup/finalize/relations.rb +53 -0
  54. data/lib/rom/support/configurable.rb +21 -7
  55. data/lib/rom/version.rb +1 -1
  56. data/rakelib/mutant.rake +4 -1
  57. data/rom.gemspec +3 -4
  58. data/spec/fixtures/app/commands/create_user.rb +2 -0
  59. data/spec/fixtures/app/mappers/user_list.rb +2 -0
  60. data/spec/fixtures/app/relations/users.rb +2 -0
  61. data/spec/fixtures/lib/persistence/commands/create_user.rb +6 -0
  62. data/spec/fixtures/lib/persistence/mappers/user_list.rb +6 -0
  63. data/spec/fixtures/lib/persistence/relations/users.rb +6 -0
  64. data/spec/{unit/rom → integration}/command_registry_spec.rb +8 -9
  65. data/spec/integration/commands/create_spec.rb +17 -13
  66. data/spec/integration/commands/delete_spec.rb +12 -11
  67. data/spec/integration/commands/error_handling_spec.rb +5 -4
  68. data/spec/integration/commands/graph_builder_spec.rb +213 -0
  69. data/spec/integration/commands/graph_spec.rb +112 -49
  70. data/spec/integration/commands/update_spec.rb +14 -11
  71. data/spec/integration/commands_spec.rb +60 -0
  72. data/spec/integration/mappers/combine_spec.rb +7 -6
  73. data/spec/integration/mappers/deep_embedded_spec.rb +5 -6
  74. data/spec/integration/mappers/definition_dsl_spec.rb +19 -18
  75. data/spec/integration/mappers/embedded_spec.rb +11 -12
  76. data/spec/integration/mappers/exclude_spec.rb +5 -6
  77. data/spec/integration/mappers/fold_spec.rb +8 -7
  78. data/spec/integration/mappers/group_spec.rb +16 -15
  79. data/spec/integration/mappers/overwrite_attributes_value_spec.rb +5 -5
  80. data/spec/integration/mappers/prefix_separator_spec.rb +5 -7
  81. data/spec/integration/mappers/prefix_spec.rb +5 -7
  82. data/spec/integration/mappers/prefixing_attributes_spec.rb +7 -7
  83. data/spec/integration/mappers/registering_custom_mappers_spec.rb +4 -5
  84. data/spec/integration/mappers/renaming_attributes_spec.rb +18 -18
  85. data/spec/integration/mappers/step_spec.rb +11 -12
  86. data/spec/integration/mappers/symbolizing_attributes_spec.rb +11 -8
  87. data/spec/integration/mappers/unfold_spec.rb +9 -10
  88. data/spec/integration/mappers/ungroup_spec.rb +10 -11
  89. data/spec/integration/mappers/unwrap_spec.rb +10 -15
  90. data/spec/integration/mappers/wrap_spec.rb +16 -15
  91. data/spec/{unit/rom → integration}/memory/commands/create_spec.rb +7 -5
  92. data/spec/{unit/rom → integration}/memory/commands/delete_spec.rb +7 -5
  93. data/spec/{unit/rom → integration}/memory/commands/update_spec.rb +7 -5
  94. data/spec/integration/multi_env_spec.rb +16 -124
  95. data/spec/integration/multi_repo_spec.rb +9 -9
  96. data/spec/integration/relations/default_dataset_spec.rb +15 -0
  97. data/spec/integration/relations/inheritance_spec.rb +5 -7
  98. data/spec/integration/relations/reading_spec.rb +32 -65
  99. data/spec/integration/relations/registry_dsl_spec.rb +5 -4
  100. data/spec/integration/repositories/extending_relations_spec.rb +6 -7
  101. data/spec/integration/repositories/setting_logger_spec.rb +5 -7
  102. data/spec/integration/setup_spec.rb +49 -61
  103. data/spec/shared/command_graph.rb +50 -0
  104. data/spec/shared/container.rb +9 -0
  105. data/spec/shared/gateway_only.rb +6 -0
  106. data/spec/shared/no_container.rb +16 -0
  107. data/spec/shared/one_behavior.rb +4 -4
  108. data/spec/shared/users_and_tasks.rb +5 -17
  109. data/spec/spec_helper.rb +5 -3
  110. data/spec/test/memory_repository_lint_test.rb +1 -1
  111. data/spec/unit/rom/auto_registration_spec.rb +54 -0
  112. data/spec/unit/rom/commands/graph_spec.rb +18 -44
  113. data/spec/unit/rom/commands/lazy_spec.rb +246 -35
  114. data/spec/unit/rom/commands/result_spec.rb +56 -0
  115. data/spec/unit/rom/commands_spec.rb +9 -73
  116. data/spec/unit/rom/configurable_spec.rb +49 -0
  117. data/spec/unit/rom/configuration_spec.rb +61 -0
  118. data/spec/unit/rom/container_spec.rb +39 -33
  119. data/spec/unit/rom/create_container_spec.rb +151 -0
  120. data/spec/unit/rom/environment_spec.rb +123 -0
  121. data/spec/unit/rom/gateway_spec.rb +58 -2
  122. data/spec/unit/rom/global_spec.rb +10 -7
  123. data/spec/unit/rom/plugin_spec.rb +44 -25
  124. data/spec/unit/rom/plugins/relation/key_inference_spec.rb +27 -0
  125. data/spec/unit/rom/plugins/relation/view_spec.rb +47 -0
  126. data/spec/unit/rom/relation/composite_spec.rb +20 -20
  127. data/spec/unit/rom/relation/curried_spec.rb +10 -11
  128. data/spec/unit/rom/relation/graph_spec.rb +27 -27
  129. data/spec/unit/rom/relation/lazy/combine_spec.rb +26 -20
  130. data/spec/unit/rom/relation/lazy_spec.rb +38 -38
  131. data/spec/unit/rom/relation/loaded_spec.rb +2 -3
  132. data/spec/unit/rom/relation_spec.rb +39 -2
  133. metadata +58 -66
  134. data/lib/rom/commands/abstract.rb +0 -184
  135. data/lib/rom/environment_plugin.rb +0 -17
  136. data/lib/rom/environment_plugins/auto_registration.rb +0 -38
  137. data/lib/rom/repository.rb +0 -16
  138. data/lib/rom/setup_dsl/command.rb +0 -36
  139. data/lib/rom/setup_dsl/mapper.rb +0 -32
  140. data/lib/rom/setup_dsl/relation.rb +0 -30
  141. data/spec/integration/inline_setup_spec.rb +0 -65
  142. data/spec/unit/rom/repository_spec.rb +0 -12
  143. data/spec/unit/rom/setup_spec.rb +0 -253
@@ -3,9 +3,10 @@ require 'spec_helper'
3
3
  require 'ostruct'
4
4
 
5
5
  describe 'Commands / Update' do
6
+ include_context 'container'
6
7
  include_context 'users and tasks'
7
8
 
8
- subject(:users) { rom.commands.users }
9
+ subject(:users) { container.commands.users }
9
10
 
10
11
  before do
11
12
  module Test
@@ -18,7 +19,9 @@ describe 'Commands / Update' do
18
19
  end
19
20
  end
20
21
 
21
- setup.relation(:users) do
22
+ configuration.relation(:users) do
23
+ register_as :users
24
+
22
25
  def all(criteria)
23
26
  restrict(criteria)
24
27
  end
@@ -28,7 +31,7 @@ describe 'Commands / Update' do
28
31
  end
29
32
  end
30
33
 
31
- setup.commands(:users) do
34
+ configuration.commands(:users) do
32
35
  define(:update) do
33
36
  validator Test::UserValidator
34
37
  end
@@ -50,14 +53,14 @@ describe 'Commands / Update' do
50
53
  expect(result.error).to be_instance_of(Test::ValidationError)
51
54
  expect(result.error.message).to eql(':email is required')
52
55
 
53
- expect(rom.relations.users.restrict(name: 'Jane')).to match_array([
56
+ expect(container.relations.users.restrict(name: 'Jane')).to match_array([
54
57
  { name: 'Jane', email: 'jane@doe.org' }
55
58
  ])
56
59
  end
57
60
 
58
61
  describe '"result" option' do
59
62
  it 'returns a single tuple when set to :one' do
60
- setup.commands(:users) do
63
+ configuration.commands(:users) do
61
64
  define(:update_one, type: :update) do
62
65
  result :one
63
66
  end
@@ -71,7 +74,7 @@ describe 'Commands / Update' do
71
74
  end
72
75
 
73
76
  it 'raises when there is more than one tuple and result is set to :one' do
74
- setup.commands(:users) do
77
+ configuration.commands(:users) do
75
78
  define(:update_one, type: :update) do
76
79
  result :one
77
80
  end
@@ -83,7 +86,7 @@ describe 'Commands / Update' do
83
86
 
84
87
  expect(result.error).to be_instance_of(ROM::TupleCountMismatchError)
85
88
 
86
- expect(rom.relations.users).to match_array([
89
+ expect(container.relations.users).to match_array([
87
90
  { name: 'Jane', email: 'jane@doe.org' },
88
91
  { name: 'Joe', email: 'joe@doe.org' }
89
92
  ])
@@ -91,12 +94,12 @@ describe 'Commands / Update' do
91
94
 
92
95
  it 'allows only valid result types' do
93
96
  expect {
94
- setup.commands(:users) do
97
+ configuration.commands(:users) do
95
98
  define(:create_one, type: :create) do
96
99
  result :invalid_type
97
100
  end
98
101
  end
99
- setup.finalize
102
+ container
100
103
  }.to raise_error(ROM::Options::InvalidOptionValueError)
101
104
  end
102
105
  end
@@ -105,14 +108,14 @@ describe 'Commands / Update' do
105
108
  it 'allows scoping to a virtual relation' do
106
109
  user_model = Class.new { include Anima.new(:name, :email) }
107
110
 
108
- setup.mappers do
111
+ configuration.mappers do
109
112
  define(:users) do
110
113
  model user_model
111
114
  register_as :entity
112
115
  end
113
116
  end
114
117
 
115
- command = rom.command(:users).as(:entity).update.by_name('Jane')
118
+ command = container.command(:users).as(:entity).update.by_name('Jane')
116
119
 
117
120
  attributes = { name: 'Jane Doe', email: 'jane@doe.org' }
118
121
  result = command[attributes]
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Commands' do
4
+ include_context 'container'
5
+ include_context 'users and tasks'
6
+
7
+ before do
8
+ configuration.relation(:users) do
9
+ def by_id(id)
10
+ restrict(id: id)
11
+ end
12
+ end
13
+ configuration.commands(:users) do
14
+ define(:update)
15
+ end
16
+ end
17
+
18
+ let(:command) { container.command(:users)[:update] }
19
+
20
+ describe '#method_missing' do
21
+ it 'forwards known relation view methods' do
22
+ expect(command.by_id(1).relation).to eql(users_relation.by_id(1))
23
+ end
24
+
25
+ it 'raises no-method error when a non-view relation method was sent' do
26
+ expect { command.as(:foo) }.to raise_error(NoMethodError, /as/)
27
+ end
28
+ end
29
+
30
+ describe 'extending command with a db-specific behavior' do
31
+ before do
32
+ gateway.instance_exec do
33
+ def extend_command_class(klass, _)
34
+ klass.class_eval do
35
+ def super_command?
36
+ true
37
+ end
38
+ end
39
+ klass
40
+ end
41
+ end
42
+ end
43
+
44
+ it 'applies to defined classes' do
45
+ klass = Class.new(ROM::Commands::Create[:memory]) { relation :users }
46
+ configuration.register_command(klass)
47
+ container
48
+ command = klass.build(users_relation)
49
+ expect(command).to be_super_command
50
+ end
51
+
52
+ it 'applies to generated classes' do
53
+ klass = ROM::ConfigurationDSL::Command.build_class(:create, :users, adapter: :memory)
54
+ configuration.register_command(klass)
55
+ container
56
+ command = klass.build(users_relation)
57
+ expect(command).to be_super_command
58
+ end
59
+ end
60
+ end
@@ -1,11 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'Mapper definition DSL' do
4
+ include_context 'container'
4
5
  include_context 'users and tasks'
5
6
 
6
7
  describe 'combine' do
7
8
  before do
8
- setup.relation(:tasks) do
9
+ configuration.relation(:tasks) do
9
10
  def for_users(users)
10
11
  names = users.map { |user| user[:name] }
11
12
  restrict { |task| names.include?(task[:name]) }
@@ -16,7 +17,7 @@ describe 'Mapper definition DSL' do
16
17
  end
17
18
  end
18
19
 
19
- setup.relation(:users) do
20
+ configuration.relation(:users) do
20
21
  def addresses(_users)
21
22
  [{ city: 'NYC', user: 'Jane' }, { city: 'Boston', user: 'Joe' }]
22
23
  end
@@ -26,7 +27,7 @@ describe 'Mapper definition DSL' do
26
27
  end
27
28
  end
28
29
 
29
- setup.mappers do
30
+ configuration.mappers do
30
31
  define(:users) do
31
32
  register_as :entity
32
33
 
@@ -63,8 +64,8 @@ describe 'Mapper definition DSL' do
63
64
  end
64
65
  end
65
66
 
66
- let(:users) { rom.relation(:users) }
67
- let(:tasks) { rom.relation(:tasks) }
67
+ let(:users) { container.relation(:users) }
68
+ let(:tasks) { container.relation(:tasks) }
68
69
 
69
70
  let(:joe) {
70
71
  Test::User.new(
@@ -98,7 +99,7 @@ describe 'Mapper definition DSL' do
98
99
  }
99
100
 
100
101
  it 'works' do
101
- rom
102
+ container
102
103
 
103
104
  Test::User.send(:include, Equalizer.new(:name, :email, :tasks, :address, :book))
104
105
  Test::Task.send(:include, Equalizer.new(:title, :meta))
@@ -2,13 +2,12 @@ require 'spec_helper'
2
2
  require 'rom/memory'
3
3
 
4
4
  describe 'Mappers / deeply embedded tuples' do
5
- let(:setup) { ROM.setup(:memory) }
6
- let(:rom) { setup.finalize }
5
+ include_context 'container'
7
6
 
8
7
  it 'allows mapping embedded tuples' do
9
- setup.relation(:users)
8
+ configuration.relation(:users)
10
9
 
11
- setup.mappers do
10
+ configuration.mappers do
12
11
  define(:users) do
13
12
  model name: 'Test::User'
14
13
 
@@ -25,7 +24,7 @@ describe 'Mappers / deeply embedded tuples' do
25
24
  end
26
25
  end
27
26
 
28
- rom.relations.users << {
27
+ container.relations.users << {
29
28
  'name' => 'Jane',
30
29
  'tasks' => [
31
30
  { 'title' => 'Task One', 'priority' => { 'value' => 1, 'desc' => 'high' } },
@@ -33,7 +32,7 @@ describe 'Mappers / deeply embedded tuples' do
33
32
  ]
34
33
  }
35
34
 
36
- jane = rom.relation(:users).as(:users).first
35
+ jane = container.relation(:users).as(:users).first
37
36
 
38
37
  expect(jane.name).to eql('Jane')
39
38
 
@@ -1,12 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'Mapper definition DSL' do
4
+ include_context 'container'
4
5
  include_context 'users and tasks'
5
6
 
6
7
  let(:header) { mapper.header }
7
8
 
8
9
  before do
9
- setup.relation(:users) do
10
+ configuration.relation(:users) do
10
11
  def email_index
11
12
  project(:email)
12
13
  end
@@ -14,10 +15,10 @@ describe 'Mapper definition DSL' do
14
15
  end
15
16
 
16
17
  describe 'default PORO mapper' do
17
- subject(:mapper) { rom.mappers.users.entity }
18
+ subject(:mapper) { container.mappers.users.entity }
18
19
 
19
20
  before do
20
- setup.mappers do
21
+ configuration.mappers do
21
22
  define(:users) do
22
23
  model name: 'Test::User'
23
24
 
@@ -40,10 +41,10 @@ describe 'Mapper definition DSL' do
40
41
 
41
42
  describe 'excluding attributes' do
42
43
  context 'by setting :inherit_header to false' do
43
- subject(:mapper) { rom.mappers.users.email_index }
44
+ subject(:mapper) { container.mappers.users.email_index }
44
45
 
45
46
  before do
46
- setup.mappers do
47
+ configuration.mappers do
47
48
  define(:users) do
48
49
  model name: 'Test::User'
49
50
 
@@ -65,10 +66,10 @@ describe 'Mapper definition DSL' do
65
66
  end
66
67
 
67
68
  describe 'virtual relation mapper' do
68
- subject(:mapper) { rom.mappers.users.email_index }
69
+ subject(:mapper) { container.mappers.users.email_index }
69
70
 
70
71
  before do
71
- setup.mappers do
72
+ configuration.mappers do
72
73
  define(:users) do
73
74
  model name: 'Test::User'
74
75
 
@@ -99,13 +100,13 @@ describe 'Mapper definition DSL' do
99
100
 
100
101
  describe 'wrapped relation mapper' do
101
102
  before do
102
- setup.relation(:tasks) do
103
+ configuration.relation(:tasks) do
103
104
  def with_user
104
105
  join(users)
105
106
  end
106
107
  end
107
108
 
108
- setup.mappers do
109
+ configuration.mappers do
109
110
  define(:tasks) do
110
111
  model name: 'Test::Task'
111
112
 
@@ -116,7 +117,7 @@ describe 'Mapper definition DSL' do
116
117
  end
117
118
 
118
119
  it 'allows defining wrapped attributes via options hash' do
119
- setup.mappers do
120
+ configuration.mappers do
120
121
  define(:with_user, parent: :tasks) do
121
122
  model name: 'Test::TaskWithUser'
122
123
 
@@ -127,11 +128,11 @@ describe 'Mapper definition DSL' do
127
128
  end
128
129
  end
129
130
 
130
- rom = setup.finalize
131
+ container
131
132
 
132
133
  Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
133
134
 
134
- jane = rom.relation(:tasks).with_user.as(:with_user).to_a.last
135
+ jane = container.relation(:tasks).with_user.as(:with_user).to_a.last
135
136
 
136
137
  expect(jane).to eql(
137
138
  Test::TaskWithUser.new(
@@ -143,7 +144,7 @@ describe 'Mapper definition DSL' do
143
144
  end
144
145
 
145
146
  it 'allows defining wrapped attributes via options block' do
146
- setup.mappers do
147
+ configuration.mappers do
147
148
  define(:with_user, parent: :tasks) do
148
149
  model name: 'Test::TaskWithUser'
149
150
 
@@ -156,11 +157,11 @@ describe 'Mapper definition DSL' do
156
157
  end
157
158
  end
158
159
 
159
- rom = setup.finalize
160
+ container
160
161
 
161
162
  Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
162
163
 
163
- jane = rom.relation(:tasks).with_user.as(:with_user).to_a.last
164
+ jane = container.relation(:tasks).with_user.as(:with_user).to_a.last
164
165
 
165
166
  expect(jane).to eql(
166
167
  Test::TaskWithUser.new(
@@ -172,7 +173,7 @@ describe 'Mapper definition DSL' do
172
173
  end
173
174
 
174
175
  it 'allows defining wrapped attributes mapped to a model' do
175
- setup.mappers do
176
+ configuration.mappers do
176
177
  define(:with_user, parent: :tasks) do
177
178
  model name: 'Test::TaskWithUser'
178
179
 
@@ -186,12 +187,12 @@ describe 'Mapper definition DSL' do
186
187
  end
187
188
  end
188
189
 
189
- rom = setup.finalize
190
+ container
190
191
 
191
192
  Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
192
193
  Test::User.send(:include, Equalizer.new(:email))
193
194
 
194
- jane = rom.relation(:tasks).with_user.as(:with_user).to_a.last
195
+ jane = container.relation(:tasks).with_user.as(:with_user).to_a.last
195
196
 
196
197
  expect(jane).to eql(
197
198
  Test::TaskWithUser.new(
@@ -2,13 +2,14 @@ require 'spec_helper'
2
2
  require 'rom/memory'
3
3
 
4
4
  describe 'Mappers / embedded' do
5
- let(:setup) { ROM.setup(:memory) }
6
- let(:rom) { setup.finalize }
5
+ include_context 'container'
7
6
 
8
- it 'allows mapping embedded tuples' do
9
- setup.relation(:users)
7
+ before do
8
+ configuration.relation(:users)
9
+ end
10
10
 
11
- setup.mappers do
11
+ it 'allows mapping embedded tuples' do
12
+ configuration.mappers do
12
13
  define(:users) do
13
14
  model name: 'Test::User'
14
15
 
@@ -20,21 +21,19 @@ describe 'Mappers / embedded' do
20
21
  end
21
22
  end
22
23
 
23
- rom.relations.users << {
24
+ container.relations.users << {
24
25
  'name' => 'Jane',
25
26
  'tasks' => [{ 'title' => 'Task One' }, { 'title' => 'Task Two' }]
26
27
  }
27
28
 
28
- jane = rom.relation(:users).map_with(:users).first
29
+ jane = container.relation(:users).map_with(:users).first
29
30
 
30
31
  expect(jane.name).to eql('Jane')
31
32
  expect(jane.tasks).to eql([{ title: 'Task One' }, { title: 'Task Two' }])
32
33
  end
33
34
 
34
35
  it 'allows mapping embedded tuple' do
35
- setup.relation(:users)
36
-
37
- setup.mappers do
36
+ configuration.mappers do
38
37
  define(:users) do
39
38
  model name: 'Test::User'
40
39
 
@@ -48,12 +47,12 @@ describe 'Mappers / embedded' do
48
47
  end
49
48
  end
50
49
 
51
- rom.relations.users << {
50
+ container.relations.users << {
52
51
  'name' => 'Jane',
53
52
  'address' => { 'street' => 'Somewhere 1', 'city' => 'NYC' }
54
53
  }
55
54
 
56
- jane = rom.relation(:users).as(:users).first
55
+ jane = container.relation(:users).as(:users).first
57
56
 
58
57
  Test::Address.send(:include, Equalizer.new(:street, :city))
59
58
 
@@ -2,23 +2,22 @@ require 'spec_helper'
2
2
  require 'rom/memory'
3
3
 
4
4
  describe 'Mapper definition DSL' do
5
- let(:setup) { ROM.setup(:memory) }
6
- let(:rom) { ROM.finalize.env }
5
+ include_context 'container'
7
6
 
8
7
  before do
9
- setup.relation(:users)
8
+ configuration.relation(:users)
10
9
 
11
- users = setup.default.dataset(:users)
10
+ users = configuration.default.dataset(:users)
12
11
 
13
12
  users.insert(name: 'Joe', email: 'joe@doe.com')
14
13
  users.insert(name: 'Jane', email: 'jane@doe.com')
15
14
  end
16
15
 
17
16
  describe 'exclude' do
18
- let(:mapped_users) { rom.relation(:users).as(:users).to_a }
17
+ let(:mapped_users) { container.relation(:users).as(:users).to_a }
19
18
 
20
19
  it 'removes the attribute' do
21
- setup.mappers do
20
+ configuration.mappers do
22
21
  define(:users) { exclude :email }
23
22
  end
24
23