diff --git a/lib/discourse_chat_integration/chat_integration_reference_post.rb b/lib/discourse_chat_integration/chat_integration_reference_post.rb index 57bad51..7aca38d 100644 --- a/lib/discourse_chat_integration/chat_integration_reference_post.rb +++ b/lib/discourse_chat_integration/chat_integration_reference_post.rb @@ -24,7 +24,7 @@ module DiscourseChatIntegration end 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 def excerpt(maxlength = nil, options = {}) diff --git a/spec/lib/discourse_chat_integration/chat_integration_reference_post_spec.rb b/spec/lib/discourse_chat_integration/chat_integration_reference_post_spec.rb index a2d5deb..8b27f58 100644 --- a/spec/lib/discourse_chat_integration/chat_integration_reference_post_spec.rb +++ b/spec/lib/discourse_chat_integration/chat_integration_reference_post_spec.rb @@ -18,7 +18,7 @@ RSpec.describe DiscourseChatIntegration::ChatIntegrationReferencePost do context["removed_tags"] = %w[tag3 tag4] end - it "creates a post with the correct raw" do + it "creates a post with the correct .raw" do post = described_class.new( user: context["user"], @@ -32,7 +32,7 @@ RSpec.describe DiscourseChatIntegration::ChatIntegrationReferencePost do expect(post.raw).to eq("Added #tag1, #tag2 and removed #tag3, #tag4") end - it "has a working excerpt" do + it "has a working .excerpt" do post = described_class.new( user: context["user"], @@ -45,5 +45,86 @@ RSpec.describe DiscourseChatIntegration::ChatIntegrationReferencePost do ) expect(post.excerpt).to eq("Added #tag1, #tag2 and removed #tag3, #tag4") 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