mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 05:13:44 +08:00
493d437e79
* Remove outdated option
04078317ba
* Use the non-globally exposed RSpec syntax
https://github.com/rspec/rspec-core/pull/2803
* Use the non-globally exposed RSpec syntax, cont
https://github.com/rspec/rspec-core/pull/2803
* Comply to strict predicate matchers
See:
- https://github.com/rspec/rspec-expectations/pull/1195
- https://github.com/rspec/rspec-expectations/pull/1196
- https://github.com/rspec/rspec-expectations/pull/1277
40 lines
1.3 KiB
Ruby
40 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.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
|
|
SiteSetting.verbose_user_stat_count_logging = true
|
|
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")
|
|
expect(@fake_logger.warnings.last).to match(post.id.to_s)
|
|
|
|
UserStatCountUpdater.decrement!(post_2, user_stat: user_stat)
|
|
|
|
expect(@fake_logger.warnings.last).to match("post_count")
|
|
expect(@fake_logger.warnings.last).to match(post_2.id.to_s)
|
|
end
|
|
|
|
it 'should log the exception when a negative count will be inserted but 0 is used instead' do
|
|
UserStatCountUpdater.set!(user_stat: user_stat, count: -10, count_column: :post_count)
|
|
|
|
expect(@fake_logger.warnings.last).to match("post_count")
|
|
expect(@fake_logger.warnings.last).to match("using 0")
|
|
expect(@fake_logger.warnings.last).to match("user #{user_stat.user_id}")
|
|
expect(user_stat.reload.post_count).to eq(0)
|
|
end
|
|
end
|