@@ -95,7 +95,7 @@ class PostWithReadonlyAttributesResource < JSONAPI::Resource
95
95
96
96
class ResourceTest < ActiveSupport ::TestCase
97
97
def setup
98
- @post = Post . first
98
+ @post = posts ( :post_1 )
99
99
end
100
100
101
101
def test_model_name
@@ -126,6 +126,33 @@ def test_resource_for_resource_does_not_exist_at_root
126
126
end
127
127
end
128
128
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
+
129
156
def test_resource_for_with_underscored_namespaced_paths
130
157
assert_equal ( JSONAPI ::Resource . resource_klass_for ( 'my_module/related' ) , MyModule ::RelatedResource )
131
158
assert_equal ( PostResource . resource_klass_for ( 'my_module/related' ) , MyModule ::RelatedResource )
0 commit comments