Supplying a Class to a factory that overrides to_s no longer results in getting the wrong Class constructed
This commit is contained in:
parent
768dfaa730
commit
8b3ee85f81
|
@ -27,7 +27,11 @@ module FactoryGirl
|
|||
end
|
||||
|
||||
def build_class #:nodoc:
|
||||
@build_class ||= class_name.to_s.camelize.constantize
|
||||
@build_class ||= if class_name.is_a? Class
|
||||
class_name
|
||||
else
|
||||
class_name.to_s.camelize.constantize
|
||||
end
|
||||
end
|
||||
|
||||
def default_strategy #:nodoc:
|
||||
|
|
|
@ -116,6 +116,25 @@ describe FactoryGirl::Factory, "when defined with a custom class" do
|
|||
its(:build_class) { should == Float }
|
||||
end
|
||||
|
||||
describe FactoryGirl::Factory, "when given a class that overrides #to_s" do
|
||||
let(:overriding_class) { Overriding::Class }
|
||||
|
||||
before do
|
||||
define_class("Overriding")
|
||||
define_class("Overriding::Class") do
|
||||
def self.to_s
|
||||
"Overriding"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
subject { FactoryGirl::Factory.new(:overriding_class, :class => Overriding::Class) }
|
||||
|
||||
it "sets build_class correctly" do
|
||||
subject.build_class.should == overriding_class
|
||||
end
|
||||
end
|
||||
|
||||
describe FactoryGirl::Factory, "when defined with a class instead of a name" do
|
||||
let(:factory_class) { ArgumentError }
|
||||
let(:name) { :argument_error }
|
||||
|
|
Loading…
Reference in New Issue