From 2cef1df2fbb15d0fbf7dae71545dc36ab9e32333 Mon Sep 17 00:00:00 2001 From: Frank Macreery Date: Sat, 23 Jan 2016 21:00:12 -0500 Subject: [PATCH] Properly set options[:expires_in] from global_cache_options Fixes #91 --- lib/garner/cache/identity.rb | 4 ++-- spec/garner/cache/identity_spec.rb | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/garner/cache/identity.rb b/lib/garner/cache/identity.rb index 131d433..147ed79 100644 --- a/lib/garner/cache/identity.rb +++ b/lib/garner/cache/identity.rb @@ -11,8 +11,8 @@ def initialize(ruby_context = nil) @key_hash = {} # Set up options hash with defaults - @options_hash = Garner.config.global_cache_options || {} - @options_hash.merge!(expires_in: Garner.config.expires_in) + @options_hash = Garner.config.global_cache_options.dup || {} + @options_hash[:expires_in] ||= Garner.config.expires_in end def fetch(&block) diff --git a/spec/garner/cache/identity_spec.rb b/spec/garner/cache/identity_spec.rb index 5204a2d..644ee4c 100644 --- a/spec/garner/cache/identity_spec.rb +++ b/spec/garner/cache/identity_spec.rb @@ -7,6 +7,13 @@ subject.options_hash[:foo].should eq 'bar' end + it 'includes Garner.config.global_cache_options[:expires_in]' do + Garner.configure do |config| + config.global_cache_options = { expires_in: 5.minutes } + end + subject.options_hash[:expires_in].should eq 5.minutes + end + it 'includes Garner.config.expires_in' do Garner.configure { |config| config.expires_in = 5.minutes } subject.options_hash[:expires_in].should eq 5.minutes