Sha256: d98246d46999e126e8c7d5ec4837f2f9cb6de840a326e84365923a516fc1fa99

Contents?: true

Size: 1.2 KB

Versions: 28

Compression:

Stored size: 1.2 KB

Contents

require 'spec_helper'

describe "a stubbed 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

      factory :post do
        user
      end
    end
  end

  subject { build_stubbed(:post) }

  it "acts as if it came from the database" do
    should_not be_new_record
  end

  it "assigns associations and acts as if it is saved" do
    subject.user.should be_kind_of(User)
    subject.user.should_not be_new_record
  end
end

describe "a stubbed instance with :method => :build" 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

      factory :post do
        association(:user, :method => :build)
      end
    end
  end

  subject { build_stubbed(:post) }

  it "acts as if it is saved in the database" do
    should_not be_new_record
  end

  it "assigns associations and acts as if it is saved" do
    subject.user.should be_kind_of(User)
    subject.user.should_not be_new_record
  end

end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
challah-0.6.1 vendor/bundle/gems/factory_girl-2.5.1/spec/acceptance/stub_spec.rb
challah-0.6.0 vendor/bundle/gems/factory_girl-2.5.1/spec/acceptance/stub_spec.rb
challah-0.5.4 vendor/bundle/gems/factory_girl-2.5.1/spec/acceptance/stub_spec.rb
challah-0.5.3 vendor/bundle/gems/factory_girl-2.5.1/spec/acceptance/stub_spec.rb
challah-0.5.2 vendor/bundle/gems/factory_girl-2.5.1/spec/acceptance/stub_spec.rb
challah-0.5.0 vendor/bundle/gems/factory_girl-2.5.1/spec/acceptance/stub_spec.rb
factory_girl-2.5.2 spec/acceptance/stub_spec.rb
challah-0.4.1 vendor/bundle/gems/factory_girl-2.5.1/spec/acceptance/stub_spec.rb
challah-0.4.0 vendor/bundle/gems/factory_girl-2.5.1/spec/acceptance/stub_spec.rb
challah-0.3.5 vendor/bundle/gems/factory_girl-2.5.1/spec/acceptance/stub_spec.rb
challah-0.3.4 vendor/bundle/gems/factory_girl-2.5.1/spec/acceptance/stub_spec.rb
challah-0.3.3 vendor/bundle/gems/factory_girl-2.5.1/spec/acceptance/stub_spec.rb
challah-0.3.2 vendor/bundle/gems/factory_girl-2.5.1/spec/acceptance/stub_spec.rb
challah-0.3.1 vendor/bundle/gems/factory_girl-2.5.1/spec/acceptance/stub_spec.rb
factory_girl-2.5.1 spec/acceptance/stub_spec.rb
challah-0.3.0 vendor/bundle/gems/factory_girl-2.5.0/spec/acceptance/stub_spec.rb
challah-0.2.1 vendor/bundle/gems/factory_girl-2.5.0/spec/acceptance/stub_spec.rb
challah-0.2.0 vendor/bundle/gems/factory_girl-2.5.0/spec/acceptance/stub_spec.rb
factory_girl-2.5.0 spec/acceptance/stub_spec.rb
factory_girl-2.4.2 spec/acceptance/stub_spec.rb