Skip to content

Commit 709ae10

Browse files
committed
Do not raise Error with multiple registry tables
1 parent d4c184a commit 709ae10

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

lib/refile/postgres/backend.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def registry_table
2323
unless @registry_table_validated
2424
with_connection do |connection|
2525
connection.exec_params("SELECT * FROM pg_catalog.pg_tables WHERE tablename = $1::varchar;", [@registry_table]) do |result|
26-
if result.count != 1
26+
if result.count == 0
2727
raise RegistryTableDoesNotExistError.new(%{Please create a table "#{@registry_table}" where backend could store list of attachments})
2828
end
2929
end

spec/refile/postgres/backend_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
}.to raise_error(ArgumentError, "When initializing new Refile::Postgres::Backend first argument should be an instance of PG::Connection or a lambda/proc that yields it.")
2222
end
2323
end
24+
2425
context "when lambda does yield a PG::Connection" do
2526
let(:connection_or_proc) { lambda { |&blk| blk.call(connection) } }
2627
it "is usable in queries" do
@@ -30,6 +31,39 @@
3031
end
3132
end
3233

34+
describe "#registry_table" do
35+
context "when no registry table is present" do
36+
it "raises an exception" do
37+
drop_registry_table
38+
expect {
39+
Refile::Postgres::Backend.new(test_connection, max_size: 100).registry_table
40+
}.to raise_error Refile::Postgres::Backend::RegistryTableDoesNotExistError
41+
end
42+
end
43+
44+
context "when registry tables exist in multiple schemas" do
45+
before do
46+
test_connection.exec %{
47+
CREATE SCHEMA other_schema;
48+
CREATE TABLE IF NOT EXISTS other_schema.#{Refile::Postgres::Backend::DEFAULT_REGISTRY_TABLE}
49+
( id serial NOT NULL );
50+
}
51+
end
52+
53+
after do
54+
test_connection.exec %{
55+
DROP SCHEMA other_schema CASCADE;
56+
}
57+
end
58+
59+
it "does not raise an exception" do
60+
expect {
61+
Refile::Postgres::Backend.new(test_connection, max_size: 100).registry_table
62+
}.not_to raise_error
63+
end
64+
end
65+
end
66+
3367
context "Refile Provided tests" do
3468
let(:connection_or_proc) { connection }
3569
it_behaves_like :backend

0 commit comments

Comments
 (0)