Sha256: a979e598344a2688fccbd6daebb43265efcf5923da2a55b846a9122785062ba2

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

require 'spec_helper'
require 'acceptance/acceptance_helper'

describe "a created instance" do
  include FactoryGirl::Syntax::Methods

  before do
    define_model('User')

    define_model('Post', :user_id => :integer) do
      belongs_to :user
    end

    FactoryGirl.define do
      factory :user do
      end

      factory :post do
        user
      end
    end
  end

  subject { create('post') }

  it "saves" do
    should_not be_new_record
  end

  it "assigns and saves associations" do
    subject.user.should be_kind_of(User)
    subject.user.should_not be_new_record
  end
end

describe "a custom create" do
  include FactoryGirl::Syntax::Methods

  before do
    define_class('User') do
      def initialize
        @persisted = false
      end

      def persist
        @persisted = true
      end

      def persisted?
        @persisted
      end
    end

    FactoryGirl.define do
      factory :user do
        to_create do |user|
          user.persist
        end
      end
    end
  end

  it "uses the custom create block instead of save" do
    FactoryGirl.create(:user).should be_persisted
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
factory_girl-2.0.0.beta3 spec/acceptance/create_spec.rb
factory_girl_kibiz0r-2.0.0.beta3 spec/acceptance/create_spec.rb
factory_girl_kibiz0r-2.0.0.beta2 spec/acceptance/create_spec.rb
factory_girl-2.0.0.beta2 spec/acceptance/create_spec.rb