vostok 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vostok (0.0.1)
4
+ vostok (0.0.3)
5
5
  pg
6
6
 
7
7
  GEM
data/lib/vostok/import.rb CHANGED
@@ -3,6 +3,7 @@ require 'pg'
3
3
  module Vostok
4
4
  class Import
5
5
  attr_reader :pg_connection, :table
6
+ @connection_external = false
6
7
 
7
8
  def initialize(connection)
8
9
  raise ArgumentError, 'Connection can not be null' unless connection
@@ -11,6 +12,7 @@ module Vostok
11
12
  @pg_connection = PG::Connection.new(connection)
12
13
  else
13
14
  @pg_connection = connection
15
+ @connection_external = true
14
16
  end
15
17
  @options = {batch_size: 1000}
16
18
  end
@@ -19,14 +21,13 @@ module Vostok
19
21
  validate_args(columns, values)
20
22
  @table = table
21
23
  begin
22
- @pg_connection.reset
23
24
  values.each_slice(options[:batch_size]) do |slice|
24
25
  sql = generate_sql(table, columns, slice)
25
26
  @pg_connection.exec(sql)
26
27
  end
27
28
  values.length
28
29
  ensure
29
- @pg_connection.close
30
+ @pg_connection.close unless @connection_external
30
31
  end
31
32
  end
32
33
 
@@ -1,3 +1,3 @@
1
1
  module Vostok
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,9 @@
1
- require 'bundler/setup'
2
- require_relative '../lib/vostok'
3
-
4
1
  require 'coveralls'
5
2
  Coveralls.wear!
6
3
 
4
+ require 'bundler/setup'
5
+ require_relative '../lib/vostok'
6
+
7
7
 
8
8
 
9
9
 
data/spec/vostok_spec.rb CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe 'vostok' do
4
4
  before {
5
- connection_stub = stub 'connection', reset: true, close: true
5
+ connection_stub = stub 'connection', close: true
6
6
  connection_stub.stub(:is_a?).with(PG::Connection).and_return(true)
7
7
  connection_stub.stub(:is_a?).with(Hash).and_return(false)
8
8
  PG::Connection.stub(:new).and_return(connection_stub)
@@ -56,12 +56,6 @@ describe 'vostok' do
56
56
  ->{import.start(:customers, [:a, :b], [[1,2,3], [1,2,3]])}.should raise_error ArgumentError
57
57
  end
58
58
 
59
- it 'should reset pg_connection if it is not yet open' do
60
- import.pg_connection.stub(:exec)
61
- import.pg_connection.should_receive(:reset)
62
- import.start(:customers, [:a], [[1]])
63
- end
64
-
65
59
  it 'should call PG library with correct sql in one go' do
66
60
  sql = <<-eos
67
61
  insert into "customers" ("a","b") values('1','2'),('3','4')
@@ -92,7 +86,15 @@ describe 'vostok' do
92
86
  import.start(:customers, [:a, :b], [[1,2]]).should == 1
93
87
  end
94
88
 
95
- it 'should close the connection' do
89
+ it 'should not close the connection if it has come from outside' do
90
+ pg_connection = PG::Connection.new(dbname: 'db1', user: 'dev')
91
+ import = Vostok::Import.new(pg_connection)
92
+ import.pg_connection.stub(:exec)
93
+ import.pg_connection.should_not_receive(:close)
94
+ import.start(:customers, [:a, :b], [[1,2]])
95
+ end
96
+
97
+ it 'should close the connection if it was created internally' do
96
98
  import.pg_connection.stub(:exec)
97
99
  import.pg_connection.should_receive(:close)
98
100
  import.start(:customers, [:a, :b], [[1,2]])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vostok
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-21 00:00:00.000000000 Z
12
+ date: 2013-03-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pg