Simplify the method and fix Rubocop warnings

This commit is contained in:
Pierre Mesure
2020-03-30 21:40:10 +02:00
parent 055ff803c6
commit 67911b4e35
2 changed files with 3 additions and 9 deletions

View File

@@ -9,13 +9,8 @@ class Admin::TagsController < Admin::BaseController
end
def create
@existing_tag = Tag.where(name: tag_params.first).first
if @existing_tag
@existing_tag.kind = "category"
@existing_tag.save
else
Tag.category.create(tag_params)
end
Tag.find_or_create_by!(name: tag_params["name"]).update!(kind: "category")
redirect_to admin_tags_path
end

View File

@@ -90,7 +90,7 @@ describe "Admin tags" do
end
scenario "Upgrade tag to category" do
not_category_tag = create(:tag, name: "Soon a category")
create(:tag, name: "Soon a category")
visit admin_tags_path
@@ -101,5 +101,4 @@ describe "Admin tags" do
expect(page).to have_content "Soon a category"
end
end