Sha256: 9c1e9b8795d31f2de5912863d8d6b6993378657d154a38364a1358f13e4e78d0

Contents?: true

Size: 1.86 KB

Versions: 10

Compression:

Stored size: 1.86 KB

Contents

require 'spec_helper'

describe Hyrax::LeaseService do
  subject { described_class }
  before { GenericWork.destroy_all }

  let(:future_date) { 2.days.from_now }
  let(:past_date) { 2.days.ago }

  let!(:work_with_expired_lease1) do
    build(:generic_work, lease_expiration_date: past_date.to_s).tap do |work|
      work.save(validate: false)
    end
  end

  let!(:work_with_expired_lease2) do
    build(:generic_work, lease_expiration_date: past_date.to_s).tap do |work|
      work.save(validate: false)
    end
  end

  let!(:work_with_lease_in_effect) { create(:generic_work, lease_expiration_date: future_date.to_s) }
  let!(:work_without_lease) { create(:generic_work) }

  describe '#assets_with_expired_leases' do
    it 'returns an array of assets with expired lease' do
      returned_pids = subject.assets_with_expired_leases.map(&:id)
      expect(returned_pids).to include work_with_expired_lease1.id, work_with_expired_lease2.id
      expect(returned_pids).not_to include work_with_lease_in_effect.id, work_without_lease.id
    end
  end

  describe '#assets_under_lease' do
    it 'returns an array of assets with active leases' do
      returned_pids = subject.assets_under_lease.map(&:id)
      expect(returned_pids).to include work_with_expired_lease1.id, work_with_expired_lease2.id, work_with_lease_in_effect.id
      expect(returned_pids).not_to include work_without_lease.id
    end
  end

  describe '#assets_with_deactivated_leases' do
    before do
      work_with_expired_lease1.deactivate_lease!
      work_with_expired_lease1.save!
      work_with_lease_in_effect.deactivate_lease!
      work_with_lease_in_effect.save!
    end
    it 'returns an array of assets with deactivated leases' do
      returned_pids = subject.assets_with_deactivated_leases.map(&:id)
      expect(returned_pids).to eq [work_with_expired_lease1.id, work_with_lease_in_effect.id]
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
hyrax-1.1.1 spec/services/hyrax/lease_service_spec.rb
hyrax-1.1.0 spec/services/hyrax/lease_service_spec.rb
hyrax-1.0.5 spec/services/hyrax/lease_service_spec.rb
hyrax-1.0.4 spec/services/hyrax/lease_service_spec.rb
hyrax-1.0.3 spec/services/hyrax/lease_service_spec.rb
hyrax-1.0.2 spec/services/hyrax/lease_service_spec.rb
hyrax-1.0.1 spec/services/hyrax/lease_service_spec.rb
hyrax-1.0.0.rc2 spec/services/hyrax/lease_service_spec.rb
hyrax-1.0.0.rc1 spec/services/hyrax/lease_service_spec.rb
test_hyrax-0.0.1.alpha spec/services/hyrax/lease_service_spec.rb