Sha256: 9b0dae346f630130127f45075c2dc4f400d8ddae69f8afb9317a95ce5e49708e

Contents?: true

Size: 1.65 KB

Versions: 7

Compression:

Stored size: 1.65 KB

Contents

require 'spec_helper'
require 'ostruct'

describe CurationConcern::Embargoable do
  let(:model) {
    Class.new(ActiveFedora::Base) {
      def save(returning_value = true)
        valid? && run_callbacks(:save) && !!returning_value
      end
      include CurationConcern::Embargoable
    }
  }

  let(:persistence) {
    Class.new {
      attr_accessor :embargo_release_date
    }.new
  }

  subject { model.new }

  before(:each) do
    subject.embargoable_persistence_container = persistence
  end

  context 'validation' do
    it 'is valid without an embargo_release_date' do
      expect(subject.valid?).to eq(true)
    end

    it 'is not valid with a past embargo date' do
      subject.embargo_release_date = 2.days.ago.to_s
      expect(subject.valid?).to eq(false)
    end
  end

  context 'persistence' do
    let(:the_date) { 2.days.from_now }

    it 'persists a date object' do
      subject.embargo_release_date = the_date
      expect {
        subject.save
      }.to change(persistence, :embargo_release_date).from(nil).to(the_date.to_date)
    end

    it 'persists a valid string' do
      subject.embargo_release_date = the_date.to_s
      expect {
        subject.save
      }.to change(persistence, :embargo_release_date).from(nil).to(the_date.to_date)
    end

    it 'persists an empty string' do
      subject.embargo_release_date = ''
      expect {
        subject.save
      }.to_not change(persistence, :embargo_release_date)
    end

    it 'does not persist an invalid string' do
      subject.embargo_release_date = "Tim"
      expect {
        expect(subject.save).to eq(false)
      }.to_not change(persistence, :embargo_release_date)
    end
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
curate-0.3.2 spec/repository_models/curation_concern/embargoable_spec.rb
curate-0.3.1 spec/repository_models/curation_concern/embargoable_spec.rb
curate-0.2.0 spec/repository_models/curation_concern/embargoable_spec.rb
curate-0.1.3 spec/repository_models/curation_concern/embargoable_spec.rb
curate-0.1.2 spec/repository_models/curation_concern/embargoable_spec.rb
curate-0.1.1 spec/repository_models/curation_concern/embargoable_spec.rb
curate-0.1.0 spec/repository_models/curation_concern/embargoable_spec.rb