Given the following ActiveModel::Serializer class:
class SampleSerializer < ActiveModel::Serializer
attributes :id, :name
end
When using active_model_serializers, there is a much easier way by simply calling serializable_hash on the serializer:
it 'should include a correct name' do
sample = FactoryBot.create(:sample)
serializer = SampleSerializer.new(sample)
expect(serializer.serializable_hash[:name]).to eq 'Heisenberg'
end