Skip to content

Commit f47f8b3

Browse files
committed
Delegate PageDefinition#blank? to name
Before we converted this into a model we used an empty hash as definition of a page that misses its definition.
1 parent e4aba31 commit f47f8b3

4 files changed

Lines changed: 26 additions & 7 deletions

File tree

app/models/alchemy/page/page_natures.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def definition
8383
definition = PageDefinition.get(page_layout)
8484
if definition.nil?
8585
log_warning "Page definition for `#{page_layout}` not found. Please check `page_layouts.yml` file."
86-
return PageDefinition.new(name: page_layout)
86+
return PageDefinition.new
8787
end
8888
definition
8989
end

app/models/alchemy/page_definition.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class PageDefinition
2828
}
2929

3030
delegate :[], to: :attributes
31+
delegate :blank?, to: :name
3132

3233
class << self
3334
# Returns all page layouts.

spec/models/alchemy/page_definition_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,22 @@ module Alchemy
2222
it { is_expected.to have_key(:hint) }
2323
end
2424

25+
describe "#blank?" do
26+
subject { definition.blank? }
27+
28+
context "with name given" do
29+
let(:definition) { described_class.new(name: "standard") }
30+
31+
it { is_expected.to be(false) }
32+
end
33+
34+
context "without name given" do
35+
let(:definition) { described_class.new }
36+
37+
it { is_expected.to be(true) }
38+
end
39+
end
40+
2541
describe "validations" do
2642
it { is_expected.to validate_presence_of(:name) }
2743
end

spec/models/alchemy/page_spec.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,20 +1214,22 @@ module Alchemy
12141214
context "if the page layout could not be found in the definition file" do
12151215
let(:page) { build_stubbed(:alchemy_page, page_layout: "notexisting") }
12161216

1217-
it "it loggs a warning." do
1217+
it "it logs a warning." do
12181218
expect(Alchemy::Logger).to receive(:warn)
12191219
page.definition
12201220
end
12211221

1222-
it "it returns empty hash." do
1222+
it "it returns empty definition." do
12231223
expect(page.definition).to be_an(Alchemy::PageDefinition)
1224-
expect(page.definition.name).to eq("notexisting")
1224+
expect(page.definition.name).to be_nil
12251225
end
12261226
end
12271227

1228-
context "for a language root page" do
1229-
it "it returns the page layout definition as hash." do
1230-
expect(language_root.definition.name).to eq("index")
1228+
context "for a page with existing definition" do
1229+
let(:page) { build_stubbed(:alchemy_page) }
1230+
1231+
it "it returns the page layout definition." do
1232+
expect(page.definition.name).to eq("standard")
12311233
end
12321234
end
12331235
end

0 commit comments

Comments
 (0)