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
@@ -0,0 +1,123 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe ROM::Environment do
4
+ let(:environment) { ROM::Environment.new(*params) }
5
+ let(:params) { [] }
6
+ let(:gateways) { environment.gateways }
7
+ let(:gateways_map) { environment.gateways_map }
8
+
9
+ context 'with an adapter identifier' do
10
+ let(:params) { [:memory] }
11
+
12
+ it 'configures the gateways hash' do
13
+ expect(gateways).to be_kind_of(Hash)
14
+ expect(gateways.keys).to eq([:default])
15
+ expect(gateways[:default]).to be_kind_of(ROM::Memory::Gateway)
16
+ end
17
+
18
+ it 'configures the gateways_map hash' do
19
+ expect(gateways_map).to be_kind_of(Hash)
20
+ expect(gateways_map.values).to eq([:memory])
21
+ expect(gateways_map.keys.first).to be_kind_of(ROM::Memory::Gateway)
22
+ expect(gateways_map.keys.first).to be(gateways[:default])
23
+ end
24
+ end
25
+
26
+ context 'with a hash' do
27
+ let(:params) { [{default: :memory}] }
28
+
29
+ it 'configures the gateways hash' do
30
+ expect(gateways).to be_kind_of(Hash)
31
+ expect(gateways.keys).to eq([:default])
32
+ expect(gateways[:default]).to be_kind_of(ROM::Memory::Gateway)
33
+ end
34
+
35
+ it 'configures the gateways_map hash' do
36
+ expect(gateways_map).to be_kind_of(Hash)
37
+ expect(gateways_map.values).to eq([:memory])
38
+ expect(gateways_map.keys.first).to be_kind_of(ROM::Memory::Gateway)
39
+ expect(gateways_map.keys.first).to be(gateways[:default])
40
+ end
41
+ end
42
+
43
+ context 'with multiple gateways' do
44
+ let(:params) { [{foo: :memory, default: :memory}] }
45
+
46
+ it 'configures the gateways hash' do
47
+ expect(gateways).to be_kind_of(Hash)
48
+ expect(gateways.keys).to eq([:foo, :default])
49
+ expect(gateways[:default]).to be_kind_of(ROM::Memory::Gateway)
50
+ expect(gateways[:foo]).to be_kind_of(ROM::Memory::Gateway)
51
+ expect(gateways[:default]).not_to be(gateways[:foo])
52
+ end
53
+
54
+ it 'configures the gateways_map hash' do
55
+ expect(gateways_map).to be_kind_of(Hash)
56
+ expect(gateways_map.values).to eq([:memory, :memory])
57
+ expect(gateways_map.keys.map(&:class)).to eq([ROM::Memory::Gateway, ROM::Memory::Gateway])
58
+ expect(gateways_map.keys).to match_array(gateways.values)
59
+ end
60
+ end
61
+
62
+ context 'with settings' do
63
+ before do
64
+ module Test
65
+ class Gateway < ROM::Gateway
66
+ attr_reader :settings
67
+
68
+ def initialize settings = {}
69
+ @settings = settings
70
+ end
71
+ end
72
+ end
73
+
74
+ ROM.register_adapter(:test, Test)
75
+ end
76
+
77
+ context 'as a hash' do
78
+ let(:params) { [{foo: [:test, "foo"], bar: [:test, ["bar"]]}] }
79
+
80
+ it 'configures the gateway instance' do
81
+ expect(gateways.values.map(&:settings)).to match_array(["foo", "bar"])
82
+ end
83
+ end
84
+
85
+ context 'as flat args' do
86
+ let(:params) { [:test, "foo"] }
87
+
88
+ it 'configures the gateway instance' do
89
+ expect(gateways.values.map(&:settings)).to match_array(["foo"])
90
+ end
91
+ end
92
+ end
93
+
94
+ context 'with a Gateway instance' do
95
+ before do
96
+ module Test
97
+ class Gateway < ROM::Gateway
98
+ attr_reader :settings
99
+
100
+ def initialize settings = {}
101
+ @settings = settings
102
+ end
103
+ end
104
+ end
105
+
106
+ ROM.register_adapter(:test, Test)
107
+ end
108
+
109
+ let(:gateway) { Test::Gateway.new }
110
+ let(:params) { [gateway] }
111
+
112
+ it 'configures the gateways hash' do
113
+ expect(gateways).to be_kind_of(Hash)
114
+ expect(gateways.keys).to eq([:default])
115
+ expect(gateways[:default]).to be(gateway)
116
+ end
117
+
118
+ it 'configures the gateways_map hash' do
119
+ expect(gateways_map).to be_kind_of(Hash)
120
+ expect(gateways_map).to be_empty
121
+ end
122
+ end
123
+ end
@@ -1,6 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ROM::Gateway do
4
+
5
+ subject(:gateway) { Class.new(ROM::Gateway).new }
6
+
4
7
  describe '.setup' do
