DEV: Add test for link watched words (#13251)
This commit is contained in:
parent
8cfe203383
commit
648d2fd793
|
@ -20,7 +20,7 @@ class WatchedWord < ActiveRecord::Base
|
|||
before_validation do
|
||||
self.word = self.class.normalize_word(self.word)
|
||||
if self.action == WatchedWord.actions[:link] && !(self.replacement =~ /^https?:\/\//)
|
||||
self.replacement = "#{Discourse.base_url}#{self.replacement.starts_with?("/") ? "" : "/"}#{self.replacement}"
|
||||
self.replacement = "#{Discourse.base_url}#{self.replacement&.starts_with?("/") ? "" : "/"}#{self.replacement}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -90,5 +90,16 @@ describe WatchedWord do
|
|||
expect(w.id).to eq(existing.id)
|
||||
}.to_not change { described_class.count }
|
||||
end
|
||||
|
||||
it "replaces link with absolute URL" do
|
||||
word = Fabricate(:watched_word, action: described_class.actions[:link], word: "meta1")
|
||||
expect(word.replacement).to eq("http://test.localhost/")
|
||||
|
||||
word = Fabricate(:watched_word, action: described_class.actions[:link], word: "meta2", replacement: "test")
|
||||
expect(word.replacement).to eq("http://test.localhost/test")
|
||||
|
||||
word = Fabricate(:watched_word, action: described_class.actions[:link], word: "meta3", replacement: "/test")
|
||||
expect(word.replacement).to eq("http://test.localhost/test")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue