Sha256: 30f3b8061059eb2d421cab1da62c3f7aed5665db4849a17e2e940940dfe1b78c

Contents?: true

Size: 1.95 KB

Versions: 7

Compression:

Stored size: 1.95 KB

Contents

# frozen_string_literal: true
RSpec.shared_examples 'a Valkyrie::ChangeSetPersister' do |*_flags|
  before do
    raise 'adapter must be set with `let(:change_set_persister)`' unless defined? change_set_persister
    class CustomResource < Valkyrie::Resource
      include Valkyrie::Resource::AccessControls
      attribute :id, Valkyrie::Types::ID.optional
      attribute :title
      attribute :member_ids
      attribute :nested_resource
    end
    class CustomChangeSet < Valkyrie::ChangeSet
      self.fields = [:title]
    end
  end
  after do
    Object.send(:remove_const, :CustomResource)
    Object.send(:remove_const, :CustomChangeSet)
  end

  subject { change_set_persister }
  let(:resource_class) { CustomResource }
  let(:resource) { resource_class.new }
  let(:change_set) { CustomChangeSet.new(resource) }

  it { is_expected.to respond_to(:save).with_keywords(:change_set) }
  it { is_expected.to respond_to(:save_all).with_keywords(:change_sets) }
  it { is_expected.to respond_to(:delete).with_keywords(:change_set) }
  it { is_expected.to respond_to(:metadata_adapter) }
  it { is_expected.to respond_to(:storage_adapter) }

  describe "#save" do
    it "saves a resource and returns it" do
      output = subject.save(change_set: change_set)

      expect(output).to be_kind_of CustomResource
      expect(output).to be_persisted
    end
  end

  describe "#delete" do
    it "deletes a resource" do
      output = subject.save(change_set: change_set)
      subject.delete(change_set: CustomChangeSet.new(output))

      expect do
        subject.metadata_adapter.query_service.find_by(id: output.id)
      end.to raise_error Valkyrie::Persistence::ObjectNotFoundError
    end
  end

  describe "#save_all" do
    it "saves multiple change_sets and returns them" do
      change_set2 = CustomChangeSet.new(resource_class.new)
      output = subject.save_all(change_sets: [change_set, change_set2])

      expect(output.map(&:id).compact.length).to eq 2
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
valkyrie-1.1.2 lib/valkyrie/specs/shared_specs/change_set_persister.rb
valkyrie-1.1.1 lib/valkyrie/specs/shared_specs/change_set_persister.rb
valkyrie-1.1.0 lib/valkyrie/specs/shared_specs/change_set_persister.rb
valkyrie-1.0.0 lib/valkyrie/specs/shared_specs/change_set_persister.rb
valkyrie-1.0.0.rc2 lib/valkyrie/specs/shared_specs/change_set_persister.rb
valkyrie-1.0.0.rc1 lib/valkyrie/specs/shared_specs/change_set_persister.rb
valkyrie-0.1.0 lib/valkyrie/specs/shared_specs/change_set_persister.rb