Sha256: e825b5ecbabca6e8102cc420d76a2ef4fb9d5e304a0e755976102c1b21fca80e

Contents?: true

Size: 1.43 KB

Versions: 6

Compression:

Stored size: 1.43 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) { double('reflection') }
  let(:association) { double('association', 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

6 entries across 6 versions & 1 rubygems

Version Path
active-fedora-11.0.0.rc7 spec/unit/files_hash_spec.rb
active-fedora-11.0.0.rc6 spec/unit/files_hash_spec.rb
active-fedora-11.0.0.rc5 spec/unit/files_hash_spec.rb
active-fedora-11.0.0.rc4 spec/unit/files_hash_spec.rb
active-fedora-11.0.0.rc3 spec/unit/files_hash_spec.rb
active-fedora-11.0.0.rc2 spec/unit/files_hash_spec.rb