FIX: 404 when filtering by category, no sub-category, and a tag
This commit is contained in:
parent
efc6408b1d
commit
82e170d6a6
|
@ -197,15 +197,21 @@ class TagsController < ::ApplicationController
|
|||
slug_or_id = params[:category]
|
||||
return true if slug_or_id.nil?
|
||||
|
||||
parent_slug_or_id = params[:parent_category]
|
||||
if slug_or_id == 'none' && params[:parent_category]
|
||||
@filter_on_category = Category.query_category(params[:parent_category], nil)
|
||||
params[:no_subcategories] = 'true'
|
||||
else
|
||||
parent_slug_or_id = params[:parent_category]
|
||||
|
||||
parent_category_id = nil
|
||||
if parent_slug_or_id.present?
|
||||
parent_category_id = Category.query_parent_category(parent_slug_or_id)
|
||||
redirect_or_not_found and return if parent_category_id.blank?
|
||||
parent_category_id = nil
|
||||
if parent_slug_or_id.present?
|
||||
parent_category_id = Category.query_parent_category(parent_slug_or_id)
|
||||
redirect_or_not_found and return if parent_category_id.blank?
|
||||
end
|
||||
|
||||
@filter_on_category = Category.query_category(slug_or_id, parent_category_id)
|
||||
end
|
||||
|
||||
@filter_on_category = Category.query_category(slug_or_id, parent_category_id)
|
||||
redirect_or_not_found and return if !@filter_on_category
|
||||
|
||||
guardian.ensure_can_see!(@filter_on_category)
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe TagsController do
|
||||
describe 'show_latest' do
|
||||
let(:tag) { Fabricate(:tag) }
|
||||
let(:category) { Fabricate(:category) }
|
||||
let(:subcategory) { Fabricate(:category, parent_category_id: category.id) }
|
||||
|
||||
context 'tagging disabled' do
|
||||
it "returns 404" do
|
||||
xhr :get, :show_latest, tag_id: tag.name
|
||||
expect(response.status).to eq(404)
|
||||
end
|
||||
end
|
||||
|
||||
context 'tagging enabled' do
|
||||
before do
|
||||
SiteSetting.tagging_enabled = true
|
||||
end
|
||||
|
||||
it "can filter by tag" do
|
||||
xhr :get, :show_latest, tag_id: tag.name
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it "can filter by category and tag" do
|
||||
xhr :get, :show_latest, tag_id: tag.name, category: category.slug
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it "can filter by category, sub-category, and tag" do
|
||||
xhr :get, :show_latest, tag_id: tag.name, category: subcategory.slug, parent_category: category.slug
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it "can filter by category, no sub-category, and tag" do
|
||||
xhr :get, :show_latest, tag_id: tag.name, category: 'none', parent_category: category.slug
|
||||
expect(response).to be_success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue