Repository: okuramasafumi/alba (Ruby)

Issue:
key_transform in super class doesn't apply to nested resource
## Describe the bug
If `transform_keys :lower_camel` is in the super class of the resource then it doesn't appear to apply nested resources within that resource (but does apply to the first level).

## To Reproduce
Run the following:
``` rb
class Library
  def library_books
    [Book.new(), Book.new()]
  end

  def created_at
    Time.now
  end
end

class Book
  def book_pages
    [Page.new(), Page.new()]
  end

  def created_at
    Time.now
  end
end

class Page
  def page_number
    1
  end

  def created_at
    Time.now
  end
end

class ApplicationResource
  include Alba::Resource

  transform_keys :lower_camel
end

class LibraryResource < ApplicationResource
  attributes :created_at

  has_many :library_books do
    attributes :created_at

    has_many :book_pages do
      attributes :created_at, :page_number
    end
  end
end

LibraryResource.new(Library.new()).to_h
```

## Expected behavior
Expected output:
```
{"createdAt"=>2023-01-24 11:19:23.673333 +0000,                     
 "libraryBooks"=>                                                   
  [{"createdAt"=>2023-01-24 11:19:23.673599 +0000, "bookPages"=>[{"createdAt"=>2023-01-24 11:19:23.673704 +0000, "pageNumber"=>1}, {"createdAt"=>2023-01-24 11:19:23.673749 +0000, "pageNumber"=>1}]},
   {"createdAt"=>2023-01-24 11:19:23.673786 +0000, "bookPages"=>[{"createdAt"=>2023-01-24 11:19:23.67383 +0000, "pageNumber"=>1}, {"createdAt"=>2023-01-24 11:19:23.673865 +0000, "pageNumber"=>1}]}]}
```

## Actual behavior
Actual output:
```
{"createdAt"=>2023-01-24 11:17:22.319571 +0000,                     
 "libraryBooks"=>                                                   
  [{"created_at"=>2023-01-24 11:17:22.319884 +0000, "book_pages"=>[{"created_at"=>2023-01-24 11:17:22.319977 +0000, "page_number"=>1}, {"created_at"=>2023-01-24 11:17:22.32 +0000, "page_number"=>1}]},
   {"created_at"=>2023-01-24 11:17:22.32002 +0000, "book_pages"=>[{"created_at"=>2023-01-24 11:17:22.320051 +0000, "page_number"=>1}, {"created_at"=>2023-01-24 11:17:22.320065 +0000, "page_number"=>1}]}]}
```

## Environment
- Ruby version: `ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [arm64-darwin21]`

## Additional context
In case it's not obvious, I want to DRY out my serializer settings by using a common super class (`ApplicationResource`). Please let me know if there's a better way to achieve this.

Thanks!



Discussion:
Not sure, but might be related to #263?
Thanks @okuramasafumi!



Patch:
diff --git a/lib/alba/resource.rb b/lib/alba/resource.rb
index 5f4197e..d24d410 100644
--- a/lib/alba/resource.rb
+++ b/lib/alba/resource.rb
@@ -11,7 +11,7 @@ module Alba
   module Resource
     # @!parse include InstanceMethods
     # @!parse extend ClassMethods
-    DSLS = {_attributes: {}, _key: nil, _key_for_collection: nil, _meta: nil, _transform_type: :none, _transforming_root_key: false, _on_error: nil, _on_nil: nil, _layout: nil, _collection_key: nil}.freeze # rubocop:disable Layout/LineLength
+    DSLS = {_attributes: {}, _key: nil, _key_for_collection: nil, _meta: nil, _transform_type: :none, _transforming_root_key: false, _key_transformation_cascade: true, _on_error: nil, _on_nil: nil, _layout: nil, _collection_key: nil}.freeze # rubocop:disable Layout/LineLength
     private_constant :DSLS
 
     WITHIN_DEFAULT = Object.new.freeze


Test patch:
diff --git a/test/usecases/key_transform_test.rb b/test/usecases/key_transform_test.rb
index 2abd496..39cecb3 100644
--- a/test/usecases/key_transform_test.rb
+++ b/test/usecases/key_transform_test.rb
@@ -199,4 +199,17 @@ def test_key_transformation_no_cascade
       UserResourceWithInlineAssociationNoCascade.new(@user).serialize
     )
   end
+
+  class InheritedResource < UserResourceLowerCamel
+    one :bank_account do
+      attributes :account_number
+    end
+  end
+
+  def test_transform_key_with_inheritance
+    assert_equal(
+      '{"id":1,"firstName":"Masafumi","lastName":"Okura","bankAccount":{"accountNumber":123456789}}',
+      InheritedResource.new(@user).serialize
+    )
+  end
 end