mirror of
https://github.com/discourse/discourse.git
synced 2025-02-09 11:49:47 +08:00
ae0625323a
Inab5361d69a
, we rescue from the PG error but the transaction is already aborted causing any DB query after to fail. As such, we avoid triggering the error in the first place by checking that we would not be insertin a negative number into the counter cache. Follow-up toab5361d69a
30 lines
740 B
Ruby
30 lines
740 B
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
describe UserStatCountUpdater do
|
|
fab!(:user) { Fabricate(:user) }
|
|
fab!(:user_stat) { user.user_stat }
|
|
fab!(:post) { Fabricate(:post) }
|
|
fab!(:post_2) { Fabricate(:post, topic: post.topic) }
|
|
|
|
before do
|
|
@orig_logger = Rails.logger
|
|
Rails.logger = @fake_logger = FakeLogger.new
|
|
end
|
|
|
|
after do
|
|
Rails.logger = @orig_logger
|
|
end
|
|
|
|
it 'should log the exception when a negative count is inserted' do
|
|
UserStatCountUpdater.decrement!(post, user_stat: user_stat)
|
|
|
|
expect(@fake_logger.warnings.last).to match("topic_count")
|
|
|
|
UserStatCountUpdater.decrement!(post_2, user_stat: user_stat)
|
|
|
|
expect(@fake_logger.warnings.last).to match("post_count")
|
|
end
|
|
end
|