I'm using active model serializers to render JSON responses from a rails controller.
I have a controller action like this:
def show
@foo = Foo.find(params[:id])
if @foo.user == current_user
render json: @foo, serializer: FooSerializer
else
render json: @foo, serializer: TrimmedFooSerializer
end
end
I want to be able to test which serializer has been used in my Rspec controller tests. Is it possible to get a reference to the serializer from the tests?
UPDATE:
I don't think this a correct use of the serializer. I now have logic in the serializer itself to conditionally include attributes. The controller shouldn't really care about which serializer to use.