Sha256: 96d59a970bc780a1bfa5ddf155a6f46384a8b62bf4930a8e2fc489f4d24a018d

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

require "shoulda-matchers"

RSpec.shared_examples_for "an alchemy ingredient" do
  let(:element) { build(:alchemy_element, name: "element_with_ingredients") }

  subject(:ingredient) do
    described_class.new(
      element: element,
      role: "headline",
    )
  end

  it { is_expected.to belong_to(:element).touch(true).class_name("Alchemy::Element") }
  it { is_expected.to belong_to(:related_object).optional }
  it { is_expected.to validate_presence_of(:role) }
  it { is_expected.to validate_presence_of(:type) }
  it { expect(subject.data).to eq({}) }

  describe "#settings" do
    subject { ingredient.settings }

    context "without element" do
      let(:element) { nil }

      it { is_expected.to eq({}) }
    end

    context "with element" do
      it { is_expected.to eq({ linkable: true }.with_indifferent_access) }
    end
  end

  describe "#definition" do
    subject { ingredient.definition }

    context "without element" do
      let(:element) { nil }

      it { is_expected.to eq({}) }
    end

    context "with element" do
      it do
        is_expected.to eq({
          role: "headline",
          type: "Text",
          default: "Hello World",
          settings: {
            linkable: true,
          },
        }.with_indifferent_access)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alchemy_cms-6.0.0.b1 lib/alchemy/test_support/shared_ingredient_examples.rb