veritas-do-adapter 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/.document +5 -0
  2. data/.gemtest +0 -0
  3. data/.rvmrc +1 -0
  4. data/.travis.yml +11 -0
  5. data/Gemfile +46 -0
  6. data/Guardfile +18 -0
  7. data/LICENSE +20 -0
  8. data/README.md +21 -0
  9. data/Rakefile +27 -0
  10. data/TODO +0 -0
  11. data/config/flay.yml +3 -0
  12. data/config/flog.yml +2 -0
  13. data/config/roodi.yml +16 -0
  14. data/config/site.reek +96 -0
  15. data/config/yardstick.yml +2 -0
  16. data/lib/veritas/adapter/data_objects/statement.rb +107 -0
  17. data/lib/veritas/adapter/data_objects/version.rb +9 -0
  18. data/lib/veritas/adapter/data_objects.rb +55 -0
  19. data/lib/veritas/relation/gateway.rb +363 -0
  20. data/lib/veritas-do-adapter.rb +4 -0
  21. data/spec/rcov.opts +6 -0
  22. data/spec/shared/binary_relation_method_behaviour.rb +51 -0
  23. data/spec/shared/command_method_behavior.rb +7 -0
  24. data/spec/shared/each_method_behaviour.rb +15 -0
  25. data/spec/shared/idempotent_method_behaviour.rb +7 -0
  26. data/spec/shared/unary_relation_method_behaviour.rb +21 -0
  27. data/spec/spec.opts +3 -0
  28. data/spec/spec_helper.rb +28 -0
  29. data/spec/unit/veritas/adapter/data_objects/class_methods/new_spec.rb +15 -0
  30. data/spec/unit/veritas/adapter/data_objects/read_spec.rb +70 -0
  31. data/spec/unit/veritas/adapter/data_objects/statement/class_methods/new_spec.rb +28 -0
  32. data/spec/unit/veritas/adapter/data_objects/statement/each_spec.rb +63 -0
  33. data/spec/unit/veritas/adapter/data_objects/statement/to_s_spec.rb +53 -0
  34. data/spec/unit/veritas/relation/gateway/class_methods/new_spec.rb +16 -0
  35. data/spec/unit/veritas/relation/gateway/difference_spec.rb +17 -0
  36. data/spec/unit/veritas/relation/gateway/drop_spec.rb +21 -0
  37. data/spec/unit/veritas/relation/gateway/each_spec.rb +84 -0
  38. data/spec/unit/veritas/relation/gateway/extend_spec.rb +27 -0
  39. data/spec/unit/veritas/relation/gateway/intersect_spec.rb +17 -0
  40. data/spec/unit/veritas/relation/gateway/join_spec.rb +44 -0
  41. data/spec/unit/veritas/relation/gateway/materialize_spec.rb +27 -0
  42. data/spec/unit/veritas/relation/gateway/optimize_spec.rb +23 -0
  43. data/spec/unit/veritas/relation/gateway/product_spec.rb +17 -0
  44. data/spec/unit/veritas/relation/gateway/project_spec.rb +21 -0
  45. data/spec/unit/veritas/relation/gateway/remove_spec.rb +21 -0
  46. data/spec/unit/veritas/relation/gateway/rename_spec.rb +21 -0
  47. data/spec/unit/veritas/relation/gateway/respond_to_spec.rb +29 -0
  48. data/spec/unit/veritas/relation/gateway/restrict_spec.rb +27 -0
  49. data/spec/unit/veritas/relation/gateway/reverse_spec.rb +21 -0
  50. data/spec/unit/veritas/relation/gateway/sort_by_spec.rb +27 -0
  51. data/spec/unit/veritas/relation/gateway/summarize_spec.rb +148 -0
  52. data/spec/unit/veritas/relation/gateway/take_spec.rb +21 -0
  53. data/spec/unit/veritas/relation/gateway/union_spec.rb +17 -0
  54. data/tasks/metrics/ci.rake +7 -0
  55. data/tasks/metrics/flay.rake +41 -0
  56. data/tasks/metrics/flog.rake +43 -0
  57. data/tasks/metrics/heckle.rake +209 -0
  58. data/tasks/metrics/metric_fu.rake +29 -0
  59. data/tasks/metrics/reek.rake +9 -0
  60. data/tasks/metrics/roodi.rake +15 -0
  61. data/tasks/metrics/yardstick.rake +23 -0
  62. data/tasks/spec.rake +39 -0
  63. data/tasks/yard.rake +9 -0
  64. data/veritas-do-adapter.gemspec +124 -0
  65. metadata +257 -0
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'veritas/adapter/data_objects/statement'
5
+
6
+ describe Adapter::DataObjects::Statement, '#to_s' do
7
+ subject { object.to_s }
8
+
9
+ let(:sql) { mock('SQL') }
10
+ let(:connection) { stub }
11
+ let(:relation) { mock('Relation') }
12
+ let(:generator) { mock('Generator', :to_sql => sql) }
13
+
14
+ context 'without a visitor' do
15
+ let(:visitor) { SQL::Generator::Relation } # default visitor
16
+ let(:object) { described_class.new(connection, relation) }
17
+
18
+ before do
19
+ visitor.stub!(:visit).and_return(generator)
20
+ end
21
+
22
+ it_should_behave_like 'an idempotent method'
23
+
24
+ it { should be_frozen }
25
+
26
+ it { should equal(sql) }
27
+
28
+ it 'visits the relation' do
29
+ visitor.should_receive(:visit).with(relation)
30
+ subject
31
+ end
32
+ end
33
+
34
+ context 'with a visitor' do
35
+ let(:visitor) { mock('Visitor', :visit => generator) }
36
+ let(:object) { described_class.new(connection, relation, visitor) }
37
+
38
+ before do
39
+ visitor.stub!(:visit).and_return(generator)
40
+ end
41
+
42
+ it_should_behave_like 'an idempotent method'
43
+
44
+ it { should be_frozen }
45
+
46
+ it { should equal(sql) }
47
+
48
+ it 'visits the relation' do
49
+ visitor.should_receive(:visit).with(relation)
50
+ subject
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'veritas/relation/gateway'
5
+
6
+ describe Relation::Gateway, '.new' do
7
+ subject { object.new(adapter, relation) }
8
+
9
+ let(:adapter) { stub }
10
+ let(:relation) { stub }
11
+ let(:object) { described_class }
12
+
13
+ it { should be_instance_of(described_class) }
14
+
15
+ it { should be_frozen }
16
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'veritas/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#difference' do
7
+ subject { object.difference(other) }
8
+
9
+ let(:adapter) { mock('Adapter') }
10
+ let(:relation) { mock('Relation') }
11
+ let(:object) { described_class.new(adapter, relation) }
12
+ let(:operation) { :difference }
13
+ let(:factory) { Algebra::Difference }
14
+ let(:binary_relation) { mock(factory) }
15
+
16
+ it_should_behave_like 'a binary relation method'
17
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'veritas/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#drop' do
7
+ subject { object.drop(args) }
8
+
9
+ let(:adapter) { mock('Adapter') }
10
+ let(:relation) { mock('Relation', :drop => response) }
11
+ let(:response) { mock('New Relation', :kind_of? => true) }
12
+ let!(:object) { described_class.new(adapter, relation) }
13
+ let(:args) { stub }
14
+
15
+ it_should_behave_like 'a unary relation method'
16
+
17
+ it 'forwards the arguments to relation#drop' do
18
+ relation.should_receive(:drop).with(args)
19
+ subject
20
+ end
21
+ end
@@ -0,0 +1,84 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'veritas/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#each' do
7
+ subject { object.each { |tuple| yields << tuple } }
8
+
9
+ let(:header) { mock('Header') }
10
+ let(:reader) { mock('Reader') }
11
+ let(:tuple) { mock('Tuple') }
12
+ let(:adapter) { mock('Adapter') }
13
+ let(:relation) { mock('Relation') }
14
+ let!(:object) { described_class.new(adapter, relation) }
15
+ let(:yields) { [] }
16
+
17
+ context 'with an unmaterialized relation' do
18
+ let(:wrapper) { stub }
19
+
20
+ before do
21
+ adapter.stub!(:read).and_return(reader)
22
+
23
+ relation.stub!(:header).and_return(header)
24
+ relation.stub!(:materialized?).and_return(false)
25
+ relation.stub!(:each).and_return(relation)
26
+
27
+ wrapper.stub!(:each).and_yield(tuple)
28
+ Relation.stub!(:new).and_return(wrapper)
29
+ end
30
+
31
+ it_should_behave_like 'an #each method'
32
+
33
+ it 'yields each tuple' do
34
+ expect { subject }.to change { yields.dup }.
35
+ from([]).
36
+ to([ tuple ])
37
+ end
38
+
39
+ it 'passes in the relation to the adapter reader' do
40
+ adapter.should_receive(:read).with(relation)
41
+ subject
42
+ end
43
+
44
+ it 'passes in the relation header and reader to the wrapper constructor' do
45
+ Relation.should_receive(:new).with(header, reader)
46
+ subject
47
+ end
48
+ end
49
+
50
+ context 'with a materialized relation' do
51
+ before do
52
+ relation.stub!(:materialized?).and_return(true)
53
+
54
+ # I do not know a better way to mock this behaviour out and
55
+ # I'm pretty sure that rspec does not provide Enumerator helpers
56
+ relation.stub!(:each) do |*args|
57
+ if args.empty?
58
+ relation.to_enum
59
+ else
60
+ args.first.call(tuple)
61
+ relation
62
+ end
63
+ end
64
+ end
65
+
66
+ it_should_behave_like 'an #each method'
67
+
68
+ it 'yields each tuple' do
69
+ expect { subject }.to change { yields.dup }.
70
+ from([]).
71
+ to([ tuple ])
72
+ end
73
+
74
+ it 'does not create a reader' do
75
+ adapter.should_not_receive(:read)
76
+ subject
77
+ end
78
+
79
+ it 'does not create a wrapper' do
80
+ Relation.should_not_receive(:new)
81
+ subject
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'veritas/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#extend' do
7
+ subject { object.extend(args, &block) }
8
+
9
+ let(:adapter) { mock('Adapter') }
10
+ let(:relation) { mock('Relation', :extend => response) }
11
+ let(:response) { mock('New Relation', :kind_of? => true) }
12
+ let!(:object) { described_class.new(adapter, relation) }
13
+ let(:args) { stub }
14
+ let(:block) { proc {} }
15
+
16
+ it_should_behave_like 'a unary relation method'
17
+
18
+ it 'forwards the arguments to relation#extend' do
19
+ relation.should_receive(:extend).with(args)
20
+ subject
21
+ end
22
+
23
+ it 'forwards the block to relation#extend' do
24
+ relation.stub!(:extend) { |_args, proc| proc.should equal(block) }
25
+ subject
26
+ end
27
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'veritas/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#intersect' do
7
+ subject { object.intersect(other) }
8
+
9
+ let(:adapter) { mock('Adapter') }
10
+ let(:relation) { mock('Relation') }
11
+ let(:object) { described_class.new(adapter, relation) }
12
+ let(:operation) { :intersect }
13
+ let(:factory) { Algebra::Intersection }
14
+ let(:binary_relation) { mock(factory) }
15
+
16
+ it_should_behave_like 'a binary relation method'
17
+ end
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'veritas/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#join' do
7
+ subject { object.join(other) }
8
+
9
+ let(:adapter) { mock('Adapter') }
10
+ let(:relation) { mock('Relation') }
11
+ let(:object) { described_class.new(adapter, relation) }
12
+ let(:operation) { :join }
13
+ let(:factory) { Algebra::Join }
14
+ let(:binary_relation) { mock(factory) }
15
+
16
+ it_should_behave_like 'a binary relation method'
17
+
18
+ context 'when passed a block' do
19
+ subject { object.join(other) { |context| yields << context } }
20
+
21
+ let(:other_relation) { mock('Other Relation') }
22
+ let(:other) { described_class.new(adapter, other_relation) }
23
+ let(:gateway) { mock('Other Gateway') }
24
+ let(:product) { mock('Product', :restrict => gateway) }
25
+ let(:yields) { [] }
26
+
27
+ before do
28
+ relation.stub!(:product).and_return(product)
29
+ end
30
+
31
+ it { should equal(gateway) }
32
+
33
+ it 'passes the other relation to the product operation' do
34
+ relation.should_receive(:product).with(other_relation)
35
+ subject
36
+ end
37
+
38
+ it 'passes the block to the product relation' do
39
+ context = mock('Context')
40
+ product.should_receive(:restrict).and_yield(context)
41
+ expect { subject }.to change { yields.dup }.from([]).to([ context ])
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'veritas/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#materialize' do
7
+ subject { object.materialize }
8
+
9
+ let(:header) { mock('Header') }
10
+ let(:directions) { mock('Directions') }
11
+ let(:adapter) { stub.as_null_object }
12
+ let(:relation) { mock('Relation', :header => header, :directions => directions, :materialized? => false) }
13
+ let!(:object) { described_class.new(adapter, relation) }
14
+ let(:materialized) { mock('Materialized') }
15
+
16
+ before do
17
+ Relation::Materialized.stub!(:new).and_return(materialized)
18
+ Relation.stub!(:new).and_return(stub.as_null_object)
19
+ end
20
+
21
+ it { should equal(materialized) }
22
+
23
+ it 'initializes the materialized relation with the header, tuples and directions' do
24
+ Relation::Materialized.should_receive(:new).with(header, [], directions)
25
+ subject
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'veritas/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#optimize' do
7
+ subject { object.optimize }
8
+
9
+ let(:adapter) { stub }
10
+ let(:relation) { mock('Relation') }
11
+ let(:object) { described_class.new(adapter, relation) }
12
+
13
+ before do
14
+ relation.stub!(:optimize).and_return(relation)
15
+ end
16
+
17
+ it_should_behave_like 'a command method'
18
+
19
+ it 'forwards the message to relation#optimize' do
20
+ relation.should_receive(:optimize).with(no_args)
21
+ subject
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'veritas/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#product' do
7
+ subject { object.product(other) }
8
+
9
+ let(:adapter) { mock('Adapter') }
10
+ let(:relation) { mock('Relation') }
11
+ let(:object) { described_class.new(adapter, relation) }
12
+ let(:operation) { :product }
13
+ let(:factory) { Algebra::Product }
14
+ let(:binary_relation) { mock(factory) }
15
+
16
+ it_should_behave_like 'a binary relation method'
17
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'veritas/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#project' do
7
+ subject { object.project(args) }
8
+
9
+ let(:adapter) { mock('Adapter') }
10
+ let(:relation) { mock('Relation', :project => response) }
11
+ let(:response) { mock('New Relation', :kind_of? => true) }
12
+ let!(:object) { described_class.new(adapter, relation) }
13
+ let(:args) { stub }
14
+
15
+ it_should_behave_like 'a unary relation method'
16
+
17
+ it 'forwards the arguments to relation#project' do
18
+ relation.should_receive(:project).with(args)
19
+ subject
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'veritas/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#remove' do
7
+ subject { object.remove(args) }
8
+
9
+ let(:adapter) { mock('Adapter') }
10
+ let(:relation) { mock('Relation', :remove => response) }
11
+ let(:response) { mock('New Relation', :kind_of? => true) }
12
+ let!(:object) { described_class.new(adapter, relation) }
13
+ let(:args) { stub }
14
+
15
+ it_should_behave_like 'a unary relation method'
16
+
17
+ it 'forwards the arguments to relation#remove' do
18
+ relation.should_receive(:remove).with(args)
19
+ subject
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'veritas/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#rename' do
7
+ subject { object.rename(args) }
8
+
9
+ let(:adapter) { mock('Adapter') }
10
+ let(:relation) { mock('Relation', :rename => response) }
11
+ let(:response) { mock('New Relation', :kind_of? => true) }
12
+ let!(:object) { described_class.new(adapter, relation) }
13
+ let(:args) { stub }
14
+
15
+ it_should_behave_like 'a unary relation method'
16
+
17
+ it 'forwards the arguments to relation#rename' do
18
+ relation.should_receive(:rename).with(args)
19
+ subject
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'veritas/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#respond_to?' do
7
+ subject { object.respond_to?(method) }
8
+
9
+ let(:relation) { mock('Relation', :header => stub) }
10
+ let(:object) { described_class.new(stub, relation) }
11
+
12
+ context 'with an unknown method' do
13
+ let(:method) { :unknown }
14
+
15
+ it { should be(false) }
16
+ end
17
+
18
+ context 'with a known method' do
19
+ let(:method) { :each }
20
+
21
+ it { should be(true) }
22
+ end
23
+
24
+ context 'with a known method in the relation' do
25
+ let(:method) { :header }
26
+
27
+ it { should be(true) }
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'veritas/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#restrict' do
7
+ subject { object.restrict(args, &block) }
8
+
9
+ let(:adapter) { mock('Adapter') }
10
+ let(:relation) { mock('Relation', :restrict => response) }
11
+ let(:response) { mock('New Relation', :kind_of? => true) }
12
+ let!(:object) { described_class.new(adapter, relation) }
13
+ let(:args) { stub }
14
+ let(:block) { proc {} }
15
+
16
+ it_should_behave_like 'a unary relation method'
17
+
18
+ it 'forwards the arguments to relation#restrict' do
19
+ relation.should_receive(:restrict).with(args)
20
+ subject
21
+ end
22
+
23
+ it 'forwards the block to relation#restrict' do
24
+ relation.stub!(:restrict) { |_args, proc| proc.should equal(block) }
25
+ subject
26
+ end
27
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'veritas/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#reverse' do
7
+ subject { object.reverse(args) }
8
+
9
+ let(:adapter) { mock('Adapter') }
10
+ let(:relation) { mock('Relation', :reverse => response) }
11
+ let(:response) { mock('New Relation', :kind_of? => true) }
12
+ let!(:object) { described_class.new(adapter, relation) }
13
+ let(:args) { stub }
14
+
15
+ it_should_behave_like 'a unary relation method'
16
+
17
+ it 'forwards the arguments to relation#reverse' do
18
+ relation.should_receive(:reverse).with(args)
19
+ subject
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'veritas/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#sort_by' do
7
+ subject { object.sort_by(args, &block) }
8
+
9
+ let(:adapter) { mock('Adapter') }
10
+ let(:relation) { mock('Relation', :sort_by => response) }
11
+ let(:response) { mock('New Relation', :kind_of? => true) }
12
+ let!(:object) { described_class.new(adapter, relation) }
13
+ let(:args) { stub }
14
+ let(:block) { proc {} }
15
+
16
+ it_should_behave_like 'a unary relation method'
17
+
18
+ it 'forwards the arguments to relation#sort_by' do
19
+ relation.should_receive(:sort_by).with(args)
20
+ subject
21
+ end
22
+
23
+ it 'forwards the block to relation#sort_by' do
24
+ relation.stub!(:sort_by) { |_args, proc| proc.should equal(block) }
25
+ subject
26
+ end
27
+ end
@@ -0,0 +1,148 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'veritas/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#summarize' do
7
+ let(:summarization) { mock('Summarization', :kind_of? => true) }
8
+ let(:adapter) { mock('Adapter') }
9
+ let(:relation) { mock('Relation', :summarize => summarization) }
10
+ let!(:object) { described_class.new(adapter, relation) }
11
+ let(:block) { proc {} }
12
+
13
+ context 'with no arguments' do
14
+ subject { object.summarize(&block) }
15
+
16
+ let(:gateway) { mock('New Gateway') }
17
+
18
+ before do
19
+ described_class.stub!(:new).and_return(gateway)
20
+ end
21
+
22
+ it { should equal(gateway) }
23
+
24
+ it 'forwards the default summarize_with relation to relation#summarize' do
25
+ relation.should_receive(:summarize) do |other|
26
+ other.should equal(TABLE_DEE)
27
+ end
28
+ subject
29
+ end
30
+
31
+ it 'forwards the block to relation#summarize' do
32
+ relation.stub!(:summarize) do |_summarize_with, proc|
33
+ proc.should equal(block)
34
+ end
35
+ subject
36
+ end
37
+
38
+ it 'initializes the gateway with the adapter and summarization' do
39
+ described_class.should_receive(:new).with(adapter, summarization)
40
+ subject
41
+ end
42
+ end
43
+
44
+ context 'with a header' do
45
+ subject { object.summarize(header, &block) }
46
+
47
+ let(:gateway) { mock('New Gateway') }
48
+ let(:header) { mock('Header') }
49
+
50
+ before do
51
+ described_class.stub!(:new).and_return(gateway)
52
+ end
53
+
54
+ it { should equal(gateway) }
55
+
56
+ it 'forwards the header to relation#summarize' do
57
+ relation.should_receive(:summarize) do |other|
58
+ other.should equal(header)
59
+ end
60
+ subject
61
+ end
62
+
63
+ it 'forwards the block to relation#summarize' do
64
+ relation.stub!(:summarize) do |_summarize_with, proc|
65
+ proc.should equal(block)
66
+ end
67
+ subject
68
+ end
69
+
70
+ it 'initializes the gateway with the adapter and summarization' do
71
+ described_class.should_receive(:new).with(adapter, summarization)
72
+ subject
73
+ end
74
+ end
75
+
76
+ context 'when summarize_with has the same adapter' do
77
+ subject { object.summarize(other, &block) }
78
+
79
+ let(:header) { mock('Header') }
80
+ let(:other_relation) { mock('Other Relation', :header => header) }
81
+ let!(:other) { described_class.new(adapter, other_relation) }
82
+ let(:gateway) { mock('New Gateway') }
83
+
84
+ before do
85
+ described_class.stub!(:new).and_return(gateway)
86
+ end
87
+
88
+ it { should equal(gateway) }
89
+
90
+ it 'forwards the other relation to relation#summarize' do
91
+ relation.should_receive(:summarize) do |other|
92
+ other.should equal(other_relation)
93
+ end
94
+ subject
95
+ end
96
+
97
+ it 'forwards the block to relation#summarize' do
98
+ relation.stub!(:summarize) do |_summarize_with, proc|
99
+ proc.should equal(block)
100
+ end
101
+ subject
102
+ end
103
+
104
+ it 'initializes the gateway with the adapter and summarization' do
105
+ described_class.should_receive(:new).with(adapter, summarization)
106
+ subject
107
+ end
108
+ end
109
+
110
+ context 'with a relation' do
111
+ subject { object.summarize(summarize_with, &block) }
112
+
113
+ let(:context_header) { mock('Context Header') }
114
+ let(:header) { mock('Header', :- => context_header) }
115
+ let(:summarize_header) { mock('Summarize With Header') }
116
+ let(:summarize_with) { mock('Other Relation', :header => summarize_header) }
117
+ let(:functions) { mock('Functions') }
118
+ let(:context) { mock('Context', :functions => functions) }
119
+
120
+ before do
121
+ relation.stub!(:header).and_return(header)
122
+ Algebra::Summarization.stub!(:new).and_return(summarization)
123
+ Evaluator::Context.stub!(:new).and_return(context)
124
+ end
125
+
126
+ it { should equal(summarization) }
127
+
128
+ it 'gets the context header' do
129
+ header.should_receive(:-).with(summarize_header)
130
+ subject
131
+ end
132
+
133
+ it 'passes the context header into the context' do
134
+ Evaluator::Context.should_receive(:new).with(context_header)
135
+ subject
136
+ end
137
+
138
+ it 'forwards the block to the context' do
139
+ Evaluator::Context.stub!(:new) { |_header, proc| proc.should equal(block) }.and_return(context)
140
+ subject
141
+ end
142
+
143
+ it 'initializes the summarization with the gateway, the relation and the functions' do
144
+ Algebra::Summarization.should_receive(:new).with(object, summarize_with, functions)
145
+ subject
146
+ end
147
+ end
148
+ end