Sha256: 811cb134d617faaa61066e3b2f1539062a043bb46c10a41e5b476dfe544d7de9

Contents?: true

Size: 1.25 KB

Versions: 7

Compression:

Stored size: 1.25 KB

Contents

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

class DbTestUser
end

describe CouchTomato::Database, 'new' do
  it "should raise an exception if the database doesn't exist" do
    lambda {
      CouchTomato::Database.new CouchRest.database('couch_tomato_invalid')
    }.should raise_error('Database \'couch_tomato_invalid\' does not exist.')
  end
end

describe CouchTomato::Database, 'load' do
  it "should raise an exception if nil given" do
    db = CouchTomato::Database.new(stub('couchrest db', :info => nil))
    lambda {
      db.load nil
    }.should raise_error("Can't load a document without an id (got nil)")
  end
  
  it "should set itself on the model" do
    user = mock 'user'
    DbTestUser.stub!(:new).and_return(user)
    db = CouchTomato::Database.new(stub('couchrest db', :info => nil, :get => {'ruby_class' => 'DbTestUser'}))
    user.should_receive(:database=).with(db)
    db.load '1'
  end
end

describe CouchTomato::Database, 'save_document' do
  it "should set itself on the model for a new object before doing anything else" do
    db = CouchTomato::Database.new(stub('couchrest db', :info => nil))
    user = stub('user', :new? => true, :valid? => false).as_null_object
    user.should_receive(:database=).with(db)
    db.save_document user
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
couch_tomato-0.2.0 spec/unit/database_spec.rb
couch_tomato-0.1.5 spec/unit/database_spec.rb
couch_tomato-0.1.4 spec/unit/database_spec.rb
couch_tomato-0.1.3 spec/unit/database_spec.rb
couch_tomato-0.1.2 spec/unit/database_spec.rb
couch_tomato-0.1.1 spec/unit/database_spec.rb
couch_tomato-0.1.0 spec/unit/database_spec.rb