[15-Minute Fix] Fix Broken Admin Tags #create and #update Forms (#14049)

* Adds name to ALLOWED_PARAMS in Admin::TagsController

* Adds local: true to /admin/tags/_form.html.erb
  - Sets local: true in tags partial for proper
redirects and to properly render flash messages
for both the #create and #update actions

* Adds local: true to the Add Moderator button for tags

* Adds and updates systems specs for tags
  - Updates the admin_updates_tag_spec.rb system spec
  - Adds an admin_creates_new_tag_spec.rb system spec
  - Updates the success flash message in Admin::TagsController
This commit is contained in:
Julianna Tetreault 2021-06-23 06:30:17 -06:00 committed by GitHub
parent 6b0d2b6173
commit 281fdc499c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 6 deletions

View file

@ -6,6 +6,7 @@ module Admin
id supported rules_markdown short_summary pretty_name bg_color_hex
text_color_hex user_id alias_for badge_id requires_approval
category social_preview_template wiki_body_markdown submission_template
name
].freeze
before_action :set_default_options, only: %i[index]
@ -28,7 +29,7 @@ module Admin
@tag.name = params[:tag][:name].downcase
if @tag.save
flash[:success] = "Tag has been created!"
flash[:success] = "#{@tag.name} has been created!"
redirect_to edit_admin_tag_path(@tag)
else
flash[:danger] = @tag.errors_as_sentence

View file

@ -1,4 +1,4 @@
<%= form_with model: [:admin, tag] do |f| %>
<%= form_with model: [:admin, tag], local: true do |f| %>
<% if !tag.persisted? %>
<div class="crayons-field">
<%= f.label :name, class: "crayons-field__label" %>

View file

@ -32,7 +32,7 @@
This tag currently has no moderators.
</div>
<% end %>
<%= form_with url: admin_tag_moderator_path(@tag.id), model: [:admin, @tag], method: :post do |f| %>
<%= form_with url: admin_tag_moderator_path(@tag.id), model: [:admin, @tag], method: :post, local: true do |f| %>
<div class="crayons-field w-50">
<%= f.label :user_id, "Add Moderator (ID):", class: "crayons-field__label" %>
<%= f.text_field :user_id, class: "crayons-textfield" %>

View file

@ -0,0 +1,23 @@
require "rails_helper"
RSpec.describe "Admin creates new tag", type: :system do
let(:admin) { create(:user, :super_admin) }
before do
sign_in admin
visit new_admin_tag_path
end
def create_and_publish_tag
fill_in("Name", with: "Tag Name")
check "Supported"
fill_in("Short summary", with: "This is a tag")
click_button("Create Tag")
end
it "creates a new tag", :aggregate_failures do
expect(page).to have_content("New Tag")
create_and_publish_tag
expect(page.driver.status_code).to eq(200)
end
end

View file

@ -13,11 +13,20 @@ RSpec.describe "Admin updates a tag", type: :system do
visit edit_admin_tag_path(tag.id)
end
it "allows an Admin to succesfully update a tag", :aggregate_failures do
visit edit_admin_tag_path(tag.id)
expect(page).to have_content("Edit details")
check "Supported"
click_on("Update Tag")
expect(page).to have_current_path(edit_admin_tag_path(tag.id))
expect(page).to have_content("#{tag.name} tag successfully updated!")
end
it "defaults to white text for the color picker" do
expect(page).to have_field("tag_text_color_hex", with: "#ffffff")
end
it "defaults to black and white upon update" do
it "defaults to black and white upon update", :aggregate_failures do
check("Supported")
click_button("Update Tag")
@ -25,6 +34,8 @@ RSpec.describe "Admin updates a tag", type: :system do
expect(tag.bg_color_hex).to eq(bg_color_hex)
expect(tag.text_color_hex).to eq(text_color_hex)
expect(page).to have_current_path(edit_admin_tag_path(tag.id))
expect(page).to have_content("#{tag.name} tag successfully updated!")
end
end
@ -33,10 +44,10 @@ RSpec.describe "Admin updates a tag", type: :system do
before do
sign_in super_admin
visit edit_admin_tag_path(tag)
visit edit_admin_tag_path(tag.id)
end
it "remains the same color it was unless otherwise updated via the color picker" do
it "remains the same color it was unless otherwise updated via the color picker", :aggregate_failures do
old_bg_color_hex = tag.bg_color_hex
old_text_color_hex = tag.text_color_hex
@ -44,6 +55,8 @@ RSpec.describe "Admin updates a tag", type: :system do
expect(tag.reload.bg_color_hex).to eq(old_bg_color_hex)
expect(tag.reload.text_color_hex).to eq(old_text_color_hex)
expect(page).to have_current_path(edit_admin_tag_path(tag.id))
expect(page).to have_content("#{tag.name} tag successfully updated!")
end
end
end