mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 06:04:11 +08:00
5a1318e3c3
* DEV: upgrade mini_sql Even though we are not planning on using this quite yet, mini_sql now supports prepared statements. Would like this upgrade merged so we can do some benchmarking. Note, this will not work with pg_bouncer, but sites that are not using it may benefit from the feature. * implement multisite friendly prepared statements
84 lines
1.9 KiB
Ruby
84 lines
1.9 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
describe MiniSqlMultisiteConnection do
|
|
|
|
describe "after_commit" do
|
|
it "works for 'fake' (joinable) transactions" do
|
|
outputString = "1"
|
|
|
|
ActiveRecord::Base.transaction do
|
|
outputString += "2"
|
|
DB.exec("SELECT 1")
|
|
ActiveRecord::Base.transaction do
|
|
DB.exec("SELECT 2")
|
|
outputString += "3"
|
|
DB.after_commit { outputString += "6" }
|
|
outputString += "4"
|
|
end
|
|
DB.after_commit { outputString += "7" }
|
|
outputString += "5"
|
|
end
|
|
|
|
expect(outputString).to eq("1234567")
|
|
end
|
|
|
|
it "works for real (non-joinable) transactions" do
|
|
outputString = "1"
|
|
|
|
ActiveRecord::Base.transaction(requires_new: true, joinable: false) do
|
|
outputString += "2"
|
|
DB.exec("SELECT 1")
|
|
ActiveRecord::Base.transaction(requires_new: true) do
|
|
DB.exec("SELECT 2")
|
|
outputString += "3"
|
|
DB.after_commit { outputString += "6" }
|
|
outputString += "4"
|
|
end
|
|
DB.after_commit { outputString += "7" }
|
|
outputString += "5"
|
|
end
|
|
|
|
expect(outputString).to eq("1234567")
|
|
end
|
|
|
|
it "does not run if the transaction is rolled back" do
|
|
outputString = "1"
|
|
|
|
ActiveRecord::Base.transaction do
|
|
outputString += "2"
|
|
|
|
DB.after_commit do
|
|
outputString += "4"
|
|
end
|
|
|
|
outputString += "3"
|
|
|
|
raise ActiveRecord::Rollback
|
|
end
|
|
|
|
expect(outputString).to eq("123")
|
|
end
|
|
|
|
it "runs immediately if there is no transaction" do
|
|
outputString = "1"
|
|
|
|
DB.after_commit do
|
|
outputString += "2"
|
|
end
|
|
|
|
outputString += "3"
|
|
|
|
expect(outputString).to eq("123")
|
|
end
|
|
|
|
it "supports prepared statements" do
|
|
DB.prepared.query("SELECT ?", 1)
|
|
DB.prepared.query("SELECT ?", 2)
|
|
end
|
|
|
|
end
|
|
|
|
end
|