rom 0.5.0 → 0.6.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +19 -15
  3. data/.rubocop_todo.yml +28 -0
  4. data/.travis.yml +8 -1
  5. data/CHANGELOG.md +40 -0
  6. data/Gemfile +10 -2
  7. data/Guardfile +12 -10
  8. data/README.md +42 -43
  9. data/Rakefile +13 -23
  10. data/lib/rom.rb +19 -27
  11. data/lib/rom/command.rb +118 -0
  12. data/lib/rom/command_registry.rb +13 -27
  13. data/lib/rom/commands.rb +1 -59
  14. data/lib/rom/commands/abstract.rb +147 -0
  15. data/lib/rom/commands/composite.rb +47 -0
  16. data/lib/rom/commands/create.rb +2 -17
  17. data/lib/rom/commands/delete.rb +5 -25
  18. data/lib/rom/commands/result.rb +5 -5
  19. data/lib/rom/commands/update.rb +3 -27
  20. data/lib/rom/constants.rb +19 -0
  21. data/lib/rom/env.rb +85 -35
  22. data/lib/rom/global.rb +173 -42
  23. data/lib/rom/header.rb +5 -5
  24. data/lib/rom/header/attribute.rb +2 -2
  25. data/lib/rom/lint/enumerable_dataset.rb +52 -0
  26. data/lib/rom/lint/linter.rb +64 -0
  27. data/lib/rom/lint/repository.rb +78 -0
  28. data/lib/rom/lint/spec.rb +20 -0
  29. data/lib/rom/lint/test.rb +98 -0
  30. data/lib/rom/mapper.rb +32 -5
  31. data/lib/rom/mapper/attribute_dsl.rb +240 -0
  32. data/lib/rom/mapper/dsl.rb +100 -0
  33. data/lib/rom/mapper/model_dsl.rb +55 -0
  34. data/lib/rom/mapper_registry.rb +8 -1
  35. data/lib/rom/memory.rb +4 -0
  36. data/lib/rom/memory/commands.rb +46 -0
  37. data/lib/rom/memory/dataset.rb +72 -0
  38. data/lib/rom/memory/relation.rb +44 -0
  39. data/lib/rom/memory/repository.rb +62 -0
  40. data/lib/rom/memory/storage.rb +57 -0
  41. data/lib/rom/model_builder.rb +44 -5
  42. data/lib/rom/processor.rb +1 -1
  43. data/lib/rom/processor/transproc.rb +109 -16
  44. data/lib/rom/reader.rb +91 -39
  45. data/lib/rom/relation.rb +165 -26
  46. data/lib/rom/relation/composite.rb +132 -0
  47. data/lib/rom/relation/curried.rb +48 -0
  48. data/lib/rom/relation/lazy.rb +173 -0
  49. data/lib/rom/relation/loaded.rb +75 -0
  50. data/lib/rom/relation/registry_reader.rb +23 -0
  51. data/lib/rom/repository.rb +93 -34
  52. data/lib/rom/setup.rb +54 -98
  53. data/lib/rom/setup/finalize.rb +85 -76
  54. data/lib/rom/setup_dsl/command.rb +36 -0
  55. data/lib/rom/setup_dsl/command_dsl.rb +34 -0
  56. data/lib/rom/setup_dsl/mapper.rb +32 -0
  57. data/lib/rom/setup_dsl/mapper_dsl.rb +30 -0
  58. data/lib/rom/setup_dsl/relation.rb +21 -0
  59. data/lib/rom/setup_dsl/setup.rb +75 -0
  60. data/lib/rom/support/array_dataset.rb +38 -0
  61. data/lib/rom/support/class_builder.rb +44 -0
  62. data/lib/rom/support/class_macros.rb +56 -0
  63. data/lib/rom/support/data_proxy.rb +102 -0
  64. data/lib/rom/support/enumerable_dataset.rb +58 -0
  65. data/lib/rom/support/inflector.rb +73 -0
  66. data/lib/rom/support/options.rb +188 -0
  67. data/lib/rom/support/registry.rb +4 -8
  68. data/lib/rom/version.rb +1 -1
  69. data/rakelib/benchmark.rake +13 -0
  70. data/rakelib/mutant.rake +16 -0
  71. data/rakelib/rubocop.rake +18 -0
  72. data/rom.gemspec +4 -7
  73. data/spec/integration/commands/create_spec.rb +32 -24
  74. data/spec/integration/commands/delete_spec.rb +15 -7
  75. data/spec/integration/commands/update_spec.rb +13 -11
  76. data/spec/integration/mappers/deep_embedded_spec.rb +4 -11
  77. data/spec/integration/mappers/definition_dsl_spec.rb +31 -44
  78. data/spec/integration/mappers/embedded_spec.rb +9 -24
  79. data/spec/integration/mappers/group_spec.rb +22 -30
  80. data/spec/integration/mappers/prefixing_attributes_spec.rb +18 -23
  81. data/spec/integration/mappers/renaming_attributes_spec.rb +23 -38
  82. data/spec/integration/mappers/symbolizing_attributes_spec.rb +18 -24
  83. data/spec/integration/mappers/wrap_spec.rb +22 -30
  84. data/spec/integration/multi_repo_spec.rb +15 -37
  85. data/spec/integration/relations/reading_spec.rb +82 -14
  86. data/spec/integration/repositories/extending_relations_spec.rb +50 -0
  87. data/spec/integration/{adapters → repositories}/setting_logger_spec.rb +6 -5
  88. data/spec/integration/setup_spec.rb +59 -62
  89. data/spec/shared/enumerable_dataset.rb +49 -0
  90. data/spec/shared/one_behavior.rb +26 -0
  91. data/spec/shared/users_and_tasks.rb +11 -23
  92. data/spec/spec_helper.rb +16 -7
  93. data/spec/support/constant_leak_finder.rb +14 -0
  94. data/spec/test/memory_repository_lint_test.rb +27 -0
  95. data/spec/unit/rom/command_registry_spec.rb +44 -0
  96. data/spec/unit/rom/commands/result_spec.rb +14 -0
  97. data/spec/unit/rom/commands_spec.rb +174 -0
  98. data/spec/unit/rom/env_spec.rb +40 -7
  99. data/spec/unit/rom/global_spec.rb +14 -0
  100. data/spec/unit/rom/{mapper_builder_spec.rb → mapper/dsl_spec.rb} +52 -38
  101. data/spec/unit/rom/mapper_spec.rb +51 -10
  102. data/spec/unit/rom/{adapter/memory → memory}/dataset_spec.rb +6 -4
  103. data/spec/unit/rom/memory/repository_spec.rb +12 -0
  104. data/spec/unit/rom/memory/storage_spec.rb +45 -0
  105. data/spec/unit/rom/model_builder_spec.rb +4 -3
  106. data/spec/unit/rom/processor/transproc_spec.rb +1 -0
  107. data/spec/unit/rom/reader_spec.rb +97 -24
  108. data/spec/unit/rom/relation/composite_spec.rb +65 -0
  109. data/spec/unit/rom/relation/lazy_spec.rb +145 -0
  110. data/spec/unit/rom/relation/loaded_spec.rb +28 -0
  111. data/spec/unit/rom/relation_spec.rb +111 -6
  112. data/spec/unit/rom/repository_spec.rb +59 -9
  113. data/spec/unit/rom/setup_spec.rb +99 -11
  114. data/spec/unit/rom/support/array_dataset_spec.rb +59 -0
  115. data/spec/unit/rom/support/class_builder_spec.rb +42 -0
  116. data/spec/unit/rom/support/enumerable_dataset_spec.rb +17 -0
  117. data/spec/unit/rom/support/inflector_spec.rb +89 -0
  118. data/spec/unit/rom/support/options_spec.rb +119 -0
  119. metadata +74 -112
  120. data/lib/rom/adapter.rb +0 -191
  121. data/lib/rom/adapter/memory.rb +0 -32
  122. data/lib/rom/adapter/memory/commands.rb +0 -31
  123. data/lib/rom/adapter/memory/dataset.rb +0 -67
  124. data/lib/rom/adapter/memory/storage.rb +0 -26
  125. data/lib/rom/commands/with_options.rb +0 -18
  126. data/lib/rom/config.rb +0 -70
  127. data/lib/rom/mapper_builder.rb +0 -52
  128. data/lib/rom/mapper_builder/mapper_dsl.rb +0 -114
  129. data/lib/rom/mapper_builder/model_dsl.rb +0 -29
  130. data/lib/rom/reader_builder.rb +0 -48
  131. data/lib/rom/relation_builder.rb +0 -62
  132. data/lib/rom/setup/base_relation_dsl.rb +0 -46
  133. data/lib/rom/setup/command_dsl.rb +0 -46
  134. data/lib/rom/setup/mapper_dsl.rb +0 -19
  135. data/lib/rom/setup/relation_dsl.rb +0 -20
  136. data/lib/rom/setup/schema_dsl.rb +0 -33
  137. data/spec/integration/adapters/extending_relations_spec.rb +0 -41
  138. data/spec/integration/commands/try_spec.rb +0 -27
  139. data/spec/integration/schema_spec.rb +0 -77
  140. data/spec/unit/config_spec.rb +0 -60
  141. data/spec/unit/rom/adapter_spec.rb +0 -79
  142. data/spec/unit/rom_spec.rb +0 -14
