mirror of
https://github.com/discourse/discourse.git
synced 2024-12-24 22:04:43 +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.
42 lines
1.3 KiB
Ruby
42 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "extralite"
|
|
|
|
RSpec.describe ::Migrations::Database::PreparedStatementCache do
|
|
let(:cache) { described_class.new(3) }
|
|
|
|
def create_statement_double
|
|
instance_double(Extralite::Query, close: nil)
|
|
end
|
|
|
|
it "should inherit behavior from LruRedux::Cache" do
|
|
expect(described_class).to be < LruRedux::Cache
|
|
end
|
|
|
|
it "closes the statement when an old entry is removed" do
|
|
cache["a"] = a_statement = create_statement_double
|
|
cache["b"] = b_statement = create_statement_double
|
|
cache["c"] = c_statement = create_statement_double
|
|
|
|
# this should remove the oldest entry "a" from the cache and call #close on the statement
|
|
cache["d"] = d_statement = create_statement_double
|
|
|
|
expect(a_statement).to have_received(:close)
|
|
expect(b_statement).not_to have_received(:close)
|
|
expect(c_statement).not_to have_received(:close)
|
|
expect(d_statement).not_to have_received(:close)
|
|
end
|
|
|
|
it "closes all statements when the cache is cleared" do
|
|
cache["a"] = a_statement = create_statement_double
|
|
cache["b"] = b_statement = create_statement_double
|
|
cache["c"] = c_statement = create_statement_double
|
|
|
|
cache.clear
|
|
|
|
expect(a_statement).to have_received(:close)
|
|
expect(b_statement).to have_received(:close)
|
|
expect(c_statement).to have_received(:close)
|
|
end
|
|
end
|