FIX: flaky post action counts specs (#27165)

After flags were moved to the database, with each save they are changing available PostActionTypes. Therefore, flag specs should clear the state before and after each example not just before.

In addition, we need to clear `nil` counts for dynamically created flags from serializer.
This commit is contained in:
Krzysztof Kotlarek 2024-05-24 11:55:32 +10:00 committed by GitHub
parent 3a3ee5e04a
commit a4c5f85b10
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View File

@ -331,7 +331,7 @@ class PostSerializer < BasicPostSerializer
summary[:count] = summary[:acted] ? 1 : 0
end
summary.delete(:count) if summary[:count] == 0
summary.delete(:count) if summary[:count].to_i.zero?
# Only include it if the user can do it or it has a count
result << summary if summary[:can_act] || summary[:count]

View File

@ -1,7 +1,11 @@
# frozen_string_literal: true
RSpec.describe Flag, type: :model do
before { Flag.reset_flag_settings! }
around do |test|
Flag.reset_flag_settings!
test.call
Flag.reset_flag_settings!
end
it "has id lower than 1000 for system flags" do
flag = Fabricate(:flag, id: 1)