Skip to content

Commit 7343a9d

Browse files
rafaelgaspardpogueartinboghosian
authored andcommitted
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 bb0f9d0 commit 7343a9d

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Features:
88

99
Fixes:
1010

11+
- [#2172](https://github.com/rails-api/active_model_serializers/pull/2172) Preserve the namespace when falling back to a superclass serializer
12+
1113
Misc:
1214

1315
### [v0.10.9 (2019-02-08)](https://github.com/rails-api/active_model_serializers/compare/v0.10.8...v0.10.9)

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)