Commit 94c364af authored by Sean Arnold's avatar Sean Arnold Committed by Douglas Barbosa Alexandre

Rewrite spec to test behaviour, not implementation

parent f4128209
......@@ -126,6 +126,10 @@ module ErrorTracking
end
end
def expire_issues_cache
Rails.cache.delete_matched(expand_cache_key('list_issues'))
end
# http://HOST/api/0/projects/ORG/PROJECT
# ->
# http://HOST/ORG/PROJECT
......@@ -140,15 +144,9 @@ module ErrorTracking
Addressable::URI.join(api_url, '/').to_s
end
def clear_cache(resource_prefix)
raise 'No resource prefix provided' unless resource_prefix
Rails.cache.delete_matched(cache_key(resource_prefix))
end
private
def cache_key(resource_prefix)
def expand_cache_key(resource_prefix)
klass_key = self.class.reactive_cache_key.call(self).join(':')
"#{klass_key}:#{resource_prefix}*"
......
......@@ -441,17 +441,17 @@ describe ErrorTracking::ProjectErrorTrackingSetting do
end
end
describe '#clear_cache' do
let(:key_prefix) { 'list_issues' }
describe '#expire_issues_cache', :use_clean_rails_memory_store_caching do
it 'clears the cache' do
klass_key = subject.class.reactive_cache_key.call(subject).join(':')
key = "#{klass_key}:list_issues:some_suffix"
Rails.cache.write(key, 1)
expect(Rails.cache.exist?(key)).to eq(true)
expect(Rails.cache)
.to receive(:delete_matched)
.with("#{klass_key}:#{key_prefix}*")
subject.expire_issues_cache
subject.clear_cache(key_prefix)
expect(Rails.cache.exist?(key)).to eq(false)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment