Skip to content

Commit

Permalink
Add Current.preview_page?
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdeyen committed Jan 22, 2024
1 parent 70fe1ea commit 2579240
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/alchemy/current.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@ def preview_page=(page)
self.language = page&.language
self.site = page&.site
end

def preview_page?(page = Current.page)
preview_page == page
end
end
end
24 changes: 24 additions & 0 deletions spec/models/alchemy/current_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,28 @@
end
end
end

describe ".preview_page?" do
let(:page) { build(:alchemy_page) }

context "with page being current preview page" do
before do
described_class.preview_page = page
end

it "returns true" do
expect(described_class.preview_page?(page)).to be_truthy
end
end

context "with page being current preview page" do
before do
described_class.preview_page = nil
end

it "returns true" do
expect(described_class.preview_page?(page)).to be_falsey
end
end
end
end

0 comments on commit 2579240

Please sign in to comment.