Skip to content

Commit 3a092c9

Browse files
committed
Fixed fragment_cached? method to check if caching
I noticed that fragment caching does not actually check if caching is enabled as it seemingly should. The way CachedSerializer#fragment_cached? worked previously would return true even in an environment where caching was disabled as defined by `ActiveModelSerializers.config.perform_caching`. Added check for `_cache` like in the `cached?` method before checking whether `_cache_only` or `_cache_except` is set. There were no existing tests for any of these methods but it's a pretty trivial change.
1 parent 6509305 commit 3a092c9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/active_model/serializer/adapter/cached_serializer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def cached?
2424
end
2525

2626
def fragment_cached?
27-
@klass._cache_only && !@klass._cache_except || !@klass._cache_only && @klass._cache_except
27+
@klass._cache && (@klass._cache_only && !@klass._cache_except || !@klass._cache_only && @klass._cache_except)
2828
end
2929

3030
def cache_key

0 commit comments

Comments
 (0)