Sha256: 76f26571dd41707d9c46558f0780af50ff1e732018eea965384fb4ef318a9734

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

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

module ScriptCacheSpec
	
	class GenericObject < RedisObject;end
	
	describe Seabright::CachedScripts do
		before do
			
			SpecHelper.flushdb
			
			(1..5).each do |n|
				GenericObject.create(n.to_s)
			end
			
		end
		
		it "should cache scripts" do
			
			GenericObject.recently_created.first.id.should eq("5")
			
		end
		
		it "should untrack a script" do
			
			GenericObject.recently_created.first.id.should eq("5")
			GenericObject.indexed(:created_at,-1,false).to_a.last.id.should eq("4")
			
			cnt = $ScriptSHAMap.keys.count
			RedisObject.untrack_script :RevScript
			$ScriptSHAMap.keys.count.should eq(cnt-1)
			
		end
		
		it "should handle a missing script SHA" do
			
			GenericObject.recently_created.first.id.should eq("5")
			RedisObject.store.script :flush
			GenericObject.recently_created.to_a[2].id.should eq("3")
			
		end
		
		it "should expire scripts" do
			
			# $ScriptSHAMap.keys.count.should eq(1)
			
			RedisObject.stores.each do |(name,store)|
				RedisObject.expire_all_script_shas(store)
			end
			
			$ScriptSHAMap.keys.count.should eq(0)
			
		end
		
		it "should error on unknown script source" do
			
			expect { GenericObject.run_script(:MysteriousCommand) }.to raise_error
			
		end
		
	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
redis_object-1.5.3 spec/script_cache_spec.rb