5
8
  it 'sets up a gateway based on a type' do
6
9
  gateway_class = Class.new(ROM::Gateway) do
@@ -82,9 +85,62 @@ describe ROM::Gateway do
82
85
 
83
86
  describe '#disconnect' do
84
87
  it 'does nothing' do
85
- gateway_class = Class.new(ROM::Gateway)
86
- gateway = gateway_class.new
87
88
  expect(gateway.disconnect).to be(nil)
88
89
  end
89
90
  end
91
+
92
+ describe '#logger' do
93
+ it 'does nothing' do
94
+ expect(gateway.logger).to be(nil)
95
+ end
96
+ end
97
+
98
+ describe '#use_logger' do
99
+ it 'does nothing' do
100
+ expect(gateway.use_logger).to be(nil)
101
+ end
102
+
103
+ it 'accepts parameters' do
104
+ params = [5, "mutations", "are", "nice"]
105
+
106
+ expect { gateway.use_logger(params) }.to_not raise_error
107
+ end
108
+ end
109
+
110
+ describe '#extend_command_class' do
111
+ it 'returns the class sent as 1st parameter' do
112
+ klass = Class.new.freeze
113
+
114
+ expect(gateway.extend_command_class(klass, "foo")).to eq(klass)
115
+ end
116
+ end
117
+
118
+ describe '.adapter' do
119
+ let(:gateway_class) { Class.new(ROM::Gateway) }
120
+
121
+ it 'gets/sets the adapter' do
122
+ expect { gateway_class.adapter :custom }
123
+ .to change { gateway_class.adapter }
124
+ .from(nil)
125
+ .to(:custom)
126
+ end
127
+ end
128
+
129
+ describe "#adapter" do
130
+ before { Test::CustomGateway = Class.new(ROM::Gateway) }
131
+
132
+ let(:gateway) { Test::CustomGateway.new }
133
+
134
+ it 'returns class adapter' do
135
+ Test::CustomGateway.adapter :custom
136
+ expect(gateway.adapter).to eql :custom
137
+ end
138
+
139
+ it 'requires the adapter to be defined' do
140
+ expect { gateway.adapter }.to raise_error(
141
+ ROM::MissingAdapterIdentifierError, /Test::CustomGateway/
142
+ )
143
+ end
144
+ end # describe #adapter
145
+
90
146
  end
@@ -1,15 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ROM do
4
- describe '.setup' do
5
- it 'allows passing in gateway instances' do
6
- klass = Class.new(ROM::Gateway)
7
- repo = klass.new
4
+ include_context 'container'
8
5
 
9
- setup = ROM.setup(test: repo)
6
+ describe '.env' do
7
+ it 'is nil by default' do
8
+ container
10
9
 
11
- expect(setup.gateways[:test]).to be(repo)
10
+ expect(ROM.env).to be(nil)
12
11
  end
13
- end
14
12
 
13
+ it 'is assignable' do
14
+ ROM.env = container
15
+ expect(ROM.env).to be(container)
16
+ end
17
+ end
15
18
  end
@@ -1,12 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "ROM::PluginRegistry" do
4
- subject(:env) { setup.finalize }
5
-
6
- let(:setup) { ROM.setup(:memory) }
4
+ include_context 'container'
7
5
 
