Sha256: 438786857f27c2e852ba3be820b57ba159171067e92dfe0ab89b31d60dad68b2

Contents?: true

Size: 1.51 KB

Versions: 7

Compression:

Stored size: 1.51 KB

Contents

require 'spec_helper'

describe ActiveFedora::FilesHash do
  before do
    class FilesContainer; end
    allow(FilesContainer).to receive(:child_resource_reflections).and_return(file: reflection)
    allow(container).to receive(:association).with(:file).and_return(association)
    allow(container).to receive(:undeclared_files).and_return([])
  end

  after { Object.send(:remove_const, :FilesContainer) }

  let(:reflection) { instance_double(ActiveFedora::Reflection::MacroReflection) }
  let(:association) { instance_double(ActiveFedora::Associations::SingularAssociation, reader: object) }
  let(:object) { double('object') }
  let(:container) { FilesContainer.new }

  subject(:file_hash) { described_class.new(container) }

  describe "#key?" do
    context 'when the key is present' do
      it "is true" do
        expect(file_hash.key?(:file)).to be true
      end
      it "returns true if a string is passed" do
        expect(file_hash.key?('file')).to be true
      end
    end

    context 'when the key is not present' do
      it "is false" do
        expect(file_hash.key?(:foo)).to be false
      end
    end
  end

  describe "#[]" do
    context 'when the key is present' do
      it "returns the object" do
        expect(file_hash[:file]).to eq object
      end
      it "returns the object if a string is passed" do
        expect(file_hash['file']).to eq object
      end
    end

    context 'when the key is not present' do
      it "is nil" do
        expect(file_hash[:foo]).to be_nil
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
active-fedora-11.1.4 spec/unit/files_hash_spec.rb
active-fedora-11.1.3 spec/unit/files_hash_spec.rb
active-fedora-11.1.2 spec/unit/files_hash_spec.rb
active-fedora-11.1.1 spec/unit/files_hash_spec.rb
active-fedora-11.1.0 spec/unit/files_hash_spec.rb
active-fedora-11.0.1 spec/unit/files_hash_spec.rb
active-fedora-11.0.0 spec/unit/files_hash_spec.rb