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.
This commit is contained in:
Sérgio Saquetim 2025-06-24 01:28:59 -03:00
parent 5aed0b41c5
commit ea194b1f4f
No known key found for this signature in database
GPG Key ID: B4E3D7F11E793062
2 changed files with 5 additions and 4 deletions

View File

@ -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

View File

@ -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)