File tree Expand file tree Collapse file tree 2 files changed +26
-7
lines changed Expand file tree Collapse file tree 2 files changed +26
-7
lines changed Original file line number Diff line number Diff line change @@ -30,13 +30,16 @@ class Serializer
30
30
class << self
31
31
attr_accessor :_attributes
32
32
attr_accessor :_attributes_keys
33
- attr_accessor :_cache
34
- attr_accessor :_fragmented
35
- attr_accessor :_cache_key
36
- attr_accessor :_cache_only
37
- attr_accessor :_cache_except
38
- attr_accessor :_cache_options
39
- attr_accessor :_cache_digest
33
+ end
34
+
35
+ with_options instance_writer : false , instance_reader : false do |serializer |
36
+ serializer . class_attribute :_cache
37
+ serializer . class_attribute :_fragmented
38
+ serializer . class_attribute :_cache_key
39
+ serializer . class_attribute :_cache_only
40
+ serializer . class_attribute :_cache_except
41
+ serializer . class_attribute :_cache_options
42
+ serializer . class_attribute :_cache_digest
40
43
end
41
44
42
45
def self . inherited ( base )
Original file line number Diff line number Diff line change @@ -34,6 +34,22 @@ def setup
34
34
@blog_serializer = BlogSerializer . new ( @blog )
35
35
end
36
36
37
+ def test_inherited_cache_configuration
38
+ inherited_serializer = Class . new ( PostSerializer )
39
+
40
+ assert_equal PostSerializer . _cache_key , inherited_serializer . _cache_key
41
+ assert_equal PostSerializer . _cache_options , inherited_serializer . _cache_options
42
+ end
43
+
44
+ def test_override_cache_configuration
45
+ inherited_serializer = Class . new ( PostSerializer ) do
46
+ cache key : 'new-key'
47
+ end
48
+
49
+ assert PostSerializer . _cache_key == 'post'
50
+ assert inherited_serializer . _cache_key == 'new-key'
51
+ end
52
+
37
53
def test_cache_definition
38
54
assert_equal ( ActionController ::Base . cache_store , @post_serializer . class . _cache )
39
55
assert_equal ( ActionController ::Base . cache_store , @author_serializer . class . _cache )
You can’t perform that action at this time.
0 commit comments