FIX: adjust `full_url` method in `ChatIntegrationReferencePost` to return the correct URL (#220)

* FIX: adjust `full_url` method in `ChatIntegrationReferencePost` to return the correct URL

before it automation would fail because topic does not have `full_url` method

* DEV: remove logs
This commit is contained in:
Gabriel Grubba 2024-09-18 05:37:52 -03:00 committed by GitHub
parent 6e7917bd5e
commit afc4540c03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 84 additions and 3 deletions

View File

@ -24,7 +24,7 @@ module DiscourseChatIntegration
end end
def full_url def full_url
@topic.posts.empty? ? @topic.full_url : @topic.posts.first.full_url @topic.posts.empty? ? @topic.url : @topic.posts.first.full_url
end end
def excerpt(maxlength = nil, options = {}) def excerpt(maxlength = nil, options = {})

View File

@ -18,7 +18,7 @@ RSpec.describe DiscourseChatIntegration::ChatIntegrationReferencePost do
context["removed_tags"] = %w[tag3 tag4] context["removed_tags"] = %w[tag3 tag4]
end end
it "creates a post with the correct raw" do it "creates a post with the correct .raw" do
post = post =
described_class.new( described_class.new(
user: context["user"], user: context["user"],
@ -32,7 +32,7 @@ RSpec.describe DiscourseChatIntegration::ChatIntegrationReferencePost do
expect(post.raw).to eq("Added #tag1, #tag2 and removed #tag3, #tag4") expect(post.raw).to eq("Added #tag1, #tag2 and removed #tag3, #tag4")
end end
it "has a working excerpt" do it "has a working .excerpt" do
post = post =
described_class.new( described_class.new(
user: context["user"], user: context["user"],
@ -45,5 +45,86 @@ RSpec.describe DiscourseChatIntegration::ChatIntegrationReferencePost do
) )
expect(post.excerpt).to eq("Added #tag1, #tag2 and removed #tag3, #tag4") expect(post.excerpt).to eq("Added #tag1, #tag2 and removed #tag3, #tag4")
end end
it "has a working .full_url" do
post =
described_class.new(
user: context["user"],
topic: context["topic"],
kind: context["kind"],
context: {
"added_tags" => context["added_tags"],
"removed_tags" => context["removed_tags"],
},
)
expect(post.full_url).to eq(topic.posts.first.full_url)
new_topic = Fabricate(:topic)
post =
described_class.new(
user: context["user"],
topic: new_topic,
kind: context["kind"],
context: {
"added_tags" => context["added_tags"],
"removed_tags" => context["removed_tags"],
},
)
expect(post.full_url).to eq(new_topic.url)
end
it "has a working .is_first_post?" do
post =
described_class.new(
user: context["user"],
topic: context["topic"],
kind: context["kind"],
context: {
"added_tags" => context["added_tags"],
"removed_tags" => context["removed_tags"],
},
)
expect(post.is_first_post?).to eq(false) # we had a post already
new_topic = Fabricate(:topic)
post =
described_class.new(
user: context["user"],
topic: new_topic,
kind: context["kind"],
context: {
"added_tags" => context["added_tags"],
"removed_tags" => context["removed_tags"],
},
)
expect(post.is_first_post?).to eq(true)
end
it "has a working .id" do
new_topic = Fabricate(:topic)
post =
described_class.new(
user: context["user"],
topic: new_topic,
kind: context["kind"],
context: {
"added_tags" => context["added_tags"],
"removed_tags" => context["removed_tags"],
},
)
expect(post.id).to eq(new_topic.id)
post =
described_class.new(
user: context["user"],
topic: context["topic"],
kind: context["kind"],
context: {
"added_tags" => context["added_tags"],
"removed_tags" => context["removed_tags"],
},
)
expect(post.id).to eq(first_post.id)
end
end end
end end