require File.expand_path(File.dirname(__FILE__) + '/spec_helper') require 'redis/raketasks' #require 'logger' describe "Redmiso" do class TestMiso < Redmiso #string(:a_string) end before(:all) do result = RedisRunner.start_detached raise("Could not start redis-server, aborting") unless result # yea, this sucks, but it seems like sometimes we try to connect too quickly w/o it sleep 1 # use database 15 for testing so we dont accidentally step on you real data TestMiso.default = { :db => 15 } @r = TestMiso.redis raise("spec runs on database 15, but it's not empty") unless @r.dbsize == 0 end before(:each) do @r['foo'] = 'bar' end after(:each) do @r.keys('*').each {|k| @r.del k } end after(:all) do begin @r.flushdb @r.save @r.quit ensure RedisRunner.stop end end it "checks existence" do TestMiso.exist?(10).should == false o = TestMiso.create(10) TestMiso.exist?(10).should == true o.exist?.should == true end it "creates" do o = TestMiso.create(10) o.should be_a(TestMiso) TestMiso.exist?(10).should == true end it "creates with auto increment" do o = TestMiso.create o.id.should == 1 o = TestMiso.create o.id.should == 2 end it "raises when create with duplicate id" do TestMiso.create(10) lambda { TestMiso.create(10) }.should raise_error end it "counts the root set" do TestMiso.create TestMiso.create TestMiso.count.should == 2 end it "gets all objects from root set" do o = TestMiso.create TestMiso.all.should == [o] end it "deletes from root set" do o = TestMiso.create o.exist?.should == true o.delete o.exist?.should == false end it "returns nil cannot find object" do TestMiso[10].should be_nil end it "finds object" do TestMiso.create(10) o = TestMiso[10].should be_a(TestMiso) end # context "ID Set" do # it "creates with auto increment" # end # it "fails" do # fail "hey buddy, you should probably rename this file and start specing for real" # end end