active_model_serializers 0.9.9 → 0.9.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/CHANGELOG.md +33 -1
 - data/lib/action_controller/serialization.rb +10 -1
 - data/lib/action_controller/serialization_test_case.rb +3 -0
 - data/lib/active_model/array_serializer.rb +2 -0
 - data/lib/active_model/default_serializer.rb +2 -0
 - data/lib/active_model/serializable/utils.rb +2 -0
 - data/lib/active_model/serializable.rb +3 -1
 - data/lib/active_model/serializer/association/has_many.rb +2 -0
 - data/lib/active_model/serializer/association/has_one.rb +2 -0
 - data/lib/active_model/serializer/association.rb +3 -3
 - data/lib/active_model/serializer/config.rb +2 -0
 - data/lib/active_model/serializer/generators/resource_override.rb +2 -0
 - data/lib/active_model/serializer/generators/serializer/scaffold_controller_generator.rb +2 -0
 - data/lib/active_model/serializer/generators/serializer/serializer_generator.rb +2 -0
 - data/lib/active_model/serializer/railtie.rb +2 -0
 - data/lib/active_model/serializer/version.rb +3 -1
 - data/lib/active_model/serializer.rb +35 -27
 - data/lib/active_model/serializer_support.rb +2 -0
 - data/lib/active_model_serializers.rb +14 -2
 - data/test/fixtures/poro.rb +4 -3
 - data/test/integration/action_controller/serialization_test.rb +13 -13
 - data/test/integration/generators/scaffold_controller_generator_test.rb +20 -20
 - data/test/test_app.rb +4 -0
 - data/test/test_helper.rb +7 -2
 - data/test/tmp/app/serializers/account_serializer.rb +1 -2
 - data/test/unit/active_model/array_serializer/serialization_test.rb +3 -3
 - data/test/unit/active_model/default_serializer_test.rb +1 -1
 - data/test/unit/active_model/serializer/url_helpers_test.rb +1 -0
 - metadata +43 -54
 - data/lib/active_model_serializers/model/caching.rb +0 -26
 - data/test/tmp/app/assets/javascripts/accounts.js +0 -2
 - data/test/tmp/app/assets/stylesheets/accounts.css +0 -4
 - data/test/tmp/app/controllers/accounts_controller.rb +0 -3
 - data/test/tmp/app/helpers/accounts_helper.rb +0 -3
 - data/test/tmp/config/routes.rb +0 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: a8649ea9bfdefabb0215cc90a6a47a87d902573ecd0e2c73b6142c9cefe17825
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 420e8afdc1ba7cbaaab42d7f8f36c3e10b702587cc7484e270428ded2eeccbdd
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 237f372c6dd5e73cb7d5f944d90918a23e6acf0f7aa137f0e2972a275445a549a6cf4ffd9e410386c611e89e1dc0137d5451c6d61702d6c6381e43a41e3434ac
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 5d009500e9e616e7d1a7f83adaf7874022f1f039594983e923ef82d4b8f6b8f6268259404b097545a27512b149ec22c8e113a8c0bb51effbef3c0fdd728d7973
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    | 
         @@ -1,6 +1,38 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ## 0.09.x
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            ### [0-9-stable](https://github.com/rails-api/active_model_serializers/compare/v0.9. 
     | 
| 
      
 3 
     | 
    
         
            +
            ### [0-9-stable](https://github.com/rails-api/active_model_serializers/compare/v0.9.13...0-9-stable)
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            ### [v0.9.13 (2024-09-17)](https://github.com/rails-api/active_model_serializers/compare/v0.9.12...v0.9.13)
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            - Perf
         
     | 
