Sha256: d0316828d9ecbcc5c54f7b0302cb9cd88cad2e2119646f480a77da2da2463153

Contents?: true

Size: 1019 Bytes

Versions: 3

Compression:

Stored size: 1019 Bytes

Contents

require 'spec_helper'

describe 'ArraySerializer' do
  let(:comments) { [comment_1, comment_2] }
  let(:comment_1) { Comment.new(text: 'a') }
  let(:comment_2) { Comment.new(text: 'b') }
  let(:post) { Post.new(name: 'c', body: 'd') }

  it 'renders csv using specified serializer' do
    array_serializer = ActiveModel::CsvArraySerializer.new(
      comments,
      each_serializer: CommentCsverizer
    )
    csv = array_serializer.to_csv

    expect(csv).to include(comment_1.text)
    expect(csv).to include(comment_2.text)
  end

  it 'renders csv without specified serializer' do
    array_serializer = ActiveModel::CsvArraySerializer.new(comments)
    csv = array_serializer.to_csv

    expect(csv).to include(comment_1.text)
    expect(csv).to include(comment_2.text)
  end

  it 'raises an exception when expected serializer not found' do
    comments << Object.new
    array_serializer = ActiveModel::CsvArraySerializer.new(comments)

    expect{ array_serializer.to_csv }.to raise_error(NameError)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
csverizer-0.0.7 spec/active_model/array_serializer_spec.rb
csverizer-0.0.6 spec/active_model/array_serializer_spec.rb
csverizer-0.0.5 spec/active_model/array_serializer_spec.rb