Sha256: 039db75553341543ed8f9c573c3c6fd9f13ea3b539c823a5f26e5806809ad7dc

Contents?: true

Size: 1.11 KB

Versions: 40

Compression:

Stored size: 1.11 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(:resource_reference_generator).and_return(->(resource, _feature) { "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).to_not be_blank
    end
  end
end

Version data entries

40 entries across 40 versions & 2 rubygems

Version Path
decidim-core-0.9.3 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.9.2 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.9.1 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.9.0 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.8.4 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.8.3 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.8.2 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.8.1 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.8.0 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.7.4 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.7.3 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.7.2 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.7.1 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.7.0 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.6.8 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-0.6.8 decidim-core/lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.6.7 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-0.6.7 decidim-core/lib/decidim/core/test/shared_examples/has_reference.rb
decidim-core-0.6.6 lib/decidim/core/test/shared_examples/has_reference.rb
decidim-0.6.6 decidim-core/lib/decidim/core/test/shared_examples/has_reference.rb