insert 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1e66a0f320d2c6c5aeb91f10c762a49f86750d9
4
- data.tar.gz: b5d769bffbaee74b058ee9e9e5faad47cc556503
3
+ metadata.gz: 92bec9125377341c85ceee3b89c29edd076b6b82
4
+ data.tar.gz: 8c745f57f99c37690466368555e073131e91c228
5
5
  SHA512:
6
- metadata.gz: fb76886411cd1d164c7d1accd6529eb67fb129d5978f7bfd88bc1b5b6923a3ce12a71641e4037a9495ff8ae66207027886aabf80d68b81d7e4562af37eb45b3d
7
- data.tar.gz: 1d52d0b6915fb21dc3175a799396843cc1b16c9a9ac4d088bfd9cfc73a24beb215d58d4713c859e193510da1b3f838702037db2d9fc3591375cacc12bfd7a66c
6
+ metadata.gz: 8da9ae6de532a4eeb65e39a37a1ccec5389481fa893452a667f58f60924ef09713c20794e8d72128647d58272afb5b9f09c85225786a500f1e408ea44a362189
7
+ data.tar.gz: f627a6badc37b5daa1fb79f34978b904ddfe8129f11d11019ea22d76dd0ae81bd21025dba802e101706af541ef8d4b8a415b3b7134ac702a9405400e0f953477
@@ -35,7 +35,11 @@ class Insert
35
35
  quoted_cols = cols.map { |col| connection.quote_ident col }
36
36
  bind_params = cols.length.times.map { |i| "$#{i+1}" }
37
37
  statement = %{INSERT INTO #{quoted_table_name} (#{quoted_cols.join(',')}) VALUES (#{bind_params.join(',')})}
38
- connection.prepare name, statement
38
+ begin
39
+ connection.prepare name, statement
40
+ rescue PG::DuplicatePstatement
41
+ # noop
42
+ end
39
43
  name
40
44
  end
41
45
  end
@@ -1,3 +1,3 @@
1
1
  class Insert
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,7 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Insert do
4
- let(:connection) { PG.connect dbname: 'test_insert' }
4
+ def new_connection
5
+ PG.connect dbname: 'test_insert'
6
+ end
7
+
8
+ let(:connection) { new_connection }
5
9
  let(:insert) { Insert.new connection }
6
10
 
7
11
  before do
@@ -27,13 +31,6 @@ describe Insert do
27
31
  end.to change{Dog.where(age: 2, name: 'bill').count}
28
32
  end
29
33
 
30
- it "blows up without deallocate" do
31
- expect do
32
- Insert.new(connection).insert :dogs, age: 7
33
- Insert.new(connection).insert :dogs, age: 7
34
- end.to raise_error(PG::DuplicatePstatement)
35
- end
36
-
37
34
  it "can deallocate" do
38
35
  a = Insert.new(connection)
39
36
  b = Insert.new(connection)
@@ -54,4 +51,44 @@ describe Insert do
54
51
  expect{insert.deallocate}.to raise_error(/can't.*dealloc/i)
55
52
  end
56
53
 
54
+ describe 'possible collisions' do
55
+ it "doesn't blow up if used on diff connections" do
56
+ a = Insert.new new_connection
57
+ b = Insert.new new_connection
58
+ expect do
59
+ a.insert :dogs, age: 7
60
+ b.insert :dogs, age: 7
61
+ end.to change{Dog.count}.by(2)
62
+ end
63
+
64
+ it "doesn't blow up when threading" do
65
+ a = Insert.new new_connection
66
+ b = Insert.new new_connection
67
+ expect do
68
+ a.insert :dogs, age: 7
69
+ Thread.new do
70
+ b.insert :dogs, age: 7
71
+ end
72
+ sleep 2
73
+ end.to change{Dog.count}.by(2)
74
+ end
75
+
76
+ it "doesn't blow up on the same connection" do
77
+ same_connection = new_connection
78
+ a = Insert.new same_connection
79
+ b = Insert.new same_connection
80
+ expect do
81
+ a.insert :dogs, age: 7
82
+ b.insert :dogs, age: 7
83
+ end.to change{Dog.count}.by(2)
84
+ end
85
+
86
+ it "automatically re-uses prepared statements on the same connection" do
87
+ expect do
88
+ Insert.new(connection).insert :dogs, age: 7
89
+ Insert.new(connection).insert :dogs, age: 7
90
+ end.not_to raise_error
91
+ end
92
+ end
93
+
57
94
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: insert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seamus Abshere
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-03 00:00:00.000000000 Z
11
+ date: 2014-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler