Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
153 lines (137 sloc) 4.62 KB
require 'spec_helper'
describe Journal do
context "Test Configuration" do
before :each do
Journal.setup do |config|
config.host = "localhost"
config.port = "6379"
config.expiry = 604800
config.password = "34524GVQSDCA2CT34CZDX2"
end
end
it { Journal.host.should eql("localhost") }
it { Journal.port.should eql("6379") }
it { Journal.expiry.should eql(604800) }
it { Journal.password.should eql("34524GVQSDCA2CT34CZDX2") }
end
context "Test Configuration again !" do
it { Journal.host.should eql("localhost") }
it { Journal.port.should eql("6379") }
it { Journal.expiry.should eql(604800) }
it { Journal.password.should eql("34524GVQSDCA2CT34CZDX2") }
end
context "Test Configuration" do
before :each do
Journal.setup do |config|
config.host = "localhost"
config.port = "6379"
config.expiry = 604800
config.password = "34524GVQSDCA2CT34CZDX2"
end
Journal.load_and_set_settings!
end
it "Test constantes" do
['JOURNAL_HOST','JOURNAL_PORT','JOURNAL_EXPIRY','JOURNAL_PASSWORD'].each do |constant|
Kernel.const_defined?(constant).should be_true
end
end
it { JOURNAL_HOST.should eql("localhost") }
it { JOURNAL_PORT.should eql("6379") }
it { JOURNAL_EXPIRY.should eql(604800) }
it { JOURNAL_PASSWORD.should eql("34524GVQSDCA2CT34CZDX2") }
end
context "Test Redis link" do
before :each do
Journal.setup do |config|
config.host = "localhost"
config.port = "6379"
config.expiry = 604800
config.password = "34524GVQSDCA2CT34CZDX2"
end
Journal.load_and_set_settings!
Journal.redis
end
it { Journal.redis.should_not eql nil }
it { Journal.redis.class.should eql Redis }
end
context "Test Function" do
before :each do
Journal.setup do |config|
config.host = "localhost"
config.port = "6379"
config.expiry = 604800
config.password = "34524GVQSDCA2CT34CZDX2"
end
Journal.load_and_set_settings!
Journal.redis
Journal.redis.flushdb
end
it "Test setting an entry" do
key = "awesome+key"
data = "created object num 42"
timestamp = Time.now.to_i
Journal.log(key, data, timestamp)
Journal.redis.zrange(key,0,1).first.should eql "#{data}@#{timestamp}"
end
it "Test creating a JournalEntry" do
key = "awesome+key"
data = "created object num 42"
timestamp = Time.now.to_i
JournalEntry.new(key, "#{data}@#{timestamp}").entry.should eql "#{data}"
end
it "Test getting date from a JournalEntry" do
key = "awesome+key"
data = "created object num 42"
timestamp = Time.now.to_i
JournalEntry.new(key, "#{data}@#{timestamp}").date.should eql Time.at(timestamp).to_datetime
end
it "Test setting an entry" do
key = "awesome+key"
data = "created object num 42"
timestamp = Time.now.to_i
Journal.log(key, data, timestamp).should eql true
end
it "Test getting an entry" do
key = "awesome+key"
data = "created object num 42"
timestamp = Time.now.to_i
Journal.log(key, data, timestamp)
Journal.last(key).class.should eql JournalEntry
end
it "Test getting last entry" do
key = "awesome+key"
data = "created object num 42"
timestamp = Time.now.to_i
Journal.log(key, data, timestamp)
Journal.log(key, data, timestamp + 10)
Journal.last(key).raw.should eql "#{data}@#{timestamp + 10}"
end
it "Test getting back several entries" do
key = "awesome+key"
data = "created object num 42"
timestamp = Time.now.to_i
Journal.log(key, data, timestamp)
Journal.log(key, data, timestamp + 10)
Journal.last(key,10).class.should eql Array
end
it "Test getting back several entries from the end" do
key = "awesome+key"
data = "created object num 42"
timestamp = Time.now.to_i
Journal.log(key, data, timestamp)
Journal.log(key, data, timestamp + 10)
Journal.last(key,10).first.class.should eql JournalEntry
end
it "Test removing old entries" do
key = "awesome+key"
data = "created object num 42"
timestamp = Time.now.to_i
Journal.log(key, data, timestamp)
Journal.log(key, data, timestamp + 10)
Journal.log(key, data, timestamp + 20)
Journal.purge(key, timestamp + 15)
Journal.last(key,10).count.should eql 1
Journal.last(key,10).first.data.split('@').first.should eql JournalEntry.new(key, "#{data}@#{timestamp}").data.split('@').first
end
end
end