@@ -19,7 +19,7 @@ module ROM
19
19
 
20
20
  def each(&block)
21
21
  return to_enum unless block
22
- elements.each(&block)
22
+ elements.each { |element| yield(element) }
23
23
  end
24
24
 
25
25
  def [](key)
@@ -27,17 +27,13 @@ module ROM
27
27
  end
28
28
 
29
29
  def respond_to_missing?(name, include_private = false)
30
- key?(name) || super
30
+ elements.key?(name) || super
31
31
  end
32
32
 
33
33
  private
34
34
 
35
- def method_missing(name, *args)
36
- if elements.key?(name)
37
- self[name]
38
- else
39
- super
40
- end
35
+ def method_missing(name, *)
36
+ elements.fetch(name) { super }
41
37
  end
42
38
  end
43
39
  end
data/lib/rom/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ROM
2
- VERSION = '0.5.0'.freeze
2
+ VERSION = '0.6.0.beta1'.freeze
3
3
  end
@@ -0,0 +1,13 @@
1
+ desc "Run benchmarks (tweak count via COUNT envvar)"
2
+ task :benchmark do
3
+ sh "ruby benchmarks/basic.rb"
4
+ end
5
+
6
+ namespace :benchmark do
7
+ desc "Verify benchmarks"
8
+ task :verify do
9
+ ENV['VERIFY'] = "true"
10
+ ENV['COUNT'] = "1"
11
+ Rake::Task[:benchmark].invoke
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ desc "Run mutant against a specific subject"
2
+ task :mutant do
3
+ subject = ARGV.last
4
+ if subject == 'mutant'
5
+ abort "usage: rake mutant SUBJECT\nexample: rake mutant ROM::Header"
6
+ else
7
+ opts = {
8
+ 'include' => 'lib',
9
+ 'require' => 'rom',
10
+ 'use' => 'rspec',
11
+ 'ignore-subject' => "#{subject}#respond_to_missing?"
12
+ }.to_a.map { |k, v| "--#{k} #{v}" }.join(' ')
13
+
14
+ exec("bundle exec mutant #{opts} #{subject}")
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ begin
2
+ require "rubocop/rake_task"
3
+
4
+ Rake::Task[:default].enhance [:rubocop]
5
+
6
+ RuboCop::RakeTask.new do |task|
7
+ task.options << "--display-cop-names"
8
+ end
9
+
10
+ namespace :rubocop do
11
+ desc 'Generate a configuration file acting as a TODO list.'
12
+ task :auto_gen_config do
13
+ exec "bundle exec rubocop --auto-gen-config"
14
+ end
15
+ end
16
+
17
+ rescue LoadError
18
+ end
data/rom.gemspec CHANGED
@@ -14,16 +14,13 @@ Gem::Specification.new do |gem|
14
14
  gem.files = `git ls-files`.split("\n").reject { |name| name.include?('benchmarks') }
