initial work to being able to use per-model redis

configurations
This commit is contained in:
2010-11-28 10:10:58 +00:00
parent 5338676a5f
commit dc162e0c89
7 changed files with 164 additions and 82 deletions

View File

@@ -1,34 +0,0 @@
require "spec_helper"
describe Redistat do
include Redistat::Database
before(:each) do
db.flushdb
end
it "should have a valid Redis client instance" do
db.should_not be_nil
end
it "should be connected to the testing server" do
db.client.port.should == 8379
db.client.host.should == "127.0.0.1"
end
it "should be able to set and get data" do
db.set("hello", "world")
db.get("hello").should == "world"
db.del("hello").should be_true
end
it "should be able to store hashes to Redis" do
db.hset("key", "field", "1")
db.hget("key", "field").should == "1"
db.hincrby("key", "field", 1)
db.hget("key", "field").should == "2"
db.hincrby("key", "field", -1)
db.hget("key", "field").should == "1"
end
end

61
spec/connection_spec.rb Normal file
View File

@@ -0,0 +1,61 @@
require "spec_helper"
include Redistat
describe Redistat::Connection do
it "should have a valid Redis client instance" do
Redistat.redis.should_not be_nil
end
it "should have initialized custom testing connection" do
redis = Redistat.redis
redis.client.host.should == '127.0.0.1'
redis.client.port.should == 8379
redis.client.db.should == 15
end
it "should be able to set and get data" do
redis = Redistat.redis
redis.set("hello", "world")
redis.get("hello").should == "world"
redis.del("hello").should be_true
end
it "should be able to store hashes to Redis" do
redis = Redistat.redis
redis.hset("hash", "field", "1")
redis.hget("hash", "field").should == "1"
redis.hincrby("hash", "field", 1)
redis.hget("hash", "field").should == "2"
redis.hincrby("hash", "field", -1)
redis.hget("hash", "field").should == "1"
redis.del("hash")
end
it "should be accessible from Redistat module" do
Redistat.redis.should == Connection.get
Redistat.redis.should == Redistat.connection
end
it "should handle multiple connections with refs" do
Redistat.redis.client.port.should == 8379
Redistat.connect(:port => 6379, :db => 15, :ref => "Custom")
Redistat.redis.client.port.should == 8379
Redistat.redis("Custom").client.port.should == 6379
end
it "should be able to overwrite default and custom refs" do
Redistat.redis.client.port.should == 8379
Redistat.connect(:port => 6379, :db => 15)
Redistat.redis.client.port.should == 6379
Redistat.redis("Custom").client.port.should == 6379
Redistat.connect(:port => 8379, :db => 15, :ref => "Custom")
Redistat.redis("Custom").client.port.should == 8379
# Reset the default connection to the testing server or all hell
# might brake loose from the rest of the specs
Redistat.connect(:port => 8379, :db => 15)
end
end

10
spec/database_spec.rb Normal file
View File

@@ -0,0 +1,10 @@
require "spec_helper"
describe Redistat::Database do
include Redistat::Database
it "should make #db method available when included" do
db.should == Redistat.redis
end
end

View File

@@ -8,5 +8,5 @@ require 'rspec'
require 'rspec/autorun'
# use the test Redistat instance
Redistat.connect({:port => 8379, :db => 15})
Redistat.connect(:port => 8379, :db => 15)
Redistat.flush