Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Supplying a Class to a factory that overrides to_s no longer results …

…in getting the wrong Class constructed
  • Loading branch information...
commit 8b3ee85f81f346902fe7a508824c27e83758f3f3 1 parent 768dfaa
Evan Larkin authored joshuaclayton committed
Showing with 24 additions and 1 deletion.
  1. +5 −1 lib/factory_girl/factory.rb
  2. +19 −0 spec/factory_girl/factory_spec.rb
View
6 lib/factory_girl/factory.rb
@@ -27,7 +27,11 @@ def factory_name
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:
View
19 spec/factory_girl/factory_spec.rb
@@ -116,6 +116,25 @@
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 }
Please sign in to comment.
Something went wrong with that request. Please try again.