Sha256: 7248aae76902c819af761beacde8f0e4cf945106199838f5bd4541d04ff34a90

Contents?: true

Size: 1.54 KB

Versions: 113

Compression:

Stored size: 1.54 KB

Contents

require 'spec_helper'

describe "callbacks" do
  before do
    define_model("User", first_name: :string, last_name: :string)

    FactoryGirl.define do
      factory :user_with_callbacks, class: :user do
        after_stub   { |user| user.first_name = 'Stubby' }
        after_build  { |user| user.first_name = 'Buildy' }
        after_create { |user| user.last_name  = 'Createy' }
      end

      factory :user_with_inherited_callbacks, parent: :user_with_callbacks do
        after_stub  { |user| user.last_name  = 'Double-Stubby' }
        after_build { |user| user.first_name = 'Child-Buildy' }
      end
    end
  end

  it "runs the after_stub callback when stubbing" do
    user = FactoryGirl.build_stubbed(:user_with_callbacks)
    user.first_name.should == 'Stubby'
  end

  it "runs the after_build callback when building" do
    user = FactoryGirl.build(:user_with_callbacks)
    user.first_name.should == 'Buildy'
  end

  it "runs both the after_build and after_create callbacks when creating" do
    user = FactoryGirl.create(:user_with_callbacks)
    user.first_name.should == 'Buildy'
    user.last_name.should == 'Createy'
  end

  it "runs both the after_stub callback on the factory and the inherited after_stub callback" do
    user = FactoryGirl.build_stubbed(:user_with_inherited_callbacks)
    user.first_name.should == 'Stubby'
    user.last_name.should == 'Double-Stubby'
  end

  it "runs child callback after parent callback" do
    user = FactoryGirl.build(:user_with_inherited_callbacks)
    user.first_name.should == 'Child-Buildy'
  end
end

Version data entries

113 entries across 67 versions & 6 rubygems

Version Path
classiccms-0.5.1 vendor/bundle/gems/factory_girl-3.2.0/spec/acceptance/callbacks_spec.rb
classiccms-0.5.1 vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/callbacks_spec.rb
classiccms-0.5.0 vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/callbacks_spec.rb
classiccms-0.5.0 vendor/bundle/gems/factory_girl-3.2.0/spec/acceptance/callbacks_spec.rb
classiccms-0.4.2 vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/callbacks_spec.rb
classiccms-0.4.2 vendor/bundle/gems/factory_girl-3.2.0/spec/acceptance/callbacks_spec.rb
classiccms-0.4.1 vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/callbacks_spec.rb
classiccms-0.4.1 vendor/bundle/gems/factory_girl-3.2.0/spec/acceptance/callbacks_spec.rb
classiccms-0.4.0 vendor/bundle/gems/factory_girl-3.2.0/spec/acceptance/callbacks_spec.rb
classiccms-0.4.0 vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/callbacks_spec.rb
classiccms-0.3.9 vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/callbacks_spec.rb
classiccms-0.3.9 vendor/bundle/gems/factory_girl-3.2.0/spec/acceptance/callbacks_spec.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/factory_girl-3.2.0/spec/acceptance/callbacks_spec.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/factory_girl-3.2.0/spec/acceptance/callbacks_spec.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/factory_girl-3.2.0/spec/acceptance/callbacks_spec.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/factory_girl-3.2.0/spec/acceptance/callbacks_spec.rb
rails-uploader-0.0.4 vendor/bundle/ruby/1.9.1/gems/factory_girl-3.2.0/spec/acceptance/callbacks_spec.rb
classiccms-0.3.8 vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/callbacks_spec.rb
classiccms-0.3.8 vendor/bundle/gems/factory_girl-3.2.0/spec/acceptance/callbacks_spec.rb
challah-0.6.1 vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/callbacks_spec.rb