Sha256: 6d463ba7297f66c70661a667a82b5ce5e96ee9d5b211f047ed25a3a21bfff6c4

Contents?: true

Size: 1.85 KB

Versions: 13

Compression:

Stored size: 1.85 KB

Contents

require 'spec_helper'

describe ActiveFedora::ChangeSet do
  let(:change_set) { described_class.new(base, base.resource, base.changed_attributes.keys) }
  subject { change_set }

  context "with an unchanged object" do
    let(:base) { ActiveFedora::Base.new }

    it { is_expected.to be_empty }
  end

  context "with a changed object" do
    before do
      class Library < ActiveFedora::Base
      end

      class Book < ActiveFedora::Base
        belongs_to :library, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.hasConstituent
        property :title, predicate: ::RDF::Vocab::DC.title
        property :alt_id, predicate: ::RDF::Vocab::DC.identifier
      end

      base.library_id = 'foo'
      base.title = ['bar']
      base.alt_id = ['12345']
    end
    after do
      Object.send(:remove_const, :Library)
      Object.send(:remove_const, :Book)
    end

    let(:base) { Book.create }

    describe "#changes" do
      subject(:changes) { change_set.changes }

      it { is_expected.to be_kind_of Hash }

      it "has three elements" do
        expect(changes.size).to eq 3
      end
      it "does not include URIs from other objects" do
        base.resource << RDF::Statement.new(RDF::URI("http://wrong.com"), RDF::Vocab::DC.title, "bad")
        base.title = nil
        expect(changes[RDF::Vocab::DC.title].to_a).to eq []
      end
      it "includes hash URIs" do
        # This is useful as an alternative to blank nodes.
        hash_uri = RDF::URI(base.uri.to_s + "#test")
        base.resource << RDF::Statement.new(hash_uri, RDF::Vocab::DC.title, "good")
        base.title = [RDF::URI(hash_uri)]
        expect(changes[RDF::Vocab::DC.title].to_a).not_to eq []
        # Include the title reference and the title for the hash URI
        expect(changes[RDF::Vocab::DC.title].to_a.length).to eq 2
      end
    end

    it { is_expected.to_not be_empty }
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
active-fedora-11.1.4 spec/unit/change_set_spec.rb
active-fedora-11.1.3 spec/unit/change_set_spec.rb
active-fedora-11.1.2 spec/unit/change_set_spec.rb
active-fedora-11.1.1 spec/unit/change_set_spec.rb
active-fedora-11.1.0 spec/unit/change_set_spec.rb
active-fedora-11.0.1 spec/unit/change_set_spec.rb
active-fedora-11.0.0 spec/unit/change_set_spec.rb
active-fedora-11.0.0.rc7 spec/unit/change_set_spec.rb
active-fedora-11.0.0.rc6 spec/unit/change_set_spec.rb
active-fedora-11.0.0.rc5 spec/unit/change_set_spec.rb
active-fedora-11.0.0.rc4 spec/unit/change_set_spec.rb
active-fedora-11.0.0.rc3 spec/unit/change_set_spec.rb
active-fedora-11.0.0.rc2 spec/unit/change_set_spec.rb