Sha256: b889145d6d33c8c72a6e2b714a9f039eab7b4c759a0c84dc410e49a454dc0cd3

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

require 'spec_helper'

describe 'has_one' do
  let(:post) { Post.new(name: 'a', body: 'b', author: author) }
  let(:author) { Author.new(name: 'd') }
  let(:category) { Category.new(name: 'e') }
  let(:post_serializer) { PostCsverizer.new(post) }
  let(:author_serializer) { AuthorCsverizer.new(author) }

  it 'appends the associated objects csv data to this' do
    csv = post_serializer.to_csv

    expect(csv).to include(post.name)
    expect(csv).to include(post.body)
    expect(csv).to include(author.name)
  end

  it 'appends all associated objects csv data to this' do
    post.category = category
    csv = post_serializer.to_csv

    expect(csv).to include(post.name)
    expect(csv).to include(post.body)
    expect(csv).to include(author.name)
    expect(csv).to include(category.name)
  end

  it 'appends associated objects associations' do
    author.category = category
    csv = post_serializer.to_csv

    expect(csv).to include(post.name)
    expect(csv).to include(post.body)
    expect(csv).to include(author.name)
    expect(csv).to include(category.name)
  end

  it 'returns this csv data if no associated object' do
    author = nil
    csv = post_serializer.to_csv

    expect(csv).to include(post.name)
    expect(csv).to include(post.body)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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