@@ -95,7 +95,7 @@ class PostWithReadonlyAttributesResource < JSONAPI::Resource
9595
9696class ResourceTest < ActiveSupport ::TestCase
9797 def setup
98- @post = Post . first
98+ @post = posts ( :post_1 )
9999 end
100100
101101 def test_model_name
@@ -126,6 +126,33 @@ def test_resource_for_resource_does_not_exist_at_root
126126 end
127127 end
128128
129+ def test_cache_ids_are_consistent_from_run_to_run
130+ assert_equal '2020-01-15 14:15:12 UTC' , @post . updated_at . to_s
131+
132+ post_resource = PostResource . new ( @post , { } )
133+ assert_equal [ @post . id , 1579097712.0 ] , post_resource . cache_id
134+ end
135+
136+ def test_cache_ids_change_when_cache_field_is_changed
137+ assert_equal '2020-01-15 14:15:12 UTC' , @post . updated_at . to_s
138+
139+ post_resource = PostResource . new ( @post , { } )
140+ assert_equal [ @post . id , 1579097712.0 ] , post_resource . cache_id
141+
142+ assert @post . touch
143+ refute_equal [ @post . id , 1579097712.0 ] , post_resource . cache_id
144+ end
145+
146+ def test_date_based_cache_ids_change_with_milliseconds_if_hash_cache_field_is_time_stamp
147+ assert_equal '2020-01-15 14:15:12 UTC' , @post . updated_at . to_s
148+
149+ post_resource = PostResource . new ( @post , { } )
150+ assert_equal [ @post . id , 1579097712.0 ] , post_resource . cache_id
151+
152+ @post . updated_at = @post . updated_at + 0.222
153+ refute_equal [ @post . id , 1579097712.0 ] , post_resource . cache_id
154+ end
155+
129156 def test_resource_for_with_underscored_namespaced_paths
130157 assert_equal ( JSONAPI ::Resource . resource_klass_for ( 'my_module/related' ) , MyModule ::RelatedResource )
131158 assert_equal ( PostResource . resource_klass_for ( 'my_module/related' ) , MyModule ::RelatedResource )
0 commit comments