Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dependent: :nullify to Page#nodes #2828

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/alchemy/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Page < BaseRecord
has_many :site_languages, through: :site, source: :languages
has_many :folded_pages, dependent: :destroy
has_many :legacy_urls, class_name: "Alchemy::LegacyPageUrl", dependent: :destroy
has_many :nodes, class_name: "Alchemy::Node", inverse_of: :page
has_many :nodes, class_name: "Alchemy::Node", inverse_of: :page, dependent: :nullify
has_many :versions, class_name: "Alchemy::PageVersion", inverse_of: :page, dependent: :destroy
has_one :draft_version, -> { drafts }, class_name: "Alchemy::PageVersion"
has_one :public_version, -> { published }, class_name: "Alchemy::PageVersion", autosave: -> { persisted? }
Expand Down
8 changes: 8 additions & 0 deletions spec/models/alchemy/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ module Alchemy
it "destroys elements along with itself" do
expect { page.destroy! }.to change(Alchemy::Element, :count).from(3).to(0)
end

context "with a node attached to the page" do
let!(:node) { create(:alchemy_node, page: page) }

it "nullifies the node" do
expect { page.destroy! }.to change { node.reload.page_id }.from(page.id).to(nil)
end
end
end
end

Expand Down
Loading