Skip to content
This repository was archived by the owner on Jul 14, 2025. It is now read-only.

Commit afc4540

Browse files
authored
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
1 parent 6e7917b commit afc4540

File tree

2 files changed

+84
-3
lines changed

2 files changed

+84
-3
lines changed

lib/discourse_chat_integration/chat_integration_reference_post.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def topic
2424
end
2525

2626
def full_url
27-
@topic.posts.empty? ? @topic.full_url : @topic.posts.first.full_url
27+
@topic.posts.empty? ? @topic.url : @topic.posts.first.full_url
2828
end
2929

3030
def excerpt(maxlength = nil, options = {})

spec/lib/discourse_chat_integration/chat_integration_reference_post_spec.rb

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
context["removed_tags"] = %w[tag3 tag4]
1919
end
2020

21-
it "creates a post with the correct raw" do
21+
it "creates a post with the correct .raw" do
2222
post =
2323
described_class.new(
2424
user: context["user"],
@@ -32,7 +32,7 @@
3232
expect(post.raw).to eq("Added #tag1, #tag2 and removed #tag3, #tag4")
3333
end
3434

35-
it "has a working excerpt" do
35+
it "has a working .excerpt" do
3636
post =
3737
described_class.new(
3838
user: context["user"],
@@ -45,5 +45,86 @@
4545
)
4646
expect(post.excerpt).to eq("Added #tag1, #tag2 and removed #tag3, #tag4")
4747
end
48+
49+
it "has a working .full_url" do
50+
post =
51+
described_class.new(
52+
user: context["user"],
53+
topic: context["topic"],
54+
kind: context["kind"],
55+
context: {
56+
"added_tags" => context["added_tags"],
57+
"removed_tags" => context["removed_tags"],
58+
},
59+
)
60+
expect(post.full_url).to eq(topic.posts.first.full_url)
61+
62+
new_topic = Fabricate(:topic)
63+
post =
64+
described_class.new(
65+
user: context["user"],
66+
topic: new_topic,
67+
kind: context["kind"],
68+
context: {
69+
"added_tags" => context["added_tags"],
70+
"removed_tags" => context["removed_tags"],
71+
},
72+
)
73+
expect(post.full_url).to eq(new_topic.url)
74+
end
75+
76+
it "has a working .is_first_post?" do
77+
post =
78+
described_class.new(
79+
user: context["user"],
80+
topic: context["topic"],
81+
kind: context["kind"],
82+
context: {
83+
"added_tags" => context["added_tags"],
84+
"removed_tags" => context["removed_tags"],
85+
},
86+
)
87+
expect(post.is_first_post?).to eq(false) # we had a post already
88+
89+
new_topic = Fabricate(:topic)
90+
post =
91+
described_class.new(
92+
user: context["user"],
93+
topic: new_topic,
94+
kind: context["kind"],
95+
context: {
96+
"added_tags" => context["added_tags"],
97+
"removed_tags" => context["removed_tags"],
98+
},
99+
)
100+
expect(post.is_first_post?).to eq(true)
101+
end
102+
103+
it "has a working .id" do
104+
new_topic = Fabricate(:topic)
105+
post =
106+
described_class.new(
107+
user: context["user"],
108+
topic: new_topic,
109+
kind: context["kind"],
110+
context: {
111+
"added_tags" => context["added_tags"],
112+
"removed_tags" => context["removed_tags"],
113+
},
114+
)
115+
expect(post.id).to eq(new_topic.id)
116+
117+
post =
118+
described_class.new(
119+
user: context["user"],
120+
topic: context["topic"],
121+
kind: context["kind"],
122+
context: {
123+
"added_tags" => context["added_tags"],
124+
"removed_tags" => context["removed_tags"],
125+
},
126+
)
127+
expect(post.id).to eq(first_post.id)
128+
end
48129
end
49130
end

0 commit comments

Comments
 (0)