Sha256: 9112ef562d9aa7ea985e6f65973b74d02fc08d20a37ce3bb5fa7dcb84d4c5c78

Contents?: true

Size: 1.29 KB

Versions: 60

Compression:

Stored size: 1.29 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) }
    after  { Timecop.return }
    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

60 entries across 59 versions & 4 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/strategy/stub_spec.rb
classiccms-0.7.4 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/strategy/stub_spec.rb
classiccms-0.7.3 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/strategy/stub_spec.rb
classiccms-0.7.2 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/strategy/stub_spec.rb
classiccms-0.7.1 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/strategy/stub_spec.rb
classiccms-0.7.0 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/strategy/stub_spec.rb
classiccms-0.6.9 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/strategy/stub_spec.rb
classiccms-0.6.8 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/strategy/stub_spec.rb
classiccms-0.6.7 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/strategy/stub_spec.rb
classiccms-0.6.6 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/strategy/stub_spec.rb
classiccms-0.6.5 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/strategy/stub_spec.rb
classiccms-0.6.4 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/strategy/stub_spec.rb
classiccms-0.6.3 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/strategy/stub_spec.rb
classiccms-0.6.2 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/strategy/stub_spec.rb
classiccms-0.6.1 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/strategy/stub_spec.rb
classiccms-0.6.0 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/strategy/stub_spec.rb
classiccms-0.5.17 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/strategy/stub_spec.rb
classiccms-0.5.16 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/strategy/stub_spec.rb
classiccms-0.5.15 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/strategy/stub_spec.rb
classiccms-0.5.14 vendor/bundle/gems/factory_girl-3.3.0/spec/factory_girl/strategy/stub_spec.rb