From a4c5f85b10ea04f57ef5b248d69b44b5797471a3 Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Fri, 24 May 2024 11:55:32 +1000 Subject: [PATCH] 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. --- app/serializers/post_serializer.rb | 2 +- spec/models/flag_spec.rb | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/serializers/post_serializer.rb b/app/serializers/post_serializer.rb index e5efff27707..1c575b1dc60 100644 --- a/app/serializers/post_serializer.rb +++ b/app/serializers/post_serializer.rb @@ -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] diff --git a/spec/models/flag_spec.rb b/spec/models/flag_spec.rb index 9f384d947e8..ff26f05d474 100644 --- a/spec/models/flag_spec.rb +++ b/spec/models/flag_spec.rb @@ -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)