Skip to content

Commit

Permalink
🤖 Extract constant to ease testing
Browse files Browse the repository at this point in the history
We're not concerned with where the cached file is for testing purposes;
so instead of hard-coding a value that can change in the ENV, let's
compare the constant that we use in the code.

tl;dr - Don't rely on magic strings
  • Loading branch information
jeremyf committed Dec 20, 2023
1 parent 4319562 commit 13775d6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,16 @@ def switch_host!(cname)
Hyrax::Engine.routes.default_url_options[:host] = cname
end

DEFAULT_FILE_CACHE_STORE = ENV.fetch('HYKU_CACHE_ROOT', '/app/samvera/file_cache')

def setup_tenant_cache(is_enabled)
Rails.application.config.action_controller.perform_caching = is_enabled
ActionController::Base.perform_caching = is_enabled
# rubocop:disable Style/ConditionalAssignment
if is_enabled
Rails.application.config.cache_store = :redis_cache_store, { url: Redis.current.id }
else
Rails.application.config.cache_store = :file_store, ENV.fetch('HYKU_CACHE_ROOT', '/app/samvera/file_cache')
Rails.application.config.cache_store = :file_store, DEFAULT_FILE_CACHE_STORE
end
# rubocop:enable Style/ConditionalAssignment
Rails.cache = ActiveSupport::Cache.lookup_store(Rails.application.config.cache_store)
Expand Down
4 changes: 2 additions & 2 deletions spec/models/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
it "reverts to using file store when cache is off" do
account.settings[:cache_api] = false
account.switch!
expect(Rails.application.config.cache_store).to eq([:file_store, kind_of(String)])
expect(Rails.application.config.cache_store).to eq([:file_store, described_class::DEFAULT_FILE_CACHE_STORE])
end
end

Expand All @@ -140,7 +140,7 @@
it "uses the file store" do
expect(Rails.application.config.action_controller.perform_caching).to be_falsey
expect(ActionController::Base.perform_caching).to be_falsey
expect(Rails.application.config.cache_store).to eq([:file_store, kind_of(String)])
expect(Rails.application.config.cache_store).to eq([:file_store, described_class::DEFAULT_FILE_CACHE_STORE])
end
end

Expand Down

0 comments on commit 13775d6

Please sign in to comment.