From 58e1211edcc9b832f36ca097eaca2d2742afa5aa Mon Sep 17 00:00:00 2001 From: Bo Jeanes Date: Tue, 18 Apr 2017 11:39:32 +1000 Subject: [PATCH] Only create/drop extensions in tests if needed --- spec/pg/decoder_spec.cr | 8 ++++---- spec/pg/encoder_spec.cr | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/pg/decoder_spec.cr b/spec/pg/decoder_spec.cr index 16f6ca87..93b682e6 100644 --- a/spec/pg/decoder_spec.cr +++ b/spec/pg/decoder_spec.cr @@ -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"}) @@ -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 diff --git a/spec/pg/encoder_spec.cr b/spec/pg/encoder_spec.cr index 8e593f8a..a605cef8 100644 --- a/spec/pg/encoder_spec.cr +++ b/spec/pg/encoder_spec.cr @@ -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" @@ -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