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
@@ -1,32 +1,33 @@
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
  describe 'folded relation mapper' do
9
10
  before do
10
- setup.relation(:tasks) do
11
+ configuration.relation(:tasks) do
11
12
  def with_users
12
13
  join(users)
13
14
  end
14
15
  end
15
16
 
16
- setup.relation(:users) do
17
+ configuration.relation(:users) do
17
18
  def with_tasks
18
19
  join(tasks)
19
20
  end
20
21
  end
21
22
  end
22
23
 
23
- let(:rom) { setup.finalize }
24
+ let(:container) { ROM.container(configuration) }
24
25
  let(:actual) do
25
- rom.relation(:users).with_tasks.map_with(:users).to_a
26
+ container.relation(:users).with_tasks.map_with(:users).to_a
26
27
  end
27
28
 
28
29
  it 'groups all attributes and folds the first key' do
29
- setup.mappers do
30
+ configuration.mappers do
30
31
  define(:users) do
31
32
  fold tasks: [:title, :priority]
32
33
  end
@@ -39,7 +40,7 @@ describe 'Mapper definition DSL' do
39
40
  end
40
41
 
41
42
  it 'is sensitive to the order of keys' do
42
- setup.mappers do
43
+ configuration.mappers do
43
44
  define(:users) do
44
45
  fold priorities: [:priority, :title]
45
46
  end
@@ -52,7 +53,7 @@ describe 'Mapper definition DSL' do
52
53
  end
53
54
 
54
55
  it 'accepts the block syntax' do
55
- setup.mappers do
56
+ configuration.mappers do
56
57
  define(:users) do
57
58
  fold :priorities do
58
59
  attribute :priority
@@ -1,25 +1,26 @@
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
  describe 'grouped relation mapper' do
9
10
  before do
10
- setup.relation(:tasks) do
11
+ configuration.relation(:tasks) do
11
12
  def with_users
12
13
  join(users)
13
14
  end
14
15
  end
15
16
 
16
- setup.relation(:users) do
17
+ configuration.relation(:users) do
17
18
  def with_tasks
18
19
  join(tasks)
19
20
  end
20
21
  end
21
22
 
22
- setup.mappers do
23
+ configuration.mappers do
23
24
  define(:users) do
24
25
  model name: 'Test::User'
25
26
 
@@ -30,7 +31,7 @@ describe 'Mapper definition DSL' do
30
31
  end
31
32
 
32
33
  it 'allows defining grouped attributes via options hash' do
33
- setup.mappers do
34
+ configuration.mappers do
34
35
  define(:with_tasks, parent: :users) do
35
36
  model name: 'Test::UserWithTasks'
36
37
 
@@ -41,11 +42,11 @@ describe 'Mapper definition DSL' do
41
42
  end
42
43
  end
43
44
 
44
- rom = setup.finalize
45
+ container
45
46
 
46
47
  Test::UserWithTasks.send(:include, Equalizer.new(:name, :email, :tasks))
47
48
 
48
- jane = rom.relation(:users).with_tasks.map_with(:with_tasks).to_a.last
49
+ jane = container.relation(:users).with_tasks.map_with(:with_tasks).to_a.last
49
50
 
