@@ -127,7 +127,7 @@ def test_cache_options_definition
127127 end
128128
129129 def test_fragment_cache_definition
130- assert_equal ( [ :name ] , @role_serializer . class . _cache_only )
130+ assert_equal ( [ :name , :slug ] , @role_serializer . class . _cache_only )
131131 assert_equal ( [ :content ] , @bio_serializer . class . _cache_except )
132132 end
133133
@@ -178,14 +178,14 @@ def test_fragment_fetch_with_virtual_associations
178178 id : @location . id ,
179179 lat : @location . lat ,
180180 lng : @location . lng ,
181- place : 'Nowhere'
181+ address : 'Nowhere'
182182 }
183183
184184 hash = render_object_with_cache ( @location )
185185
186186 assert_equal ( hash , expected_result )
187187 key = "#{ @location . cache_key } /#{ adapter . cache_key } "
188- assert_equal ( { place : 'Nowhere' } , cache_store . fetch ( key ) )
188+ assert_equal ( { address : 'Nowhere' } , cache_store . fetch ( key ) )
189189 end
190190
191191 def test_fragment_cache_with_inheritance
@@ -434,21 +434,46 @@ def test_fragment_cached_false_with_cache_store_and_cache_except_and_cache_only
434434 end
435435
436436 def test_fragment_fetch_with_virtual_attributes
437- @author = Author . new ( name : 'Joao M. D. Moura' )
438- @role = Role . new ( name : 'Great Author' , description : nil )
439- @role . author = [ @author ]
440- @role_serializer = RoleSerializer . new ( @role )
441- adapter_instance = ActiveModelSerializers ::Adapter . configured_adapter . new ( @role_serializer )
442- @role_hash = @role_serializer . fetch_attributes_fragment ( adapter_instance )
437+ author = Author . new ( name : 'Joao M. D. Moura' )
438+ role = Role . new ( name : 'Great Author' , description : nil )
439+ role . author = [ author ]
440+ role_serializer = RoleSerializer . new ( role )
441+ adapter_instance = ActiveModelSerializers ::Adapter . configured_adapter . new ( role_serializer )
442+ expected_result = {
443+ id : role . id ,
444+ description : role . description ,
445+ slug : "#{ role . name } -#{ role . id } " ,
446+ name : role . name
447+ }
448+ cache_store . clear
449+
450+ role_hash = role_serializer . fetch_attributes_fragment ( adapter_instance )
451+ assert_equal ( role_hash , expected_result )
452+
453+ role . attributes [ :id ] = 'this has been updated'
454+ role . name = 'this was cached'
443455
456+ role_hash = role_serializer . fetch_attributes_fragment ( adapter_instance )
457+ assert_equal ( expected_result . merge ( id : role . id ) , role_hash )
458+ end
459+
460+ def test_fragment_fetch_with_except
461+ adapter_instance = ActiveModelSerializers ::Adapter . configured_adapter . new ( @bio_serializer )
444462 expected_result = {
445- id : @role . id ,
446- description : @role . description ,
447- slug : "#{ @role . name } -#{ @role . id } " ,
448- name : @role . name
463+ id : @bio . id ,
464+ rating : nil ,
465+ content : @bio . content
449466 }
467+ cache_store . clear
468+
469+ bio_hash = @bio_serializer . fetch_attributes_fragment ( adapter_instance )
470+ assert_equal ( expected_result , bio_hash )
471+
472+ @bio . content = 'this has been updated'
473+ @bio . rating = 'this was cached'
450474
451- assert_equal ( @role_hash , expected_result )
475+ bio_hash = @bio_serializer . fetch_attributes_fragment ( adapter_instance )
476+ assert_equal ( expected_result . merge ( content : @bio . content ) , bio_hash )
452477 end
453478
454479 def test_fragment_fetch_with_namespaced_object
0 commit comments