Sha256: c56ef78ffa79544d2db5989ffc859a553f7c53a8726f8d351beb323ca5a02dcc

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

require 'spec_helper'
require 'dragonfly-activerecord/store.rb'

describe Dragonfly::ActiveRecord::Store do
  FakeFile = Struct.new(:data, :meta)

  let(:fake_file) { FakeFile.new data, metadata }
  let(:metadata) { {a:1} }

  before { prepare_database }

  share_examples_for 'store and retrieve' do
    it 'retrieves the data' do
      id = subject.write(fake_file)
      returned_data, returned_meta = subject.read(id)

      returned_data.length.should == data.length
      returned_data.should == data
    end
  end


  context 'for small chunks of text data' do
    let(:data) { "foobar" }
    it_should_behave_like 'store and retrieve'
  end

  context 'for small chunks of binary data' do
    let(:data) { SecureRandom.random_bytes(64) }
    it_should_behave_like 'store and retrieve'
  end

  context 'for large chunks of binary data' do
    let(:data) { SecureRandom.random_bytes(2_000_000) }
    it_should_behave_like 'store and retrieve'
  end

  it 'returns nil for missing files' do
    subject.read('1337').should be_nil
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dragonfly-activerecord-0.0.2 spec/dragonfly-activerecord/store_spec.rb
dragonfly-activerecord-0.0.1 spec/dragonfly-activerecord/store_spec.rb