15
15
  gem.test_files = `git ls-files -- {spec}/*`.split("\n")
16
16
  gem.license = 'MIT'
17
+ gem.required_ruby_version = '~> 2.0'
17
18
 
18
- gem.add_runtime_dependency 'addressable', '~> 2.3'
19
19
  gem.add_runtime_dependency 'transproc', '~> 0.1'
20
20
  gem.add_runtime_dependency 'equalizer', '~> 0.0', '>= 0.0.9'
21
- gem.add_runtime_dependency 'concord', '~> 0.1', '>= 0.1.4'
22
- gem.add_runtime_dependency 'charlatan', '~> 0.1', '>= 0.1'
23
- gem.add_runtime_dependency 'inflecto', '~> 0.0', '>= 0.0.2'
24
21
 
25
22
  gem.add_development_dependency 'rake', '~> 10.3'
26
- gem.add_development_dependency 'rspec-core', '~> 3.1'
27
- gem.add_development_dependency 'rspec-mocks', '~> 3.1'
28
- gem.add_development_dependency 'rspec-expectations', '~> 3.1'
23
+ gem.add_development_dependency 'rspec-core', '~> 3.2'
24
+ gem.add_development_dependency 'rspec-mocks', '~> 3.2'
25
+ gem.add_development_dependency 'rspec-expectations', '~> 3.2'
29
26
  end
