Sha256: cc96604f6d2245042a8f57dcae5f379c7e840396c28684149cffa89e0844aa8c

Contents?: true

Size: 1.57 KB

Versions: 2

Compression:

Stored size: 1.57 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper'


describe "Jackfs Db Adapter" do
  before(:each) do
    File.delete("test.db") if File.exists?("test.db")
    YAML.should_receive(:load_file).and_return("test" => {
      "adapter" => "db",
      "connection" => 'sqlite://test.db',
      "table_name" => 'jackfs'
    })

    root = File.dirname(__FILE__) + '/..'
    @dba = Jackfs::DbAdapter.new(root, :test)
  end


  it "should save a file to a configured database name" do
    @dba.connection.should == 'sqlite://test.db'
  end


  it "should save a file to a configured table name" do
    @dba.table_name.should == 'jackfs'
  end

  it "should save the file in db using the given name" do
    @dba.store(File.open(File.dirname(__FILE__) + '/../fixtures/test.pdf', 'r'),"COOLBEANS").should eq("COOLBEANS")
  end

  it "should allow connection string with odd characters" do
    @dba.connection = "sqlite://root:abc!#%@test.db"
    @dba.uri_escape(@dba.connection).should eq("sqlite://root:abc!%23%25@test.db")
  end

  it "should throw an error when connection string is bad URI" do
    URI.stub(:escape).and_raise(Exception)
    $stdout.should_receive(:puts).with('Error encountered when parsing sqlite://test.db - Exception')
    @dba.uri_escape(@dba.connection)
  end

  # it "should get a file from a configured from db" do
  #   f = File.open(File.dirname(__FILE__) + '/../fixtures/test.pdf', 'r')
  #   @dba.store(f, "COOLBEANS")
  #   orig = File.open(File.dirname(__FILE__) + '/../fixtures/test.pdf', 'r')
  #
  #   @dba.get("COOLBEANS").read.length.should == orig.read.length
  # end


end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jackfs-0.1.1 spec/adapters/db_adapter_spec.rb
jackfs-0.1.0 spec/adapters/db_adapter_spec.rb