Sha256: 2526ea0f0e59142567e90c55f70fb04405eb0b31250fa01e2cc939ff70bbb1e1

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

require File.join(File.dirname(__FILE__), '..', 'spec_helper')

describe Rack::Bundle::DatabaseStore do  
  before do
    ENV['DATABASE_URL'] = "sqlite://#{Dir.tmpdir}/foo.db"
    @db_store = Rack::Bundle::DatabaseStore.new
  end
  
  context 'initializing' do
    it 'looks for a DATABASE_URL environment variable when a database URL is not specified' do
      @db_store.db.url.should == "sqlite:/#{Dir.tmpdir}/foo.db"
    end
    it 'takes a database url as a parameter' do
      db_store = Rack::Bundle::DatabaseStore.new "sqlite://#{Dir.tmpdir}/bar.db"
      db_store.db.url.should == "sqlite:/#{Dir.tmpdir}/bar.db"
    end
    it 'creates a table to store bundles in' do
      @db_store.db.tables.should include(:rack_bundle)
    end
  end
  
  context '#find_bundle_by_hash' do
    it 'takes a bundle hash as argument and returns a matching bundle' do
      jsbundle = Rack::Bundle::JSBundle.new fixture('jquery-1.4.1.min.js'), fixture('mylib.js')
      @db_store.db[:rack_bundle].insert(:hash => jsbundle.hash, :contents => jsbundle.contents, :type => 'js')
      @db_store.find_bundle_by_hash(jsbundle.hash).should be_an_instance_of Rack::Bundle::JSBundle
    end    
    it "returns nil when a bundle can't be found with a matching hash" do
      @db_store.find_bundle_by_hash('non existant').should be_nil
    end
  end
  
  it "saves bundles to the database on #add" do
    jsbundle = make_js_bundle
    @db_store.add jsbundle
    @db_store.db[:rack_bundle].where(:hash => jsbundle.hash).first[:hash].should == jsbundle.hash
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rack-bundle-0.2.3 spec/store/database_store_spec.rb
rack-bundle-0.2.2 spec/store/database_store_spec.rb