<commit_before># frozen_string_literal: true

require 'test_helper'

class AssociationTest < Test::Unit::TestCase
  test 'decorating associations' do
    a = Author.create! name: 'yugui'
    ActiveDecorator::Decorator.instance.decorate a

    b = a.books.build title: 'giraffe'
    assert b.is_a? ActiveDecorator::Decorated
    b = a.books.clear

    b = a.books.create! title: 'giraffe'
    assert b.is_a? ActiveDecorator::Decorated
    id = b.id

    b = a.books.first
    assert b.is_a? ActiveDecorator::Decorated

    b = a.books.last
    assert b.is_a? ActiveDecorator::Decorated

    b = a.books.find id
    assert b.is_a? ActiveDecorator::Decorated

    if ActiveRecord::VERSION::MAJOR >= 4
      b = a.books.take
      assert b.is_a? ActiveDecorator::Decorated
    end

    b = a.books.order(:id).first
    assert b.is_a? ActiveDecorator::Decorated

    b = a.books.order(:id).last
    assert b.is_a? ActiveDecorator::Decorated

    b = a.books.order(:id).find id
    assert b.is_a? ActiveDecorator::Decorated

    if ActiveRecord::VERSION::MAJOR >= 4
      b = a.books.order(:id).take
      assert b.is_a? ActiveDecorator::Decorated
    end
  end
end<commit_msg>Separate each association decoration test<commit_after># frozen_string_literal: true

require 'test_helper'

class AssociationTest < Test::Unit::TestCase
  setup do
    a = Author.create! name: 'pragdave'
    ActiveDecorator::Decorator.instance.decorate a

    @books = a.books

    b = @books.create! title: 'pragprog'
    @id = b.id
  end

  test 'build' do
    b = @books.build title: 'pickaxe'
    assert b.is_a? ActiveDecorator::Decorated
  end

  test 'create!' do
    b = @books.create! title: 'pickaxe'
    assert b.is_a? ActiveDecorator::Decorated
  end

  test 'first' do
    assert @books.first.is_a? ActiveDecorator::Decorated
  end

  test 'last' do
    assert @books.last.is_a? ActiveDecorator::Decorated
  end

  test 'find' do
    assert @books.find(@id).is_a? ActiveDecorator::Decorated
  end

  if ActiveRecord::VERSION::MAJOR >= 4
    test 'take' do
      assert @books.take.is_a? ActiveDecorator::Decorated
    end
  end

  sub_test_case 'when method chained' do
    setup do
      @books = @books.order(:id)
    end

    test 'first' do
      assert @books.first.is_a? ActiveDecorator::Decorated
    end

    test 'last' do
      assert @books.last.is_a? ActiveDecorator::Decorated
    end

    test 'find' do
      assert @books.find(@id).is_a? ActiveDecorator::Decorated
    end

    if ActiveRecord::VERSION::MAJOR >= 4
      test 'take' do
        assert @books.take.is_a? ActiveDecorator::Decorated
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10903545558520777, 'fraction_numerical': 0.0015249714067861228, 'mean_word_length': 3.1257861635220126, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '2246645', 'n_tokens_mistral': 962, 'n_tokens_neox': 931, 'n_words': 214}