Skip to content
Merged
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: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,5 @@ gem "dartsass-rails", "~> 0.5.0"
gem "propshaft", "~> 1.0"

gem "gem-release", "~> 2.2"

gem "i18n-debug", "~> 1.2", require: false # Set to `"i18n/debug"` if you want to debug missing translations
9 changes: 2 additions & 7 deletions app/models/alchemy/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
module Alchemy
class Language < BaseRecord
belongs_to :site
has_many :pages, inverse_of: :language
has_many :nodes, inverse_of: :language
has_many :pages, inverse_of: :language, dependent: :restrict_with_error
has_many :nodes, inverse_of: :language, dependent: :restrict_with_error

before_validation :set_locale, if: -> { locale.blank? }

Expand Down Expand Up @@ -54,11 +54,6 @@ class Language < BaseRecord
after_update :set_pages_language,
if: :should_set_pages_language?

before_destroy if: -> { pages.any? } do
errors.add(:pages, :still_present)
throw(:abort)
end

scope :published, -> { where(public: true) }
scope :with_root_page, -> { joins(:pages).where(Page.table_name => {language_root: true}) }

Expand Down
7 changes: 1 addition & 6 deletions app/models/alchemy/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,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: :restrict_with_error
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 All @@ -132,11 +132,6 @@ class Page < BaseRecord
before_create -> { versions.build },
if: -> { versions.none? }

before_destroy if: -> { nodes.any? } do
errors.add(:nodes, :still_present)
throw(:abort)
end

before_save :set_language_code,
if: -> { language.present? }

Expand Down
7 changes: 1 addition & 6 deletions app/models/alchemy/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ class Site < BaseRecord
validates_uniqueness_of :host, case_sensitive: false

# associations
has_many :languages

before_destroy if: -> { languages.any? } do
errors.add(:languages, :still_present)
throw(:abort)
end
has_many :languages, dependent: :restrict_with_error

scope :published, -> { where(public: true) }

Expand Down
17 changes: 11 additions & 6 deletions config/locales/alchemy.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -786,16 +786,19 @@ en:
node_ingredients_present: "This menu item is in use inside an Alchemy element on the following pages: %{page_names}."
alchemy/site:
attributes:
languages:
still_present: "are still attached to this site. Please remove them first."
base:
restrict_dependent_destroy:
has_many: "There are still %{record} attached to this site. Please remove them first."
alchemy/language:
attributes:
pages:
still_present: "are still attached to this language. Please remove them first."
base:
restrict_dependent_destroy:
has_many: "There are still %{record} attached to this language. Please remove them first."
alchemy/page:
attributes:
nodes:
still_present: "are still attached to this page. Please remove them first."
base:
restrict_dependent_destroy:
has_many: "There are still %{record} attached to this page. Please remove them first."
models:
gutentag/tag:
one: Tag
Expand Down Expand Up @@ -882,6 +885,7 @@ en:
public: "Public"
locale: Localization
code: ISO Code
nodes: Menu nodes
alchemy/legacy_page_url:
urlname: "URL-Path"
alchemy/node:
Expand All @@ -900,6 +904,7 @@ en:
meta_description: "Description"
meta_keywords: "Keywords"
name: "Name"
nodes: "Menu nodes"
page_layout: "Page type"
public: "public"
restricted: "restricted"
Expand Down
13 changes: 12 additions & 1 deletion spec/controllers/alchemy/admin/languages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,18 @@
delete :destroy, params: {id: language.id}
expect(response).to redirect_to admin_languages_path
expect(flash[:warning]).to \
eq("Pages are still attached to this language. Please remove them first.")
eq("There are still pages attached to this language. Please remove them first.")
end
end

context "with nodes attached" do
let!(:node) { create(:alchemy_node, language: language) }

it "returns with error message" do
delete :destroy, params: {id: language.id}
expect(response).to redirect_to admin_languages_path
expect(flash[:warning]).to \
eq("There are still menu nodes attached to this language. Please remove them first.")
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/alchemy/admin/pages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
delete :destroy, params: {id: page.id, format: :js}
expect(response).to redirect_to(admin_pages_path)
expect(flash[:warning]).to \
eq("Nodes are still attached to this page. Please remove them first.")
eq("There are still menu nodes attached to this page. Please remove them first.")
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/alchemy/admin/sites_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
delete :destroy, params: {id: site.id}
expect(response).to redirect_to admin_sites_path
expect(flash[:warning]).to \
eq("Languages are still attached to this site. Please remove them first.")
eq("There are still languages attached to this site. Please remove them first.")
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/models/alchemy/language_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ module Alchemy
context "without pages" do
it "works" do
subject
expect(language.errors[:pages]).to be_empty
expect(language.errors[:base]).to be_empty
end
end

Expand All @@ -309,7 +309,7 @@ module Alchemy

it "must not work" do
subject
expect(language.errors[:pages]).to_not be_empty
expect(language.errors[:base]).to include("There are still pages attached to this language. Please remove them first.")
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/models/alchemy/site_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ module Alchemy
context "without languages" do
it "works" do
subject
expect(site.errors[:languages]).to be_empty
expect(site.errors[:base]).to be_empty
end
end

Expand All @@ -254,7 +254,7 @@ module Alchemy

it "must not work" do
subject
expect(site.errors[:languages]).to_not be_empty
expect(site.errors[:base]).to include("There are still languages attached to this site. Please remove them first.")
end
end
end
Expand Down
Loading