2010-06-10 13:37:51 -04:00
|
|
|
require 'spec_helper'
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-24 09:45:57 -04:00
|
|
|
describe FactoryGirl::Factory do
|
2010-06-10 14:58:47 -04:00
|
|
|
include DefinesConstants
|
2009-10-30 13:25:47 -04:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
before do
|
|
|
|
@name = :user
|
2010-11-11 16:33:45 -05:00
|
|
|
@class = define_class('User')
|
2010-06-24 09:45:57 -04:00
|
|
|
@factory = FactoryGirl::Factory.new(@name)
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should have a factory name" do
|
2010-10-02 00:00:58 -04:00
|
|
|
@factory.name.should == @name
|
|
|
|
end
|
|
|
|
|
|
|
|
it "responds to factory_name" do
|
2010-06-10 14:58:47 -04:00
|
|
|
@factory.factory_name.should == @name
|
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should have a build class" do
|
|
|
|
@factory.build_class.should == @class
|
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should have a default strategy" do
|
|
|
|
@factory.default_strategy.should == :create
|
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
describe "after adding an attribute" do
|
|
|
|
before do
|
2011-08-12 22:06:10 -04:00
|
|
|
@attribute = stub("attribute", :name => :name, :add_to => nil)
|
|
|
|
@proxy = stub("proxy", :result => "result", :set => nil)
|
2009-06-30 06:32:55 -04:00
|
|
|
|
2011-08-12 22:06:10 -04:00
|
|
|
FactoryGirl::Attribute::Static.stubs(:new => @attribute)
|
|
|
|
FactoryGirl::Proxy::Build.stubs(:new => @proxy)
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
@factory.define_attribute(@attribute)
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should create the right proxy using the build class when running" do
|
2011-08-12 22:06:10 -04:00
|
|
|
FactoryGirl::Proxy::Build.stubs(:new => @proxy)
|
2010-06-24 09:45:57 -04:00
|
|
|
@factory.run(FactoryGirl::Proxy::Build, {})
|
2011-08-12 22:06:10 -04:00
|
|
|
FactoryGirl::Proxy::Build.should have_received(:new).with(@factory.build_class)
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should add the attribute to the proxy when running" do
|
2011-08-12 22:06:10 -04:00
|
|
|
@attribute.stubs(:add_to)
|
2010-06-24 09:45:57 -04:00
|
|
|
@factory.run(FactoryGirl::Proxy::Build, {})
|
2011-08-12 22:06:10 -04:00
|
|
|
@attribute.should have_received(:add_to).with(@proxy)
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should return the result from the proxy when running" do
|
2011-08-12 22:06:10 -04:00
|
|
|
@proxy.stubs(:result => "result")
|
2010-06-24 09:45:57 -04:00
|
|
|
@factory.run(FactoryGirl::Proxy::Build, {}).should == 'result'
|
2011-08-12 22:06:10 -04:00
|
|
|
@proxy.should have_received(:result).with(nil)
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
2010-06-10 14:58:47 -04:00
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-11-12 16:21:16 -05:00
|
|
|
it "passes a custom creation block" do
|
2011-08-12 22:06:10 -04:00
|
|
|
proxy = stub("proxy", :result => nil)
|
|
|
|
FactoryGirl::Proxy::Build.stubs(:new => proxy)
|
2010-11-12 16:21:16 -05:00
|
|
|
block = lambda {}
|
|
|
|
factory = FactoryGirl::Factory.new(:object)
|
|
|
|
factory.to_create(&block)
|
|
|
|
|
|
|
|
factory.run(FactoryGirl::Proxy::Build, {})
|
|
|
|
|
2011-08-12 22:06:10 -04:00
|
|
|
proxy.should have_received(:result).with(block)
|
2010-11-12 16:21:16 -05:00
|
|
|
end
|
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should return associations" do
|
2010-06-24 09:45:57 -04:00
|
|
|
factory = FactoryGirl::Factory.new(:post)
|
2011-05-19 10:56:45 -04:00
|
|
|
FactoryGirl.register_factory(FactoryGirl::Factory.new(:admin))
|
2010-06-24 09:45:57 -04:00
|
|
|
factory.define_attribute(FactoryGirl::Attribute::Association.new(:author, :author, {}))
|
|
|
|
factory.define_attribute(FactoryGirl::Attribute::Association.new(:editor, :editor, {}))
|
2011-05-19 10:56:45 -04:00
|
|
|
factory.define_attribute(FactoryGirl::Attribute::Implicit.new(:admin))
|
2010-06-10 14:58:47 -04:00
|
|
|
factory.associations.each do |association|
|
2011-05-19 10:56:45 -04:00
|
|
|
association.should be_association
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
2011-05-19 10:56:45 -04:00
|
|
|
factory.associations.size.should == 3
|
2010-06-10 14:58:47 -04:00
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should raise for a self referencing association" do
|
2010-06-24 09:45:57 -04:00
|
|
|
factory = FactoryGirl::Factory.new(:post)
|
2010-06-10 14:58:47 -04:00
|
|
|
lambda {
|
2010-06-24 09:45:57 -04:00
|
|
|
factory.define_attribute(FactoryGirl::Attribute::Association.new(:parent, :post, {}))
|
|
|
|
}.should raise_error(FactoryGirl::AssociationDefinitionError)
|
2010-06-10 14:58:47 -04:00
|
|
|
end
|
2009-09-15 16:56:20 -04:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
describe "when overriding generated attributes with a hash" do
|
|
|
|
before do
|
|
|
|
@name = :name
|
|
|
|
@value = 'The price is right!'
|
|
|
|
@hash = { @name => @value }
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should return the overridden value in the generated attributes" do
|
2010-06-24 09:45:57 -04:00
|
|
|
attr = FactoryGirl::Attribute::Static.new(@name, 'The price is wrong, Bob!')
|
2010-06-10 14:58:47 -04:00
|
|
|
@factory.define_attribute(attr)
|
2010-06-24 09:45:57 -04:00
|
|
|
result = @factory.run(FactoryGirl::Proxy::AttributesFor, @hash)
|
2010-06-10 14:58:47 -04:00
|
|
|
result[@name].should == @value
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should not call a lazy attribute block for an overridden attribute" do
|
2010-06-24 09:45:57 -04:00
|
|
|
attr = FactoryGirl::Attribute::Dynamic.new(@name, lambda { flunk })
|
2010-06-10 14:58:47 -04:00
|
|
|
@factory.define_attribute(attr)
|
2010-06-24 09:45:57 -04:00
|
|
|
result = @factory.run(FactoryGirl::Proxy::AttributesFor, @hash)
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should override a symbol parameter with a string parameter" do
|
2010-06-24 09:45:57 -04:00
|
|
|
attr = FactoryGirl::Attribute::Static.new(@name, 'The price is wrong, Bob!')
|
2010-06-10 14:58:47 -04:00
|
|
|
@factory.define_attribute(attr)
|
|
|
|
@hash = { @name.to_s => @value }
|
2010-06-24 09:45:57 -04:00
|
|
|
result = @factory.run(FactoryGirl::Proxy::AttributesFor, @hash)
|
2010-06-10 14:58:47 -04:00
|
|
|
result[@name].should == @value
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
2010-06-10 14:58:47 -04:00
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
describe "overriding an attribute with an alias" do
|
|
|
|
before do
|
2010-06-24 09:45:57 -04:00
|
|
|
@factory.define_attribute(FactoryGirl::Attribute::Static.new(:test, 'original'))
|
2010-06-10 14:58:47 -04:00
|
|
|
Factory.alias(/(.*)_alias/, '\1')
|
2010-06-24 09:45:57 -04:00
|
|
|
@result = @factory.run(FactoryGirl::Proxy::AttributesFor,
|
2010-06-10 14:58:47 -04:00
|
|
|
:test_alias => 'new')
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should use the passed in value for the alias" do
|
|
|
|
@result[:test_alias].should == 'new'
|
2009-09-15 15:47:47 -04:00
|
|
|
end
|
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should discard the predefined value for the attribute" do
|
|
|
|
@result[:test].should be_nil
|
2009-09-15 15:47:47 -04:00
|
|
|
end
|
2010-06-10 14:58:47 -04:00
|
|
|
end
|
2009-09-15 15:47:47 -04:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should guess the build class from the factory name" do
|
|
|
|
@factory.build_class.should == User
|
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should create a new factory using the class of the parent" do
|
2010-06-24 09:45:57 -04:00
|
|
|
child = FactoryGirl::Factory.new(:child)
|
2010-06-10 14:58:47 -04:00
|
|
|
child.inherit_from(@factory)
|
|
|
|
child.build_class.should == @factory.build_class
|
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should create a new factory while overriding the parent class" do
|
2010-06-24 09:45:57 -04:00
|
|
|
child = FactoryGirl::Factory.new(:child, :class => String)
|
2010-06-10 14:58:47 -04:00
|
|
|
child.inherit_from(@factory)
|
|
|
|
child.build_class.should == String
|
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
describe "given a parent with attributes" do
|
|
|
|
before do
|
|
|
|
@parent_attr = :name
|
2010-06-24 09:45:57 -04:00
|
|
|
@factory.define_attribute(FactoryGirl::Attribute::Static.new(@parent_attr, 'value'))
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should create a new factory with attributes of the parent" do
|
2010-06-24 09:45:57 -04:00
|
|
|
child = FactoryGirl::Factory.new(:child)
|
2010-06-10 14:58:47 -04:00
|
|
|
child.inherit_from(@factory)
|
|
|
|
child.attributes.size.should == 1
|
|
|
|
child.attributes.first.name.should == @parent_attr
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should allow a child to define additional attributes" do
|
2010-06-24 09:45:57 -04:00
|
|
|
child = FactoryGirl::Factory.new(:child)
|
|
|
|
child.define_attribute(FactoryGirl::Attribute::Static.new(:email, 'value'))
|
2010-06-10 14:58:47 -04:00
|
|
|
child.inherit_from(@factory)
|
|
|
|
child.attributes.size.should == 2
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should allow to override parent attributes" do
|
2010-06-24 09:45:57 -04:00
|
|
|
child = FactoryGirl::Factory.new(:child)
|
|
|
|
@child_attr = FactoryGirl::Attribute::Static.new(@parent_attr, 'value')
|
2010-06-10 14:58:47 -04:00
|
|
|
child.define_attribute(@child_attr)
|
|
|
|
child.inherit_from(@factory)
|
|
|
|
child.attributes.size.should == 1
|
|
|
|
child.attributes.first.should == @child_attr
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
2010-09-03 12:07:37 -04:00
|
|
|
|
|
|
|
it "should allow to use parent attributes in defining additional attributes" do
|
|
|
|
User.class_eval { attr_accessor :name, :email }
|
|
|
|
|
|
|
|
child = FactoryGirl::Factory.new(:child)
|
|
|
|
@child_attr = FactoryGirl::Attribute::Dynamic.new(:email, lambda {|u| "#{u.name}@example.com"})
|
|
|
|
child.define_attribute(@child_attr)
|
|
|
|
child.inherit_from(@factory)
|
|
|
|
child.attributes.size.should == 2
|
|
|
|
|
|
|
|
result = child.run(FactoryGirl::Proxy::Build, {})
|
|
|
|
result.email.should == 'value@example.com'
|
|
|
|
end
|
2010-06-10 14:58:47 -04:00
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "inherit all callbacks" do
|
|
|
|
@factory.add_callback(:after_stub) { |object| object.name = 'Stubby' }
|
2010-06-24 09:45:57 -04:00
|
|
|
child = FactoryGirl::Factory.new(:child)
|
2010-06-10 14:58:47 -04:00
|
|
|
child.inherit_from(@factory)
|
2010-06-24 09:45:57 -04:00
|
|
|
child.attributes.last.should be_kind_of(FactoryGirl::Attribute::Callback)
|
2010-06-10 14:58:47 -04:00
|
|
|
end
|
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-24 09:45:57 -04:00
|
|
|
describe FactoryGirl::Factory, "when defined with a custom class" do
|
2010-06-10 14:58:47 -04:00
|
|
|
before do
|
|
|
|
@class = Float
|
2010-06-24 09:45:57 -04:00
|
|
|
@factory = FactoryGirl::Factory.new(:author, :class => @class)
|
2010-06-10 14:58:47 -04:00
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should use the specified class as the build class" do
|
|
|
|
@factory.build_class.should == @class
|
|
|
|
end
|
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-24 09:45:57 -04:00
|
|
|
describe FactoryGirl::Factory, "when defined with a class instead of a name" do
|
2010-06-10 14:58:47 -04:00
|
|
|
before do
|
|
|
|
@class = ArgumentError
|
|
|
|
@name = :argument_error
|
2010-06-24 09:45:57 -04:00
|
|
|
@factory = FactoryGirl::Factory.new(@class)
|
2010-06-10 14:58:47 -04:00
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should guess the name from the class" do
|
2010-10-02 00:00:58 -04:00
|
|
|
@factory.name.should == @name
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should use the class as the build class" do
|
|
|
|
@factory.build_class.should == @class
|
|
|
|
end
|
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-24 09:45:57 -04:00
|
|
|
describe FactoryGirl::Factory, "when defined with a custom class name" do
|
2010-06-10 14:58:47 -04:00
|
|
|
before do
|
|
|
|
@class = ArgumentError
|
2010-06-24 09:45:57 -04:00
|
|
|
@factory = FactoryGirl::Factory.new(:author, :class => :argument_error)
|
2010-06-10 14:58:47 -04:00
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should use the specified class as the build class" do
|
|
|
|
@factory.build_class.should == @class
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
2010-06-10 14:58:47 -04:00
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-24 09:45:57 -04:00
|
|
|
describe FactoryGirl::Factory, "with a name ending in s" do
|
2010-06-10 14:58:47 -04:00
|
|
|
include DefinesConstants
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
before do
|
2010-11-11 16:33:45 -05:00
|
|
|
define_class('Business')
|
2010-06-10 14:58:47 -04:00
|
|
|
@name = :business
|
|
|
|
@class = Business
|
2010-06-24 09:45:57 -04:00
|
|
|
@factory = FactoryGirl::Factory.new(@name)
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should have a factory name" do
|
2010-10-02 00:00:58 -04:00
|
|
|
@factory.name.should == @name
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should have a build class" do
|
|
|
|
@factory.build_class.should == @class
|
|
|
|
end
|
|
|
|
end
|
2010-03-17 18:49:35 -04:00
|
|
|
|
2010-06-24 09:45:57 -04:00
|
|
|
describe FactoryGirl::Factory, "with a string for a name" do
|
2010-06-10 14:58:47 -04:00
|
|
|
before do
|
|
|
|
@name = :string
|
2010-06-24 09:45:57 -04:00
|
|
|
@factory = FactoryGirl::Factory.new(@name.to_s) {}
|
2010-06-10 14:58:47 -04:00
|
|
|
end
|
2010-03-17 18:49:35 -04:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should convert the string to a symbol" do
|
2010-10-02 00:00:58 -04:00
|
|
|
@factory.name.should == @name
|
2010-03-17 18:49:35 -04:00
|
|
|
end
|
2010-06-10 14:58:47 -04:00
|
|
|
end
|
2010-03-17 18:49:35 -04:00
|
|
|
|
2010-06-24 09:45:57 -04:00
|
|
|
describe FactoryGirl::Factory, "for namespaced class" do
|
2010-06-10 14:58:47 -04:00
|
|
|
include DefinesConstants
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
before do
|
2010-11-11 16:33:45 -05:00
|
|
|
define_class('Admin')
|
|
|
|
define_class('Admin::Settings')
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
@name = :settings
|
|
|
|
@class = Admin::Settings
|
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should build namespaced class passed by string" do
|
2010-06-24 09:45:57 -04:00
|
|
|
factory = FactoryGirl::Factory.new(@name.to_s, :class => @class.name)
|
2010-06-10 14:58:47 -04:00
|
|
|
factory.build_class.should == @class
|
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should build Admin::Settings class from Admin::Settings string" do
|
2010-06-24 09:45:57 -04:00
|
|
|
factory = FactoryGirl::Factory.new(@name.to_s, :class => 'admin/settings')
|
2010-06-10 14:58:47 -04:00
|
|
|
factory.build_class.should == @class
|
|
|
|
end
|
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-24 09:45:57 -04:00
|
|
|
describe FactoryGirl::Factory do
|
2010-06-10 14:58:47 -04:00
|
|
|
include DefinesConstants
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
before do
|
2010-11-11 16:33:45 -05:00
|
|
|
define_class('User')
|
|
|
|
define_class('Admin', User)
|
2010-06-10 14:58:47 -04:00
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should raise an ArgumentError when trying to use a non-existent strategy" do
|
|
|
|
lambda {
|
2010-06-24 09:45:57 -04:00
|
|
|
FactoryGirl::Factory.new(:object, :default_strategy => :nonexistent) {}
|
2010-06-10 14:58:47 -04:00
|
|
|
}.should raise_error(ArgumentError)
|
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should create a new factory with a specified default strategy" do
|
2010-06-24 09:45:57 -04:00
|
|
|
factory = FactoryGirl::Factory.new(:object, :default_strategy => :stub)
|
2010-06-10 14:58:47 -04:00
|
|
|
factory.default_strategy.should == :stub
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
describe 'defining a child factory without setting default strategy' do
|
2009-04-11 11:27:23 -04:00
|
|
|
before do
|
2010-06-24 09:45:57 -04:00
|
|
|
@parent = FactoryGirl::Factory.new(:object, :default_strategy => :stub)
|
|
|
|
@child = FactoryGirl::Factory.new(:child_object)
|
2010-06-10 14:58:47 -04:00
|
|
|
@child.inherit_from(@parent)
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should inherit default strategy from its parent" do
|
|
|
|
@child.default_strategy.should == :stub
|
2009-10-10 01:23:57 -04:00
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
describe 'defining a child factory with a default strategy' do
|
|
|
|
before do
|
2010-06-24 09:45:57 -04:00
|
|
|
@parent = FactoryGirl::Factory.new(:object, :default_strategy => :stub)
|
|
|
|
@child = FactoryGirl::Factory.new(:child_object2, :default_strategy => :build)
|
2010-06-10 14:58:47 -04:00
|
|
|
@child.inherit_from(@parent)
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
2010-01-08 00:07:41 -05:00
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
it "should override the default strategy from parent" do
|
|
|
|
@child.default_strategy.should == :build
|
2010-01-08 00:07:41 -05:00
|
|
|
end
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
|
2010-06-10 14:58:47 -04:00
|
|
|
end
|
|
|
|
|
2011-06-30 18:27:25 -04:00
|
|
|
describe FactoryGirl::Factory, "human names" do
|
|
|
|
context "factory name without underscores" do
|
|
|
|
subject { FactoryGirl::Factory.new("user") }
|
|
|
|
its(:human_names) { should == ["user"] }
|
|
|
|
end
|
2010-10-02 00:00:58 -04:00
|
|
|
|
2011-06-30 18:27:25 -04:00
|
|
|
context "factory name with underscores" do
|
|
|
|
subject { FactoryGirl::Factory.new("happy_user") }
|
|
|
|
its(:human_names) { should == ["happy user"] }
|
2010-10-02 00:00:58 -04:00
|
|
|
end
|
|
|
|
|
2011-06-30 18:27:25 -04:00
|
|
|
context "factory name with aliases" do
|
|
|
|
subject { FactoryGirl::Factory.new("happy_user", :aliases => ["gleeful_user", "person"]) }
|
|
|
|
its(:human_names) { should == ["happy user", "gleeful user", "person"] }
|
|
|
|
end
|
|
|
|
end
|
2010-11-11 17:34:01 -05:00
|
|
|
|
|
|
|
describe FactoryGirl::Factory, "with aliases" do
|
|
|
|
it "registers the aliases" do
|
2011-01-25 17:55:40 -05:00
|
|
|
name = :user
|
2010-11-11 17:34:01 -05:00
|
|
|
aliased_name = :guest
|
2011-01-25 17:55:40 -05:00
|
|
|
factory = FactoryGirl::Factory.new(:user, :aliases => [aliased_name])
|
|
|
|
factory.names.should =~ [name, aliased_name]
|
2010-11-11 17:34:01 -05:00
|
|
|
end
|
2011-06-30 18:27:25 -04:00
|
|
|
|
|
|
|
it "has human names" do
|
|
|
|
name = :user
|
|
|
|
aliased_name = :guest
|
|
|
|
factory = FactoryGirl::Factory.new(:user, :aliases => [aliased_name])
|
|
|
|
factory.human_names.should =~ [name.to_s, aliased_name.to_s]
|
|
|
|
end
|
2010-11-11 17:34:01 -05:00
|
|
|
end
|