pg_advisory_locker 1.0.0 → 1.0.1
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
|
-
pg_advisory_locker (0.
|
4
|
+
pg_advisory_locker (1.0.1)
|
5
5
|
pg
|
6
6
|
rails (>= 3.0.0)
|
7
7
|
rspec-rails
|
@@ -77,19 +77,19 @@ GEM
|
|
77
77
|
rake (0.9.2.2)
|
78
78
|
rdoc (3.12)
|
79
79
|
json (~> 1.4)
|
80
|
-
rspec (2.
|
81
|
-
rspec-core (~> 2.
|
82
|
-
rspec-expectations (~> 2.
|
83
|
-
rspec-mocks (~> 2.
|
84
|
-
rspec-core (2.
|
85
|
-
rspec-expectations (2.
|
86
|
-
diff-lcs (~> 1.1.
|
87
|
-
rspec-mocks (2.
|
88
|
-
rspec-rails (2.
|
80
|
+
rspec (2.11.0)
|
81
|
+
rspec-core (~> 2.11.0)
|
82
|
+
rspec-expectations (~> 2.11.0)
|
83
|
+
rspec-mocks (~> 2.11.0)
|
84
|
+
rspec-core (2.11.1)
|
85
|
+
rspec-expectations (2.11.3)
|
86
|
+
diff-lcs (~> 1.1.3)
|
87
|
+
rspec-mocks (2.11.3)
|
88
|
+
rspec-rails (2.11.0)
|
89
89
|
actionpack (>= 3.0)
|
90
90
|
activesupport (>= 3.0)
|
91
91
|
railties (>= 3.0)
|
92
|
-
rspec (~> 2.
|
92
|
+
rspec (~> 2.11.0)
|
93
93
|
sprockets (2.1.3)
|
94
94
|
hike (~> 1.2)
|
95
95
|
rack (~> 1.0)
|
data/pg_advisory_locker.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.name = 'pg_advisory_locker'
|
8
8
|
s.version = PgAdvisoryLocker::VERSION
|
9
9
|
s.license = 'New BSD License'
|
10
|
-
s.date = '2012-09-
|
10
|
+
s.date = '2012-09-20'
|
11
11
|
s.summary = "Helper for calling PostgreSQL pg_advisory_lock, pg_advisory_try_lock, and pg_advisory_unlock."
|
12
12
|
s.description = "This gem provides a module that, when included in your ActiveRecord model, provides methods to acquire and release advisory locks for PostgreSQL connections."
|
13
13
|
s.authors = ["Keith Gabryelski"]
|
@@ -1,5 +1,82 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
class Temp < ActiveRecord::Base
|
4
|
+
include PgAdvisoryLocker
|
5
|
+
end
|
6
|
+
|
3
7
|
describe PgAdvisoryLocker do
|
4
8
|
|
9
|
+
before do
|
10
|
+
ActiveRecord::Base.connection.execute <<-SQL
|
11
|
+
create table temps
|
12
|
+
(
|
13
|
+
id serial not null primary key,
|
14
|
+
created_at timestamp not null default now(),
|
15
|
+
name text null unique,
|
16
|
+
identification_number integer not null unique
|
17
|
+
);
|
18
|
+
SQL
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:lock_id) { 239 }
|
22
|
+
subject { Temp.new }
|
23
|
+
|
24
|
+
describe "advisory_lock" do
|
25
|
+
it "should receive lock_record" do
|
26
|
+
Temp.should_receive(:lock_record)
|
27
|
+
subject.advisory_lock
|
28
|
+
end
|
29
|
+
end # advisory_lock
|
30
|
+
|
31
|
+
describe "advisory_try_lock" do
|
32
|
+
it "should receive try_lock_record" do
|
33
|
+
Temp.should_receive(:try_lock_record)
|
34
|
+
subject.advisory_try_lock
|
35
|
+
end
|
36
|
+
end # advisory_try_lock
|
37
|
+
|
38
|
+
describe "advisory_unlock" do
|
39
|
+
it "should receive unlock_record" do
|
40
|
+
Temp.should_receive(:unlock_record)
|
41
|
+
subject.advisory_unlock
|
42
|
+
end
|
43
|
+
end # advisory_unlock
|
44
|
+
|
45
|
+
describe "table_oid" do
|
46
|
+
it "returns table_oid" do
|
47
|
+
Temp.find_by_sql("SELECT * FROM pg_class WHERE pg_class.oid = #{Temp.table_oid}").
|
48
|
+
first.relname.should == "temps"
|
49
|
+
end
|
50
|
+
end # table_oid
|
51
|
+
|
52
|
+
describe "lock_record" do
|
53
|
+
it "locks record" do
|
54
|
+
Temp.lock_record(lock_id)
|
55
|
+
Temp.find_by_sql("select * from pg_locks").
|
56
|
+
select{|x| x.objid == "#{lock_id}" && x.classid == "#{Temp.table_oid}"}.
|
57
|
+
should have(1).item
|
58
|
+
Temp.unlock_record(lock_id)
|
59
|
+
end
|
60
|
+
end # lock_record
|
61
|
+
|
62
|
+
describe "try_lock_record" do
|
63
|
+
it "locks record" do
|
64
|
+
Temp.try_lock_record(lock_id)
|
65
|
+
Temp.find_by_sql("select * from pg_locks").
|
66
|
+
select{|x| x.objid == "#{lock_id}" && x.classid == "#{Temp.table_oid}"}.
|
67
|
+
should have(1).item
|
68
|
+
Temp.unlock_record(lock_id)
|
69
|
+
end
|
70
|
+
end # try_lock_record
|
71
|
+
|
72
|
+
describe "unlock_record" do
|
73
|
+
it "unlocks record" do
|
74
|
+
Temp.lock_record(lock_id)
|
75
|
+
Temp.unlock_record(lock_id)
|
76
|
+
Temp.find_by_sql("select * from pg_locks").
|
77
|
+
select{|x| x.objid == "#{lock_id}" && x.classid == "#{Temp.table_oid}"}.
|
78
|
+
should be_blank
|
79
|
+
end
|
80
|
+
end # unlock_record
|
81
|
+
|
5
82
|
end # PgAdvisoryLocker
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_advisory_locker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
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: 2012-09-
|
12
|
+
date: 2012-09-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pg
|