8
6
  before do
9
- Test::EnvironmentPlugin = Module.new
7
+ Test::ConfigurationPlugin = Module.new
10
8
  Test::CommandPlugin = Module.new
11
9
  Test::MapperPlugin = Module.new
12
10
  Test::RelationPlugin = Module.new do
@@ -16,11 +14,13 @@ describe "ROM::PluginRegistry" do
16
14
  end
17
15
 
18
16
  ROM.plugins do
19
- register :registration, Test::EnvironmentPlugin, type: :environment
17
+ register :registration, Test::ConfigurationPlugin, type: :configuration
20
18
  register :publisher, Test::CommandPlugin, type: :command
21
19
  register :pager, Test::RelationPlugin, type: :relation
22
20
  register :translater, Test::MapperPlugin, type: :mapper
23
21
  end
22
+
23
+ configuration
24
24
  end
25
25
 
26
26
  around do |example|
@@ -29,45 +29,56 @@ describe "ROM::PluginRegistry" do
29
29
  ROM.instance_variable_set('@plugin_registry', orig_plugins)
30
30
  end
31
31
 
32
- it "makes environment plugins available" do
33
- expect(ROM.plugin_registry.environment[:registration].mod).to eq Test::EnvironmentPlugin
32
+ it "makes configuration plugins available" do
33
+ expect(ROM.plugin_registry.configuration[:registration].mod).to eq Test::ConfigurationPlugin
34
34
  end
35
35
 
36
36
  it "includes relation plugins" do
37
- setup.relation(:users) do
37
+ users = Class.new(ROM::Relation[:memory]) do
38
+ register_as :users
38
39
  use :pager
39
40
  end
41
+ configuration.register_relation(users)
40
42
 
41
- expect(env.relation(:users).plugged_in).to eq "a relation"
43
+ expect(container.relation(:users).plugged_in).to eq "a relation"
42
44
  end
43
45
 
44
46
  it "makes command plugins available" do
45
- setup.relation(:users)
47
+ users = Class.new(ROM::Relation[:memory]) do
48
+ register_as :users
49
+ end
46
50
 
47
- Class.new(ROM::Commands::Create[:memory]) do
51
+ create_user = Class.new(ROM::Commands::Create[:memory]) do
48
52
  relation :users
49
53
  register_as :create
50
54
  use :publisher
51
55
  end
52
56
 
53
- expect(env.command(:users).create).to be_kind_of Test::CommandPlugin
57
+ configuration.register_relation(users)
58
+ configuration.register_command(create_user)
59
+
60
+ expect(container.command(:users).create).to be_kind_of Test::CommandPlugin
54
61
  end
55
62
 
56
63
  it "inclues plugins in mappers" do
57
- setup.relation(:users)
58
-
59
- Class.new(ROM::Mapper) do
64
+ users = Class.new(ROM::Relation[:memory]) do
65
+ register_as :users
66
+ end
67
+ translator = Class.new(ROM::Mapper) do
60
68
  relation :users
61
69
  register_as :translator
62
70
  use :translater
63
71
  end
64
72
 
65
- expect(env.mappers[:users][:translator]).to be_kind_of Test::MapperPlugin
73
+ configuration.register_relation(users)
74
+ configuration.register_mapper(translator)
75
+
76
+ expect(container.mappers[:users][:translator]).to be_kind_of Test::MapperPlugin
66
77
  end
67
78
 
68
79
  it "restricts plugins to defined type" do
69
80
  expect {
70
- setup.relation(:users) do
81
+ configuration.relation(:users) do
71
82
  use :publisher
72
83
  end
73
84
  }.to raise_error ROM::UnknownPluginError
@@ -86,11 +97,13 @@ describe "ROM::PluginRegistry" do
86
97
  end
87
98
  end
88
99
 
89
- setup.relation(:users) do
100
+ users = Class.new(ROM::Relation[:memory]) do
101
+ register_as :users
90
102
  use :lazy
91
103
  end
104
+ configuration.register_relation(users)
92
105
 
93
- expect(env.relation(:users)).to be_lazy
106
+ expect(container.relation(:users)).to be_lazy
94
107
  end
95
108
 
96
109
  it "respects adapter restrictions" do
@@ -110,22 +123,28 @@ describe "ROM::PluginRegistry" do
110
123
  end
111
124
  end
112
125
 
113
- setup.relation(:users)
126
+ users = Class.new(ROM::Relation[:memory]) do
127
+ register_as :users
128
+ end
114
129
 
115
- Class.new(ROM::Commands::Create[:memory]) do
130
+ create_user = Class.new(ROM::Commands::Create[:memory]) do
116
131
  relation :users
117
132
  register_as :create
118
133
  use :lazy
119
134
  end
120
135
 
121
- Class.new(ROM::Commands::Update[:memory]) do
136
+ update_user = Class.new(ROM::Commands::Update[:memory]) do
122
137
  relation :users
123
138
  register_as :update
124
139
  use :lazy_command
125
140
  end
126
141
 
127
- expect(env.command(:users).create).not_to be_kind_of Test::LazySQLPlugin
128
- expect(env.command(:users).create).to be_kind_of Test::LazyPlugin
129
- expect(env.command(:users).update).to be_kind_of Test::LazyMemoryPlugin
142
+ configuration.register_relation(users)
143
+ configuration.register_command(create_user)
144
+ configuration.register_command(update_user)
145
+
146
+ expect(container.command(:users).create).not_to be_kind_of Test::LazySQLPlugin
147
+ expect(container.command(:users).create).to be_kind_of Test::LazyPlugin
148
+ expect(container.command(:users).update).to be_kind_of Test::LazyMemoryPlugin
130
149
  end
131
150
  end
@@ -0,0 +1,27 @@
1
+ require 'rom'
2
+ require 'rom/memory'
3
+ require 'rom/plugins/relation/key_inference'
4
+
5
+ RSpec.describe ROM::Plugins::Relation::KeyInference do
6
+ subject(:relation) { relation_class.new([]) }
7
+
8
+ let(:relation_class) do
9
+ Class.new(ROM::Memory::Relation) do
10
+ use :key_inference
11
+
12
+ dataset :users
13
+ end
14
+ end
15
+
16
+ describe '#base_name' do
17
+ it 'returns dataset name by default' do
18
+ expect(relation.base_name).to be(:users)
19
+ end
20
+ end
21
+
22
+ describe '#foreign_key' do
23
+ it 'returns default value' do
24
+ expect(relation.foreign_key).to be(:user_id)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,47 @@
1
+ require 'rom'
2
+ require 'rom/memory'
3
+ require 'rom/plugins/relation/view'
4
+
5
+ RSpec.describe ROM::Plugins::Relation::View do
6
+ subject(:relation) { relation_class.new([]) }
7
+
8
+ let(:relation_class) do
9
+ Class.new(ROM::Memory::Relation) do
10
+ use :view
11
+
12
+ view(:base, [:id, :name]) do
13
+ self
14
+ end
15
+
16
+ view(:ids, [:id]) do
17
+ self
18
+ end
19
+
20
+ view(:names, [:name]) do |id|
21
+ self
22
+ end
23
+ end
24
+ end
25
+
26
+ describe '#attributes' do
27
+ it 'returns base view attributes by default' do
28
+ expect(relation.attributes).to eql([:id, :name])
29
+ end
30
+
31
+ it 'returns attributes for a view' do
32
+ expect(relation.ids.attributes).to eql([:id])
33
+ end
34
+
35
+ it 'returns attributes for a view with args' do
36
+ expect(relation.names(1).attributes).to eql([:name])
37
+ end
38
+
39
+ it 'returns attributes for a curried view' do
40
+ expect(relation.names.attributes).to eql([:name])
41
+ end
42
+
43
+ it 'returns correct arity for a curried view' do
44
+ expect(relation.names.arity).to be(1)
45
+ end
46
+ end
47
+ end