Sha256: 18fbc1f319467515d802c4c95c8e6b4ade13caee2cb565e1f3f5a9a9187b2a42

Contents?: true

Size: 1.26 KB

Versions: 28

Compression:

Stored size: 1.26 KB

Contents

require 'spec_helper'

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

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

    let(:evaluation)  { stub("evaluation", object: result_instance, notify: true) }

    it { subject.result(evaluation).should_not be_new_record }
    it { subject.result(evaluation).should be_persisted }

    it "assigns created_at" do
      created_at = subject.result(evaluation).created_at
      created_at.should == Time.now

      Timecop.travel(150000)

      subject.result(evaluation).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(evaluation).send(database_method)
        end.to raise_error(RuntimeError, "stubbed models are not allowed to access the database")
      end
    end
  end
end

Version data entries

28 entries across 20 versions & 4 rubygems

Version Path
challah-1.0.0.beta vendor/bundle/gems/factory_girl-4.1.0/spec/factory_girl/strategy/stub_spec.rb
challah-0.9.1.beta.3 vendor/bundle/gems/factory_girl-4.1.0/spec/factory_girl/strategy/stub_spec.rb
challah-0.9.1.beta vendor/bundle/gems/factory_girl-4.1.0/spec/factory_girl/strategy/stub_spec.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/factory_girl-4.1.0/spec/factory_girl/strategy/stub_spec.rb
challah-0.9.0 vendor/bundle/gems/factory_girl-4.1.0/spec/factory_girl/strategy/stub_spec.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/factory_girl-4.0.0/spec/factory_girl/strategy/stub_spec.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/factory_girl-4.1.0/spec/factory_girl/strategy/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/factory_girl/strategy/stub_spec.rb
challah-rolls-0.2.0 vendor/bundle/gems/factory_girl-3.6.1/spec/factory_girl/strategy/stub_spec.rb
challah-rolls-0.2.0 vendor/bundle/gems/factory_girl-4.0.0/spec/factory_girl/strategy/stub_spec.rb
challah-rolls-0.2.0 vendor/bundle/gems/factory_girl-4.1.0/spec/factory_girl/strategy/stub_spec.rb
challah-0.8.3 vendor/bundle/gems/factory_girl-4.1.0/spec/factory_girl/strategy/stub_spec.rb
challah-0.8.3 vendor/bundle/gems/factory_girl-4.0.0/spec/factory_girl/strategy/stub_spec.rb
factory_girl-3.6.2 spec/factory_girl/strategy/stub_spec.rb
challah-0.8.1 vendor/bundle/gems/factory_girl-4.0.0/spec/factory_girl/strategy/stub_spec.rb
factory_girl-4.1.0 spec/factory_girl/strategy/stub_spec.rb
challah-rolls-0.1.0 vendor/bundle/gems/factory_girl-3.6.1/spec/factory_girl/strategy/stub_spec.rb
challah-rolls-0.1.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/factory_girl-3.6.1/spec/factory_girl/strategy/stub_spec.rb
challah-rolls-0.1.0 vendor/bundle/gems/factory_girl-4.0.0/spec/factory_girl/strategy/stub_spec.rb
challah-0.8.0.pre vendor/bundle/gems/factory_girl-3.6.1/spec/factory_girl/strategy/stub_spec.rb