discourse/spec/lib/mini_sql_multisite_connection_spec.rb
Sam Saffron 4ea21fa2d0 DEV: use #frozen_string_literal: true on all spec
This change both speeds up specs (less strings to allocate) and helps catch
cases where methods in Discourse are mutating inputs.

Overall we will be migrating everything to use #frozen_string_literal: true
it will take a while, but this is the first and safest move in this direction
2019-04-30 10:27:42 +10:00

55 lines
1.1 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
describe MiniSqlMultisiteConnection do
describe "after_commit" do
it "runs callbacks after outermost transaction is committed" do
outputString = "1"
# Main transaction
ActiveRecord::Base.transaction do
outputString += "2"
# Nested transaction
ActiveRecord::Base.transaction do
outputString += "3"
DB.after_commit do
outputString += "6"
end
outputString += "4"
end
DB.after_commit do
outputString += "7"
end
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
end
end