From ea194b1f4f4e6e4755d6e5bfffb342f28690ecdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Saquetim?= Date: Tue, 24 Jun 2025 01:28:59 -0300 Subject: [PATCH] DEV: Update tests to use `topic_with_op` fabrication for topic consistency This ensures tests work with topics that include an original post by default, improving test reliability and coverage. Adjustments were made to guardian_extensions_spec and solved_spec to reflect this. --- spec/integration/solved_spec.rb | 4 ++-- spec/lib/guardian_extensions_spec.rb | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/spec/integration/solved_spec.rb b/spec/integration/solved_spec.rb index 9a65f76..a6769a2 100644 --- a/spec/integration/solved_spec.rb +++ b/spec/integration/solved_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" RSpec.describe "Managing Posts solved status" do - let(:topic) { Fabricate(:topic) } + let(:topic) { Fabricate(:topic_with_op) } fab!(:user) { Fabricate(:trust_level_4) } let(:p1) { Fabricate(:post, topic: topic) } @@ -238,7 +238,7 @@ RSpec.describe "Managing Posts solved status" do it "gives priority to category's solved_topics_auto_close_hours setting" do freeze_time custom_auto_close_category = Fabricate(:category) - topic_2 = Fabricate(:topic, category: custom_auto_close_category) + topic_2 = Fabricate(:topic_with_op, category: custom_auto_close_category) post_2 = Fabricate(:post, topic: topic_2) custom_auto_close_category.custom_fields["solved_topics_auto_close_hours"] = 4 custom_auto_close_category.save_custom_fields diff --git a/spec/lib/guardian_extensions_spec.rb b/spec/lib/guardian_extensions_spec.rb index a3354b5..1ac6f99 100644 --- a/spec/lib/guardian_extensions_spec.rb +++ b/spec/lib/guardian_extensions_spec.rb @@ -5,7 +5,7 @@ require "rails_helper" describe DiscourseSolved::GuardianExtensions do fab!(:user) { Fabricate(:user, refresh_auto_groups: true) } fab!(:other_user) { Fabricate(:user, refresh_auto_groups: true) } - fab!(:topic) + fab!(:topic) { Fabricate(:topic_with_op) } fab!(:post) { Fabricate(:post, topic: topic, user: other_user) } let(:guardian) { user.guardian } @@ -17,9 +17,10 @@ describe DiscourseSolved::GuardianExtensions do expect(Guardian.new.can_accept_answer?(topic, post)).to eq(false) end - it "returns false if the topic is nil, the post is nil, or for whispers" do + it "returns false if the topic is nil, the post is nil, for the first post or for whispers" do expect(guardian.can_accept_answer?(nil, post)).to eq(false) expect(guardian.can_accept_answer?(topic, nil)).to eq(false) + expect(guardian.can_accept_answer?(topic, topic.first_post)).to eq(false) post.update!(post_type: Post.types[:whisper]) expect(guardian.can_accept_answer?(topic, post)).to eq(false)