50
51
  expect(jane).to eql(
51
52
  Test::UserWithTasks.new(
@@ -57,7 +58,7 @@ describe 'Mapper definition DSL' do
57
58
  end
58
59
 
59
60
  it 'allows defining grouped attributes via block' do
60
- setup.mappers do
61
+ configuration.mappers do
61
62
  define(:with_tasks, parent: :users) do
62
63
  model name: 'Test::UserWithTasks'
63
64
 
@@ -71,11 +72,11 @@ describe 'Mapper definition DSL' do
71
72
  end
72
73
  end
73
74
 
74
- rom = setup.finalize
75
+ container
75
76
 
76
77
  Test::UserWithTasks.send(:include, Equalizer.new(:name, :email, :tasks))
77
78
 
78
- jane = rom.relation(:users).with_tasks.map_with(:with_tasks).to_a.last
79
+ jane = container.relation(:users).with_tasks.map_with(:with_tasks).to_a.last
79
80
 
80
81
  expect(jane).to eql(
81
82
  Test::UserWithTasks.new(
@@ -87,7 +88,7 @@ describe 'Mapper definition DSL' do
87
88
  end
88
89
 
89
90
  it 'allows defining grouped attributes mapped to a model via block' do
90
- setup.mappers do
91
+ configuration.mappers do
91
92
  define(:with_tasks, parent: :users) do
92
93
  model name: 'Test::UserWithTasks'
93
94
 
@@ -103,12 +104,12 @@ describe 'Mapper definition DSL' do
103
104
  end
104
105
  end
105
106
 
106
- rom = setup.finalize
107
+ container
107
108
 
108
109
  Test::UserWithTasks.send(:include, Equalizer.new(:name, :email, :tasks))
109
110
  Test::Task.send(:include, Equalizer.new(:title, :priority))
110
111
 
111
- jane = rom.relation(:users).with_tasks.map_with(:with_tasks).to_a.last
112
+ jane = container.relation(:users).with_tasks.map_with(:with_tasks).to_a.last
112
113
 
113
114
  expect(jane).to eql(
114
115
  Test::UserWithTasks.new(
@@ -120,7 +121,7 @@ describe 'Mapper definition DSL' do
120
121
  end
121
122
 
122
123
  it 'allows defining nested grouped attributes mapped to a model via block' do
123
- setup.mappers do
124
+ configuration.mappers do
124
125
  define(:tasks)
125
126
 
126
127
  define(:with_users, parent: :tasks, inherit_header: false) do
@@ -142,13 +143,13 @@ describe 'Mapper definition DSL' do
142
143
  end
143
144
  end
144
145
 
145
- rom = setup.finalize
146
+ container
146
147
 
147
148
  Test::TaskWithUsers.send(:include, Equalizer.new(:title, :priority, :users))
148
149
  Test::TaskUser.send(:include, Equalizer.new(:name, :contacts))
149
150
  Test::Contact.send(:include, Equalizer.new(:email))
150
151
 
151
- task = rom.relation(:tasks).with_users.map_with(:with_users).first
152
+ task = container.relation(:tasks).with_users.map_with(:with_users).first
152
153
 
153
154
  expect(task).to eql(
154
155
  Test::TaskWithUsers.new(title: 'be nice', priority: 1, users: [
@@ -2,10 +2,10 @@ require 'spec_helper'
2
2
  require 'rom/memory'
3
3
 
4
4
  describe 'Mappers / Attributes value' do
5
- let(:setup) { ROM.setup(:memory) }
5
+ include_context 'container'
6
6
 
7
7
  before do
8
- setup.relation(:users)
8
+ configuration.relation(:users)
9
9
  end
10
10
 
11
11
  it 'allows to manipulate attribute value' do
@@ -24,15 +24,15 @@ describe 'Mappers / Attributes value' do
24
24
  end
25
25
  end
26
26
 
27
- rom = setup.finalize
27
+ configuration.register_mapper(Test::UserMapper)
28
28
 
29
- rom.relations.users << {
29
+ container.relations.users << {
30
30
  id: 123,
31
31
  first_name: 'Jane',
32
32
  weight: 75
33
33
  }
34
34
 
35
- jane = rom.relation(:users).as(:users).first
35
+ jane = container.relation(:users).as(:users).first
36
36
 
37
37
  expect(jane).to eql(id: 123, name: 'John', weight: 90, age: 18)
38
38
  end
@@ -2,13 +2,12 @@ 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
  users.insert(
13
12
  user_id: 1,
14
13
  user_name: 'Joe',
@@ -19,12 +18,11 @@ describe 'Mapper definition DSL' do
19
18
  end
20
19
 
21
20
  describe 'prefix' do
22
- subject(:mapped_users) { rom.relation(:users).as(:users).to_a }
21
+ subject(:mapped_users) { container.relation(:users).as(:users).to_a }
23
22
 
24
23
  it 'applies new separator to the attributes following it' do
25
- setup.mappers do
24
+ configuration.mappers do
26
25
  define(:users) do
27
-
28
26
  prefix :user
29
27
  attribute :id
30
28
  attribute :name
@@ -2,13 +2,12 @@ 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
  users.insert(
13
12
  user_id: 1,
14
13
  user_name: 'Joe',
@@ -19,12 +18,11 @@ describe 'Mapper definition DSL' do
19
18
  end
20
19
 
21
20
  describe 'prefix' do
22
- subject(:mapped_users) { rom.relation(:users).as(:users).to_a }
21
+ subject(:mapped_users) { container.relation(:users).as(:users).to_a }
23
22
 
24
23
  it 'applies new prefix to the attributes following it' do
25
- setup.mappers do
24
+ configuration.mappers do
26
25
  define(:users) do
27
-
28
26
  prefix :user
29
27
  attribute :id
30
28
  attribute :name
@@ -2,10 +2,10 @@ require 'spec_helper'
2
2
  require 'rom/memory'
3
3
 
4
4
  describe 'Mappers / Prefixing attributes' do
5
- let(:setup) { ROM.setup(:memory) }
5
+ include_context 'container'
6
6
 
7
7
  before do
8
- setup.relation(:users)
8
+ configuration.relation(:users)
9
9
  end
10
10
 
11
11
  it 'automatically maps all attributes using the provided prefix' do
@@ -20,17 +20,17 @@ describe 'Mappers / Prefixing attributes' do
20
20
  attribute :email
21
21
  end
22
22
 
23
- rom = setup.finalize
23
+ configuration.register_mapper(Test::UserMapper)
24
24
 
25
- Test::User.send(:include, Equalizer.new(:id, :name, :email))
26
-
27
- rom.relations.users << {
25
+ container.relations.users << {
28
26
  user_id: 123,
29
27
  user_name: 'Jane',
30
28
  user_email: 'jane@doe.org'
31
29
  }
32
30
 
33
- jane = rom.relation(:users).as(:users).first
31
+ Test::User.send(:include, Equalizer.new(:id, :name, :email))
32
+
33
+ jane = container.relation(:users).as(:users).first
34
34
 
35
35
  expect(jane).to eql(Test::User.new(id: 123, name: 'Jane', email: 'jane@doe.org'))
36
36
  end
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'Registering Custom Mappers' do
4
+ include_context 'container'
4
5
  include_context 'users and tasks'
5
6
 
6
7
  it 'allows registering arbitrary objects as mappers' do
@@ -10,19 +11,17 @@ describe 'Registering Custom Mappers' do
10
11
  users.map { |tuple| model.new(*tuple.values_at(:name, :email)) }
11
12
  }
12
13
 
13
- setup.relation(:users) do
14
+ configuration.relation(:users) do
14
15
  def by_name(name)
15
16
  restrict(name: name)
16
17
  end
17
18
  end
18
19
 
19
- setup.mappers do
20
+ configuration.mappers do
20
21
  register(:users, entity: mapper)
21
22
  end
22
23
 
23
- rom = setup.finalize
24
-
25
- users = rom.relation(:users).by_name('Jane').as(:entity)
24
+ users = container.relation(:users).by_name('Jane').as(:entity)
26
25
 
27
26
  expect(users).to match_array([model.new('Jane', 'jane@doe.org')])
28
27
  end
@@ -2,12 +2,12 @@ require 'spec_helper'
2
2
  require 'rom/memory'
3
3
 
4
4
  describe 'Mappers / Renaming attributes' do
5
- let(:setup) { ROM.setup(:memory) }
5
+ include_context 'container'
6
6
 
7
7
  before do
8
- setup.relation(:addresses)
8
+ configuration.relation(:addresses)
9
9
 
10
- setup.relation(:users) do
10
+ configuration.relation(:users) do
11
11
  def with_address
12
12
  join(addresses)
13
13
  end
@@ -19,7 +19,7 @@ describe 'Mappers / Renaming attributes' do
19
19
  end
20
20
 
21
21
  it 'maps renamed attributes for a base relation' do
22
- setup.mappers do
22
+ configuration.mappers do
23
23
  define(:users) do
24
24
  model name: 'Test::User'
25
25
 
@@ -28,19 +28,19 @@ describe 'Mappers / Renaming attributes' do
28
28
  end
29
29
  end
30
30
 
31
- rom = setup.finalize
31
+ container
32
32
 
33
33
  Test::User.send(:include, Equalizer.new(:id, :name))
34
34
 
35
- rom.relations.users << { _id: 123, user_name: 'Jane' }
35
+ container.relations.users << { _id: 123, user_name: 'Jane' }
36
36
 
37
- jane = rom.relation(:users).as(:users).first
37
+ jane = container.relation(:users).as(:users).first
38
38
 
39
39
  expect(jane).to eql(Test::User.new(id: 123, name: 'Jane'))
40
40
  end
41
41
 
42
42
  it 'maps renamed attributes for a wrapped relation' do
43
- setup.mappers do
43
+ configuration.mappers do
44
44
  define(:users) do
45
45
  model name: 'Test::User'
46
46
 
@@ -61,16 +61,16 @@ describe 'Mappers / Renaming attributes' do
61
61
  end
62
62
  end
63
63
 
64
- rom = setup.finalize
64
+ container
65
65
 
66
66
  Test::UserWithAddress.send(:include, Equalizer.new(:id, :name, :address))
67
67
 
68
- rom.relations.users << { _id: 123, user_name: 'Jane' }
68
+ container.relations.users << { _id: 123, user_name: 'Jane' }
69
69
 
70
- rom.relations.addresses <<
70
+ container.relations.addresses <<
71
71
  { _id: 123, address_id: 321, address_street: 'Street 1' }
72
72
 
73
- jane = rom.relation(:users).with_address.as(:with_address).first
73
+ jane = container.relation(:users).with_address.as(:with_address).first
74
74
 
75
75
  expect(jane).to eql(
76
76
  Test::UserWithAddress.new(id: 123, name: 'Jane',
@@ -79,7 +79,7 @@ describe 'Mappers / Renaming attributes' do
79
79
  end
80
80
 
81
81
  it 'maps renamed attributes for a grouped relation' do
82
- setup.mappers do
82
+ configuration.mappers do
83
83
  define(:users) do
84
84
  model name: 'Test::User'
85
85
 
@@ -100,18 +100,18 @@ describe 'Mappers / Renaming attributes' do
100
100
  end
101
101
  end
102
102
 
103
- rom = setup.finalize
103
+ container
104
104
 
105
105
  Test::UserWithAddresses.send(:include, Equalizer.new(:id, :name, :addresses))
106
106
 
107
- rom.relations.users << { _id: 123, user_name: 'Jane' }
107
+ container.relations.users << { _id: 123, user_name: 'Jane' }
108
108
 
109
- rom.relations.addresses <<
109
+ container.relations.addresses <<
110
110
  { _id: 123, address_id: 321, address_street: 'Street 1' }
111
- rom.relations.addresses <<
111
+ container.relations.addresses <<
112
112
  { _id: 123, address_id: 654, address_street: 'Street 2' }
113
113
 
114
- jane = rom.relation(:users).with_addresses.as(:with_addresses).first
114
+ jane = container.relation(:users).with_addresses.as(:with_addresses).first
115
115
 
116
116
  expect(jane).to eql(
117
117
  Test::UserWithAddresses.new(
@@ -1,13 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'Mapper definition DSL' do
4
- let(:setup) { ROM.setup(:memory) }
5
- let(:rom) { ROM.finalize.env }
4
+ include_context 'container'
5
+ include_context 'users and tasks'
6
6
 
7
7
  before do
8
- setup.relation(:lists)
8
+ configuration.relation(:lists)
9
9
 
10
- setup.default.dataset(:lists).insert(
10
+ configuration.default.dataset(:lists).insert(
11
11
  list_id: 1,
12
12
  list_tasks: [
13
13
  { user: 'Jacob', task_id: 1, task_title: 'be nice' },
@@ -17,10 +17,10 @@ describe 'Mapper definition DSL' do
17
17
  end
18
18
 
19
19
  describe 'step' do
20
- let(:mapped) { rom.relation(:lists).as(:lists).to_a }
20
+ let(:mapped) { container.relation(:lists).as(:lists).to_a }
21
21
 
22
22
  it 'applies transformations one by one' do
23
- setup.mappers do
23
+ configuration.mappers do
24
24
  define(:lists) do
25
25
  step do
26
26
  prefix 'list'
@@ -68,9 +68,8 @@ describe 'Mapper definition DSL' do
68
68
  end
69
69
 
70
70
  it 'applies settings from root' do
71
- setup.mappers do
71
+ configuration.mappers do
72
72
  define(:lists) do
73
-
74
73
  prefix 'list'
75
74
 
76
75
  step do
@@ -92,7 +91,7 @@ describe 'Mapper definition DSL' do
92
91
  end
93
92
 
94
93
  it 'cannot precede attributes' do
95
- setup.mappers do
94
+ configuration.mappers do
96
95
  define(:lists) do
97
96
  step do
98
97
  unfold :tasks, from: :list_tasks
@@ -101,11 +100,11 @@ describe 'Mapper definition DSL' do
101
100
  end
102
101
  end
103
102
 
104
- expect { rom }.to raise_error ROM::MapperMisconfiguredError
103
+ expect { container }.to raise_error ROM::MapperMisconfiguredError
105
104
  end
106
105
 
107
106
  it 'cannot succeed attributes' do
108
- setup.mappers do
107
+ configuration.mappers do
109
108
  define(:lists) do
110
109
  attribute :id, from: :list_id
111
110
  step do
@@ -114,7 +113,7 @@ describe 'Mapper definition DSL' do
114
113
  end
115
114
  end
116
115
 
117
- expect { rom }.to raise_error ROM::MapperMisconfiguredError
116
+ expect { container }.to raise_error ROM::MapperMisconfiguredError
118
117
  end
119
118
  end
120
119
  end