<commit_before>require 'spec_helper'

describe 'headers' do
  it 'includes headers based on attribute names by default' do
    post = Post.new(name: 'Samwise', body: 'Hobbit extraordinaire.')
    serializer = PostCsvSerializer.new(post)
    csv = serializer.to_csv

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

  context 'when root option set to false during serializer instantiation' do
    it 'does not include headers' do
      post = Post.new(name: 'Samwise', body: 'Hobbit extraordinaire.')
      serializer = PostCsvSerializer.new(post, root: false)
      csv = serializer.to_csv

      expect(csv).to_not include('name')
      expect(csv).to_not include('body')
    end
  end

  context 'when root set to false during class definition' do
    it 'does not include headers' do
      post = Post.new(name: 'Samwise', body: 'Hobbit extraordinaire.')
      PostCsvSerializer.root = false
      serializer = PostCsvSerializer.new(post, root: false)
      csv = serializer.to_csv

      expect(csv).to_not include('name')
      expect(csv).to_not include('body')
    end
  end

  context 'when parent serializer root set to false' do
    it 'does not include headers' do
      post = Post.new(name: 'Samwise', body: 'Hobbit extraordinaire.')
      ActiveModel::CsvSerializer.root = false
      serializer = PostCsvSerializer.new(post, root: false)
      csv = serializer.to_csv

      expect(csv).to_not include('name')
      expect(csv).to_not include('body')
    end
  end

  context 'when serialized object has one associated object' do
    it 'renders associated attributes prepended with its name' do
      category = Category.new(name: 'a')
      author = Author.new(name: 'b', category: category)
      serializer = AuthorCsvSerializer.new(author)
      csv = serializer.to_csv

      expect(csv).to include('name')
      expect(csv).to include('category_name')
    end
  end
end<commit_msg>test nested has one associations<commit_after>require 'spec_helper'

describe 'headers' do
  it 'includes headers based on attribute names by default' do
    post = Post.new(name: 'Samwise', body: 'Hobbit extraordinaire.')
    serializer = PostCsvSerializer.new(post)
    csv = serializer.to_csv

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

  context 'when root option set to false during serializer instantiation' do
    it 'does not include headers' do
      post = Post.new(name: 'Samwise', body: 'Hobbit extraordinaire.')
      serializer = PostCsvSerializer.new(post, root: false)
      csv = serializer.to_csv

      expect(csv).to_not include('name')
      expect(csv).to_not include('body')
    end
  end

  context 'when root set to false during class definition' do
    it 'does not include headers' do
      post = Post.new(name: 'Samwise', body: 'Hobbit extraordinaire.')
      PostCsvSerializer.root = false
      serializer = PostCsvSerializer.new(post, root: false)
      csv = serializer.to_csv

      expect(csv).to_not include('name')
      expect(csv).to_not include('body')
    end
  end

  context 'when parent serializer root set to false' do
    it 'does not include headers' do
      post = Post.new(name: 'Samwise', body: 'Hobbit extraordinaire.')
      ActiveModel::CsvSerializer.root = false
      serializer = PostCsvSerializer.new(post, root: false)
      csv = serializer.to_csv

      expect(csv).to_not include('name')
      expect(csv).to_not include('body')
    end
  end

  context 'when serialized object has one associated object' do
    it 'renders associated attributes prepended with its name' do
      category = Category.new(name: 'a')
      author = Author.new(name: 'b', category: category)
      serializer = AuthorCsvSerializer.new(author)
      csv = serializer.to_csv

      expect(csv).to include('name')
      expect(csv).to include('category_name')
    end
  end

  context 'when serialized object has nested associated objects' do
    it 'renders associated attributes prepended with its objects name' do
      category = Category.new(name: 'a')
      author = Author.new(name: 'b', category: category)
      post = Post.new(name: 'a', body: 'b', author: author)
      serializer = PostCsvSerializer.new(post)
      csv = serializer.to_csv

      expect(csv).to include('name')
      expect(csv).to include('body')
      expect(csv).to include('author_name')
      expect(csv).to include('category_name')
    end
  end
end
{'fraction_non_alphanumeric': 0.1056782334384858, 'fraction_numerical': 0.0, 'mean_word_length': 3.356231599607458, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1043113', 'n_tokens_mistral': 1350, 'n_tokens_neox': 1321, 'n_words': 397}