Sha256: 665bb707c9062d64ef8749c282fb1b1d3127c19d6487f18b6871cbad728e21cb

Contents?: true

Size: 1.69 KB

Versions: 2

Compression:

Stored size: 1.69 KB

Contents

#!/usr/bin/env ruby

require_relative '../../helpers'

require 'fileutils'
require 'rspec'

require 'thingfish/behaviors'
require 'thingfish/datastore/filesystem'


describe Thingfish::Datastore::Filesystem do

	before( :each ) do
		@testing_root_path = described_class.defaults[:root_path]
		@testing_root_path.mkpath
		described_class.configure( root_path: @testing_root_path )
	end

	after( :each ) do
		@testing_root_path.rmtree
	end


	let( :test_spoolfile ) { @testing_root_path + 'test_io' }
	let( :file_io ) do
		io = test_spoolfile.open( 'w+' )
		io.print( TEST_PNG_DATA )
		io.rewind
		io
	end

	let( :string_io ) do
		StringIO.new( TEST_PNG_DATA )
	end

	let( :store ) { Thingfish::Datastore.create(:filesystem) }


	it_behaves_like "a Thingfish datastore"


	it "has a default root" do
		expect( described_class.root_path ).to_not be_nil
	end


	it "raises an exception if the configured root directory doesn't exist" do
		expect {
			described_class.configure( root_path: '/nonexistent' )
			described_class.new
		}.to raise_error( ArgumentError, /root path \/nonexistent does not exist/ )
	end


	it "stores an IO with a path by moving it into place" do
		new_uuid = store.save( file_io )

		rval = store.fetch( new_uuid )
		expect( rval ).to respond_to( :read )
		expect( rval.read ).to eq( TEST_PNG_DATA )

		expect( test_spoolfile ).to_not exist
	end


	it "spools an in-memory file to the datastore directory" do
		io = string_io
		io.seek( 0, IO::SEEK_END )
		pos = io.pos

		new_uuid = store.save( io )
		rval = store.fetch( new_uuid )

		expect( io.pos ).to eq( pos )
		expect( rval.read ).to eq( TEST_PNG_DATA )
		expect( test_spoolfile ).to_not exist
	end

end

# vim: set nosta noet ts=4 sw=4 ft=rspec:

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
thingfish-datastore-filesystem-0.2.2 spec/thingfish/datastore/filesystem_spec.rb
thingfish-datastore-filesystem-0.2.1 spec/thingfish/datastore/filesystem_spec.rb