Skip to content

Commit

Permalink
Scope has one site (AlchemyCMS#1832)
Browse files Browse the repository at this point in the history
* Make alchemy_pages.layoutpage null: false

We want to have an actual Boolean and no nil values.

* Scope Language Root Page to Non-Layoutpages

Layoutpages can not be root pages.
  • Loading branch information
mamhoff authored May 14, 2020
1 parent 8ff8ca2 commit 02983a0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/models/alchemy/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Language < BaseRecord

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

has_one :root_page, -> { where(parent: nil) }, class_name: "Alchemy::Page"
has_one :root_page, -> { where(parent: nil, layoutpage: false) }, class_name: "Alchemy::Page"

validates :name, presence: true
validates :page_layout, presence: true
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20200514091507_make_page_layoutpage_null_false.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true
class MakePageLayoutpageNullFalse < ActiveRecord::Migration[5.2]
def change
change_column_null :alchemy_pages, :layoutpage, false, false
end
end
4 changes: 2 additions & 2 deletions spec/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_05_05_215518) do
ActiveRecord::Schema.define(version: 2020_05_14_091507) do

create_table "alchemy_attachments", force: :cascade do |t|
t.string "name"
Expand Down Expand Up @@ -221,7 +221,7 @@
t.boolean "robot_index", default: true
t.boolean "robot_follow", default: true
t.boolean "sitemap", default: true
t.boolean "layoutpage", default: false
t.boolean "layoutpage", default: false, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "creator_id"
Expand Down
10 changes: 4 additions & 6 deletions spec/models/alchemy/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module Alchemy
end

context "a page not being a language_root and without parent" do
let(:page) { build(:alchemy_page, parent: nil, layoutpage: nil) }
let(:page) { build(:alchemy_page, parent: nil, layoutpage: false) }

it { expect(page).to_not be_valid }
end
Expand Down Expand Up @@ -360,7 +360,7 @@ module Alchemy
let!(:klingon_lang_root) do
create :alchemy_page, :language_root, {
name: "klingon_lang_root",
layoutpage: nil,
layoutpage: false,
language: klingon,
}
end
Expand All @@ -385,10 +385,8 @@ module Alchemy
expect(Page.contentpages.to_a.select { |p| p.layoutpage == true }).to be_empty
end

it "contains pages with attribute :layoutpage set to nil" do
expect(Page.contentpages.to_a.select do |page|
page.layoutpage.nil?
end).to include(klingon_lang_root)
it "contains pages with attribute :layoutpage set to false" do
expect(Page.contentpages.to_a.select { |p| p.layoutpage == false }).to include(klingon_lang_root)
end
end

Expand Down

0 comments on commit 02983a0

Please sign in to comment.