Skip to content

Commit

Permalink
FIX: unable to remove required tag group from a category
Browse files Browse the repository at this point in the history
  • Loading branch information
nlalonde committed Nov 18, 2019
1 parent 228c481 commit a4dbec5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/controllers/categories_controller.rb
Expand Up @@ -281,6 +281,7 @@ def category_params
if SiteSetting.tagging_enabled
params[:allowed_tags] ||= []
params[:allowed_tag_groups] ||= []
params[:required_tag_group_name] ||= ''
end

result = params.permit(
Expand Down
2 changes: 1 addition & 1 deletion app/models/category.rb
Expand Up @@ -559,7 +559,7 @@ def allowed_tag_groups=(group_names)
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
Expand Down
17 changes: 17 additions & 0 deletions spec/requests/categories_controller_spec.rb
Expand Up @@ -334,6 +334,7 @@

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)
Expand Down Expand Up @@ -415,6 +416,22 @@
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
Expand Down

0 comments on commit a4dbec5

Please sign in to comment.