Skip to content

Commit beffbb2

Browse files
rafaelgaspardpogueartinboghosian
committed
Follows inheritance with a namespace
Co-authored-by: Rafael Gaspar <[email protected]> Co-authored-by: Darryl Pogue <[email protected]> Co-authored-by: Artin Boghosian <[email protected]>
1 parent 777fab0 commit beffbb2

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Fixes:
1717
- [#2223](https://github.com/rails-api/active_model_serializers/pull/2223) Support Fieldset in Attributes/JSON adapters documented in [docs/general/fields.md](https://github.com/rails-api/active_model_serializers/blob/0-10-stable/docs/general/fields.md) that worked partially before (@bf4)
1818
- [#2337](https://github.com/rails-api/active_model_serializers/pull/2337) fix incorrect belongs_to serialization when foreign_key on object and belongs_to is blank (@InteNs)
1919
- Fixes incorrect json-api generation when `jsonapi_use_foreign_key_on_belongs_to_relationship` is `true` and the relationship is blank
20+
- [#2172](https://github.com/rails-api/active_model_serializers/pull/2172) Preserve the namespace when falling back to a superclass serializer
2021

2122
Misc:
2223

lib/active_model/serializer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def self.get_serializer_for(klass, namespace = nil)
9494
if serializer_class
9595
serializer_class
9696
elsif klass.superclass
97-
get_serializer_for(klass.superclass)
97+
get_serializer_for(klass.superclass, namespace)
9898
else
9999
nil # No serializer found
100100
end

test/serializers/serializer_for_with_namespace_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Book < ::Model
99
attributes :title, :author_name
1010
associations :publisher, :pages
1111
end
12+
class Ebook < Book; end
1213
class Page < ::Model; attributes :number, :text end
1314
class Publisher < ::Model; attributes :name end
1415

@@ -85,6 +86,11 @@ class BookSerializer < ActiveModel::Serializer
8586
}
8687
assert_equal expected, result
8788
end
89+
90+
test 'follows inheritance with a namespace' do
91+
serializer = ActiveModel::Serializer.serializer_for(Ebook.new, namespace: Api::V3)
92+
assert_equal Api::V3::BookSerializer, serializer
93+
end
8894
end
8995
end
9096
end

0 commit comments

Comments
 (0)