Skip to content

Commit

Permalink
Move navigation delete action to edit page
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanCornthwaiteKatalyst authored and sfnelson committed Sep 7, 2022
1 parent c5f80db commit c7f35f5
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/controllers/katalyst/navigation/menus_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def destroy

menu.destroy!

redirect_to action: :index
redirect_to action: :index, status: :see_other
end

private
Expand Down
7 changes: 6 additions & 1 deletion app/views/katalyst/navigation/menus/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@
<%= form.text_field :slug %>
</div>

<%= form.submit :save %>
<div class="button-row">
<%= form.submit :save %>
<%= link_to "Delete", url_for(action: :show),
class: "button button-secondary",
data: { turbo_method: :delete, turbo_confirm: "Are you sure?" } %>
</div>
<% end %>
3 changes: 0 additions & 3 deletions app/views/katalyst/navigation/menus/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,4 @@
<%= link_to cell.value, menu %>
<% end %>
<%= row.cell :slug %>
<%= row.cell :actions do |cell| %>
<%= button_to "Delete", menu, method: :delete, class: "button button--text" %>
<% end %>
<% end %>
8 changes: 8 additions & 0 deletions spec/dummy/app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,11 @@ main {
.index-table-actions {
grid-area: sidebar;
}

.button-row {
display: flex;
flex-direction: row;
> * {
margin-right: 0.5rem;
}
}
9 changes: 9 additions & 0 deletions spec/requests/katalyst/navigation/menus_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,13 @@
it { expect { action }.to change { menu.reload.state }.from(:draft).to(:published) }
end
end

describe "DELETE /navigation/menus/:id" do
let(:action) { delete katalyst_navigation.menu_path(menu) }
let!(:menu) { create :katalyst_navigation_menu }

it { is_expected.to have_http_status(:see_other) }
it { is_expected.to redirect_to(katalyst_navigation.menus_path) }
it { expect { action }.to change(Katalyst::Navigation::Menu, :count).to(0) }
end
end
52 changes: 52 additions & 0 deletions spec/system/katalyst/navigation/menu_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe "katalyst/navigation/menu" do
it "can add a menu" do
visit katalyst_navigation.menus_path

expect(page).to have_text("Title")

click_on "Add"

fill_in "Title", with: "Magic"
fill_in "Slug", with: "magic"

click_on "Create Menu"

# Menu show page
expect(page).to have_text "Publish"
end

it "can edit a menu" do
menu = create :katalyst_navigation_menu, title: "Magic", slug: "magic"

visit katalyst_navigation.menus_path

expect(page).to have_text("Magic")

visit katalyst_navigation.edit_menu_path(menu)

fill_in "Title", with: "Not Magic"

click_on "save"

visit katalyst_navigation.menus_path
expect(page).to have_text("Not Magic")
end

it "can delete a menu" do
menu = create :katalyst_navigation_menu, title: "Magic", slug: "magic"

visit katalyst_navigation.menus_path

expect(page).to have_text("Magic")

visit katalyst_navigation.edit_menu_path(menu)

click_on "Delete"

expect(page).not_to have_text("Magic")
end
end

0 comments on commit c7f35f5

Please sign in to comment.