Skip to content

Commit

Permalink
Follows inheritance with a namespace
Browse files Browse the repository at this point in the history
Co-authored-by: Rafael Gaspar <rafael.gaspar@me.com>
Co-authored-by: Darryl Pogue <darryl@dpogue.ca>
Co-authored-by: Artin Boghosian <artinboghosian@gmail.com>
  • Loading branch information
3 people committed Jul 10, 2019
1 parent 777fab0 commit 6ef6a35
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/active_model/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def self.get_serializer_for(klass, namespace = nil)
if serializer_class
serializer_class
elsif klass.superclass
get_serializer_for(klass.superclass)
get_serializer_for(klass.superclass, namespace)
else
nil # No serializer found
end
Expand Down
6 changes: 6 additions & 0 deletions test/serializers/serializer_for_with_namespace_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Book < ::Model
attributes :title, :author_name
associations :publisher, :pages
end
class Ebook < Book; end
class Page < ::Model; attributes :number, :text end
class Publisher < ::Model; attributes :name end

Expand Down Expand Up @@ -85,6 +86,11 @@ class BookSerializer < ActiveModel::Serializer
}
assert_equal expected, result
end

test 'follows inheritance with a namespace' do
serializer = ActiveModel::Serializer.serializer_for(Ebook.new, namespace: Api::V3)
assert_equal Api::V3::BookSerializer, serializer
end
end
end
end

0 comments on commit 6ef6a35

Please sign in to comment.