Search code examples
rubycouchrest

couchrest_model - how to drop a database?


I want to be able to start my tests pointing at a non-existant couchdb database, so that I can test from a blank canvas. How should I do this?

describe MyCouchModel do
  before :all do
    described_class.drop # This doesn't work!
  end

  it 'should be empty' do
    described-class.all.length.should == 0
  end
end

Solution

  • I found this inside some tests for another library:

    MyCouchModel.database.delete!
    

    So in a test you could do:

    describe MyCouchModel do
      before :all do
        described_class.database.delete!
        described_class.database.create!
      end
    end