mirror of
https://github.com/discourse/discourse.git
synced 2025-03-06 12:35:21 +08:00

In ab5361d69ae4b55a7635676eef7d80dd96d8460c, 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 to ab5361d69ae4b55a7635676eef7d80dd96d8460c
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
|