FIX: Link to category settings should use slug
Links to category settings were created using the category name. If the name was a single word, the link would be valid (regardless of capitalization). For example, if the category was named `Awesome` `/c/Awesome/edit/settings` is a valid URL as that is a case-insensitive match for the category slug of `awesome`. However, if the category had a space in it, the URL would be `/c/Awesome%20Name/edit/settings` which does not match the slug of `awesome-name`. This change uses the category slug, rather than the name, which is the expected behaviour (see `Category.find_by_slug_path`).
This commit is contained in:
parent
c4ea158656
commit
19a0bdc0ee
|
@ -72,7 +72,7 @@ class ReviewableScoreSerializer < ApplicationSerializer
|
||||||
when 'watched_word'
|
when 'watched_word'
|
||||||
"#{Discourse.base_url}/admin/customize/watched_words"
|
"#{Discourse.base_url}/admin/customize/watched_words"
|
||||||
when 'category'
|
when 'category'
|
||||||
"#{Discourse.base_url}/c/#{object.reviewable.category&.name}/edit/settings"
|
"#{Discourse.base_url}/c/#{object.reviewable.category&.slug}/edit/settings"
|
||||||
else
|
else
|
||||||
"#{Discourse.base_url}/admin/site_settings/category/all_results?filter=#{text}"
|
"#{Discourse.base_url}/admin/site_settings/category/all_results?filter=#{text}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
Fabricator(:category) do
|
Fabricator(:category) do
|
||||||
name { sequence(:name) { |n| "Amazing Category #{n}" } }
|
name { sequence(:name) { |n| "Amazing Category #{n}" } }
|
||||||
|
slug { sequence(:slug) { |n| "amazing-category-#{n}" } }
|
||||||
skip_category_definition true
|
skip_category_definition true
|
||||||
user
|
user
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,7 +18,7 @@ RSpec.describe ReviewableScoreSerializer do
|
||||||
category = Fabricate.build(:category)
|
category = Fabricate.build(:category)
|
||||||
reviewable.category = category
|
reviewable.category = category
|
||||||
serialized = serialized_score('category')
|
serialized = serialized_score('category')
|
||||||
link_url = "#{Discourse.base_url}/c/#{category.name}/edit/settings"
|
link_url = "#{Discourse.base_url}/c/#{category.slug}/edit/settings"
|
||||||
category_link = "<a href=\"#{link_url}\">#{I18n.t('reviewables.reasons.links.category')}</a>"
|
category_link = "<a href=\"#{link_url}\">#{I18n.t('reviewables.reasons.links.category')}</a>"
|
||||||
|
|
||||||
expect(serialized.reason).to include(category_link)
|
expect(serialized.reason).to include(category_link)
|
||||||
|
|
Loading…
Reference in New Issue