mirror of
https://github.com/discourse/discourse.git
synced 2025-09-05 08:59:27 +08:00
Fix bug where links to posts weren't being tracked
This commit is contained in:
parent
941820ac88
commit
dee9e9a51f
4 changed files with 58 additions and 1 deletions
|
@ -148,6 +148,14 @@ test
|
|||
PrettyText.extract_links("<a href='http://cnn.com'>http://bla.com</a>").to_a.should == ["http://cnn.com"]
|
||||
end
|
||||
|
||||
it "should extract links to topics" do
|
||||
PrettyText.extract_links("<aside class=\"quote\" data-topic=\"321\">aside</aside>").to_a.should == ["/t/topic/321"]
|
||||
end
|
||||
|
||||
it "should extract links to posts" do
|
||||
PrettyText.extract_links("<aside class=\"quote\" data-topic=\"1234\" data-post=\"4567\">aside</aside>").to_a.should == ["/t/topic/1234/4567"]
|
||||
end
|
||||
|
||||
it "should not preserve tags in code blocks" do
|
||||
PrettyText.excerpt("<pre><code class='handlebars'><h3>Hours</h3></code></pre>",100).should == "<h3>Hours</h3>"
|
||||
end
|
||||
|
|
|
@ -46,12 +46,40 @@ describe TopicLink do
|
|||
|
||||
describe 'internal links' do
|
||||
|
||||
context "rendered onebox" do
|
||||
|
||||
before do
|
||||
@other_topic = Fabricate(:topic, user: @user)
|
||||
@other_topic.posts.create(user: @user, raw: "some content for the first post")
|
||||
@other_post = @other_topic.posts.create(user: @user, raw: "some content for the second post")
|
||||
|
||||
@url = "http://#{test_uri.host}/t/#{@other_topic.slug}/#{@other_topic.id}/#{@other_post.post_number}"
|
||||
|
||||
@topic.posts.create(user: @user, raw: 'initial post')
|
||||
@post = @topic.posts.create(user: @user, raw: "Link to another topic:\n\n#{@url}\n\n")
|
||||
@post.reload
|
||||
TopicLink.extract_from(@post)
|
||||
|
||||
@link = @topic.topic_links.first
|
||||
end
|
||||
|
||||
it "should have a link" do
|
||||
@link.should be_present
|
||||
end
|
||||
|
||||
it "should be the canonical URL" do
|
||||
@link.url.should == @url
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
context 'topic link' do
|
||||
before do
|
||||
@other_topic = Fabricate(:topic, user: @user)
|
||||
@other_post = @other_topic.posts.create(user: @user, raw: "some content")
|
||||
|
||||
@url = "http://#{test_uri.host}/t/topic-slug/#{@other_topic.id}"
|
||||
@url = "http://#{test_uri.host}/t/#{@other_topic.slug}/#{@other_topic.id}"
|
||||
|
||||
@topic.posts.create(user: @user, raw: 'initial post')
|
||||
@post = @topic.posts.create(user: @user, raw: "Link to another topic: #{@url}")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue