mirror of
https://github.com/discourse/discourse.git
synced 2024-12-24 10:24:01 +08:00
7c3a29c9d6
* Updates GitHub Actions * Switches from `bundler/inline` to an optional group in the `Gemfile` because the previous solution didn't work well with rspec * Adds the converter framework and tests * Allows loading private converters (see README) * Switches from multiple CLI tools to a single CLI * Makes DB connections reusable and adds a new abstraction for the `IntermediateDB` * `IntermediateDB` acts as an interface for IPC calls when a converter steps runs in parallel (forks). Only the main process writes to the DB. * Includes a simple example implementation of a converter for now.
68 lines
2.0 KiB
Ruby
68 lines
2.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe ::Migrations::Database::OfflineConnection do
|
|
subject(:connection) { described_class.new }
|
|
|
|
let!(:sql) { "INSERT INTO foo (id, name) VALUES (?, ?)" }
|
|
|
|
it_behaves_like "a database connection"
|
|
|
|
describe "#close" do
|
|
it "removes the cached statements" do
|
|
connection.insert(sql, [1, "Alice"])
|
|
connection.insert(sql, [2, "Bob"])
|
|
|
|
expect(connection.parametrized_insert_statements).to_not be_empty
|
|
|
|
connection.close
|
|
expect(connection.parametrized_insert_statements).to be_nil
|
|
end
|
|
end
|
|
|
|
describe "#closed?" do
|
|
it "correctly reports if connection is closed" do
|
|
expect(connection.closed?).to be false
|
|
connection.close
|
|
expect(connection.closed?).to be true
|
|
end
|
|
end
|
|
|
|
describe "#insert" do
|
|
it "can be called without errors" do
|
|
expect { connection.insert(sql, [1, "Alice"]) }.not_to raise_error
|
|
end
|
|
end
|
|
|
|
describe "#parametrized_insert_statements" do
|
|
it "returns an empty array if nothing has been cached" do
|
|
expect(connection.parametrized_insert_statements).to eq([])
|
|
end
|
|
|
|
it "returns the cached INSERT statements and parameters in original order" do
|
|
connection.insert(sql, [1, "Alice"])
|
|
connection.insert(sql, [2, "Bob"])
|
|
connection.insert(sql, [3, "Carol"])
|
|
|
|
expected_data = [[sql, [1, "Alice"]], [sql, [2, "Bob"]], [sql, [3, "Carol"]]]
|
|
expect(connection.parametrized_insert_statements).to eq(expected_data)
|
|
|
|
# multiple calls return the same data
|
|
expect(connection.parametrized_insert_statements).to eq(expected_data)
|
|
expect(connection.parametrized_insert_statements).to eq(expected_data)
|
|
end
|
|
end
|
|
|
|
describe "#clear!" do
|
|
it "clears all cached data" do
|
|
connection.insert(sql, [1, "Alice"])
|
|
connection.insert(sql, [2, "Bob"])
|
|
connection.insert(sql, [3, "Carol"])
|
|
|
|
expect(connection.parametrized_insert_statements).to_not be_empty
|
|
|
|
connection.clear!
|
|
expect(connection.parametrized_insert_statements).to eq([])
|
|
end
|
|
end
|
|
end
|