From a4dbec5bf9a96156c2cc8a912f1db55f47662ef7 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Mon, 18 Nov 2019 15:54:00 -0500 Subject: [PATCH] FIX: unable to remove required tag group from a category --- app/controllers/categories_controller.rb | 1 + app/models/category.rb | 2 +- spec/requests/categories_controller_spec.rb | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 12b77e55475..191b2f433e2 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -281,6 +281,7 @@ class CategoriesController < ApplicationController if SiteSetting.tagging_enabled params[:allowed_tags] ||= [] params[:allowed_tag_groups] ||= [] + params[:required_tag_group_name] ||= '' end result = params.permit( diff --git a/app/models/category.rb b/app/models/category.rb index 62ae074692b..e2f40f91f0d 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -559,7 +559,7 @@ class Category < ActiveRecord::Base end def required_tag_group_name=(group_name) - self.required_tag_group = group_name ? TagGroup.where(name: group_name).first : nil + self.required_tag_group = group_name.blank? ? nil : TagGroup.where(name: group_name).first end def downcase_email diff --git a/spec/requests/categories_controller_spec.rb b/spec/requests/categories_controller_spec.rb index 0ff51d1c924..941e4b06ff3 100644 --- a/spec/requests/categories_controller_spec.rb +++ b/spec/requests/categories_controller_spec.rb @@ -334,6 +334,7 @@ describe CategoriesController do describe "success" do it "updates attributes correctly" do + SiteSetting.tagging_enabled = true readonly = CategoryGroup.permission_types[:readonly] create_post = CategoryGroup.permission_types[:create_post] tag_group = Fabricate(:tag_group) @@ -415,6 +416,22 @@ describe CategoriesController do expect(category.num_auto_bump_daily).to eq(10) expect(category.navigate_to_first_post_after_read).to eq(true) end + + it "can remove required tag group" do + SiteSetting.tagging_enabled = true + category.update!(required_tag_group: Fabricate(:tag_group)) + put "/categories/#{category.id}.json", params: { + name: category.name, + color: category.color, + text_color: category.text_color, + allow_global_tags: 'false', + min_tags_from_required_group: 1 + } + + expect(response.status).to eq(200) + category.reload + expect(category.required_tag_group).to be_nil + end end end end