Skip to content

Commit

Permalink
Only create/drop extensions in tests if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
bjeanes committed Apr 18, 2017
1 parent 2dc4bda commit 58e1211
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions spec/pg/decoder_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ describe PG::Decoders do

it "citext" do
begin
PG_DB.exec("CREATE EXTENSION \"citext\"")
PG_DB.exec("CREATE EXTENSION IF NOT EXISTS \"citext\"")
with_connection do |conn| # fresh connection so decoders are evaluated
value = conn.query_one "select 'abc'::citext", &.read
value.should eq("abc")
end
ensure
PG_DB.exec("DROP EXTENSION \"citext\"")
PG_DB.exec("DROP EXTENSION IF EXISTS \"citext\"")
end
end

it "hstore" do
begin
PG_DB.exec("CREATE EXTENSION \"hstore\"")
PG_DB.exec("CREATE EXTENSION IF NOT EXISTS \"hstore\"")
with_connection do |conn| # fresh connection so decoders are evaluated
value = conn.query_one "select 'foo=>bar,baz=>42'::hstore", &.read
value.should eq({"foo" => "bar", "baz" => "42"})
Expand All @@ -67,7 +67,7 @@ describe PG::Decoders do
value.should eq(nil)
end
ensure
PG_DB.exec("DROP EXTENSION \"hstore\"")
PG_DB.exec("DROP EXTENSION IF EXISTS \"hstore\"")
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/pg/encoder_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require "../spec_helper"
private def test_insert_and_read(datatype, value, extension = nil, file = __FILE__, line = __LINE__)
it "inserts #{datatype}", file, line do
begin
PG_DB.exec "create extension \"#{extension}\"" if extension
PG_DB.exec "create extension if not exists \"#{extension}\"" if extension

with_connection do |conn|
conn.exec "drop table if exists test_table"
Expand All @@ -19,7 +19,7 @@ private def test_insert_and_read(datatype, value, extension = nil, file = __FILE
actual_value.should eq(value)
end
ensure
PG_DB.exec "drop extension \"#{extension}\" cascade" if extension
PG_DB.exec "drop extension if exists \"#{extension}\" cascade" if extension
end
end
end
Expand Down

0 comments on commit 58e1211

Please sign in to comment.