active_model_serializers 0.9.7 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +5 -1
  3. data/README.md +1 -1
  4. data/lib/action_controller/serialization.rb +9 -1
  5. data/lib/active_model/serializer/version.rb +1 -1
  6. data/lib/active_model_serializers/model/caching.rb +25 -0
  7. data/test/benchmark/tmp/miniprofiler/mp_timers_6eqewtfgrhitvq5gqm25 +0 -0
  8. data/test/benchmark/tmp/miniprofiler/{mp_timers_6b9d32ftlk8v5xy2op05 → mp_timers_8083sx03hu72pxz1a4d0} +0 -0
  9. data/test/benchmark/tmp/miniprofiler/{mp_timers_3f0bdfx4nib4hxfb5lmq → mp_timers_fyz2gsml4z0ph9kpoy1c} +0 -0
  10. data/test/benchmark/tmp/miniprofiler/{mp_timers_m78k2w11sd7ba5oh40rw → mp_timers_hjry5rc32imd42oxoi48} +0 -0
  11. data/test/benchmark/tmp/miniprofiler/{mp_timers_7nlok5ykeley83h8bine → mp_timers_m8fpoz2cvt3g9agz0bs3} +0 -0
  12. data/test/benchmark/tmp/miniprofiler/{mp_timers_uc1b3hwqrd4q512gy6c9 → mp_timers_p92m2drnj1i568u3sta0} +0 -0
  13. data/test/benchmark/tmp/miniprofiler/mp_timers_qg52tpca3uesdfguee9i +0 -0
  14. data/test/benchmark/tmp/miniprofiler/{mp_timers_c3a27vo6uvfijeh105nt → mp_timers_s15t1a6mvxe0z7vjv790} +0 -0
  15. data/test/benchmark/tmp/miniprofiler/{mp_timers_54wkvaidi0avdc8yawyt → mp_timers_x8kal3d17nfds6vp4kcj} +0 -0
  16. data/test/benchmark/tmp/miniprofiler/mp_views_127.0.0.1 +0 -0
  17. data/test/tmp/app/assets/javascripts/accounts.js +2 -0
  18. data/test/tmp/app/assets/stylesheets/accounts.css +4 -0
  19. data/test/tmp/app/controllers/accounts_controller.rb +2 -0
  20. data/test/tmp/app/helpers/accounts_helper.rb +2 -0
  21. data/test/tmp/app/serializers/account_serializer.rb +1 -1
  22. data/test/tmp/config/routes.rb +1 -0
  23. metadata +68 -103
  24. data/lib/bulk_cache_fetcher.rb +0 -105
  25. data/test/action_controller/http_cache_test.rb +0 -56
  26. data/test/action_controller/regression_test.rb +0 -35
  27. data/test/benchmark/bm_rails_cache.rb +0 -141
  28. data/test/benchmark/tmp/miniprofiler/mp_timers_16x1i2wkkt8b8zybbfbx +0 -0
  29. data/test/benchmark/tmp/miniprofiler/mp_timers_3aa299ezxdqvog6sfjzr +0 -0
  30. data/test/benchmark/tmp/miniprofiler/mp_timers_b36ymkc1vgu5fy9fvm9k +0 -0
  31. data/test/benchmark/tmp/miniprofiler/mp_timers_eqcbrj14r4c341abi3h6 +0 -0
  32. data/test/benchmark/tmp/miniprofiler/mp_timers_hqodkd691tbr7sbfdiez +0 -0
  33. data/test/benchmark/tmp/miniprofiler/mp_timers_j7y5frtod7cw4qc4cear +0 -0
  34. data/test/benchmark/tmp/miniprofiler/mp_timers_jpxzfgo92l24t7wzt8g1 +0 -0
  35. data/test/benchmark/tmp/miniprofiler/mp_timers_mkvat4ehphrje9n2hu3t +0 -0
  36. data/test/benchmark/tmp/miniprofiler/mp_timers_nd3ymt54l1ga22i2brn8 +0 -0
  37. data/test/benchmark/tmp/miniprofiler/mp_timers_o2dk1yhw6ez9jzxf6p0a +0 -0
  38. data/test/benchmark/tmp/miniprofiler/mp_timers_p76i310zb4y12iqm5o0n +0 -0
  39. data/test/benchmark/tmp/miniprofiler/mp_timers_pi3hvrrkfxnxl300wvah +0 -0
  40. data/test/benchmark/tmp/miniprofiler/mp_timers_q4w5d86flb4u9tsadqvw +0 -0
  41. data/test/benchmark/tmp/miniprofiler/mp_timers_sfa5nundogo63o056n5y +0 -0
  42. data/test/benchmark/tmp/miniprofiler/mp_timers_tkjlmqeauf5gur2u5nob +0 -0
  43. data/test/benchmark/tmp/miniprofiler/mp_timers_tngbj11ilv2i75rqn2d2 +0 -0
  44. data/test/benchmark/tmp/miniprofiler/mp_timers_u4haqgvgybvc1sb5nihw +0 -0
  45. data/test/benchmark/tmp/miniprofiler/mp_timers_uwholuf0iix2vvbo2l3c +0 -0
  46. data/test/benchmark/tmp/miniprofiler/mp_timers_waye238ygft3p4xvppc4 +0 -0
  47. data/test/benchmark/tmp/miniprofiler/mp_timers_ydwo7p117loo2ky40lk3 +0 -0
  48. data/test/benchmark/tmp/miniprofiler/mp_timers_zhgmyfizfa8slppitgua +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2f73f5aff52f42003b604fcc209782d1b074eb9a
