Sha256: 3f38b67c89435c0e601f99dd3fcf3576784b223a51eac89ef82d564eed0facd9

Contents?: true

Size: 1.67 KB

Versions: 8

Compression:

Stored size: 1.67 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) }

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

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

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

    context "with element" do
      before do
        expect(element).to receive(:ingredient_definition_for) do
          {
            settings: {
              linkable: true,
            },
          }.with_indifferent_access
        end
      end

      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
      let(:definition) do
        {
          role: "headline",
          type: "Text",
          default: "Hello World",
          settings: {
            linkable: true,
          },
        }.with_indifferent_access
      end

      before do
        expect(element).to receive(:ingredient_definition_for) { definition }
      end

      it "returns ingredient definition" do
        is_expected.to eq(definition)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
alchemy_cms-6.0.0.pre.rc6 lib/alchemy/test_support/shared_ingredient_examples.rb
alchemy_cms-6.0.0.pre.rc5 lib/alchemy/test_support/shared_ingredient_examples.rb
alchemy_cms-6.0.0.pre.rc4 lib/alchemy/test_support/shared_ingredient_examples.rb
alchemy_cms-6.0.0.pre.rc3 lib/alchemy/test_support/shared_ingredient_examples.rb
alchemy_cms-6.0.0.pre.rc2 lib/alchemy/test_support/shared_ingredient_examples.rb
alchemy_cms-6.0.0.pre.rc1 lib/alchemy/test_support/shared_ingredient_examples.rb
alchemy_cms-6.0.0.pre.b6 lib/alchemy/test_support/shared_ingredient_examples.rb
alchemy_cms-6.0.0.pre.b5 lib/alchemy/test_support/shared_ingredient_examples.rb