Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/graphql/fragment_cache/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ class Railtie < ::Rails::Railtie # :nodoc:
module Config
class << self
def store=(store)
if Rails.version.to_f >= 7.0 && Rails.application
cache_format_version = 7.0
ActiveSupport::Cache.format_version = cache_format_version if cache_format_version
end

# Handle both:
# store = :memory
# store = :mem_cache, ENV['MEMCACHE']
Expand All @@ -30,7 +25,13 @@ def store=(store)
config.graphql_fragment_cache = Config

if ENV["RACK_ENV"] == "test" || ENV["RAILS_ENV"] == "test"
config.graphql_fragment_cache.store = :null_store
initializer "graphql-fragment_cache" do
config.graphql_fragment_cache.store = if Rails.version.to_f >= 7.0
[:null_store, serializer: :marshal_7_0]
else
:null_store
end
end
end
end
end
Expand Down
11 changes: 3 additions & 8 deletions spec/graphql/fragment_cache/cacher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ def write_multi(hash, options)

let(:store) { write_multi_store_class.new }

around do |ex|
old_store = GraphQL::FragmentCache.cache_store
before do
allow(store).to receive(:write_multi).and_call_original
GraphQL::FragmentCache.cache_store = store
ex.run
GraphQL::FragmentCache.cache_store = old_store
end

it "uses #write_multi" do
Expand Down Expand Up @@ -134,11 +132,8 @@ def write(key, value, options)

let(:store) { write_with_error_store_class.new }

around do |ex|
old_store = GraphQL::FragmentCache.cache_store
before do
GraphQL::FragmentCache.cache_store = store
ex.run
GraphQL::FragmentCache.cache_store = old_store
end

it "raises error" do
Expand Down
8 changes: 0 additions & 8 deletions spec/graphql/fragment_cache/rails/railtie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,5 @@
expect(GraphQL::FragmentCache.cache_store).to be_a(ActiveSupport::Cache::MemoryStore)
expect(GraphQL::FragmentCache.cache_store.options[:max_size]).to eq 10.megabytes
end

it "updates ActiveSupport::Cache.format_version when rails version is 7.0 or higher" do
allow(Rails).to receive(:version).and_return("7.0")
Rails.application.config.active_support.cache_format_version = 7.0
Rails.application.config.graphql_fragment_cache.store = :memory_store

expect(ActiveSupport::Cache.format_version).to eq 7.0
end
end
end
2 changes: 0 additions & 2 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@
require "combustion"
require "graphql/fragment_cache/railtie"

GraphQL::FragmentCache.cache_store = GraphQL::FragmentCache::MemoryStore.new

Combustion.initialize! :active_record
7 changes: 5 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@
config.include SchemaHelper
config.include_context "graphql"

config.after do
GraphQL::FragmentCache.cache_store.clear if GraphQL::FragmentCache.cache_store.respond_to?(:clear)
config.before do
GraphQL::FragmentCache.cache_store = GraphQL::FragmentCache::MemoryStore.new
end

config.before do
Post.delete_all
Timecop.return
end
Expand Down
Loading