Skip to content

Commit

Permalink
Remove attach_to_menu feature
Browse files Browse the repository at this point in the history
The attach-page-to-menu button in the page form was meant as a transitional feature for introducing menus. Now that they have been established and managing menus has been refined we can remove this rather complex feature.
  • Loading branch information
tvdeyen committed Jun 5, 2020
1 parent 9a19906 commit 44c4a3f
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 91 deletions.
18 changes: 0 additions & 18 deletions app/models/alchemy/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ class Page < BaseRecord
after_update :create_legacy_url,
if: :saved_change_to_urlname?

after_update :attach_to_menu!,
if: :should_attach_to_menu?

after_update -> { nodes.update_all(updated_at: Time.current) }

# Concerns
Expand All @@ -152,8 +149,6 @@ class Page < BaseRecord
# site_name accessor
delegate :name, to: :site, prefix: true, allow_nil: true

attr_accessor :menu_id

# Class methods
#
class << self
Expand Down Expand Up @@ -545,18 +540,5 @@ def create_legacy_url
def set_published_at
self.published_at = Time.current
end

def attach_to_menu!
node = Alchemy::Node.find_by!(id: menu_id, language_id: language_id)
node.children.create!(
language_id: language_id,
page_id: id,
name: name,
)
end

def should_attach_to_menu?
menu_id.present? && nodes.none?
end
end
end
2 changes: 1 addition & 1 deletion app/views/alchemy/admin/pages/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="control_group">
<%= render 'alchemy/admin/pages/publication_fields' %>
<%= page_status_checkbox(@page, :restricted) %>
<%= render 'alchemy/admin/pages/menu_fields', f: f %>
<%= page_status_checkbox(@page, :visible) %>
<% if configuration(:sitemap)['show_flag'] %>
<%= page_status_checkbox(@page, :sitemap) %>
<% end %>
Expand Down
33 changes: 0 additions & 33 deletions app/views/alchemy/admin/pages/_menu_fields.html.erb

This file was deleted.

39 changes: 0 additions & 39 deletions spec/models/alchemy/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1991,45 +1991,6 @@ module Alchemy
end
end

describe "#attach_to_menu!" do
let(:page) { create(:alchemy_page) }

context "if menu_id is set" do
let(:root_node) { create(:alchemy_node) }

before do
page.menu_id = root_node.id
end

context "and no nodes are present yet" do
it "attaches to menu" do
expect { page.save }.to change { page.nodes.count }.from(0).to(1)
end
end

context "and nodes are already present" do
let!(:page_node) { create(:alchemy_node, page: page) }

it "does not attach to menu" do
expect { page.save }.not_to change { page.nodes.count }
end
end
end

context "if menu_id is not set" do
it "does not attach to menu" do
expect { page.save }.not_to change { page.nodes.count }
end
end

context "if menu_id is empty" do
it "does not raise error" do
page.menu_id = ""
expect { page.save }.not_to raise_error
end
end
end

describe "#nodes" do
let(:page) { create(:alchemy_page) }
let(:node) { create(:alchemy_node, page: page, updated_at: 1.hour.ago) }
Expand Down

0 comments on commit 44c4a3f

Please sign in to comment.