@@ -7,12 +7,14 @@ describe 'Commands / Create' do
7
7
  let(:tasks) { rom.commands.tasks }
8
8
 
9
9
  before do
10
- UserValidator = Class.new do
11
- ValidationError = Class.new(ROM::CommandError)
10
+ module Test
11
+ UserValidator = Class.new do
12
+ ValidationError = Class.new(ROM::CommandError)
12
13
 
13
- def self.call(params)
14
- unless params[:name] && params[:email]
15
- raise ValidationError, ":name and :email are required"
14
+ def self.call(params)
15
+ unless params[:name] && params[:email]
16
+ raise ValidationError, ":name and :email are required"
17
+ end
16
18
  end
17
19
  end
18
20
  end
@@ -20,40 +22,46 @@ describe 'Commands / Create' do
20
22
  setup.relation(:users)
21
23
  setup.relation(:tasks)
22
24
 
23
- setup.commands(:users) do
24
- define(:create) do
25
- validator UserValidator
26
- end
25
+ class Test::CreateUser < ROM::Commands::Create[:memory]
26
+ relation :users
27
+ register_as :create
28
+ result :one
29
+ validator Test::UserValidator
27
30
  end
28
31
 
29
- setup.commands(:tasks) do
30
- define(:create)
32
+ class Test::CreateTask < ROM::Commands::Create[:memory]
33
+ relation :tasks
34
+ register_as :create
35
+ result :one
36
+
37
+ def execute(user, task)
38
+ super(task.merge(name: user[:name]))
39
+ end
31
40
  end
32
41
  end
33
42
 
34
43
  it 'inserts user on successful validation' do
35
- result = users.try { create(name: 'Piotr', email: 'piotr@solnic.eu') }
44
+ result = users.try do
45
+ users.create.call(name: 'Piotr', email: 'piotr@solnic.eu')
46
+ end
36
47
 
37
- expect(result).to match_array([{ name: 'Piotr', email: 'piotr@solnic.eu' }])
48
+ expect(result.value).to eql(name: 'Piotr', email: 'piotr@solnic.eu')
38
49
  end
39
50
 
40
51
  it 'inserts user and associated task when things go well' do
41
52
  result = users.try {
42
- create(name: 'Piotr', email: 'piotr@solnic.eu')
43
- } >-> users {
44
- tasks.try {
45
- create(name: users.first[:name], title: 'Finish command-api')
46
- }
53
+ command = users.create.with(name: 'Piotr', email: 'piotr@solnic.eu')
54
+ command >>= tasks.create.with(title: 'Finish command-api')
55
+ command
47
56
  }
48
57
 
49
- expect(result)
50
- .to match_array([{ name: 'Piotr', title: 'Finish command-api' }])
58
+ expect(result.value).to eql(name: 'Piotr', title: 'Finish command-api')
51
59
  end
52
60
 
53
61
  it 'returns validation object with errors on failed validation' do
54
- result = users.try { create(name: 'Piotr') }
62
+ result = users.try { users.create.call(name: 'Piotr') }
55
63
 
56
- expect(result.error).to be_instance_of(ValidationError)
64
+ expect(result.error).to be_instance_of(Test::ValidationError)
57
65
  expect(result.error.message).to eql(":name and :email are required")
58
66
  expect(rom.relations.users.count).to be(2)
59
67
  end
@@ -69,7 +77,7 @@ describe 'Commands / Create' do
69
77
  tuple = { name: 'Piotr', email: 'piotr@solnic.eu' }
70
78
 
71
79
  result = users.try {
72
- create_one(tuple)
80
+ users.create_one.call(tuple)
73
81
  }
74
82
 
75
83
  expect(result.value).to eql(tuple)
@@ -83,7 +91,7 @@ describe 'Commands / Create' do
83
91
  end
