2019-10-14 15:27:33 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe PrettyText::Helpers do
|
2022-07-28 00:14:14 +08:00
|
|
|
describe ".lookup_upload_urls" do
|
2019-10-14 15:27:33 +08:00
|
|
|
let(:upload) { Fabricate(:upload) }
|
|
|
|
|
|
|
|
it "should return cdn url if available" do
|
|
|
|
short_url = upload.short_url
|
|
|
|
result = PrettyText::Helpers.lookup_upload_urls([short_url])
|
|
|
|
expect(result[short_url][:url]).to eq(upload.url)
|
|
|
|
|
|
|
|
set_cdn_url "https://awesome.com"
|
|
|
|
|
|
|
|
result = PrettyText::Helpers.lookup_upload_urls([short_url])
|
|
|
|
expect(result[short_url][:url]).to eq("https://awesome.com#{upload.url}")
|
|
|
|
end
|
|
|
|
end
|
2022-10-11 07:04:51 +08:00
|
|
|
|
|
|
|
describe ".category_tag_hashtag_lookup" do
|
|
|
|
fab!(:tag) { Fabricate(:tag, name: "somecooltag") }
|
|
|
|
fab!(:category) do
|
|
|
|
Fabricate(:category, name: "Some Awesome Category", slug: "someawesomecategory")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "handles tags based on slug with TAG_HASHTAG_POSTFIX" do
|
|
|
|
expect(
|
|
|
|
PrettyText::Helpers.category_tag_hashtag_lookup(
|
|
|
|
+"somecooltag#{PrettyText::Helpers::TAG_HASHTAG_POSTFIX}",
|
|
|
|
),
|
|
|
|
).to eq([tag.url, "somecooltag"])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "handles categories based on slug" do
|
|
|
|
expect(PrettyText::Helpers.category_tag_hashtag_lookup("someawesomecategory")).to eq(
|
|
|
|
[category.url, "someawesomecategory"],
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "handles tags based on slug without TAG_HASHTAG_POSTFIX" do
|
|
|
|
expect(PrettyText::Helpers.category_tag_hashtag_lookup(+"somecooltag")).to eq(
|
|
|
|
[tag.url, "somecooltag"],
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns nil when no tag or category that matches exists" do
|
|
|
|
expect(PrettyText::Helpers.category_tag_hashtag_lookup("blah")).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
2019-10-14 15:27:33 +08:00
|
|
|
end
|