Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.9 stable] Revert "Allow serializer_for to accept String instead of just class objects" #2468

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions lib/active_model/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,7 @@ def build_serializer_class(resource, options)
klass_name = +""
klass_name << "#{options[:namespace]}::" if options[:namespace]
klass_name << options[:prefix].to_s.classify if options[:prefix]
if resource.is_a?(String)
klass_name << "#{resource}Serializer"
else
klass_name << "#{resource.class.name}Serializer"
end
klass_name << "#{resource.class.name}Serializer"
end

def associate(klass, *attrs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_serializer_for_array_returns_appropriate_type
def object.serializer_class; CustomSerializer; end

assert_equal CustomSerializer, Serializer.serializer_for(object)
assert_equal CustomSerializer, Serializer.serializer_for('Custom')
assert_nil Serializer.serializer_for('Custom')
Copy link
Member

@bf4 bf4 Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with reverting this behavior change

I either missed or misunderstood it when originally reviewing 460d4c5 in https://github.com/rails-api/active_model_serializers/pull/2446/files

end
end

Expand Down
Loading