Sha256: fd044194a02900973d2b8f357869861e2c0329cbea9573936468161e0e96d0ae

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

require 'spec_helper'

describe FactoryGirl::Declaration::Implicit do
  let(:name)      { :author }
  let(:proxy)     { stub("proxy") }
  subject         { FactoryGirl::Declaration::Implicit.new(name) }
  let(:attribute) { subject.to_attributes.first }

  context "with a known factory" do
    before do
      FactoryGirl.factories.stubs(:registered? => true)
    end

    it "generates an association" do
      attribute.should be_association
    end

    it "generates an association with the correct factory" do
      attribute.factory.should == name
    end

    it "associates the factory" do
      proxy.stubs(:associate)
      attribute.add_to(proxy)
      proxy.should have_received(:associate).with(name, name, {})
    end
  end

  context "with a known sequence" do
    let(:sequence) { FactoryGirl::Sequence.new(name, 1) { "magic" } }
    before         { FactoryGirl.register_sequence(sequence) }

    it "doesn't generate an association" do
      attribute.should_not be_association
    end

    it "generates the sequence" do
      proxy.stubs(:set)
      attribute.add_to(proxy)
      proxy.should have_received(:set).with(name, "magic")
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
factory_girl-2.3.0 spec/factory_girl/declaration/implicit_spec.rb
factory_girl-2.2.0 spec/factory_girl/declaration/implicit_spec.rb
factory_girl-2.1.2 spec/factory_girl/declaration/implicit_spec.rb