Sha256: 0d4f425089631dc14c77de5a1af502952863bef298319b37b3b88e422fdf6df8

Contents?: true

Size: 1.1 KB

Versions: 74

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

shared_examples_for "has reference" do
  context "when the reference is nil" do
    before do
      subject[:reference] = nil
    end

    context "when there is not a custom resource reference generator present" do
      it "generates a valid reference" do
        expect(subject.reference).to match(/[A-z]+/)
      end
    end

    context "when there is a custom resource reference generator present" do
      before do
        allow(Decidim).to receive(:reference_generator).and_return(->(resource, _component) { "1234-#{resource.id}" })
      end

      it "generates a valid reference" do
        expect(subject.reference).to eq("1234-#{subject.id}")
      end
    end
  end

  context "when the reference is already set" do
    before do
      subject[:reference] = "ARBITRARYREF"
    end

    it "keeps the pre-existing reference" do
      expect(subject.reference).to eq("ARBITRARYREF")
    end
  end

  context "when saving" do
    it "stores the reference" do
      subject.reference = nil
      subject.save!
      expect(subject.reload.reference).not_to be_blank
    end
  end
end

Version data entries

74 entries across 74 versions & 1 rubygems

Version Path
decidim-core-0.26.10 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.26.9 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.28.0 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.27.5 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.28.0.rc5 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.28.0.rc4 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.26.8 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.27.4 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.27.3 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.26.7 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.26.5 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.27.2 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.27.1 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.26.4 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.27.0 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.26.3 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.27.0.rc2 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.27.0.rc1 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.26.2 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.26.1 lib/decidim/core/test/shared_examples/has_reference.rb