84
92
  end
85
93
  setup.finalize
86
- }.to raise_error(ROM::InvalidOptionError)
94
+ }.to raise_error(ROM::InvalidOptionValueError)
87
95
  end
88
96
  end
89
97
  end
@@ -11,14 +11,14 @@ describe 'Commands / Delete' do
11
11
  restrict(name: name)
12
12
  end
13
13
  end
14
+ end
14
15
 
16
+ it 'deletes all tuples when there is no restriction' do
15
17
  setup.commands(:users) do
16
18
  define(:delete)
17
19
  end
18
- end
19
20
 
20
- it 'deletes all tuples when there is no restriction' do
21
- result = users.try { delete }
21
+ result = users.try { users.delete.call }
22
22
 
23
23
  expect(result).to match_array([
24
24
  { name: 'Jane', email: 'jane@doe.org' },
@@ -27,13 +27,21 @@ describe 'Commands / Delete' do
27
27
  end
28
28
 
29
29
  it 'deletes tuples matching restriction' do
30
- result = users.try { delete(:by_name, 'Joe') }
30
+ setup.commands(:users) do
31
+ define(:delete)
32
+ end
33
+
34
+ result = users.try { users.delete.by_name('Joe').call }
31
35
 
32
36
  expect(result).to match_array([{ name: 'Joe', email: 'joe@doe.org' }])
33
37
  end
34
38
 
35
39
  it 'returns untouched relation if there are no tuples to delete' do
36
- result = users.try { delete(:by_name, 'Not here') }
40
+ setup.commands(:users) do
41
+ define(:delete)
42
+ end
43
+
44
+ result = users.try { users.delete.by_name('Not here').call }
37
45
 
38
46
  expect(result).to match_array([])
39
47
  end
@@ -45,7 +53,7 @@ describe 'Commands / Delete' do
45
53
  end
46
54
  end
47
55
 
48
- result = users.try { delete_one(:by_name, 'Jane') }
56
+ result = users.try { users.delete_one.by_name('Jane').call }
49
57
 
50
58
  expect(result.value).to eql(name: 'Jane', email: 'jane@doe.org')
51
59
  end
@@ -57,7 +65,7 @@ describe 'Commands / Delete' do
57
65
  end
58
66
  end
59
67
 
60
- result = users.try { delete }
68
+ result = users.try { users.delete.call }
61
69
 
62
70
  expect(result.error).to be_instance_of(ROM::TupleCountMismatchError)
63
71
 
@@ -8,11 +8,13 @@ describe 'Commands / Update' do
8
8
  subject(:users) { rom.commands.users }
9
9
 
10
10
  before do
11
- UserValidator = Class.new do
12
- ValidationError = Class.new(ROM::CommandError)
11
+ module Test
12
+ UserValidator = Class.new do
13
+ ValidationError = Class.new(ROM::CommandError)
13
14
 
14
- def self.call(params)
15
- raise ValidationError, ":email is required" unless params[:email]
15
+ def self.call(params)
16
+ raise ValidationError, ":email is required" unless params[:email]
17
+ end
16
18
  end
17
19
  end
18
20
 
@@ -28,14 +30,14 @@ describe 'Commands / Update' do
28
30
 
29
31
  setup.commands(:users) do
30
32
  define(:update) do
31
- validator UserValidator
33
+ validator Test::UserValidator
32
34
  end
33
35
  end
34
36
  end
35
37
 
36
38
  it 'update tuples on successful validation' do
37
39
  result = users.try {
38
- update(:all, name: 'Jane').set(email: 'jane.doe@test.com')
40
+ users.update.all(name: 'Jane').set(email: 'jane.doe@test.com')
39
41
  }
40
42
 
41
43
  expect(result)
@@ -43,9 +45,9 @@ describe 'Commands / Update' do
43
45
  end
44
46
 
45
47
  it 'returns validation object with errors on failed validation' do
46
- result = users.try { update(:all, name: 'Jane').set(email: nil) }
48
+ result = users.try { users.update.all(name: 'Jane').set(email: nil) }
47
49
 
48
- expect(result.error).to be_instance_of(ValidationError)
50
+ expect(result.error).to be_instance_of(Test::ValidationError)
49
51
  expect(result.error.message).to eql(':email is required')
50
52
 
51
53
  expect(rom.relations.users.restrict(name: 'Jane')).to match_array([
@@ -62,7 +64,7 @@ describe 'Commands / Update' do
62
64
  end
63
65
 
64
66
  result = users.try {
65
- update_one(:by_name, 'Jane').set(email: 'jane.doe@test.com')
67
+ users.update_one.by_name('Jane').set(email: 'jane.doe@test.com')
66
68
  }
67
69
 
68
70
  expect(result.value).to eql(name: 'Jane', email: 'jane.doe@test.com')
@@ -76,7 +78,7 @@ describe 'Commands / Update' do
76
78
  end
77
79
 
78
80
  result = users.try {
79
- update_one.set(email: 'jane.doe@test.com')
81
+ users.update_one.set(email: 'jane.doe@test.com')
80
82
  }
81
83
 
82
84
  expect(result.error).to be_instance_of(ROM::TupleCountMismatchError)
@@ -95,7 +97,7 @@ describe 'Commands / Update' do
95
97
  end
96
98
  end
97
99
  setup.finalize
98
- }.to raise_error(ROM::InvalidOptionError)
100
+ }.to raise_error(ROM::InvalidOptionValueError)
99
101
  end
100
102
  end
101
103
  end
@@ -1,23 +1,16 @@
1
1
  require 'spec_helper'
2
+ require 'rom/memory'
2
3
 
3
4
  describe 'Mappers / deeply embedded tuples' do
4
- let(:setup) { ROM.setup('memory://test') }
5
+ let(:setup) { ROM.setup(:memory) }
5
6
  let(:rom) { setup.finalize }
6
7
 
7
8
  it 'allows mapping embedded tuples' do
8
- setup.schema do
9
- base_relation(:users) do
10
- repository :default
11
- attribute 'name'
12
- attribute 'tasks'
13
- end
14
- end
15
-
16
9
  setup.relation(:users)
17
10
 
18
11
  setup.mappers do
19
12
  define(:users) do
20
- model name: 'User'
13
+ model name: 'Test::User'
21
14
 
22
15
  attribute :name, from: 'name'
23
16
 
@@ -32,7 +25,7 @@ describe 'Mappers / deeply embedded tuples' do
32
25
  end
33
26
  end
34
27
 
35
- rom.schema.users << {
28
+ rom.relations.users << {
36
29
  'name' => 'Jane',
37
30
  'tasks' => [
38
31
  { 'title' => 'Task One', 'priority' => { 'value' => 1, 'desc' => 'high' } },
@@ -19,50 +19,38 @@ describe 'Mapper definition DSL' do
19
19
  before do
20
20
  setup.mappers do
21
21
  define(:users) do
22
- model name: 'User'
22
+ model name: 'Test::User'
23
+
24
+ attribute :name
25
+ attribute :email
23
26
  end
24
27
  end
25
28
  end
26
29
 
27
30
  it 'defines a constant for the model class' do
28
- expect(mapper.model).to be(User)
31
+ expect(mapper.model).to be(Test::User)
29
32
  end
30
33
 
31
- it 'uses all attributes from the relation header by default' do
32
- expect(header.keys).to eql(rom.relations.users.header)
34
+ it 'defines header with attributes' do
35
+ expect(header.keys).to eql([:name, :email])
33
36
  end
34
37
  end
35
38
 
36
39
  describe 'excluding attributes' do
37
- context 'using exclude' do
38
- subject(:mapper) { rom.read(:users).mapper }
39
-
40
- before do
41
- setup.mappers do
42
- define(:users) do
43
- model name: 'User'
44
-
45
- exclude :name
46
- end
47
- end
48
- end
49
-
50
- it 'only maps provided attributes' do
51
- expect(header.keys).to eql([:email])
52
- end
53
- end
54
-
55
40
  context 'by setting :inherit_header to false' do
56
41
  subject(:mapper) { rom.read(:users).email_index.mapper }
57
42
 
58
43
  before do
59
44
  setup.mappers do
60
45
  define(:users) do
61
- model name: 'User'
46
+ model name: 'Test::User'
47
+
48
+ attribute :name
49
+ attribute :email
62
50
  end
63
51
 
64
52
  define(:email_index, parent: :users, inherit_header: false) do
65
- model name: 'UserWithoutName'
53
+ model name: 'Test::UserWithoutName'
66
54
  attribute :email
67
55
  end
68
56
  end
@@ -80,13 +68,14 @@ describe 'Mapper definition DSL' do
80
68
  before do
81
69
  setup.mappers do
82
70
  define(:users) do
83
- model name: 'User'
71
+ model name: 'Test::User'
72
+
73
+ attribute :name
74
+ attribute :email
84
75
  end
85
- end
86
76
 
87
- setup.mappers do
88
77
  define(:email_index, parent: :users) do
89
- model name: 'UserWithoutName'
78
+ model name: 'Test::UserWithoutName'
90
79
  exclude :name
91
80
  end
92
81
  end
@@ -97,7 +86,7 @@ describe 'Mapper definition DSL' do
97
86
  end
98
87
 
99
88
  it 'builds a new model' do
100
- expect(mapper.model).to be(UserWithoutName)
89
+ expect(mapper.model).to be(Test::UserWithoutName)
101
90
  end
102
91
  end
103
92
 
@@ -109,11 +98,9 @@ describe 'Mapper definition DSL' do
109
98
  end
110
99
  end
111
100
 
112
- setup.relation(:users)
113
-
114
101
  setup.mappers do
115
102
  define(:tasks) do
116
- model name: 'Task'
103
+ model name: 'Test::Task'
117
104
 
118
105
  attribute :title
119
106
  attribute :priority
@@ -124,7 +111,7 @@ describe 'Mapper definition DSL' do
124
111
  it 'allows defining wrapped attributes via options hash' do
125
112
  setup.mappers do
126
113
  define(:with_user, parent: :tasks) do
127
- model name: 'TaskWithUser'
114
+ model name: 'Test::TaskWithUser'
128
115
 
129
116
  attribute :title
130
117
  attribute :priority
@@ -135,12 +122,12 @@ describe 'Mapper definition DSL' do
135
122
 
136
123
  rom = setup.finalize
137
124
 
138
- TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
125
+ Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
139
126
 
140
127
  jane = rom.read(:tasks).with_user.to_a.last
141
128
 
142
129
  expect(jane).to eql(
143
- TaskWithUser.new(
130
+ Test::TaskWithUser.new(
144
131
  title: 'be cool',
145
132
  priority: 2,
146
133
  user: { email: 'jane@doe.org' }
@@ -151,7 +138,7 @@ describe 'Mapper definition DSL' do
151
138
  it 'allows defining wrapped attributes via options block' do
152
139
  setup.mappers do
153
140
  define(:with_user, parent: :tasks) do
154
- model name: 'TaskWithUser'
141
+ model name: 'Test::TaskWithUser'
155
142
 
156
143
  attribute :title
157
144
  attribute :priority
@@ -164,12 +151,12 @@ describe 'Mapper definition DSL' do
164
151
 
165
152
  rom = setup.finalize
166
153
 
167
- TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
154
+ Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
168
155
 
169
156
  jane = rom.read(:tasks).with_user.to_a.last
170
157
 
171
158
  expect(jane).to eql(
172
- TaskWithUser.new(
159
+ Test::TaskWithUser.new(
173
160
  title: 'be cool',
174
161
  priority: 2,
175
162
  user: { email: 'jane@doe.org' }
@@ -180,13 +167,13 @@ describe 'Mapper definition DSL' do
180
167
  it 'allows defining wrapped attributes mapped to a model' do
181
168
  setup.mappers do
182
169
  define(:with_user, parent: :tasks) do
183
- model name: 'TaskWithUser'
170
+ model name: 'Test::TaskWithUser'
184
171
 
185
172
  attribute :title
186
173
  attribute :priority
187
174
 
188
175
  wrap :user do
189
- model name: 'User'
176
+ model name: 'Test::User'
190
177
  attribute :email
191
178
  end
192
179
  end
@@ -194,16 +181,16 @@ describe 'Mapper definition DSL' do
194
181
 
195
182
  rom = setup.finalize
196
183
 
197
- TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
198
- User.send(:include, Equalizer.new(:email))
184
+ Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
185
+ Test::User.send(:include, Equalizer.new(:email))
199
186
 
200
187
  jane = rom.read(:tasks).with_user.to_a.last
201
188
 
202
189
  expect(jane).to eql(
203
- TaskWithUser.new(
190
+ Test::TaskWithUser.new(
204
191
  title: 'be cool',
205
192
  priority: 2,
206
- user: User.new(email: 'jane@doe.org')
193
+ user: Test::User.new(email: 'jane@doe.org')
207
194
  )
208
195
  )
209
196
  end