Merge pull request #3477 from PierreMesure/upgrade-tag-to-category

Fix a bug where a category can't be created if it already exists as a tag
This commit is contained in:
Javier Martín
2020-04-06 15:52:52 +02:00
committed by GitHub
2 changed files with 15 additions and 1 deletions

View File

@@ -9,7 +9,8 @@ class Admin::TagsController < Admin::BaseController
end
def create
Tag.category.create!(tag_params)
Tag.find_or_create_by!(name: tag_params["name"]).update!(kind: "category")
redirect_to admin_tags_path
end

View File

@@ -88,4 +88,17 @@ describe "Admin tags" do
expect(Tag.category.where(name: "wow_category")).to exist
end
end
scenario "Upgrade tag to category" do
create(:tag, name: "Soon a category")
visit admin_tags_path
within("form.new_tag") do
fill_in "tag_name", with: "Soon a category"
click_button "Create topic"
end
expect(page).to have_content "Soon a category"
end
end