Skip to content

Commit

Permalink
tweak cache enabling
Browse files Browse the repository at this point in the history
  • Loading branch information
lsat12357 committed May 9, 2018
1 parent cab59c8 commit 775917c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
13 changes: 7 additions & 6 deletions spec/controllers/terms_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,11 @@ def get_new
end
end

describe "update_cache" do
describe "update_cache", :caching do
context 'when html exists in cache' do
let(:format) {}
let(:file_cache) { ActiveSupport::Cache.lookup_store(:file_store, Settings.cache_dir) }
let(:cache) { Rails.cache }
before do
stub_repository
full_graph = instance_double("RDF::Graph")
Expand All @@ -508,6 +510,7 @@ def get_new
allow(resource).to receive(:commit_history=)
allow(resource).to receive(:persisted?).and_return(true)
FileUtils.mkdir_p("#{Settings.cache_dir}/ns/test")
allow(Rails).to receive(:cache).and_return(file_cache)
end
after do
FileUtils.rm_rf(Settings.cache_dir + '/ns/test')
Expand All @@ -517,10 +520,9 @@ def get_new
before do
allow_any_instance_of(DecoratingRepository).to receive(:find).with("test/bla").and_return(decorated_resource)
allow(resource).to receive(:term_uri_vocabulary_id).and_return("test")
allow_any_instance_of(ActionController::Base).to receive(:perform_caching).and_return(true)
end
it 'should refresh the cache' do
get :show, :id => resource.id, :format => "nt"
FileUtils.touch("#{Settings.cache_dir}/ns/test/bla.nt")
time_old = File.mtime("#{Settings.cache_dir}/ns/test/bla.nt")
sleep(1)
put :cache_update, :id => resource.id, :term_type => "Term"
Expand All @@ -534,12 +536,11 @@ def get_new
context "when the term is not a Term" do
let(:uri) { "http://opaquenamespace.org/ns/test" }
let(:resource) { instance_double("Vocabulary") }

before do
allow(resource).to receive(:id).and_return("test")
allow_any_instance_of(DecoratingRepository).to receive(:find).with("test").and_return(decorated_resource)
allow_any_instance_of(ActionController::Base).to receive(:perform_caching).and_return(true)
get :show, :id => "test"
get :show, :id => "test", :format => "nt"
FileUtils.touch("#{Settings.cache_dir}/ns/test.nt")
put :cache_update, :id => resource.id, :term_type => "Vocabulary"
end
it 'should expire the cache' do
Expand Down
12 changes: 12 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@
mocks.verify_partial_doubles = true
end

config.around(:each, :caching ) do |example|
status = ActionController::Base.perform_caching
store = ActionController::Base.cache_store
ActionController::Base.perform_caching = true
ActionController::Base.cache_store = :file_store, Settings.cache_dir
Rails.cache = ActionController::Base.cache_store
example.run
Rails.cache = store
ActionController::Base.perform_caching = status
ActionController::Base.cache_store = store
end

# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
begin
Expand Down

0 comments on commit 775917c

Please sign in to comment.