| 
      
 8 
     | 
    
         
            +
              - [#2471](https://github.com/rails-api/active_model_serializers/pull/2471) Generate better attribute accessors, that also don't trigger warnings when redefined. (@byroot)
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            ### [v0.9.12 (2024-04-11)](https://github.com/rails-api/active_model_serializers/compare/v0.9.11...v0.9.12)
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            - Fix
         
     | 
| 
      
 13 
     | 
    
         
            +
              - [#2468](https://github.com/rails-api/active_model_serializers/pull/2468) Fix bug introduced in v0.9.9. Revert "Allow serializer_for to accept String instead of just class objects". (@byroot)
         
     | 
| 
      
 14 
     | 
    
         
            +
            - Perf
         
     | 
| 
      
 15 
     | 
    
         
            +
              - [#2466](https://github.com/rails-api/active_model_serializers/pull/2466) Prefer `defined?` to `Object.constants.include?` (@byroot)
         
     | 
| 
      
 16 
     | 
    
         
            +
              - [#2467](https://github.com/rails-api/active_model_serializers/pull/2467) Lazily compute possible serializer class names (@byroot)
         
     | 
| 
      
 17 
     | 
    
         
            +
            - Chore
         
     | 
| 
      
 18 
     | 
    
         
            +
              - [#2469](https://github.com/rails-api/active_model_serializers/pull/2469) Fix various warnings in the test suite (@byroot)
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
            ### [v0.9.11 (2024-04-09)](https://github.com/rails-api/active_model_serializers/compare/v0.9.10...v0.9.11)
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
            v0.9.10 was built with an extra file included and so was yanked.
         
     | 
| 
      
 23 
     | 
    
         
            +
            v0.9.11 is the same as v0.9.10 but doesn't have the extra file.
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            ### [v0.9.10 (2024-04-09)](https://github.com/rails-api/active_model_serializers/compare/v0.9.9...v0.9.10)
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
            - Fix
         
     | 
| 
      
 28 
     | 
    
         
            +
              - [#2464](https://github.com/rails-api/active_model_serializers/pull/2464) Do not load ActionController::TestCase in production (@byroot)
         
     | 
| 
      
 29 
     | 
    
         
            +
            - Perf
         
     | 
| 
      
 30 
     | 
    
         
            +
              - [#2465](https://github.com/rails-api/active_model_serializers/pull/2465) Make compatible with enable-frozen-string-literal (@byroot)
         
     | 
| 
      
 31 
     | 
    
         
            +
              - [#2463](https://github.com/rails-api/active_model_serializers/pull/2463) Shape Friendly ActionController:Serialization (@byroot)
         
     | 
| 
      
 32 
     | 
    
         
            +
            - Chore
         
     | 
| 
      
 33 
     | 
    
         
            +
              - [#2462](https://github.com/rails-api/active_model_serializers/pull/2462]) Rails 7.1, Ruby 3.3 compat (@byroot)
         
     | 
| 
      
 34 
     | 
    
         
            +
            - Test
         
     | 
| 
      
 35 
     | 
    
         
            +
              - [#2447](https://github.com/rails-api/active_model_serializers/pull/2447) Configure CI on GitHub actoins (@Physium)
         
     | 
| 
       4 
36 
     | 
    
         | 
| 
       5 
37 
     | 
    
         
             
            ### [v0.9.9 (2023-05-18)](https://github.com/rails-api/active_model_serializers/compare/v0.9.8...v0.9.8)
         
     | 
| 
       6 
38 
     | 
    
         | 
| 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require 'active_support/core_ext/class/attribute'
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
       3 
5 
     | 
    
         
             
            module ActionController
         
     | 
| 
         @@ -45,6 +47,12 @@ module ActionController 
     | 
|
| 
       45 
47 
     | 
    
         
             
                  end
         
     | 
| 
       46 
48 
     | 
    
         
             
                end
         
     | 
| 
       47 
49 
     | 
    
         | 
| 
      
 50 
     | 
    
         
            +
                def initialize(*)
         
     | 
| 
      
 51 
     | 
    
         
            +
                  super
         
     | 
| 
      
 52 
     | 
    
         
            +
                  @namespace_for_serializer = nil
         
     | 
| 
      
 53 
     | 
    
         
            +
                end
         
     | 
| 
      
 54 
     | 
    
         
            +
                ruby2_keywords :initialize if respond_to?(:ruby2_keywords, true)
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
       48 
56 
     | 
    
         
             
                [:_render_option_json, :_render_with_renderer_json].each do |renderer_method|
         
     | 
| 
       49 
57 
     | 
    
         
             
                  define_method renderer_method do |resource, options|
         
     | 
| 
       50 
58 
     | 
    
         
             
                    serializer = build_json_serializer(resource, options)
         
     | 
| 
         @@ -60,7 +68,8 @@ module ActionController 
     | 
|
| 
       60 
68 
     | 
    
         
             
                private
         
     | 
| 
       61 
69 
     | 
    
         | 
| 
       62 
70 
     | 
    
         
             
                def namespace_for_serializer
         
     | 
| 
       63 
     | 
    
         
            -
                  @namespace_for_serializer ||= namespace_for_class(self.class) 
     | 
| 
      
 71 
     | 
    
         
            +
                  @namespace_for_serializer ||= namespace_for_class(self.class)
         
     | 
| 
      
 72 
     | 
    
         
            +
                  @namespace_for_serializer unless @namespace_for_serializer == Object
         
     | 
| 
       64 
73 
     | 
    
         
             
                end
         
     | 
| 
       65 
74 
     | 
    
         | 
| 
       66 
75 
     | 
    
         
             
                def namespace_for_class(klass)
         
     | 
| 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            module ActionController
         
     | 
| 
       2 
4 
     | 
    
         
             
              module SerializationAssertions
         
     | 
| 
       3 
5 
     | 
    
         
             
                extend ActiveSupport::Concern
         
     | 
| 
         @@ -24,6 +26,7 @@ module ActionController 
     | 
|
| 
       24 
26 
     | 
    
         
             
                  @serializers = Hash.new(0)
         
     | 
| 
       25 
27 
     | 
    
         
             
                  super
         
     | 
| 
       26 
28 
     | 
    
         
             
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
                ruby2_keywords :process if respond_to?(:ruby2_keywords, true)
         
     | 
| 
       27 
30 
     | 
    
         | 
| 
       28 
31 
     | 
    
         
             
                # Asserts that the request was rendered with the appropriate serializers.
         
     | 
| 
       29 
32 
     | 
    
         
             
                #
         
     | 
| 
         @@ -1,8 +1,10 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require 'active_model/serializable/utils'
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
       3 
5 
     | 
    
         
             
            module ActiveModel
         
     | 
| 
       4 
6 
     | 
    
         
             
              module Serializable
         
     | 
| 
       5 
     | 
    
         
            -
                INSTRUMENTATION_KEY = '!serialize.active_model_serializers' 
     | 
| 
      
 7 
     | 
    
         
            +
                INSTRUMENTATION_KEY = '!serialize.active_model_serializers'
         
     | 
| 
       6 
8 
     | 
    
         | 
| 
       7 
9 
     | 
    
         
             
                def self.included(base)
         
     | 
| 
       8 
10 
     | 
    
         
             
                  base.extend Utils
         
     | 
| 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require 'active_model/default_serializer'
         
     | 
| 
       2 
4 
     | 
    
         
             
            require 'active_model/serializer/association/has_one'
         
     | 
| 
       3 
5 
     | 
    
         
             
            require 'active_model/serializer/association/has_many'
         
     | 
| 
         @@ -7,9 +9,7 @@ module ActiveModel 
     | 
|
| 
       7 
9 
     | 
    
         
             
                class Association
         
     | 
| 
       8 
10 
     | 
    
         
             
                  def initialize(name, options={})
         
     | 
| 
       9 
11 
     | 
    
         
             
                    if options.has_key?(:include)
         
     | 
| 
       10 
     | 
    
         
            -
                      ActiveSupport::Deprecation.warn  
     | 
| 
       11 
     | 
    
         
            -
            ** Notice: include was renamed to embed_in_root. **
         
     | 
| 
       12 
     | 
    
         
            -
                      WARN
         
     | 
| 
      
 12 
     | 
    
         
            +
                      ActiveSupport::Deprecation.warn("** Notice: include was renamed to embed_in_root. **")
         
     | 
| 
       13 
13 
     | 
    
         
             
                    end
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
15 
     | 
    
         
             
                    @name          = name.to_s
         
     | 
| 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require 'active_model/array_serializer'
         
     | 
| 
       2 
4 
     | 
    
         
             
            require 'active_model/serializable'
         
     | 
| 
       3 
5 
     | 
    
         
             
            require 'active_model/serializer/association'
         
     | 
| 
         @@ -60,20 +62,19 @@ end 
     | 
|
| 
       60 
62 
     | 
    
         
             
                    if resource.respond_to?(:serializer_class)
         
     | 
| 
       61 
63 
     | 
    
         
             
                      resource.serializer_class
         
     | 
| 
       62 
64 
     | 
    
         
             
                    elsif resource.respond_to?(:to_ary)
         
     | 
| 
       63 
     | 
    
         
            -
                      if  
     | 
| 
      
 65 
     | 
    
         
            +
                      if defined?(::ArraySerializer)
         
     | 
| 
       64 
66 
     | 
    
         
             
                        ::ArraySerializer
         
     | 
| 
       65 
67 
     | 
    
         
             
                      else
         
     | 
| 
       66 
68 
     | 
    
         
             
                        ArraySerializer
         
     | 
| 
       67 
69 
     | 
    
         
             
                      end
         
     | 
| 
       68 
70 
     | 
    
         
             
                    else
         
     | 
| 
       69 
     | 
    
         
            -
                       
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
                      result.find { |serializer| !serializer.nil? }
         
     | 
| 
      
 71 
     | 
    
         
            +
                      each_possible_serializer(resource, options) do |klass_name|
         
     | 
| 
      
 72 
     | 
    
         
            +
                        serializer = Serializer.serializers_cache.fetch_or_store(klass_name) do
         
     | 
| 
      
 73 
     | 
    
         
            +
                          _const_get(klass_name)
         
     | 
| 
      
 74 
     | 
    
         
            +
                        end
         
     | 
| 
      
 75 
     | 
    
         
            +
                        return serializer unless serializer.nil?
         
     | 
| 
      
 76 
     | 
    
         
            +
                      end
         
     | 
| 
      
 77 
     | 
    
         
            +
                      nil
         
     | 
| 
       77 
78 
     | 
    
         
             
                    end
         
     | 
| 
       78 
79 
     | 
    
         
             
                  end
         
     | 
| 
       79 
80 
     | 
    
         | 
| 
         @@ -89,15 +90,27 @@ end 
     | 
|
| 
       89 
90 
     | 
    
         
             
                  end
         
     | 
| 
       90 
91 
     | 
    
         | 
| 
       91 
92 
     | 
    
         
             
                  def attributes(*attrs)
         
     | 
| 
      
 93 
     | 
    
         
            +
                    # Use `class_eval` rather than `define_method` for faster access
         
     | 
| 
      
 94 
     | 
    
         
            +
                    # and avoid retaining objects in the closure.
         
     | 
| 
      
 95 
     | 
    
         
            +
                    # Batch all methods in a single `class_eval` for efficiceny,
         
     | 
| 
      
 96 
     | 
    
         
            +
                    # and define all methods on the same line so the eventual backtrace
         
     | 
| 
      
 97 
     | 
    
         
            +
                    # properly maps to the `attributes` call.
         
     | 
| 
      
 98 
     | 
    
         
            +
                    source = ["# frozen_string_literal: true\n"]
         
     | 
| 
       92 
99 
     | 
    
         
             
                    attrs.each do |attr|
         
     | 
| 
       93 
100 
     | 
    
         
             
                      striped_attr = strip_attribute attr
         
     | 
| 
       94 
101 
     | 
    
         | 
| 
       95 
102 
     | 
    
         
             
                      @_attributes << striped_attr
         
     | 
| 
       96 
103 
     | 
    
         | 
| 
       97 
     | 
    
         
            -
                       
     | 
| 
       98 
     | 
    
         
            -
                         
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
      
 104 
     | 
    
         
            +
                      unless method_defined?(attr)
         
     | 
| 
      
 105 
     | 
    
         
            +
                        source <<
         
     | 
| 
      
 106 
     | 
    
         
            +
                        "def #{striped_attr}" <<
         
     | 
| 
      
 107 
     | 
    
         
            +
                          "object.read_attribute_for_serialization(#{attr.inspect})" <<
         
     | 
| 
      
 108 
     | 
    
         
            +
                        "end" <<
         
     | 
| 
      
 109 
     | 
    
         
            +
                        "alias_method :#{striped_attr}, :#{striped_attr}" # suppress method redefinition warning
         
     | 
| 
      
 110 
     | 
    
         
            +
                      end
         
     | 
| 
       100 
111 
     | 
    
         
             
                    end
         
     | 
| 
      
 112 
     | 
    
         
            +
                    caller = caller_locations(1, 1).first
         
     | 
| 
      
 113 
     | 
    
         
            +
                    class_eval(source.join(";"), caller.path, caller.lineno - 1)
         
     | 
| 
       101 
114 
     | 
    
         
             
                  end
         
     | 
| 
       102 
115 
     | 
    
         | 
| 
       103 
116 
     | 
    
         
             
                  def has_one(*attrs)
         
     | 
| 
         @@ -122,23 +135,17 @@ end 
     | 
|
| 
       122 
135 
     | 
    
         
             
                    attr
         
     | 
| 
       123 
136 
     | 
    
         
             
                  end
         
     | 
| 
       124 
137 
     | 
    
         | 
| 
       125 
     | 
    
         
            -
                  def  
     | 
| 
       126 
     | 
    
         
            -
                     
     | 
| 
       127 
     | 
    
         
            -
                     
     | 
| 
       128 
     | 
    
         
            -
                     
     | 
| 
       129 
     | 
    
         
            -
                    list << build_serializer_class(resource.class.name.demodulize, {})
         
     | 
| 
      
 138 
     | 
    
         
            +
                  def each_possible_serializer(resource, options)
         
     | 
| 
      
 139 
     | 
    
         
            +
                    yield build_serializer_class(resource, options)
         
     | 
| 
      
 140 
     | 
    
         
            +
                    yield build_serializer_class(resource, {})
         
     | 
| 
      
 141 
     | 
    
         
            +
                    yield build_serializer_class(resource.class.name.demodulize, {})
         
     | 
| 
       130 
142 
     | 
    
         
             
                  end
         
     | 
| 
       131 
143 
     | 
    
         | 
| 
       132 
144 
     | 
    
         
             
                  def build_serializer_class(resource, options)
         
     | 
| 
       133 
     | 
    
         
            -
                    "" 
     | 
| 
       134 
     | 
    
         
            -
             
     | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
       136 
     | 
    
         
            -
             
     | 
| 
       137 
     | 
    
         
            -
                        klass_name << "#{resource}Serializer"
         
     | 
| 
       138 
     | 
    
         
            -
                      else
         
     | 
| 
       139 
     | 
    
         
            -
                        klass_name << "#{resource.class.name}Serializer"
         
     | 
| 
       140 
     | 
    
         
            -
                      end
         
     | 
| 
       141 
     | 
    
         
            -
                    end
         
     | 
| 
      
 145 
     | 
    
         
            +
                    klass_name = +""
         
     | 
| 
      
 146 
     | 
    
         
            +
                    klass_name << "#{options[:namespace]}::" if options[:namespace]
         
     | 
| 
      
 147 
     | 
    
         
            +
                    klass_name << options[:prefix].to_s.classify if options[:prefix]
         
     | 
| 
      
 148 
     | 
    
         
            +
                    klass_name << "#{resource.class.name}Serializer"
         
     | 
| 
       142 
149 
     | 
    
         
             
                  end
         
     | 
| 
       143 
150 
     | 
    
         | 
| 
       144 
151 
     | 
    
         
             
                  def associate(klass, *attrs)
         
     | 
| 
         @@ -168,7 +175,8 @@ end 
     | 
|
| 
       168 
175 
     | 
    
         
             
                  @context       = options[:context]
         
     | 
| 
       169 
176 
     | 
    
         
             
                  @namespace     = options[:namespace]
         
     | 
| 
       170 
177 
     | 
    
         
             
                end
         
     | 
| 
       171 
     | 
    
         
            -
                attr_accessor :object, :scope, :root, :meta_key, :meta, : 
     | 
| 
      
 178 
     | 
    
         
            +
                attr_accessor :object, :scope, :root, :meta_key, :meta, :context, :polymorphic
         
     | 
| 
      
 179 
     | 
    
         
            +
                attr_writer :key_format
         
     | 
| 
       172 
180 
     | 
    
         | 
| 
       173 
181 
     | 
    
         
             
                def json_key
         
     | 
| 
       174 
182 
     | 
    
         
             
                  key = if root == true || root.nil?
         
     | 
| 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require 'active_model'
         
     | 
| 
       2 
4 
     | 
    
         
             
            require 'active_model/serializer'
         
     | 
| 
       3 
5 
     | 
    
         
             
            require 'active_model/serializer_support'
         
     | 
| 
         @@ -7,12 +9,22 @@ require 'active_model/serializer/railtie' if defined?(Rails) 
     | 
|
| 
       7 
9 
     | 
    
         
             
            begin
         
     | 
| 
       8 
10 
     | 
    
         
             
              require 'action_controller'
         
     | 
| 
       9 
11 
     | 
    
         
             
              require 'action_controller/serialization'
         
     | 
| 
       10 
     | 
    
         
            -
              require 'action_controller/serialization_test_case'
         
     | 
| 
       11 
12 
     | 
    
         | 
| 
       12 
13 
     | 
    
         
             
              ActiveSupport.on_load(:action_controller) do
         
     | 
| 
       13 
14 
     | 
    
         
             
                if ::ActionController::Serialization.enabled
         
     | 
| 
       14 
15 
     | 
    
         
             
                  ActionController::Base.send(:include, ::ActionController::Serialization)
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                  # action_controller_test_case load hook was added in Rails 5.1
         
     | 
| 
      
 18 
     | 
    
         
            +
                  # https://github.com/rails/rails/commit/0510208dd1ff23baa619884c0abcae4d141fae53
         
     | 
| 
      
 19 
     | 
    
         
            +
                  if ActiveSupport::VERSION::STRING < '5.1'
         
     | 
| 
      
 20 
     | 
    
         
            +
                    require 'action_controller/serialization_test_case'
         
     | 
| 
      
 21 
     | 
    
         
            +
                    ActionController::TestCase.send(:include, ::ActionController::SerializationAssertions)
         
     | 
| 
      
 22 
     | 
    
         
            +
                  else
         
     | 
| 
      
 23 
     | 
    
         
            +
                    ActiveSupport.on_load(:action_controller_test_case) do
         
     | 
| 
      
 24 
     | 
    
         
            +
                      require 'action_controller/serialization_test_case'
         
     | 
| 
      
 25 
     | 
    
         
            +
                      ActionController::TestCase.send(:include, ::ActionController::SerializationAssertions)
         
     | 
| 
      
 26 
     | 
    
         
            +
                    end
         
     | 
| 
      
 27 
     | 
    
         
            +
                  end
         
     | 
| 
       16 
28 
     | 
    
         
             
                end
         
     | 
| 
       17 
29 
     | 
    
         
             
              end
         
     | 
| 
       18 
30 
     | 
    
         
             
            rescue LoadError
         
     | 
    
        data/test/fixtures/poro.rb
    CHANGED
    
    | 
         @@ -144,14 +144,14 @@ end 
     | 
|
| 
       144 
144 
     | 
    
         | 
| 
       145 
145 
     | 
    
         
             
            class SelfReferencingUserParentSerializer < ActiveModel::Serializer
         
     | 
| 
       146 
146 
     | 
    
         
             
              attributes :name
         
     | 
| 
       147 
     | 
    
         
            -
              has_one :type, serializer: TypeSerializer, embed: :ids,  
     | 
| 
      
 147 
     | 
    
         
            +
              has_one :type, serializer: TypeSerializer, embed: :ids, embed_in_root: true
         
     | 
| 
       148 
148 
     | 
    
         
             
            end
         
     | 
| 
       149 
149 
     | 
    
         | 
| 
       150 
150 
     | 
    
         
             
            class SelfReferencingUserSerializer < ActiveModel::Serializer
         
     | 
| 
       151 
151 
     | 
    
         
             
              attributes :name
         
     | 
| 
       152 
152 
     | 
    
         | 
| 
       153 
     | 
    
         
            -
              has_one :type, serializer: TypeSerializer, embed: :ids,  
     | 
| 
       154 
     | 
    
         
            -
              has_one :parent, serializer: SelfReferencingUserSerializer, embed: :ids,  
     | 
| 
      
 153 
     | 
    
         
            +
              has_one :type, serializer: TypeSerializer, embed: :ids, embed_in_root: true
         
     | 
| 
      
 154 
     | 
    
         
            +
              has_one :parent, serializer: SelfReferencingUserSerializer, embed: :ids, embed_in_root: true
         
     | 
| 
       155 
155 
     | 
    
         
             
            end
         
     | 
| 
       156 
156 
     | 
    
         | 
| 
       157 
157 
     | 
    
         
             
            class UserInfoSerializer < ActiveModel::Serializer
         
     | 
| 
         @@ -176,6 +176,7 @@ end 
     | 
|
| 
       176 
176 
     | 
    
         
             
            class PostSerializer < ActiveModel::Serializer
         
     | 
| 
       177 
177 
     | 
    
         
             
              attributes :title, :body
         
     | 
| 
       178 
178 
     | 
    
         | 
| 
      
 179 
     | 
    
         
            +
              alias_method :title, :title # silence method redefinition warning
         
     | 
| 
       179 
180 
     | 
    
         
             
              def title
         
     | 
| 
       180 
181 
     | 
    
         
             
                keyword = serialization_options[:highlight_keyword]
         
     | 
| 
       181 
182 
     | 
    
         
             
                title = object.read_attribute_for_serialization(:title)
         
     | 
| 
         @@ -13,7 +13,7 @@ module ActionController 
     | 
|
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
                  def test_render_using_implicit_serializer
         
     | 
| 
       15 
15 
     | 
    
         
             
                    get :render_using_implicit_serializer
         
     | 
| 
       16 
     | 
    
         
            -
                     
     | 
| 
      
 16 
     | 
    
         
            +
                    assert_includes @response.content_type, 'application/json'
         
     | 
| 
       17 
17 
     | 
    
         
             
                    assert_equal '{"profile":{"name":"Name 1","description":"Description 1"}}', @response.body
         
     | 
| 
       18 
18 
     | 
    
         
             
                  end
         
     | 
| 
       19 
19 
     | 
    
         
             
                end
         
     | 
| 
         @@ -35,7 +35,7 @@ module ActionController 
     | 
|
| 
       35 
35 
     | 
    
         | 
| 
       36 
36 
     | 
    
         
             
                  def test_render_using_implicit_serializer_and_scope
         
     | 
| 
       37 
37 
     | 
    
         
             
                    get :render_using_implicit_serializer_and_scope
         
     | 
| 
       38 
     | 
    
         
            -
                     
     | 
| 
      
 38 
     | 
    
         
            +
                    assert_includes @response.content_type, 'application/json'
         
     | 
| 
       39 
39 
     | 
    
         
             
                    assert_equal '{"profile":{"name":"Name 1","description":"Description 1 - current_user"}}', @response.body
         
     | 
| 
       40 
40 
     | 
    
         
             
                  end
         
     | 
| 
       41 
41 
     | 
    
         
             
                end
         
     | 
| 
         @@ -65,7 +65,7 @@ module ActionController 
     | 
|
| 
       65 
65 
     | 
    
         | 
| 
       66 
66 
     | 
    
         
             
                  def test_render_using_scope_set_in_default_serializer_options
         
     | 
| 
       67 
67 
     | 
    
         
             
                    get :render_using_scope_set_in_default_serializer_options
         
     | 
| 
       68 
     | 
    
         
            -
                     
     | 
| 
      
 68 
     | 
    
         
            +
                    assert_includes @response.content_type, 'application/json'
         
     | 
| 
       69 
69 
     | 
    
         
             
                    assert_equal '{"profile":{"name":"Name 1","description":"Description 1 - current_admin"}}', @response.body
         
     | 
| 
       70 
70 
     | 
    
         
             
                  end
         
     | 
| 
       71 
71 
     | 
    
         
             
                end
         
     | 
| 
         @@ -91,7 +91,7 @@ module ActionController 
     | 
|
| 
       91 
91 
     | 
    
         | 
| 
       92 
92 
     | 
    
         
             
                  def test_render_using_implicit_serializer_and_explicit_scope
         
     | 
| 
       93 
93 
     | 
    
         
             
                    get :render_using_implicit_serializer_and_explicit_scope
         
     | 
| 
       94 
     | 
    
         
            -
                     
     | 
| 
      
 94 
     | 
    
         
            +
                    assert_includes @response.content_type, 'application/json'
         
     | 
| 
       95 
95 
     | 
    
         
             
                    assert_equal '{"profile":{"name":"Name 1","description":"Description 1 - current_admin"}}', @response.body
         
     | 
| 
       96 
96 
     | 
    
         
             
                  end
         
     | 
| 
       97 
97 
     | 
    
         
             
                end
         
     | 
| 
         @@ -117,7 +117,7 @@ module ActionController 
     | 
|
| 
       117 
117 
     | 
    
         | 
| 
       118 
118 
     | 
    
         
             
                  def test_render_overriding_serialization_scope
         
     | 
| 
       119 
119 
     | 
    
         
             
                    get :render_overriding_serialization_scope
         
     | 
| 
       120 
     | 
    
         
            -
                     
     | 
| 
      
 120 
     | 
    
         
            +
                    assert_includes @response.content_type, 'application/json'
         
     | 
| 
       121 
121 
     | 
    
         
             
                    assert_equal '{"profile":{"name":"Name 1","description":"Description 1 - current_admin"}}', @response.body
         
     | 
| 
       122 
122 
     | 
    
         
             
                  end
         
     | 
| 
       123 
123 
     | 
    
         
             
                end
         
     | 
| 
         @@ -141,7 +141,7 @@ module ActionController 
     | 
|
| 
       141 
141 
     | 
    
         | 
| 
       142 
142 
     | 
    
         
             
                  def test_render_calling_serialization_scope
         
     | 
| 
       143 
143 
     | 
    
         
             
                    get :render_calling_serialization_scope
         
     | 
| 
       144 
     | 
    
         
            -
                     
     | 
| 
      
 144 
     | 
    
         
            +
                    assert_includes @response.content_type, 'application/json'
         
     | 
| 
       145 
145 
     | 
    
         
             
                    assert_equal '{"profile":{"name":"Name 1","description":"Description 1 - current_user"}}', @response.body
         
     | 
| 
       146 
146 
     | 
    
         
             
                  end
         
     | 
| 
       147 
147 
     | 
    
         
             
                end
         
     | 
| 
         @@ -157,7 +157,7 @@ module ActionController 
     | 
|
| 
       157 
157 
     | 
    
         | 
| 
       158 
158 
     | 
    
         
             
                  def test_render_using_json_dump
         
     | 
| 
       159 
159 
     | 
    
         
             
                    get :render_using_json_dump
         
     | 
| 
       160 
     | 
    
         
            -
                     
     | 
| 
      
 160 
     | 
    
         
            +
                    assert_includes @response.content_type, 'application/json'
         
     | 
| 
       161 
161 
     | 
    
         
             
                    assert_equal '{"hello":"world"}', @response.body
         
     | 
| 
       162 
162 
     | 
    
         
             
                  end
         
     | 
| 
       163 
163 
     | 
    
         
             
                end
         
     | 
| 
         @@ -173,7 +173,7 @@ module ActionController 
     | 
|
| 
       173 
173 
     | 
    
         | 
| 
       174 
174 
     | 
    
         
             
                  def test_render_using_rails_behavior
         
     | 
| 
       175 
175 
     | 
    
         
             
                    get :render_using_rails_behavior
         
     | 
| 
       176 
     | 
    
         
            -
                     
     | 
| 
      
 176 
     | 
    
         
            +
                    assert_includes @response.content_type, 'application/json'
         
     | 
| 
       177 
177 
     | 
    
         
             
                    assert_equal '[{"attributes":{"name":"Name 1","description":"Description 1","comments":"Comments 1"}}]', @response.body
         
     | 
| 
       178 
178 
     | 
    
         
             
                  end
         
     | 
| 
       179 
179 
     | 
    
         
             
                end
         
     | 
| 
         @@ -189,7 +189,7 @@ module ActionController 
     | 
|
| 
       189 
189 
     | 
    
         | 
| 
       190 
190 
     | 
    
         
             
                  def test_render_array
         
     | 
| 
       191 
191 
     | 
    
         
             
                    get :render_array
         
     | 
| 
       192 
     | 
    
         
            -
                     
     | 
| 
      
 192 
     | 
    
         
            +
                    assert_includes @response.content_type, 'application/json'
         
     | 
| 
       193 
193 
     | 
    
         
             
                    assert_equal '{"my":[{"name":"Name 1","description":"Description 1"}]}', @response.body
         
     | 
| 
       194 
194 
     | 
    
         
             
                  end
         
     | 
| 
       195 
195 
     | 
    
         
             
                end
         
     | 
| 
         @@ -205,7 +205,7 @@ module ActionController 
     | 
|
| 
       205 
205 
     | 
    
         | 
| 
       206 
206 
     | 
    
         
             
                  def test_render_array
         
     | 
| 
       207 
207 
     | 
    
         
             
                    get :render_array
         
     | 
| 
       208 
     | 
    
         
            -
                     
     | 
| 
      
 208 
     | 
    
         
            +
                    assert_includes @response.content_type, 'application/json'
         
     | 
| 
       209 
209 
     | 
    
         
             
                    assert_equal '{"webLog":[{"name":"Name 1","displayName":"Display Name 1"},{"name":"Name 2","displayName":"Display Name 2"}]}', @response.body
         
     | 
| 
       210 
210 
     | 
    
         
             
                  end
         
     | 
| 
       211 
211 
     | 
    
         
             
                end
         
     | 
| 
         @@ -223,7 +223,7 @@ module ActionController 
     | 
|
| 
       223 
223 
     | 
    
         | 
| 
       224 
224 
     | 
    
         
             
                  def test_render_without_root
         
     | 
| 
       225 
225 
     | 
    
         
             
                    get :render_without_root
         
     | 
| 
       226 
     | 
    
         
            -
                     
     | 
| 
      
 226 
     | 
    
         
            +
                    assert_includes @response.content_type, 'application/json'
         
     | 
| 
       227 
227 
     | 
    
         
             
                    assert_equal '{"name":"Name 1","displayName":"Display Name 1"}', @response.body
         
     | 
| 
       228 
228 
     | 
    
         
             
                  end
         
     | 
| 
       229 
229 
     | 
    
         
             
                end
         
     | 
| 
         @@ -242,7 +242,7 @@ module ActionController 
     | 
|
| 
       242 
242 
     | 
    
         | 
| 
       243 
243 
     | 
    
         
             
                  def test_render_array_without_root
         
     | 
| 
       244 
244 
     | 
    
         
             
                    get :render_array_without_root
         
     | 
| 
       245 
     | 
    
         
            -
                     
     | 
| 
      
 245 
     | 
    
         
            +
                    assert_includes @response.content_type, 'application/json'
         
     | 
| 
       246 
246 
     | 
    
         
             
                    assert_equal '[{"name":"Name 1","displayName":"Display Name 1"},{"name":"Name 2","displayName":"Display Name 2"}]', @response.body
         
     | 
| 
       247 
247 
     | 
    
         
             
                  end
         
     | 
| 
       248 
248 
     | 
    
         
             
                end
         
     | 
| 
         @@ -278,7 +278,7 @@ module ActionController 
     | 
|
| 
       278 
278 
     | 
    
         
             
                    @association.embed_in_root = true
         
     | 
| 
       279 
279 
     | 
    
         | 
| 
       280 
280 
     | 
    
         
             
                    get :render_array_embeding_in_root
         
     | 
| 
       281 
     | 
    
         
            -
                     
     | 
| 
      
 281 
     | 
    
         
            +
                    assert_includes @response.content_type, 'application/json'
         
     | 
| 
       282 
282 
     | 
    
         | 
| 
       283 
283 
     | 
    
         
             
                    assert_equal("{\"my\":[{\"name\":\"Name 1\",\"email\":\"mail@server.com\",\"profile_id\":#{@controller.user.profile.object_id}}],\"profiles\":[{\"name\":\"N1\",\"description\":\"D1\"}]}", @response.body)
         
     | 
| 
       284 
284 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -17,44 +17,44 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase 
     | 
|
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
                assert_file 'app/controllers/accounts_controller.rb' do |content|
         
     | 
| 
       19 
19 
     | 
    
         
             
                  assert_instance_method :index, content do |m|
         
     | 
| 
       20 
     | 
    
         
            -
                    assert_match 
     | 
| 
       21 
     | 
    
         
            -
                    assert_match 
     | 
| 
       22 
     | 
    
         
            -
                    assert_match 
     | 
| 
      
 20 
     | 
    
         
            +
                    assert_match(/@accounts = Account\.all/, m)
         
     | 
| 
      
 21 
     | 
    
         
            +
                    assert_match(/format.html/, m)
         
     | 
| 
      
 22 
     | 
    
         
            +
                    assert_match(/format.json \{ render json: @accounts \}/, m)
         
     | 
| 
       23 
23 
     | 
    
         
             
                  end
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
25 
     | 
    
         
             
                  assert_instance_method :show, content do |m|
         
     | 
| 
       26 
     | 
    
         
            -
                    assert_match 
     | 
| 
       27 
     | 
    
         
            -
                    assert_match 
     | 
| 
      
 26 
     | 
    
         
            +
                    assert_match(/format.html/, m)
         
     | 
| 
      
 27 
     | 
    
         
            +
                    assert_match(/format.json \{ render json: @account \}/, m)
         
     | 
| 
       28 
28 
     | 
    
         
             
                  end
         
     | 
| 
       29 
29 
     | 
    
         | 
| 
       30 
30 
     | 
    
         
             
                  assert_instance_method :new, content do |m|
         
     | 
| 
       31 
     | 
    
         
            -
                    assert_match 
     | 
| 
      
 31 
     | 
    
         
            +
                    assert_match(/@account = Account\.new/, m)
         
     | 
| 
       32 
32 
     | 
    
         
             
                  end
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
       34 
34 
     | 
    
         
             
                  assert_instance_method :edit, content do |m|
         
     | 
| 
       35 
     | 
    
         
            -
                     
     | 
| 
      
 35 
     | 
    
         
            +
                    assert_predicate m, :blank?
         
     | 
| 
       36 
36 
     | 
    
         
             
                  end
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
       38 
38 
     | 
    
         
             
                  assert_instance_method :create, content do |m|
         
     | 
| 
       39 
     | 
    
         
            -
                    assert_match 
     | 
| 
       40 
     | 
    
         
            -
                    assert_match 
     | 
| 
       41 
     | 
    
         
            -
                    assert_match 
     | 
| 
       42 
     | 
    
         
            -
                    assert_match 
     | 
| 
       43 
     | 
    
         
            -
                    assert_match 
     | 
| 
       44 
     | 
    
         
            -
                    assert_match 
     | 
| 
      
 39 
     | 
    
         
            +
                    assert_match(/@account = Account\.new\(account_params\)/, m)
         
     | 
| 
      
 40 
     | 
    
         
            +
                    assert_match(/@account\.save/, m)
         
     | 
| 
      
 41 
     | 
    
         
            +
                    assert_match(/format\.html \{ redirect_to @account, notice: 'Account was successfully created\.' \}/, m)
         
     | 
| 
      
 42 
     | 
    
         
            +
                    assert_match(/format\.json \{ render json: @account, status: :created \}/, m)
         
     | 
| 
      
 43 
     | 
    
         
            +
                    assert_match(/format\.html \{ render action: 'new' \}/, m)
         
     | 
| 
      
 44 
     | 
    
         
            +
                    assert_match(/format\.json \{ render json: @account\.errors, status: :unprocessable_entity \}/, m)
         
     | 
| 
       45 
45 
     | 
    
         
             
                  end
         
     | 
| 
       46 
46 
     | 
    
         | 
| 
       47 
47 
     | 
    
         
             
                  assert_instance_method :update, content do |m|
         
     | 
| 
       48 
     | 
    
         
            -
                    assert_match 
     | 
| 
       49 
     | 
    
         
            -
                    assert_match 
     | 
| 
       50 
     | 
    
         
            -
                    assert_match 
     | 
| 
       51 
     | 
    
         
            -
                    assert_match 
     | 
| 
      
 48 
     | 
    
         
            +
                    assert_match(/format\.html \{ redirect_to @account, notice: 'Account was successfully updated\.' \}/, m)
         
     | 
| 
      
 49 
     | 
    
         
            +
                    assert_match(/format\.json \{ head :no_content \}/, m)
         
     | 
| 
      
 50 
     | 
    
         
            +
                    assert_match(/format\.html \{ render action: 'edit' \}/, m)
         
     | 
| 
      
 51 
     | 
    
         
            +
                    assert_match(/format\.json \{ render json: @account.errors, status: :unprocessable_entity \}/, m)
         
     | 
| 
       52 
52 
     | 
    
         
             
                  end
         
     | 
| 
       53 
53 
     | 
    
         | 
| 
       54 
54 
     | 
    
         
             
                  assert_instance_method :destroy, content do |m|
         
     | 
| 
       55 
     | 
    
         
            -
                    assert_match 
     | 
| 
       56 
     | 
    
         
            -
                    assert_match 
     | 
| 
       57 
     | 
    
         
            -
                    assert_match 
     | 
| 
      
 55 
     | 
    
         
            +
                    assert_match(/@account\.destroy/, m)
         
     | 
| 
      
 56 
     | 
    
         
            +
                    assert_match(/format\.html { redirect_to accounts_url \}/, m)
         
     | 
| 
      
 57 
     | 
    
         
            +
                    assert_match(/format\.json \{ head :no_content \}/, m)
         
     | 
| 
       58 
58 
     | 
    
         
             
                  end
         
     | 
| 
       59 
59 
     | 
    
         | 
| 
       60 
60 
     | 
    
         
             
                  assert_match(/def account_params/, content)
         
     | 
    
        data/test/test_app.rb
    CHANGED
    
    
    
        data/test/test_helper.rb
    CHANGED
    
    | 
         @@ -2,8 +2,13 @@ require 'bundler/setup' 
     | 
|
| 
       2 
2 
     | 
    
         
             
            require 'minitest/autorun'
         
     | 
| 
       3 
3 
     | 
    
         
             
            require 'active_model_serializers'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require 'fixtures/poro'
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
      
 5 
     | 
    
         
            +
            begin
         
     | 
| 
      
 6 
     | 
    
         
            +
              require 'rails-controller-testing'
         
     | 
| 
      
 7 
     | 
    
         
            +
              Rails::Controller::Testing.install
         
     | 
| 
      
 8 
     | 
    
         
            +
            rescue LoadError
         
     | 
| 
      
 9 
     | 
    
         
            +
              false # Rails 5 < backward compatibility
         
     | 
| 
      
 10 
     | 
    
         
            +
            end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
       7 
12 
     | 
    
         | 
| 
       8 
13 
     | 
    
         
             
            # Ensure backward compatibility with Minitest 4
         
     | 
| 
       9 
14 
     | 
    
         
             
            Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
         
     | 
| 
         @@ -49,7 +49,7 @@ module ActiveModel 
     | 
|
| 
       49 
49 
     | 
    
         
             
                    def object.serializer_class; CustomSerializer; end
         
     | 
| 
       50 
50 
     | 
    
         | 
| 
       51 
51 
     | 
    
         
             
                    assert_equal CustomSerializer, Serializer.serializer_for(object)
         
     | 
| 
       52 
     | 
    
         
            -
                     
     | 
| 
      
 52 
     | 
    
         
            +
                    assert_nil Serializer.serializer_for('Custom')
         
     | 
| 
       53 
53 
     | 
    
         
             
                  end
         
     | 
| 
       54 
54 
     | 
    
         
             
                end
         
     | 
| 
       55 
55 
     | 
    
         | 
| 
         @@ -66,8 +66,8 @@ module ActiveModel 
     | 
|
| 
       66 
66 
     | 
    
         
             
                    serializer = ArraySerializer.new(array)
         
     | 
| 
       67 
67 
     | 
    
         | 
| 
       68 
68 
     | 
    
         
             
                    expected = [
         
     | 
| 
       69 
     | 
    
         
            -
                      { name: 'Test 1', email: 'test1@test.com', sub_test: { name: 'Name 1', description: 'Description 1' }},
         
     | 
| 
       70 
     | 
    
         
            -
                      { name: 'Test  
     | 
| 
      
 69 
     | 
    
         
            +
                      { name: 'Test 1', email: 'test1@test.com', sub_test: { name: 'Name 1', description: 'Description 1' } },
         
     | 
| 
      
 70 
     | 
    
         
            +
                      { name: 'Test 2', email: 'test2@test.com', sub_test: { name: 'Name 2', description: 'Description 2' } }
         
     | 
| 
       71 
71 
     | 
    
         
             
                    ]
         
     | 
| 
       72 
72 
     | 
    
         | 
| 
       73 
73 
     | 
    
         
             
                    assert_equal expected, serializer.serializable_array
         
     | 
| 
         @@ -4,7 +4,7 @@ module ActiveModel 
     | 
|
| 
       4 
4 
     | 
    
         
             
              class DefaultSerializer
         
     | 
| 
       5 
5 
     | 
    
         
             
                class Test < Minitest::Test
         
     | 
| 
       6 
6 
     | 
    
         
             
                  def test_serialize_objects
         
     | 
| 
       7 
     | 
    
         
            -
                     
     | 
| 
      
 7 
     | 
    
         
            +
                    assert_nil(DefaultSerializer.new(nil).serializable_object)
         
     | 
| 
       8 
8 
     | 
    
         
             
                    assert_equal(1, DefaultSerializer.new(1).serializable_object)
         
     | 
| 
       9 
9 
     | 
    
         
             
                    assert_equal('hi', DefaultSerializer.new('hi').serializable_object)
         
     | 
| 
       10 
10 
     | 
    
         
             
                  end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: active_model_serializers
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.9. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.9.13
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - José Valim
         
     | 
| 
         @@ -10,7 +10,7 @@ authors: 
     | 
|
| 
       10 
10 
     | 
    
         
             
            autorequire:
         
     | 
| 
       11 
11 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       12 
12 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       13 
     | 
    
         
            -
            date:  
     | 
| 
      
 13 
     | 
    
         
            +
            date: 2024-09-17 00:00:00.000000000 Z
         
     | 
| 
       14 
14 
     | 
    
         
             
            dependencies:
         
     | 
| 
       15 
15 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       16 
16 
     | 
    
         
             
              name: activemodel
         
     | 
| 
         @@ -89,7 +89,6 @@ 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/active_model_serializers/model/caching.rb
         
     | 
| 
       93 
92 
     | 
    
         
             
            - test/benchmark/app.rb
         
     | 
| 
       94 
93 
     | 
    
         
             
            - test/benchmark/benchmarking_support.rb
         
     | 
| 
       95 
94 
     | 
    
         
             
            - test/benchmark/bm_active_record.rb
         
     | 
| 
         @@ -116,12 +115,7 @@ files: 
     | 
|
| 
       116 
115 
     | 
    
         
             
            - test/integration/generators/serializer_generator_test.rb
         
     | 
| 
       117 
116 
     | 
    
         
             
            - test/test_app.rb
         
     | 
| 
       118 
117 
     | 
    
         
             
            - 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
         
     | 
| 
       123 
118 
     | 
    
         
             
            - test/tmp/app/serializers/account_serializer.rb
         
     | 
| 
       124 
     | 
    
         
            -
            - test/tmp/config/routes.rb
         
     | 
| 
       125 
119 
     | 
    
         
             
            - test/unit/active_model/array_serializer/except_test.rb
         
     | 
| 
       126 
120 
     | 
    
         
             
            - test/unit/active_model/array_serializer/key_format_test.rb
         
     | 
| 
       127 
121 
     | 
    
         
             
            - test/unit/active_model/array_serializer/meta_test.rb
         
     | 
| 
         @@ -167,67 +161,62 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       167 
161 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       168 
162 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       169 
163 
     | 
    
         
             
            requirements: []
         
     | 
| 
       170 
     | 
    
         
            -
            rubygems_version: 3. 
     | 
| 
      
 164 
     | 
    
         
            +
            rubygems_version: 3.3.7
         
     | 
| 
       171 
165 
     | 
    
         
             
            signing_key:
         
     | 
| 
       172 
166 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       173 
167 
     | 
    
         
             
            summary: Bringing consistency and object orientation to model serialization. Works
         
     | 
| 
       174 
168 
     | 
    
         
             
              great for client-side MVC frameworks!
         
     | 
| 
       175 
169 
     | 
    
         
             
            test_files:
         
     | 
| 
       176 
170 
     | 
    
         
             
            - test/benchmark/app.rb
         
     | 
| 
       177 
     | 
    
         
            -
            - test/benchmark/ 
     | 
| 
      
 171 
     | 
    
         
            +
            - test/benchmark/benchmarking_support.rb
         
     | 
| 
       178 
172 
     | 
    
         
             
            - test/benchmark/bm_active_record.rb
         
     | 
| 
       179 
     | 
    
         
            -
            - test/benchmark/ 
     | 
| 
       180 
     | 
    
         
            -
            - test/benchmark/tmp/miniprofiler/ 
     | 
| 
       181 
     | 
    
         
            -
            - test/benchmark/tmp/miniprofiler/ 
     | 
| 
       182 
     | 
    
         
            -
            - test/benchmark/tmp/miniprofiler/mp_timers_qg52tpca3uesdfguee9i
         
     | 
| 
       183 
     | 
    
         
            -
            - test/benchmark/tmp/miniprofiler/mp_views_127.0.0.1
         
     | 
| 
      
 173 
     | 
    
         
            +
            - test/benchmark/setup.rb
         
     | 
| 
      
 174 
     | 
    
         
            +
            - test/benchmark/tmp/miniprofiler/mp_timers_6eqewtfgrhitvq5gqm25
         
     | 
| 
      
 175 
     | 
    
         
            +
            - test/benchmark/tmp/miniprofiler/mp_timers_8083sx03hu72pxz1a4d0
         
     | 
| 
       184 
176 
     | 
    
         
             
            - test/benchmark/tmp/miniprofiler/mp_timers_fyz2gsml4z0ph9kpoy1c
         
     | 
| 
      
 177 
     | 
    
         
            +
            - test/benchmark/tmp/miniprofiler/mp_timers_hjry5rc32imd42oxoi48
         
     | 
| 
      
 178 
     | 
    
         
            +
            - test/benchmark/tmp/miniprofiler/mp_timers_m8fpoz2cvt3g9agz0bs3
         
     | 
| 
       185 
179 
     | 
    
         
             
            - test/benchmark/tmp/miniprofiler/mp_timers_p92m2drnj1i568u3sta0
         
     | 
| 
       186 
     | 
    
         
            -
            - test/benchmark/tmp/miniprofiler/ 
     | 
| 
      
 180 
     | 
    
         
            +
            - test/benchmark/tmp/miniprofiler/mp_timers_qg52tpca3uesdfguee9i
         
     | 
| 
      
 181 
     | 
    
         
            +
            - test/benchmark/tmp/miniprofiler/mp_timers_s15t1a6mvxe0z7vjv790
         
     | 
| 
       187 
182 
     | 
    
         
             
            - test/benchmark/tmp/miniprofiler/mp_timers_x8kal3d17nfds6vp4kcj
         
     | 
| 
       188 
     | 
    
         
            -
            - test/benchmark/tmp/miniprofiler/ 
     | 
| 
       189 
     | 
    
         
            -
            - test/ 
     | 
| 
       190 
     | 
    
         
            -
            - test/ 
     | 
| 
       191 
     | 
    
         
            -
            - test/ 
     | 
| 
      
 183 
     | 
    
         
            +
            - test/benchmark/tmp/miniprofiler/mp_views_127.0.0.1
         
     | 
| 
      
 184 
     | 
    
         
            +
            - test/fixtures/active_record.rb
         
     | 
| 
      
 185 
     | 
    
         
            +
            - test/fixtures/poro.rb
         
     | 
| 
      
 186 
     | 
    
         
            +
            - test/fixtures/template.html.erb
         
     | 
| 
      
 187 
     | 
    
         
            +
            - test/integration/action_controller/namespaced_serialization_test.rb
         
     | 
| 
      
 188 
     | 
    
         
            +
            - test/integration/action_controller/serialization_test.rb
         
     | 
| 
      
 189 
     | 
    
         
            +
            - test/integration/action_controller/serialization_test_case_test.rb
         
     | 
| 
      
 190 
     | 
    
         
            +
            - test/integration/active_record/active_record_test.rb
         
     | 
| 
      
 191 
     | 
    
         
            +
            - test/integration/generators/resource_generator_test.rb
         
     | 
| 
      
 192 
     | 
    
         
            +
            - test/integration/generators/scaffold_controller_generator_test.rb
         
     | 
| 
      
 193 
     | 
    
         
            +
            - test/integration/generators/serializer_generator_test.rb
         
     | 
| 
      
 194 
     | 
    
         
            +
            - test/test_app.rb
         
     | 
| 
      
 195 
     | 
    
         
            +
            - test/test_helper.rb
         
     | 
| 
      
 196 
     | 
    
         
            +
            - test/tmp/app/serializers/account_serializer.rb
         
     | 
| 
      
 197 
     | 
    
         
            +
            - test/unit/active_model/array_serializer/except_test.rb
         
     | 
| 
      
 198 
     | 
    
         
            +
            - test/unit/active_model/array_serializer/key_format_test.rb
         
     | 
| 
      
 199 
     | 
    
         
            +
            - test/unit/active_model/array_serializer/meta_test.rb
         
     | 
| 
      
 200 
     | 
    
         
            +
            - test/unit/active_model/array_serializer/only_test.rb
         
     | 
| 
      
 201 
     | 
    
         
            +
            - test/unit/active_model/array_serializer/options_test.rb
         
     | 
| 
      
 202 
     | 
    
         
            +
            - test/unit/active_model/array_serializer/root_test.rb
         
     | 
| 
      
 203 
     | 
    
         
            +
            - test/unit/active_model/array_serializer/scope_test.rb
         
     | 
| 
      
 204 
     | 
    
         
            +
            - test/unit/active_model/array_serializer/serialization_test.rb
         
     | 
| 
      
 205 
     | 
    
         
            +
            - test/unit/active_model/default_serializer_test.rb
         
     | 
| 
       192 
206 
     | 
    
         
             
            - 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
         
     | 
| 
       195 
207 
     | 
    
         
             
            - test/unit/active_model/serializer/associations_test.rb
         
     | 
| 
       196 
     | 
    
         
            -
            - test/unit/active_model/serializer/options_test.rb
         
     | 
| 
       197 
208 
     | 
    
         
             
            - test/unit/active_model/serializer/attributes_test.rb
         
     | 
| 
       198 
     | 
    
         
            -
            - test/unit/active_model/serializer/ 
     | 
| 
       199 
     | 
    
         
            -
            - test/unit/active_model/serializer/ 
     | 
| 
      
 209 
     | 
    
         
            +
            - test/unit/active_model/serializer/config_test.rb
         
     | 
| 
      
 210 
     | 
    
         
            +
            - test/unit/active_model/serializer/filter_test.rb
         
     | 
| 
       200 
211 
     | 
    
         
             
            - test/unit/active_model/serializer/has_many_polymorphic_test.rb
         
     | 
| 
       201 
     | 
    
         
            -
            - test/unit/active_model/serializer/has_one_polymorphic_test.rb
         
     | 
| 
       202 
212 
     | 
    
         
             
            - test/unit/active_model/serializer/has_many_test.rb
         
     | 
| 
       203 
213 
     | 
    
         
             
            - test/unit/active_model/serializer/has_one_and_has_many_test.rb
         
     | 
| 
       204 
     | 
    
         
            -
            - test/unit/active_model/serializer/ 
     | 
| 
      
 214 
     | 
    
         
            +
            - test/unit/active_model/serializer/has_one_polymorphic_test.rb
         
     | 
| 
      
 215 
     | 
    
         
            +
            - test/unit/active_model/serializer/has_one_test.rb
         
     | 
| 
      
 216 
     | 
    
         
            +
            - test/unit/active_model/serializer/key_format_test.rb
         
     | 
| 
      
 217 
     | 
    
         
            +
            - test/unit/active_model/serializer/meta_test.rb
         
     | 
| 
      
 218 
     | 
    
         
            +
            - test/unit/active_model/serializer/options_test.rb
         
     | 
| 
      
 219 
     | 
    
         
            +
            - test/unit/active_model/serializer/root_test.rb
         
     | 
| 
       205 
220 
     | 
    
         
             
            - test/unit/active_model/serializer/scope_test.rb
         
     | 
| 
       206 
     | 
    
         
            -
            - test/unit/active_model/ 
     | 
| 
       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
         
     | 
| 
      
 221 
     | 
    
         
            +
            - test/unit/active_model/serializer/url_helpers_test.rb
         
     | 
| 
       215 
222 
     | 
    
         
             
            - 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,26 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # frozen_string_literal: true
         
     | 
| 
       2 
     | 
    
         
            -
            module ActiveModelSerializers
         
     | 
| 
       3 
     | 
    
         
            -
              class Model
         
     | 
| 
       4 
     | 
    
         
            -
                module Caching
         
     | 
| 
       5 
     | 
    
         
            -
                  extend ActiveSupport::Concern
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
                  included do
         
     | 
| 
       8 
     | 
    
         
            -
                    attr_writer :updated_at
         
     | 
| 
       9 
     | 
    
         
            -
                    attributes :id
         
     | 
| 
       10 
     | 
    
         
            -
                  end
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                  # Defaults to the downcased model name and updated_at
         
     | 
| 
       13 
     | 
    
         
            -
                  def cache_key
         
     | 
| 
       14 
     | 
    
         
            -
                    ActiveSupport::Cache.expand_cache_key([
         
     | 
| 
       15 
     | 
    
         
            -
                      self.class.model_name.name.downcase,
         
     | 
| 
       16 
     | 
    
         
            -
                      "#{id}-#{updated_at.strftime('%Y%m%d%H%M%S%9N')}"
         
     | 
| 
       17 
     | 
    
         
            -
                    ].compact)
         
     | 
| 
       18 
     | 
    
         
            -
                  end
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
                  # Defaults to the time the serializer file was modified.
         
     | 
| 
       21 
     | 
    
         
            -
                  def updated_at
         
     | 
| 
       22 
     | 
    
         
            -
                    defined?(@updated_at) ? @updated_at : File.mtime(__FILE__)
         
     | 
| 
       23 
     | 
    
         
            -
                  end
         
     | 
| 
       24 
     | 
    
         
            -
                end
         
     | 
| 
       25 
     | 
    
         
            -
              end
         
     | 
| 
       26 
     | 
    
         
            -
            end
         
     | 
    
        data/test/tmp/config/routes.rb
    DELETED