4
- data.tar.gz: 0fce31e1d5f8f01da8c0c9d70c30fee124dc87ff
2
+ SHA256:
3
+ metadata.gz: e9f526564b9458ceea3d9391ddbf81cf996ff713dbb217bcec1c22931b4cd028
4
+ data.tar.gz: ac5641428e5b17ffa605bc7337f8f77000354a2a47f1a5ed7244ab50cdca84b2
5
5
  SHA512:
6
- metadata.gz: 983ed0d1faf8a9e4cb9cf65e4d71fdc5064016e42190a81aa96f73a37e1e342eecead421ebe69c04cca27db142a622eb966e9fc04b79cc152af5b744d6f97812
7
- data.tar.gz: 97accf62bff15dc099483199c8ca58c974fc2ee227f64bdbd10223924cdbaa923d4fb59c5ea5a8973fb5612c50e8ef9abf50f300cc8b6f64b80dd9b3a181829f
6
+ metadata.gz: af47a8298fbc563716f0c7b4a9e0d92b85243ead1b0ccac561703d17f09574a3e65f280adedbb24ee7d65c0634c4ca343c58aa665628ff75d7e220b89025e91d
7
+ data.tar.gz: 6974a26799a967fbb8b172092be014deb775909a52cf10cf4e7dc88b5c05c96f6b6acbb3d245f9ad9032c743c2048c1afd8335d3a899c3111f2d6b48015800f7
@@ -1,6 +1,10 @@
1
1
  ## 0.09.x
2
2
 
3
- ### [0-9-stable](https://github.com/rails-api/active_model_serializers/compare/v0.9.7...0-9-stable)
3
+ ### [0-9-stable](https://github.com/rails-api/active_model_serializers/compare/v0.9.8...0-9-stable)
4
+
5
+ ### [v0.9.8 (2020-12-10)](https://github.com/rails-api/active_model_serializers/compare/v0.9.7...v0.9.8)
6
+
7
+ - [#2373](https://github.com/rails-api/active_model_serializers/pull/2373) Fix Rails 6.0 deprecation warnings. (@supremebeing7)
4
8
 
5
9
  ### [v0.9.7 (2017-05-01)](https://github.com/rails-api/active_model_serializers/compare/v0.9.6...v0.9.7)
6
10
 
data/README.md CHANGED
@@ -85,7 +85,7 @@ it exists, use it to serialize the `Post`.
85
85
 
86
86
  This also works with `respond_with`, which uses `to_json` under the hood. Also
87
87
  note that any options passed to `render :json` will be passed to your
88
- serializer and available as `@options` inside.
88
+ serializer and available as `@serialization_options` inside.
89
89
 
90
90
  To specify a custom serializer for an object, you can specify the
91
91
  serializer when you render the object:
@@ -60,7 +60,15 @@ module ActionController
60
60
  private
61
61
 
62
62
  def namespace_for_serializer
63
- @namespace_for_serializer ||= self.class.parent unless self.class.parent == Object
63
+ @namespace_for_serializer ||= namespace_for_class(self.class) unless namespace_for_class(self.class) == Object
64
+ end
65
+
66
+ def namespace_for_class(klass)
67
+ if Module.method_defined?(:module_parent)
68
+ klass.module_parent
69
+ else
70
+ klass.parent
71
+ end
64
72
  end
65
73
 
66
74
  def default_serializer(resource)
@@ -1,5 +1,5 @@
1
1
  module ActiveModel
2
2
  class Serializer
3
- VERSION = '0.9.7'
3
+ VERSION = '0.9.8'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,25 @@
1
+ module ActiveModelSerializers
2
+ class Model
3
+ module Caching
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ attr_writer :updated_at
8
+ attributes :id
9
+ end
10
+
11
+ # Defaults to the downcased model name and updated_at
12
+ def cache_key
13
+ ActiveSupport::Cache.expand_cache_key([
14
+ self.class.model_name.name.downcase,
15
+ "#{id}-#{updated_at.strftime('%Y%m%d%H%M%S%9N')}"
16
+ ].compact)
17
+ end
18
+
19
+ # Defaults to the time the serializer file was modified.
20
+ def updated_at
21
+ defined?(@updated_at) ? @updated_at : File.mtime(__FILE__)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,2 @@
1
+ class AccountsController < ApplicationController
2
+ end
@@ -0,0 +1,2 @@
1
+ module AccountsHelper
2
+ end
@@ -1,3 +1,3 @@
1
- class AccountSerializer < MySerializer
1
+ class AccountSerializer < ActiveModel::Serializer
2
2
  attributes :id
3
3
  end
@@ -0,0 +1 @@
1
+ Rails.application.routes.draw { }
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_model_serializers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.7
4
+ version: 0.9.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - José Valim
8
8
  - Yehuda Katz
9
9
  - Santiago Pastorino
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-05-01 00:00:00.000000000 Z
13
+ date: 2020-12-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
@@ -89,42 +89,20 @@ files:
89
89
  - lib/active_model/serializer/version.rb
90
90
  - lib/active_model/serializer_support.rb
91
91
  - lib/active_model_serializers.rb
92
- - lib/bulk_cache_fetcher.rb
93
- - test/action_controller/http_cache_test.rb
94
- - test/action_controller/regression_test.rb
92
+ - lib/active_model_serializers/model/caching.rb
95
93
  - test/benchmark/app.rb
96
94
  - test/benchmark/benchmarking_support.rb
97
95
  - test/benchmark/bm_active_record.rb
98
- - test/benchmark/bm_rails_cache.rb
99
96
  - test/benchmark/setup.rb
100
- - test/benchmark/tmp/miniprofiler/mp_timers_16x1i2wkkt8b8zybbfbx
101
- - test/benchmark/tmp/miniprofiler/mp_timers_3aa299ezxdqvog6sfjzr
102
- - test/benchmark/tmp/miniprofiler/mp_timers_3f0bdfx4nib4hxfb5lmq
103
- - test/benchmark/tmp/miniprofiler/mp_timers_54wkvaidi0avdc8yawyt
104
- - test/benchmark/tmp/miniprofiler/mp_timers_6b9d32ftlk8v5xy2op05
105
- - test/benchmark/tmp/miniprofiler/mp_timers_7nlok5ykeley83h8bine
106
- - test/benchmark/tmp/miniprofiler/mp_timers_b36ymkc1vgu5fy9fvm9k
107
- - test/benchmark/tmp/miniprofiler/mp_timers_c3a27vo6uvfijeh105nt
108
- - test/benchmark/tmp/miniprofiler/mp_timers_eqcbrj14r4c341abi3h6
109
- - test/benchmark/tmp/miniprofiler/mp_timers_hqodkd691tbr7sbfdiez
110
- - test/benchmark/tmp/miniprofiler/mp_timers_j7y5frtod7cw4qc4cear
111
- - test/benchmark/tmp/miniprofiler/mp_timers_jpxzfgo92l24t7wzt8g1
112
- - test/benchmark/tmp/miniprofiler/mp_timers_m78k2w11sd7ba5oh40rw
113
- - test/benchmark/tmp/miniprofiler/mp_timers_mkvat4ehphrje9n2hu3t
114
- - test/benchmark/tmp/miniprofiler/mp_timers_nd3ymt54l1ga22i2brn8
115
- - test/benchmark/tmp/miniprofiler/mp_timers_o2dk1yhw6ez9jzxf6p0a
116
- - test/benchmark/tmp/miniprofiler/mp_timers_p76i310zb4y12iqm5o0n
117
- - test/benchmark/tmp/miniprofiler/mp_timers_pi3hvrrkfxnxl300wvah
118
- - test/benchmark/tmp/miniprofiler/mp_timers_q4w5d86flb4u9tsadqvw
119
- - test/benchmark/tmp/miniprofiler/mp_timers_sfa5nundogo63o056n5y
120
- - test/benchmark/tmp/miniprofiler/mp_timers_tkjlmqeauf5gur2u5nob
121
- - test/benchmark/tmp/miniprofiler/mp_timers_tngbj11ilv2i75rqn2d2
122
- - test/benchmark/tmp/miniprofiler/mp_timers_u4haqgvgybvc1sb5nihw
123
- - test/benchmark/tmp/miniprofiler/mp_timers_uc1b3hwqrd4q512gy6c9
124
- - test/benchmark/tmp/miniprofiler/mp_timers_uwholuf0iix2vvbo2l3c
125
- - test/benchmark/tmp/miniprofiler/mp_timers_waye238ygft3p4xvppc4
126
- - test/benchmark/tmp/miniprofiler/mp_timers_ydwo7p117loo2ky40lk3
127
- - test/benchmark/tmp/miniprofiler/mp_timers_zhgmyfizfa8slppitgua
97
+ - test/benchmark/tmp/miniprofiler/mp_timers_6eqewtfgrhitvq5gqm25
98
+ - test/benchmark/tmp/miniprofiler/mp_timers_8083sx03hu72pxz1a4d0
99
+ - test/benchmark/tmp/miniprofiler/mp_timers_fyz2gsml4z0ph9kpoy1c
100
+ - test/benchmark/tmp/miniprofiler/mp_timers_hjry5rc32imd42oxoi48
101
+ - test/benchmark/tmp/miniprofiler/mp_timers_m8fpoz2cvt3g9agz0bs3
102
+ - test/benchmark/tmp/miniprofiler/mp_timers_p92m2drnj1i568u3sta0
103
+ - test/benchmark/tmp/miniprofiler/mp_timers_qg52tpca3uesdfguee9i
104
+ - test/benchmark/tmp/miniprofiler/mp_timers_s15t1a6mvxe0z7vjv790
105
+ - test/benchmark/tmp/miniprofiler/mp_timers_x8kal3d17nfds6vp4kcj
128
106
  - test/benchmark/tmp/miniprofiler/mp_views_127.0.0.1
129
107
  - test/fixtures/active_record.rb
130
108
  - test/fixtures/poro.rb
@@ -138,7 +116,12 @@ files:
138
116
  - test/integration/generators/serializer_generator_test.rb
139
117
  - test/test_app.rb
140
118
  - test/test_helper.rb
119
+ - test/tmp/app/assets/javascripts/accounts.js
120
+ - test/tmp/app/assets/stylesheets/accounts.css
121
+ - test/tmp/app/controllers/accounts_controller.rb
122
+ - test/tmp/app/helpers/accounts_helper.rb
141
123
  - test/tmp/app/serializers/account_serializer.rb
124
+ - test/tmp/config/routes.rb
142
125
  - test/unit/active_model/array_serializer/except_test.rb
143
126
  - test/unit/active_model/array_serializer/key_format_test.rb
144
127
  - test/unit/active_model/array_serializer/meta_test.rb
@@ -169,7 +152,7 @@ homepage: https://github.com/rails-api/active_model_serializers
169
152
  licenses:
170
153
  - MIT
171
154
  metadata: {}
172
- post_install_message:
155
+ post_install_message:
173
156
  rdoc_options: []
174
157
  require_paths:
175
158
  - lib
@@ -184,85 +167,67 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
167
  - !ruby/object:Gem::Version
185
168
  version: '0'
186
169
  requirements: []
187
- rubyforge_project:
188
- rubygems_version: 2.4.8
189
- signing_key:
170
+ rubygems_version: 3.1.4
171
+ signing_key:
190
172
  specification_version: 4
191
173
  summary: Bringing consistency and object orientation to model serialization. Works
192
174
  great for client-side MVC frameworks!
193
175
  test_files:
194
- - test/action_controller/http_cache_test.rb
195
- - test/action_controller/regression_test.rb
196
176
  - test/benchmark/app.rb
197
- - test/benchmark/benchmarking_support.rb
198
- - test/benchmark/bm_active_record.rb
199
- - test/benchmark/bm_rails_cache.rb
200
177
  - test/benchmark/setup.rb
201
- - test/benchmark/tmp/miniprofiler/mp_timers_16x1i2wkkt8b8zybbfbx
202
- - test/benchmark/tmp/miniprofiler/mp_timers_3aa299ezxdqvog6sfjzr
203
- - test/benchmark/tmp/miniprofiler/mp_timers_3f0bdfx4nib4hxfb5lmq
204
- - test/benchmark/tmp/miniprofiler/mp_timers_54wkvaidi0avdc8yawyt
205
- - test/benchmark/tmp/miniprofiler/mp_timers_6b9d32ftlk8v5xy2op05
206
- - test/benchmark/tmp/miniprofiler/mp_timers_7nlok5ykeley83h8bine
207
- - test/benchmark/tmp/miniprofiler/mp_timers_b36ymkc1vgu5fy9fvm9k
208
- - test/benchmark/tmp/miniprofiler/mp_timers_c3a27vo6uvfijeh105nt
209
- - test/benchmark/tmp/miniprofiler/mp_timers_eqcbrj14r4c341abi3h6
210
- - test/benchmark/tmp/miniprofiler/mp_timers_hqodkd691tbr7sbfdiez
211
- - test/benchmark/tmp/miniprofiler/mp_timers_j7y5frtod7cw4qc4cear
212
- - test/benchmark/tmp/miniprofiler/mp_timers_jpxzfgo92l24t7wzt8g1
213
- - test/benchmark/tmp/miniprofiler/mp_timers_m78k2w11sd7ba5oh40rw
214
- - test/benchmark/tmp/miniprofiler/mp_timers_mkvat4ehphrje9n2hu3t
215
- - test/benchmark/tmp/miniprofiler/mp_timers_nd3ymt54l1ga22i2brn8
216
- - test/benchmark/tmp/miniprofiler/mp_timers_o2dk1yhw6ez9jzxf6p0a
217
- - test/benchmark/tmp/miniprofiler/mp_timers_p76i310zb4y12iqm5o0n
218
- - test/benchmark/tmp/miniprofiler/mp_timers_pi3hvrrkfxnxl300wvah
219
- - test/benchmark/tmp/miniprofiler/mp_timers_q4w5d86flb4u9tsadqvw
220
- - test/benchmark/tmp/miniprofiler/mp_timers_sfa5nundogo63o056n5y
221
- - test/benchmark/tmp/miniprofiler/mp_timers_tkjlmqeauf5gur2u5nob
222
- - test/benchmark/tmp/miniprofiler/mp_timers_tngbj11ilv2i75rqn2d2
223
- - test/benchmark/tmp/miniprofiler/mp_timers_u4haqgvgybvc1sb5nihw
224
- - test/benchmark/tmp/miniprofiler/mp_timers_uc1b3hwqrd4q512gy6c9
225
- - test/benchmark/tmp/miniprofiler/mp_timers_uwholuf0iix2vvbo2l3c
226
- - test/benchmark/tmp/miniprofiler/mp_timers_waye238ygft3p4xvppc4
227
- - test/benchmark/tmp/miniprofiler/mp_timers_ydwo7p117loo2ky40lk3
228
- - test/benchmark/tmp/miniprofiler/mp_timers_zhgmyfizfa8slppitgua
178
+ - test/benchmark/bm_active_record.rb
179
+ - test/benchmark/tmp/miniprofiler/mp_timers_m8fpoz2cvt3g9agz0bs3
180
+ - test/benchmark/tmp/miniprofiler/mp_timers_s15t1a6mvxe0z7vjv790
181
+ - test/benchmark/tmp/miniprofiler/mp_timers_hjry5rc32imd42oxoi48
182
+ - test/benchmark/tmp/miniprofiler/mp_timers_qg52tpca3uesdfguee9i
229
183
  - test/benchmark/tmp/miniprofiler/mp_views_127.0.0.1
230
- - test/fixtures/active_record.rb
231
- - test/fixtures/poro.rb
232
- - test/fixtures/template.html.erb
233
- - test/integration/action_controller/namespaced_serialization_test.rb
234
- - test/integration/action_controller/serialization_test.rb
235
- - test/integration/action_controller/serialization_test_case_test.rb
236
- - test/integration/active_record/active_record_test.rb
237
- - test/integration/generators/resource_generator_test.rb
238
- - test/integration/generators/scaffold_controller_generator_test.rb
239
- - test/integration/generators/serializer_generator_test.rb
240
- - test/test_app.rb
241
- - test/test_helper.rb
242
- - test/tmp/app/serializers/account_serializer.rb
243
- - test/unit/active_model/array_serializer/except_test.rb
244
- - test/unit/active_model/array_serializer/key_format_test.rb
245
- - test/unit/active_model/array_serializer/meta_test.rb
246
- - test/unit/active_model/array_serializer/only_test.rb
247
- - test/unit/active_model/array_serializer/options_test.rb
248
- - test/unit/active_model/array_serializer/root_test.rb
249
- - test/unit/active_model/array_serializer/scope_test.rb
250
- - test/unit/active_model/array_serializer/serialization_test.rb
251
- - test/unit/active_model/default_serializer_test.rb
184
+ - test/benchmark/tmp/miniprofiler/mp_timers_fyz2gsml4z0ph9kpoy1c
185
+ - test/benchmark/tmp/miniprofiler/mp_timers_p92m2drnj1i568u3sta0
186
+ - test/benchmark/tmp/miniprofiler/mp_timers_6eqewtfgrhitvq5gqm25
187
+ - test/benchmark/tmp/miniprofiler/mp_timers_x8kal3d17nfds6vp4kcj
188
+ - test/benchmark/tmp/miniprofiler/mp_timers_8083sx03hu72pxz1a4d0
189
+ - test/benchmark/benchmarking_support.rb
190
+ - test/unit/active_model/serializer/config_test.rb
191
+ - test/unit/active_model/serializer/has_one_test.rb
252
192
  - test/unit/active_model/serializer/associations/build_serializer_test.rb
193
+ - test/unit/active_model/serializer/key_format_test.rb
194
+ - test/unit/active_model/serializer/url_helpers_test.rb
253
195
  - test/unit/active_model/serializer/associations_test.rb
196
+ - test/unit/active_model/serializer/options_test.rb
254
197
  - test/unit/active_model/serializer/attributes_test.rb
255
- - test/unit/active_model/serializer/config_test.rb
256
- - test/unit/active_model/serializer/filter_test.rb
198
+ - test/unit/active_model/serializer/root_test.rb
199
+ - test/unit/active_model/serializer/meta_test.rb
257
200
  - test/unit/active_model/serializer/has_many_polymorphic_test.rb
201
+ - test/unit/active_model/serializer/has_one_polymorphic_test.rb
258
202
  - test/unit/active_model/serializer/has_many_test.rb
259
203
  - test/unit/active_model/serializer/has_one_and_has_many_test.rb
260
- - test/unit/active_model/serializer/has_one_polymorphic_test.rb
261
- - test/unit/active_model/serializer/has_one_test.rb
262
- - test/unit/active_model/serializer/key_format_test.rb
263
- - test/unit/active_model/serializer/meta_test.rb
264
- - test/unit/active_model/serializer/options_test.rb
265
- - test/unit/active_model/serializer/root_test.rb
204
+ - test/unit/active_model/serializer/filter_test.rb
266
205
  - test/unit/active_model/serializer/scope_test.rb
267
- - test/unit/active_model/serializer/url_helpers_test.rb
206
+ - test/unit/active_model/default_serializer_test.rb
207
+ - test/unit/active_model/array_serializer/serialization_test.rb
208
+ - test/unit/active_model/array_serializer/key_format_test.rb
209
+ - test/unit/active_model/array_serializer/options_test.rb
210
+ - test/unit/active_model/array_serializer/only_test.rb
211
+ - test/unit/active_model/array_serializer/root_test.rb
212
+ - test/unit/active_model/array_serializer/except_test.rb
213
+ - test/unit/active_model/array_serializer/meta_test.rb
214
+ - test/unit/active_model/array_serializer/scope_test.rb
268
215
  - test/unit/active_model/serilizable_test.rb
216
+ - test/test_app.rb
217
+ - test/integration/action_controller/serialization_test.rb
218
+ - test/integration/action_controller/serialization_test_case_test.rb
219
+ - test/integration/action_controller/namespaced_serialization_test.rb
220
+ - test/integration/active_record/active_record_test.rb
221
+ - test/integration/generators/scaffold_controller_generator_test.rb
222
+ - test/integration/generators/resource_generator_test.rb
223
+ - test/integration/generators/serializer_generator_test.rb
224
+ - test/fixtures/poro.rb
225
+ - test/fixtures/template.html.erb
226
+ - test/fixtures/active_record.rb
227
+ - test/test_helper.rb
228
+ - test/tmp/app/serializers/account_serializer.rb
229
+ - test/tmp/app/controllers/accounts_controller.rb
230
+ - test/tmp/app/assets/javascripts/accounts.js
231
+ - test/tmp/app/assets/stylesheets/accounts.css
232
+ - test/tmp/app/helpers/accounts_helper.rb
233
+ - test/tmp/config/routes.rb
@@ -1,105 +0,0 @@
1
- # frozen_string_literal: true
2
- # https://github.com/justinweiss/bulk_cache_fetcher/blob/df1c83e06b9641b7ec3408ec577b37528021190f/lib/bulk_cache_fetcher.rb
3
- # Fetches many objects from a cache in order. In the event that some
4
- # objects can't be served from the cache, you will have the
5
- # opportunity to fetch them in bulk. This allows you to preload and
6
- # cache entire object hierarchies, which works particularly well with
7
- # Rails' nested caching while avoiding the n+1 queries problem in the
8
- # uncached case.
9
- class BulkCacheFetcher
10
- VERSION = '1.0.0'
11
-
12
- # Creates a new bulk cache fetcher, backed by +cache+. Cache must
13
- # respond to the standard Rails cache API, described on
14
- # http://guides.rubyonrails.org/caching_with_rails.html
15
- def initialize(cache)
16
- @cache = cache
17
- end
18
-
19
- # Returns a list of objects identified by
20
- # <tt>object_identifiers</tt>. +fetch+ will try to find the objects
21
- # from the cache first. Identifiers for objects that aren't in the
22
- # cache will be passed as an ordered list to <tt>finder_block</tt>,
23
- # where you can find the objects as you see fit. These objects
24
- # should be returned in the same order as the identifiers that were
25
- # passed into the block, because they'll be cached under their
26
- # respective keys. The objects returned by +fetch+ will be returned
27
- # in the same order as the <tt>object_identifiers</tt> passed in.
28
- #
29
- # +options+ will be passed along unmodified when caching newly found
30
- # objects, so you can use it for things like setting cache
31
- # expiration.
32
- def fetch(object_identifiers, options = {}, &finder_block)
33
- object_identifiers = normalize(object_identifiers)
34
- cached_keys_with_objects, uncached_identifiers = partition(object_identifiers)
35
- found_objects = find(uncached_identifiers, options, &finder_block)
36
- coalesce(cache_keys(object_identifiers), cached_keys_with_objects, found_objects)
37
- end
38
-
39
- private
40
-
41
- # Splits a list of identifiers into two objects. The first is a hash
42
- # of <tt>{cache_key: object}</tt> for all the objects we were able to serve
43
- # from the cache. The second is a list of all of the identifiers for
44
- # objects that weren't cached.
45
- def partition(object_identifiers)
46
- uncached_identifiers = object_identifiers.dup
47
-
48
- cache_keys = cache_keys(object_identifiers)
49
- cached_keys_with_objects = @cache.read_multi(*cache_keys)
50
-
51
- cache_keys.each do |cache_key|
52
- uncached_identifiers.delete(cache_key) if cached_keys_with_objects.key?(cache_key)
53
- end
54
-
55
- [cached_keys_with_objects, uncached_identifiers]
56
- end
57
-
58
- # Finds all of the objects identified by +identifiers+, using the
59
- # +finder_block+. Will pass +options+ on to the cache.
60
- def find(identifiers, options = {})
61
- return [] if identifiers.empty?
62
- Array(yield(identifiers)).tap do |objects|
63
- verify_equal_key_and_value_counts!(identifiers, objects)
64
- cache_all(identifiers, objects, options)
65
- end
66
- end
67
-
68
- # Makes sure we have enough +identifiers+ to cache all of our
69
- # +objects+, and vice-versa.
70
- def verify_equal_key_and_value_counts!(identifiers, objects)
71
- fail ArgumentError, 'You are returning too many objects from your cache block!' if objects.length > identifiers.length
72
- fail ArgumentError, 'You are returning too few objects from your cache block!' if objects.length < identifiers.length
73
- end
74
-
75
- # Caches all +values+ under their respective +keys+.
76
- def cache_all(keys, values, options = {})
77
- keys.zip(values) { |k, v| @cache.write(cache_key(k), v, options) }
78
- end
79
-
80
- # Given a list of +cache_keys+, either find associated objects from
81
- # +cached_keys_with_objects, or grab them from +found_objects+, in
82
- # order.
83
- def coalesce(cache_keys, cached_keys_with_objects, found_objects)
84
- found_objects = Array(found_objects)
85
- cache_keys.map { |key| cached_keys_with_objects.fetch(key) { found_objects.shift } }
86
- end
87
-
88
- # Returns the part of the identifier that we can use as the cache
89
- # key. For simple identifiers, it's just the identifier, for
90
- # identifiers with extra information attached, it's the first part
91
- # of the identifier.
92
- def cache_key(identifier)
93
- Array(identifier).first
94
- end
95
-
96
- # Returns the cache keys for all of the +identifiers+.
97
- def cache_keys(identifiers)
98
- identifiers.map { |identifier| cache_key(identifier) }
99
- end
100
-
101
- # Makes sure we can iterate over identifiers.
102
- def normalize(identifiers)
103
- identifiers.respond_to?(:each) ? identifiers : Array(identifiers)
104
- end
105
- end
@@ -1,56 +0,0 @@
1
- # require 'test_helper'
2
- #
3
- # # https://github.com/rails/rails/blob/4-2-stable/actionpack/lib/action_dispatch/testing/integration.rb
4
- # # rubocop:disable Style/ClassAndModuleChildren:
5
- # class ActionController::Serialization::HttpCacheTest < ActionController::TestCase
6
- # # class ActionController::Serialization::HttpCacheTest < ActionDispatch::IntegrationTest
7
- # class HttpCacheTestController < ActionController::Base
8
- # class Model < ActiveModelSerializers::Model
9
- # attr_accessor :name, :description, :comments
10
- # end
11
- # class ModelSerializer < ActiveModel::Serializer
12
- # attributes :name, :description, :comments
13
- # end
14
- #
15
- # def render_as_serializable_object
16
- # render serialization_options.merge!(json: model)
17
- # end
18
- #
19
- # def render_as_json_string
20
- # json = ActiveModelSerializers::SerializableResource.new(model, serialization_options).to_json
21
- # render json: json
22
- # end
23
- #
24
- # private
25
- #
26
- # def model
27
- # Model.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
28
- # end
29
- #
30
- # def serialization_options
31
- # { serializer: ModelSerializer, adapter: :json }
32
- # end
33
- # end
34
- #
35
- # tests HttpCacheTestController
36
- #
37
- # DATE = 'Date'.freeze
38
- # LAST_MODIFIED = 'Last-Modified'.freeze
39
- # ETAG = 'ETag'.freeze
40
- # CACHE_CONTROL = 'Cache-Control'.freeze
41
- # SPECIAL_KEYS = Set.new(%w(extras no-cache max-age public must-revalidate))
42
- # def test_render_as_serializable_object
43
- # 10.times do
44
- # get :render_as_serializable_object
45
- # end
46
- # p [@response.etag?, @response.last_modified, @response.date, @response.headers[CACHE_CONTROL], @response.headers[ETAG], @response.headers[LAST_MODIFIED], @response.headers[DATE]]
47
- # end
48
- #
49
- # def test_render_as_json_string
50
- # 10.times do
51
- # get :render_as_json_string
52
- # end
53
- # p [@response.etag?, @response.last_modified, @response.date, @response.headers[CACHE_CONTROL], @response.headers[ETAG], @response.headers[LAST_MODIFIED], @response.headers[DATE]]
54
- # end
55
- # end
56
- # # rubocop:enable Style/ClassAndModuleChildren:
@@ -1,35 +0,0 @@
1
- # require 'test_helper'
2
- #
3
- # module ActionController
4
- # module Serialization
5
- # class ImplicitSerializerTest < ActionController::TestCase
6
- # class PostWithoutSerializer < ActiveRecord::Base
7
- # self.table_name = :posts
8
- # end
9
- # class ImplicitSerializationTestController < ActionController::Base
10
- # def render_record_without_serializer
11
- # @post = PostWithoutSerializer.new(title: 'Title', body: 'Body')
12
- # render json: @post
13
- # end
14
- # end
15
- #
16
- # tests ImplicitSerializationTestController
17
- #
18
- # def test_record_without_serializer
19
- # with_adapter :json do
20
- # get :render_record_without_serializer
21
- # end
22
- #
23
- # expected = {}
24
- # PostWithoutSerializer.column_names.each { |field| expected[field] ||= nil }
25
- # expected.update(
26
- # title: 'Title',
27
- # body: 'Body'
28
- # )
29
- #
30
- # assert_equal 'application/json', @response.content_type
31
- # assert_equal expected.to_json, @response.body
32
- # end
33
- # end
34
- # end
35
- # end
@@ -1,141 +0,0 @@
1
- require 'bundler/setup'
2
- require_relative './benchmarking_support'
3
- require_relative './app'
4
-
5
- time = 10
6
- cache_store = ActiveSupport::Cache.lookup_store(:memory_store)
7
- comments = (0..50).map do |i|
8
- Comment.new(id: i, body: 'ZOMG A COMMENT')
9
- end
10
- author = Author.new(id: 42, first_name: 'Joao', last_name: 'Moura')
11
- model = Post.new(id: 1337, title: 'New Post', blog: nil, body: 'Body', comments: comments, author: author)
12
-
13
- define_method :json do
14
- model.to_json
15
- end
16
- define_method :cached_json do
17
- parts = []
18
- parts << 'key_name'
19
- parts << 'adapter_name'
20
- cache_key = parts.join('/')
21
- cache_store.fetch(cache_key) { model.to_json }
22
- end
23
- define_method :ams do
24
- ActiveModelSerializers::SerializableResource.new(model, adapter: :json, serializer: PostSerializer).as_json
25
- end
26
- define_method :cached_ams do
27
- ActiveModelSerializers::SerializableResource.new(model, adapter: :json, serializer: CachingPostSerializer).as_json
28
- end
29
- def as_json(serializer_instance, adapter_instance, fields, includes = '*')
30
- if serializer_instance.respond_to?(:each)
31
- return serializer_instance.map do |each_serializer|
32
- as_json(each_serializer, adapter_instance, fields, includes)
33
- end
34
- end
35
- cache_key = serializer_instance.cache_key(adapter_instance)
36
- include_tree = includes || ActiveModel::Serializer::IncludeTree.from_include_args(includes)
37
- cache_store = ActiveModelSerializers.config.cache_store
38
- json = cache_store.fetch(cache_key) do
39
- serializer_instance.attributes(fields)
40
- end
41
- serializer_instance.associations(include_tree).each do |association|
42
- # FIXME: yields each association twice
43
- json[association.key] ||= as_json(association.serializer, adapter_instance, [], includes[association.key])
44
- end
45
- json
46
- end
47
-
48
- define_method :cached_virtual_ams do
49
- ### OMG
50
- post_serializer = CachingPostSerializer.new(model)
51
- adapter_instance = ActiveModelSerializers::Adapter::Attributes.new(post_serializer)
52
- fields = nil
53
- includes = ActiveModel::Serializer::IncludeTree.from_include_args('*')
54
- { post: as_json(post_serializer, adapter_instance, fields, includes) }
55
- # parts = []
56
- # parts << 'ams_blog'
57
- # parts << 'attributes'
58
- # cache_key = parts.join('/')
59
- # cache_store.fetch(cache_key) do
60
- # include_tree = ActiveModel::Serializer::IncludeTree.from_include_args('*')
61
- # post_serializer = CachingPostSerializer.new(model)
62
- # json = { post: post_serializer.attributes }
63
- # post_serializer.associations(include_tree).each do |association|
64
- # # FIXME: yields each association twice
65
- # json[:post][association.key] ||=
66
- # case association.key
67
- # when :comments
68
- # cache_store.fetch(%w(ams_comments attributes).join('/')) do
69
- # association.serializer.map(&:attributes)
70
- # end
71
- # when :blog
72
- # association.serializer.attributes
73
- # when :author
74
- # cache_store.fetch(%w(ams_author attributes).join('/')) do
75
- # association.serializer.attributes
76
- # end
77
- # else
78
- # fail ArgumentError, "unexpected association #{association}"
79
- # end
80
- # end
81
- # json
82
- # end
83
- end
84
- puts JSON.pretty_generate(
85
- equality: { cached_ams: ams == cached_ams, cached_virtual_ams: ams == cached_virtual_ams },
86
- ams: ams,
87
- cached_ams: cached_ams,
88
- cached_virtual_ams: cached_virtual_ams
89
- )
90
-
91
- {
92
- # 'cached json' => { disable_gc: true, send: :cached_json },
93
- # 'json' => { disable_gc: true, send: :json },
94
- # 'cached ams' => { disable_gc: true, send: :cached_ams },
95
- 'cached virtual ams' => { disable_gc: true, send: :cached_virtual_ams },
96
- 'ams' => { disable_gc: true, send: :ams }
97
- }.each do |label, options|
98
- Benchmark.ams(label, time: time, disable_gc: options[:disable_gc]) do
99
- send(options[:send])
100
- end
101
- end
102
- __END__
103
- cached json 121321.3745504354/ips; 16 objects
104
- json 1177.243210850789/ips; 1984 objects
105
- cached ams 251.90341731442047/ips; 5879 objects
106
- cached virtual ams 89169.87612473704/ips; 16 objects
107
- ams 598.9890084759535/ips; 2348 objects
108
- Benchmark results:
109
- {
110
- "commit_hash": "aa0be94",
111
- "version": "0.10.0.rc5",
112
- "rails_version": "4.2.5.1",
113
- "benchmark_run[environment]": "2.2.3p173",
114
- "runs": [
115
- {
116
- "benchmark_type[category]": "cached json",
117
- "benchmark_run[result][iterations_per_second]": 121321.375,
118
- "benchmark_run[result][total_allocated_objects_per_iteration]": 16
119
- },
120
- {
121
- "benchmark_type[category]": "json",
122
- "benchmark_run[result][iterations_per_second]": 1177.243,
123
- "benchmark_run[result][total_allocated_objects_per_iteration]": 1984
124
- },
125
- {
126
- "benchmark_type[category]": "cached ams",
127
- "benchmark_run[result][iterations_per_second]": 251.903,
128
- "benchmark_run[result][total_allocated_objects_per_iteration]": 5879
129
- },
130
- {
131
- "benchmark_type[category]": "cached virtual ams",
132
- "benchmark_run[result][iterations_per_second]": 89169.876,
133
- "benchmark_run[result][total_allocated_objects_per_iteration]": 16
134
- },
135
- {
136
- "benchmark_type[category]": "ams",
137
- "benchmark_run[result][iterations_per_second]": 598.989,
138
- "benchmark_run[result][total_allocated_objects_per_iteration]": 2348
139
- }
140
- ]
141
- }