test/store/redis_test.rb in progressrus-0.1.7 vs test/store/redis_test.rb in progressrus-0.1.8
- old
+ new
@@ -1,8 +1,13 @@
require_relative "../test_helper"
class RedisStoreTest < Minitest::Test
+ class PrefixClass
+ def self.call(scope)
+ "custom_prefix:#{scope.join(':')}"
+ end
+ end
def setup
@scope = ["walrus", "1234"]
@progress = Progressrus.new(
scope: @scope,
id: "oemg",
@@ -15,17 +20,25 @@
id: "oemg-two",
total: 100,
name: "oemg-name-two"
)
- @store = Progressrus::Store::Redis.new(::Redis.new(host: ENV["PROGRESSRUS_REDIS_HOST"] || "localhost"))
+ @redis = ::Redis.new(host: ENV["PROGRESSRUS_REDIS_HOST"] || "localhost")
+
+ @store = Progressrus::Store::Redis.new(@redis)
end
def teardown
- @store.flush(@scope)
+ @store.flush(@scope)
end
+ def test_prefix_can_be_a_proc
+ store = Progressrus::Store::Redis.new(@redis, prefix: PrefixClass)
+ store.persist(@progress)
+ refute_empty(@redis.hgetall('custom_prefix:walrus:1234'))
+ end
+
def test_persist_should_set_key_value_if_outdated
@store.persist(@progress)
assert_equal 'oemg', @store.find(['walrus', '1234'], 'oemg').id
end
@@ -97,7 +110,6 @@
@store.redis.expects(:hset).twice
@store.persist(@progress)
@store.persist(@progress, force: true)
end
-
end