mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Add specs for hashtags related code (#18526)
Adding a couple of small specs to code around hashtags for tags and categories since I will be working in this area soon and these were not covered.
This commit is contained in:
parent
dc89b72d46
commit
cab173d3b5
@ -15,4 +15,35 @@ RSpec.describe PrettyText::Helpers do
|
||||
expect(result[short_url][:url]).to eq("https://awesome.com#{upload.url}")
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
@ -32,6 +32,16 @@ RSpec.describe HashtagsController do
|
||||
)
|
||||
end
|
||||
|
||||
it "handles tags with the TAG_HASHTAG_POSTFIX" do
|
||||
get "/hashtags.json", params: { slugs: ["#{tag.name}#{PrettyText::Helpers::TAG_HASHTAG_POSTFIX}"] }
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.parsed_body).to eq(
|
||||
"categories" => {},
|
||||
"tags" => { tag.name => tag.full_url }
|
||||
)
|
||||
end
|
||||
|
||||
it "does not return restricted categories or hidden tags" do
|
||||
get "/hashtags.json", params: { slugs: [private_category.slug, hidden_tag.name] }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user