Sha256: e8583288406a9634eaf2f7c2cc566e9055f34196319ad0b0247046b5937cde44

Contents?: true

Size: 1.8 KB

Versions: 7

Compression:

Stored size: 1.8 KB

Contents

# frozen_string_literal: true

require "rails_helper"

module Archangel
  module Liquid
    module Filters
      RSpec.describe LinkToFilter, type: :liquid_filter do
        let(:site) { create(:site) }
        let(:context) do
          ::Liquid::Context.new({ "site" => site }, {}, view: view)
        end

        context "#link_to" do
          let(:link_text) { "Hello world!" }

          it "returns the link with no text provided" do
            content = "{{ '#{link_text}' | link_to }}"
            result = ::Liquid::Template.parse(content).render(context)

            expect(result).to eq(link_text)
          end

          it "returns the link with nil link provided" do
            link = nil
            content = "{{ '#{link_text}' | link_to: #{link} }}"
            result = ::Liquid::Template.parse(content).render(context)

            expect(result).to eq(link_text)
          end

          it "returns the link with empty link string provided" do
            link = ""
            content = "{{ '#{link_text}' | link_to: #{link} }}"
            result = ::Liquid::Template.parse(content).render(context)

            expect(result).to eq(link_text)
          end

          it "returns the link with URL" do
            link = "https://example.com"
            content = "{{ '#{link_text}' | link_to: '#{link}' }}"
            result = ::Liquid::Template.parse(content).render(context)

            expect(result).to eq("<a href=\"#{link}\">#{link_text}</a>")
          end

          it "returns the link with path" do
            link = "path/to/something"
            content = "{{ '#{link_text}' | link_to: '#{link}' }}"
            result = ::Liquid::Template.parse(content).render(context)

            expect(result).to eq("<a href=\"#{link}\">#{link_text}</a>")
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
archangel-0.3.0 spec/lib/archangel/liquid/filters/link_to_filter_spec.rb
archangel-0.0.8 spec/lib/archangel/liquid/filters/link_to_filter_spec.rb
archangel-0.0.7 spec/lib/archangel/liquid/filters/link_to_filter_spec.rb
archangel-0.0.6 spec/lib/archangel/liquid/filters/link_to_filter_spec.rb
archangel-0.0.5 spec/lib/archangel/liquid/filters/link_to_filter_spec.rb
archangel-0.0.4 spec/lib/archangel/liquid/filters/link_to_filter_spec.rb
archangel-0.0.3 spec/lib/archangel/liquid/filters/link_to_filter_spec.rb