Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/with_model/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def teardown(_klass)
end

def destroy
connection.drop_table(@name)
connection.drop_table(@name) if exists?
end

private
Expand Down
37 changes: 37 additions & 0 deletions spec/table_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

require "spec_helper"

RSpec.describe WithModel::Table do
let(:connection_owner) do
klass = Class.new(ActiveRecord::Base)
stub_const("TableSpecConnection", klass)
klass.abstract_class = true
klass.establish_connection(adapter: "sqlite3", database: ":memory:")
klass
end
let(:connection) { connection_owner.connection }
let(:table) { described_class.new(:temporary_records, connection:) }

after { connection_owner.connection_pool.disconnect! }

describe "#destroy" do
it "does not raise after its connection reconnects before teardown" do
table.create

connection.disconnect!
connection.reconnect!

expect(connection.data_source_exists?(:temporary_records)).to be false
expect { table.destroy }.not_to raise_error
end

it "drops an existing table" do
table.create

table.destroy

expect(connection.data_source_exists?(:temporary_records)).to be false
end
end
end