axiom-do-adapter 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -0
- data/.ruby-gemset +1 -0
- data/.travis.yml +17 -23
- data/CONTRIBUTING.md +1 -2
- data/Gemfile +10 -5
- data/Gemfile.devtools +39 -27
- data/README.md +3 -6
- data/axiom-do-adapter.gemspec +5 -7
- data/config/devtools.yml +2 -0
- data/config/reek.yml +2 -7
- data/config/rubocop.yml +59 -0
- data/lib/axiom/adapter/data_objects/statement.rb +4 -7
- data/lib/axiom/adapter/data_objects/version.rb +1 -1
- data/lib/axiom/relation/gateway.rb +3 -3
- data/spec/shared/binary_relation_method_behaviour.rb +11 -11
- data/spec/shared/unary_relation_method_behaviour.rb +4 -4
- data/spec/spec_helper.rb +13 -18
- data/spec/support/config_alias.rb +2 -0
- data/spec/unit/axiom/adapter/data_objects/class_methods/new_spec.rb +1 -1
- data/spec/unit/axiom/adapter/data_objects/read_spec.rb +14 -18
- data/spec/unit/axiom/adapter/data_objects/statement/class_methods/new_spec.rb +3 -3
- data/spec/unit/axiom/adapter/data_objects/statement/each_spec.rb +23 -24
- data/spec/unit/axiom/adapter/data_objects/statement/to_s_spec.rb +9 -9
- data/spec/unit/axiom/relation/gateway/class_methods/new_spec.rb +2 -2
- data/spec/unit/axiom/relation/gateway/difference_spec.rb +3 -3
- data/spec/unit/axiom/relation/gateway/drop_spec.rb +6 -6
- data/spec/unit/axiom/relation/gateway/each_spec.rb +19 -23
- data/spec/unit/axiom/relation/gateway/extend_spec.rb +10 -12
- data/spec/unit/axiom/relation/gateway/intersect_spec.rb +3 -3
- data/spec/unit/axiom/relation/gateway/join_spec.rb +11 -11
- data/spec/unit/axiom/relation/gateway/materialize_spec.rb +9 -9
- data/spec/unit/axiom/relation/gateway/optimize_spec.rb +4 -4
- data/spec/unit/axiom/relation/gateway/product_spec.rb +3 -3
- data/spec/unit/axiom/relation/gateway/project_spec.rb +6 -6
- data/spec/unit/axiom/relation/gateway/remove_spec.rb +6 -6
- data/spec/unit/axiom/relation/gateway/rename_spec.rb +6 -6
- data/spec/unit/axiom/relation/gateway/respond_to_spec.rb +2 -2
- data/spec/unit/axiom/relation/gateway/restrict_spec.rb +10 -12
- data/spec/unit/axiom/relation/gateway/reverse_spec.rb +6 -6
- data/spec/unit/axiom/relation/gateway/sort_by_spec.rb +10 -12
- data/spec/unit/axiom/relation/gateway/summarize_spec.rb +48 -54
- data/spec/unit/axiom/relation/gateway/take_spec.rb +6 -6
- data/spec/unit/axiom/relation/gateway/union_spec.rb +3 -3
- metadata +23 -44
- data/.rvmrc +0 -1
- data/spec/support/example_group_methods.rb +0 -7
- data/spec/support/ice_nine_config.rb +0 -6
@@ -1,21 +1,21 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
shared_examples_for 'a unary relation method' do
|
4
|
-
let(:gateway) {
|
4
|
+
let(:gateway) { double('New Gateway') }
|
5
5
|
|
6
6
|
before do
|
7
|
-
described_class.
|
7
|
+
allow(described_class).to receive(:new).and_return(gateway)
|
8
8
|
end
|
9
9
|
|
10
10
|
it { should equal(gateway) }
|
11
11
|
|
12
12
|
it 'tests the response is a relation' do
|
13
|
-
response.
|
13
|
+
expect(response).to receive(:kind_of?).with(Relation)
|
14
14
|
subject
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'initializes the new gateway with the adapter and response' do
|
18
|
-
described_class.
|
18
|
+
expect(described_class).to receive(:new).with(adapter, response)
|
19
19
|
subject
|
20
20
|
end
|
21
21
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,38 +1,33 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'backports'
|
4
|
-
require 'backports/basic_object' unless defined?(::BasicObject)
|
5
|
-
require 'devtools/spec_helper'
|
6
|
-
require 'ice_nine'
|
7
|
-
|
8
3
|
if ENV['COVERAGE'] == 'true'
|
9
4
|
require 'simplecov'
|
10
5
|
require 'coveralls'
|
11
6
|
|
12
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
13
|
-
|
14
|
-
|
15
|
-
]
|
7
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ SimpleCov::Formatter::HTMLFormatter,
|
8
|
+
Coveralls::SimpleCov::Formatter
|
9
|
+
]
|
16
10
|
|
17
11
|
SimpleCov.start do
|
18
|
-
command_name
|
19
|
-
|
20
|
-
add_filter
|
12
|
+
command_name 'spec:unit'
|
13
|
+
|
14
|
+
add_filter 'config'
|
15
|
+
add_filter 'spec'
|
16
|
+
add_filter 'vendor'
|
17
|
+
|
21
18
|
minimum_coverage 100
|
22
19
|
end
|
23
20
|
end
|
24
21
|
|
22
|
+
require 'devtools/spec_helper'
|
25
23
|
require 'axiom-do-adapter'
|
26
24
|
|
27
25
|
include Axiom
|
28
26
|
|
29
|
-
# require spec support files and shared behavior
|
30
|
-
Dir[File.expand_path('../{support,shared}/**/*.rb', __FILE__)].each do |file|
|
31
|
-
require file
|
32
|
-
end
|
33
|
-
|
34
27
|
RSpec.configure do |config|
|
35
|
-
config.
|
28
|
+
config.expect_with :rspec do |expect_with|
|
29
|
+
expect_with.syntax = :expect
|
30
|
+
end
|
36
31
|
|
37
32
|
# Record the original Attribute descendants
|
38
33
|
config.before do
|
@@ -4,56 +4,52 @@ require 'spec_helper'
|
|
4
4
|
require 'axiom/adapter/data_objects'
|
5
5
|
|
6
6
|
describe Adapter::DataObjects, '#read' do
|
7
|
-
let(:uri) {
|
7
|
+
let(:uri) { double }
|
8
8
|
let(:object) { described_class.new(uri) }
|
9
|
-
let(:relation) {
|
10
|
-
let(:statement) {
|
11
|
-
let(:rows) { [
|
9
|
+
let(:relation) { double('Relation') }
|
10
|
+
let(:statement) { double('Statement') }
|
11
|
+
let(:rows) { [[1], [2], [3]] }
|
12
12
|
let(:yields) { [] }
|
13
13
|
|
14
14
|
before do
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
described_class::Statement.stub!(:new).and_return(statement)
|
15
|
+
allow(statement).to receive(:each, &rows.method(:each))
|
16
|
+
allow(described_class::Statement).to receive(:new).and_return(statement)
|
19
17
|
end
|
20
18
|
|
21
19
|
context 'with a block' do
|
22
20
|
subject { object.read(relation) { |row| yields << row } }
|
23
21
|
|
24
|
-
let(:connection) {
|
22
|
+
let(:connection) { double('Connection', close: nil) }
|
25
23
|
|
26
24
|
before do
|
27
|
-
DataObjects::Connection.
|
25
|
+
allow(DataObjects::Connection).to receive(:new).and_return(connection)
|
28
26
|
end
|
29
27
|
|
30
28
|
it_should_behave_like 'a command method'
|
31
29
|
|
32
30
|
it 'opens a connection' do
|
33
|
-
DataObjects::Connection.
|
31
|
+
expect(DataObjects::Connection).to receive(:new).with(uri).and_return(connection)
|
34
32
|
subject
|
35
33
|
end
|
36
34
|
|
37
35
|
it 'closes a connection' do
|
38
|
-
connection.
|
36
|
+
expect(connection).to receive(:close).with(no_args)
|
39
37
|
subject
|
40
38
|
end
|
41
39
|
|
42
40
|
it 'does not close a connection if the constructor throws an exception' do
|
43
41
|
mock_exception = Class.new(Exception)
|
44
|
-
DataObjects::Connection.
|
45
|
-
connection.
|
42
|
+
expect(DataObjects::Connection).to receive(:new).and_raise(mock_exception)
|
43
|
+
expect(connection).not_to receive(:close)
|
46
44
|
expect { subject }.to raise_error(mock_exception)
|
47
45
|
end
|
48
46
|
|
49
47
|
it 'yields each row' do
|
50
|
-
expect { subject }.to change { yields.dup }.
|
51
|
-
from([]).
|
52
|
-
to(rows)
|
48
|
+
expect { subject }.to change { yields.dup }.from([]).to(rows)
|
53
49
|
end
|
54
50
|
|
55
51
|
it 'initializes a statement' do
|
56
|
-
described_class::Statement.
|
52
|
+
expect(described_class::Statement).to receive(:new).with(connection, relation).and_return(statement)
|
57
53
|
subject
|
58
54
|
end
|
59
55
|
end
|
@@ -4,8 +4,8 @@ require 'spec_helper'
|
|
4
4
|
require 'axiom/adapter/data_objects/statement'
|
5
5
|
|
6
6
|
describe Adapter::DataObjects::Statement, '.new' do
|
7
|
-
let(:connection) {
|
8
|
-
let(:relation) {
|
7
|
+
let(:connection) { double }
|
8
|
+
let(:relation) { double }
|
9
9
|
let(:object) { described_class }
|
10
10
|
|
11
11
|
context 'without a visitor' do
|
@@ -19,7 +19,7 @@ describe Adapter::DataObjects::Statement, '.new' do
|
|
19
19
|
context 'with a visitor' do
|
20
20
|
subject { object.new(connection, relation, visitor) }
|
21
21
|
|
22
|
-
let(:visitor) {
|
22
|
+
let(:visitor) { double }
|
23
23
|
|
24
24
|
it { should be_instance_of(described_class) }
|
25
25
|
|
@@ -4,20 +4,21 @@ require 'spec_helper'
|
|
4
4
|
require 'axiom/adapter/data_objects/statement'
|
5
5
|
|
6
6
|
describe Adapter::DataObjects::Statement, '#each' do
|
7
|
-
let(:reader) {
|
8
|
-
let(:command) {
|
9
|
-
let(:connection) {
|
10
|
-
let(:attribute) {
|
11
|
-
let(:primitive) {
|
12
|
-
let(:relation) {
|
13
|
-
let(:generator) {
|
14
|
-
let(:rows) { [
|
15
|
-
let(:object) { described_class.new(connection, relation, generator)
|
16
|
-
let(:yields) { []
|
7
|
+
let(:reader) { double('Reader', :next! => false).as_null_object }
|
8
|
+
let(:command) { double('Command', execute_reader: reader).as_null_object }
|
9
|
+
let(:connection) { double('Connection', create_command: command) }
|
10
|
+
let(:attribute) { double }
|
11
|
+
let(:primitive) { double }
|
12
|
+
let(:relation) { double('Relation', header: [attribute]) }
|
13
|
+
let(:generator) { double('Generator').as_null_object }
|
14
|
+
let(:rows) { [double, double] }
|
15
|
+
let(:object) { described_class.new(connection, relation, generator) }
|
16
|
+
let(:yields) { [] }
|
17
17
|
|
18
18
|
before do
|
19
|
-
command.
|
20
|
-
|
19
|
+
allow(command).to receive(:dup).and_return(command)
|
20
|
+
allow(command).to receive(:freeze).and_return(command)
|
21
|
+
attribute.stub_chain(:type, :primitive).and_return(primitive)
|
21
22
|
end
|
22
23
|
|
23
24
|
context 'with no block' do
|
@@ -26,7 +27,7 @@ describe Adapter::DataObjects::Statement, '#each' do
|
|
26
27
|
it { should be_instance_of(to_enum.class) }
|
27
28
|
|
28
29
|
it 'yields the expected attributes' do
|
29
|
-
subject.to_a.
|
30
|
+
expect(subject.to_a).to eql(object.to_a)
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
@@ -34,30 +35,28 @@ describe Adapter::DataObjects::Statement, '#each' do
|
|
34
35
|
subject { object.each { |row| yields << row } }
|
35
36
|
|
36
37
|
before do
|
37
|
-
connection.
|
38
|
+
expect(connection).to receive(:create_command).with(object.to_s)
|
38
39
|
|
39
|
-
command.
|
40
|
-
command.
|
40
|
+
expect(command).to receive(:set_types).with([primitive]).ordered
|
41
|
+
expect(command).to receive(:execute_reader).with(no_args).ordered
|
41
42
|
|
42
43
|
rows.each do |values|
|
43
|
-
reader.
|
44
|
-
reader.
|
44
|
+
expect(reader).to receive(:next!).with(no_args).ordered.and_return(true)
|
45
|
+
expect(reader).to receive(:values).with(no_args).ordered.and_return(values)
|
45
46
|
end
|
46
47
|
|
47
|
-
reader.
|
48
|
-
reader.
|
48
|
+
expect(reader).to receive(:next!).with(no_args).ordered.and_return(false)
|
49
|
+
expect(reader).to receive(:close).with(no_args).ordered
|
49
50
|
end
|
50
51
|
|
51
52
|
before do
|
52
|
-
relation.
|
53
|
+
expect(relation).to receive(:header)
|
53
54
|
end
|
54
55
|
|
55
56
|
it_should_behave_like 'a command method'
|
56
57
|
|
57
58
|
it 'yields each row' do
|
58
|
-
expect { subject }.to change { yields.dup }.
|
59
|
-
from([]).
|
60
|
-
to(rows)
|
59
|
+
expect { subject }.to change { yields.dup }.from([]).to(rows)
|
61
60
|
end
|
62
61
|
end
|
63
62
|
end
|
@@ -6,17 +6,17 @@ require 'axiom/adapter/data_objects/statement'
|
|
6
6
|
describe Adapter::DataObjects::Statement, '#to_s' do
|
7
7
|
subject { object.to_s }
|
8
8
|
|
9
|
-
let(:sql) {
|
10
|
-
let(:connection) {
|
11
|
-
let(:relation) {
|
12
|
-
let(:generator) {
|
9
|
+
let(:sql) { double('SQL') }
|
10
|
+
let(:connection) { double }
|
11
|
+
let(:relation) { double('Relation') }
|
12
|
+
let(:generator) { double('Generator', to_sql: sql) }
|
13
13
|
|
14
14
|
context 'without a visitor' do
|
15
15
|
let(:visitor) { SQL::Generator::Relation } # default visitor
|
16
16
|
let(:object) { described_class.new(connection, relation) }
|
17
17
|
|
18
18
|
before do
|
19
|
-
visitor.
|
19
|
+
allow(visitor).to receive(:visit).and_return(generator)
|
20
20
|
end
|
21
21
|
|
22
22
|
it_should_behave_like 'an idempotent method'
|
@@ -26,17 +26,17 @@ describe Adapter::DataObjects::Statement, '#to_s' do
|
|
26
26
|
it { should equal(sql) }
|
27
27
|
|
28
28
|
it 'visits the relation' do
|
29
|
-
visitor.
|
29
|
+
expect(visitor).to receive(:visit).with(relation)
|
30
30
|
subject
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
context 'with a visitor' do
|
35
|
-
let(:visitor) {
|
35
|
+
let(:visitor) { double('Visitor', visit: generator) }
|
36
36
|
let(:object) { described_class.new(connection, relation, visitor) }
|
37
37
|
|
38
38
|
before do
|
39
|
-
visitor.
|
39
|
+
allow(visitor).to receive(:visit).and_return(generator)
|
40
40
|
end
|
41
41
|
|
42
42
|
it_should_behave_like 'an idempotent method'
|
@@ -46,7 +46,7 @@ describe Adapter::DataObjects::Statement, '#to_s' do
|
|
46
46
|
it { should equal(sql) }
|
47
47
|
|
48
48
|
it 'visits the relation' do
|
49
|
-
visitor.
|
49
|
+
expect(visitor).to receive(:visit).with(relation)
|
50
50
|
subject
|
51
51
|
end
|
52
52
|
end
|
@@ -6,8 +6,8 @@ require 'axiom/relation/gateway'
|
|
6
6
|
describe Relation::Gateway, '.new' do
|
7
7
|
subject { object.new(adapter, relation) }
|
8
8
|
|
9
|
-
let(:adapter) {
|
10
|
-
let(:relation) {
|
9
|
+
let(:adapter) { double }
|
10
|
+
let(:relation) { double }
|
11
11
|
let(:object) { described_class }
|
12
12
|
|
13
13
|
it { should be_instance_of(described_class) }
|
@@ -6,12 +6,12 @@ require 'axiom/relation/gateway'
|
|
6
6
|
describe Relation::Gateway, '#difference' do
|
7
7
|
subject { object.difference(other) }
|
8
8
|
|
9
|
-
let(:adapter) {
|
10
|
-
let(:relation) {
|
9
|
+
let(:adapter) { double('Adapter') }
|
10
|
+
let(:relation) { double('Relation') }
|
11
11
|
let(:object) { described_class.new(adapter, relation) }
|
12
12
|
let(:operation) { :difference }
|
13
13
|
let(:factory) { Algebra::Difference }
|
14
|
-
let(:binary_relation) {
|
14
|
+
let(:binary_relation) { double(factory) }
|
15
15
|
|
16
16
|
it_should_behave_like 'a binary relation method'
|
17
17
|
end
|
@@ -6,16 +6,16 @@ require 'axiom/relation/gateway'
|
|
6
6
|
describe Relation::Gateway, '#drop' do
|
7
7
|
subject { object.drop(args) }
|
8
8
|
|
9
|
-
let(:adapter) {
|
10
|
-
let(:relation) {
|
11
|
-
let(:response) {
|
12
|
-
let!(:object) { described_class.new(adapter, relation)
|
13
|
-
let(:args) {
|
9
|
+
let(:adapter) { double('Adapter') }
|
10
|
+
let(:relation) { double('Relation', drop: response) }
|
11
|
+
let(:response) { double('New Relation', :kind_of? => true) }
|
12
|
+
let!(:object) { described_class.new(adapter, relation) }
|
13
|
+
let(:args) { double }
|
14
14
|
|
15
15
|
it_should_behave_like 'a unary relation method'
|
16
16
|
|
17
17
|
it 'forwards the arguments to relation#drop' do
|
18
|
-
relation.
|
18
|
+
expect(relation).to receive(:drop).with(args)
|
19
19
|
subject
|
20
20
|
end
|
21
21
|
end
|
@@ -6,50 +6,48 @@ require 'axiom/relation/gateway'
|
|
6
6
|
describe Relation::Gateway, '#each' do
|
7
7
|
subject { object.each { |tuple| yields << tuple } }
|
8
8
|
|
9
|
-
let(:header) {
|
10
|
-
let(:reader) {
|
11
|
-
let(:tuple) {
|
12
|
-
let(:adapter) {
|
13
|
-
let(:relation) {
|
9
|
+
let(:header) { double('Header') }
|
10
|
+
let(:reader) { double('Reader') }
|
11
|
+
let(:tuple) { double('Tuple') }
|
12
|
+
let(:adapter) { double('Adapter') }
|
13
|
+
let(:relation) { double('Relation') }
|
14
14
|
let!(:object) { described_class.new(adapter, relation) }
|
15
15
|
let(:yields) { [] }
|
16
16
|
|
17
17
|
context 'with an unmaterialized relation' do
|
18
|
-
let(:wrapper) {
|
18
|
+
let(:wrapper) { double }
|
19
19
|
|
20
20
|
before do
|
21
|
-
adapter.
|
21
|
+
allow(adapter).to receive(:read).and_return(reader)
|
22
22
|
|
23
|
-
relation.
|
24
|
-
relation.
|
25
|
-
relation.
|
23
|
+
allow(relation).to receive(:header).and_return(header)
|
24
|
+
allow(relation).to receive(:materialized?).and_return(false)
|
25
|
+
allow(relation).to receive(:each).and_return(relation)
|
26
26
|
|
27
|
-
wrapper.
|
28
|
-
Relation.
|
27
|
+
allow(wrapper).to receive(:each).and_yield(tuple)
|
28
|
+
allow(Relation).to receive(:new).and_return(wrapper)
|
29
29
|
end
|
30
30
|
|
31
31
|
it_should_behave_like 'an #each method'
|
32
32
|
|
33
33
|
it 'yields each tuple' do
|
34
|
-
expect { subject }.to change { yields.dup }.
|
35
|
-
from([]).
|
36
|
-
to([ tuple ])
|
34
|
+
expect { subject }.to change { yields.dup }.from([]).to([tuple])
|
37
35
|
end
|
38
36
|
|
39
37
|
it 'passes in the relation to the adapter reader' do
|
40
|
-
adapter.
|
38
|
+
expect(adapter).to receive(:read).with(relation)
|
41
39
|
subject
|
42
40
|
end
|
43
41
|
|
44
42
|
it 'passes in the relation header and reader to the wrapper constructor' do
|
45
|
-
Relation.
|
43
|
+
expect(Relation).to receive(:new).with(header, reader)
|
46
44
|
subject
|
47
45
|
end
|
48
46
|
end
|
49
47
|
|
50
48
|
context 'with a materialized relation' do
|
51
49
|
before do
|
52
|
-
relation.
|
50
|
+
allow(relation).to receive(:materialized?).and_return(true)
|
53
51
|
|
54
52
|
tuple = self.tuple
|
55
53
|
|
@@ -68,18 +66,16 @@ describe Relation::Gateway, '#each' do
|
|
68
66
|
it_should_behave_like 'an #each method'
|
69
67
|
|
70
68
|
it 'yields each tuple' do
|
71
|
-
expect { subject }.to change { yields.dup }.
|
72
|
-
from([]).
|
73
|
-
to([ tuple ])
|
69
|
+
expect { subject }.to change { yields.dup }.from([]).to([tuple])
|
74
70
|
end
|
75
71
|
|
76
72
|
it 'does not create a reader' do
|
77
|
-
adapter.
|
73
|
+
expect(adapter).not_to receive(:read)
|
78
74
|
subject
|
79
75
|
end
|
80
76
|
|
81
77
|
it 'does not create a wrapper' do
|
82
|
-
Relation.
|
78
|
+
expect(Relation).not_to receive(:new)
|
83
79
|
subject
|
84
80
|
end
|
85
81
|
end
|