Sha256: c79de4bc70053ca755559da2f08edf15a437b1373c7b17f75a61cece2b72c582

Contents?: true

Size: 1.18 KB

Versions: 201

Compression:

Stored size: 1.18 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 overriding strategy" 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, strategy: :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

201 entries across 93 versions & 7 rubygems

Version Path
challah-0.9.1.beta vendor/bundle/gems/factory_girl-4.1.0/spec/acceptance/stub_spec.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/factory_girl-4.1.0/spec/acceptance/stub_spec.rb
challah-0.9.0 vendor/bundle/gems/factory_girl-4.1.0/spec/acceptance/stub_spec.rb
classiccms-0.6.9 vendor/bundle/gems/factory_girl-3.3.0/spec/acceptance/stub_spec.rb
classiccms-0.6.9 vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/stub_spec.rb
classiccms-0.6.9 vendor/bundle/gems/factory_girl-3.2.0/spec/acceptance/stub_spec.rb
challah-rolls-0.2.0 vendor/bundle/gems/factory_girl-4.0.0/spec/acceptance/stub_spec.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/factory_girl-3.6.1/spec/acceptance/stub_spec.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/factory_girl-4.0.0/spec/acceptance/stub_spec.rb
challah-rolls-0.2.0 vendor/bundle/gems/factory_girl-3.6.1/spec/acceptance/stub_spec.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/factory_girl-4.1.0/spec/acceptance/stub_spec.rb
challah-rolls-0.2.0 vendor/bundle/gems/factory_girl-4.1.0/spec/acceptance/stub_spec.rb
challah-0.8.3 vendor/bundle/gems/factory_girl-4.0.0/spec/acceptance/stub_spec.rb
challah-0.8.3 vendor/bundle/gems/factory_girl-4.1.0/spec/acceptance/stub_spec.rb
classiccms-0.6.8 vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/stub_spec.rb
classiccms-0.6.8 vendor/bundle/gems/factory_girl-3.3.0/spec/acceptance/stub_spec.rb
classiccms-0.6.8 vendor/bundle/gems/factory_girl-3.2.0/spec/acceptance/stub_spec.rb
classiccms-0.6.7 vendor/bundle/gems/factory_girl-3.3.0/spec/acceptance/stub_spec.rb
classiccms-0.6.7 vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/stub_spec.rb
classiccms-0.6.7 vendor/bundle/gems/factory_girl-3.2.0/spec/acceptance/stub_spec.rb