Sha256: c2c843882bb8996bd56714150e965a14e8f55df2d02ce5488ee652323be8f713

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

require 'test_helper'

class AssociationsTest < ActiveSupport::TestCase

  setup do
    Makers.define do
      maker :user do
        maker :user_with_built_posts do
          posts
        end
        maker :user_with_created_posts do
          posts 2, strategy: :create
        end
      end
      maker :post do
        maker :post_with_built_user do
          user
        end
        maker :post_with_created_user do
          user strategy: :create
        end
      end
    end
  end

  test 'belongs to association' do
    user = build(:post_with_built_user).user
    assert_kind_of User, user
    assert user.new_record?

    user = build(:post_with_created_user).user
    assert_kind_of User, user
    assert user.persisted?
  end

  test 'has many association' do
    posts = build(:user_with_built_posts).posts
    assert_equal 1, posts.size
    post = posts.first
    assert_kind_of Post, post
    assert post.new_record?

    posts = build(:user_with_created_posts).posts
    assert_equal 2, posts.size
    post = posts.first
    assert_kind_of Post, post
    assert post.persisted?
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
makers-0.1.3 test/associations_test.rb
makers-0.1.2 test/associations_test.rb