Sha256: 3ea0d9f4ae5cacc9343010adc5dcfaab7e0390820ff34de447ba0307e68cd27b

Contents?: true

Size: 1.41 KB

Versions: 13

Compression:

Stored size: 1.41 KB

Contents

require 'spec_helper'

describe FactoryGirl::Strategy::Stub do
  it_should_behave_like "strategy with association support", FactoryGirl::Strategy::Stub
  it_should_behave_like "strategy with callbacks", :after_stub
  it_should_behave_like "strategy with :strategy => :build", FactoryGirl::Strategy::Stub

  context "asking for a result" do
    before { Timecop.freeze(Time.now) }
    after  { Timecop.return }
    let(:result_instance) do
      define_class("ResultInstance") do
        attr_accessor :id
      end.new
    end

    let(:assigner)  { stub("attribute assigner", :object => result_instance) }
    let(:to_create) { lambda {|instance| instance } }

    it { subject.result(assigner, to_create).should_not be_new_record }
    it { subject.result(assigner, to_create).should be_persisted }

    it "assigns created_at" do
      created_at = subject.result(assigner, to_create).created_at
      created_at.should == Time.now

      Timecop.travel(150000)

      subject.result(assigner, to_create).created_at.should == created_at
    end

    [:save, :destroy, :connection, :reload, :update_attribute].each do |database_method|
      it "raises when attempting to connect to the database by calling #{database_method}" do
        expect do
          subject.result(assigner, to_create).send(database_method)
        end.to raise_error(RuntimeError, "stubbed models are not allowed to access the database")
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/factory_girl-2.6.4/spec/factory_girl/strategy/stub_spec.rb
challah-0.6.2 vendor/bundle/gems/factory_girl-2.6.1/spec/factory_girl/strategy/stub_spec.rb
challah-0.6.1 vendor/bundle/gems/factory_girl-2.6.1/spec/factory_girl/strategy/stub_spec.rb
challah-0.6.0 vendor/bundle/gems/factory_girl-2.6.1/spec/factory_girl/strategy/stub_spec.rb
challah-0.5.4 vendor/bundle/gems/factory_girl-2.6.1/spec/factory_girl/strategy/stub_spec.rb
challah-0.5.3 vendor/bundle/gems/factory_girl-2.6.1/spec/factory_girl/strategy/stub_spec.rb
challah-0.5.2 vendor/bundle/gems/factory_girl-2.6.1/spec/factory_girl/strategy/stub_spec.rb
factory_girl-2.6.4 spec/factory_girl/strategy/stub_spec.rb
factory_girl-2.6.3 spec/factory_girl/strategy/stub_spec.rb
factory_girl-2.6.2 spec/factory_girl/strategy/stub_spec.rb
challah-0.5.1 vendor/bundle/gems/factory_girl-2.6.1/spec/factory_girl/strategy/stub_spec.rb
factory_girl-2.6.1 spec/factory_girl/strategy/stub_spec.rb
factory_girl-2.6.0 spec/factory_girl/strategy/stub_spec.rb