Sha256: b38c0504231aa9895dfddfb7fb7375cb9d9eafecc21ef75d7fe11f94f4ebf2fe

Contents?: true

Size: 1.93 KB

Versions: 1

Compression:

Stored size: 1.93 KB

Contents

# frozen_string_literal: true

require "rails_helper"

RSpec.describe "Liquid custom variable", type: :feature do
  let(:site) { create(:site) }

  let(:inline_current_page) do
    %(
      {% if current_page == page.permalink %}
        Current Page?: Yup!
      {% else %}
        Current Page?: Nope!
      {% endif %}
    )
  end
  let(:inline_other_page) do
    %(
      {% if current_page == '/some-other-page' %}
        Current Page?: Yup!
      {% else %}
        Current Page?: Nope!
      {% endif %}
    )
  end

  describe "for `current_page` variable" do
    it "knows the current page at root level" do
      create(:page, site: site,
                    slug: "amazing",
                    content: "Current Page: {{ current_page }}")

      visit "/amazing"

      expect(page).to have_content("Current Page: /amazing")
    end

    it "knows the current page at child level" do
      parent_resource = create(:page, site: site, slug: "amazing")
      create(:page, site: site, parent: parent_resource,
                    slug: "grace", content: "Current Page: {{ current_page }}")

      visit "/amazing/grace"

      expect(page).to have_content("Current Page: /amazing/grace")
    end

    it "knows it is on the current page" do
      create(:page, site: site, slug: "amazing", content: inline_current_page)

      visit "/amazing"

      expect(page).to have_content("Current Page?: Yup!")
    end

    it "knows it is not on the current page" do
      create(:page, site: site, slug: "amazing", content: inline_other_page)

      visit "/amazing"

      expect(page).to have_content("Current Page?: Nope!")
    end

    it "knows the current page with all known slug characters" do
      slug = "abcdefghijklmnopqrstuvwxyz0123456789-_"
      create(:page, site: site,
                    slug: slug, content: "Current Page: {{ current_page }}")

      visit "/#{slug}"

      expect(page).to have_content("Current Page: /#{slug}")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
archangel-0.4.0 spec/features/frontend/liquid/variables/current_page_spec.rb