Skip to content
Browse files

Undefine most private methods on DefinitionProxy

  • Loading branch information...
1 parent 3f15c23 commit 289ba4316ef90c638d2075fed39cda04a783741e @jferris jferris committed Jul 5, 2011
Showing with 9 additions and 2 deletions.
  1. +4 −2 lib/factory_girl/definition_proxy.rb
  2. +5 −0 spec/factory_girl/definition_proxy_spec.rb
View
6 lib/factory_girl/definition_proxy.rb
@@ -1,7 +1,9 @@
module FactoryGirl
class DefinitionProxy
- instance_methods.each do |method|
- undef_method(method) unless method =~ /(^__|^nil\?$|^send$|^object_id$|^extend$|^instance_eval$)/
+ UNPROXIED_METHODS = %w(__send__ nil? send object_id extend instance_eval initialize block_given? raise)
+
+ (instance_methods + private_instance_methods).each do |method|
+ undef_method(method) unless UNPROXIED_METHODS.include?(method)
end
attr_reader :child_factories
View
5 spec/factory_girl/definition_proxy_spec.rb
@@ -37,6 +37,11 @@
}.should raise_error(FactoryGirl::AttributeDefinitionError)
end
+ it "should add an attribute with a built-in private method" do
+ subject.instance_eval { sleep(0.1) }
+ factory.attributes.map { |attribute| attribute.name }.should == [:sleep]
+ end
+
describe "child factories" do
its(:child_factories) { should == [] }

2 comments on commit 289ba43

@itspriddle

This commit generates warnings under ruby 1.9.2-p180:

factory_girl-2.0.0.rc3/lib/factory_girl/definition_proxy.rb:6: warning: undefining `object_id' may cause serious problems
factory_girl-2.0.0.rc3/lib/factory_girl/definition_proxy.rb:6: warning: undefining `__send__' may cause serious problems
factory_girl-2.0.0.rc3/lib/factory_girl/definition_proxy.rb:6: warning: undefining `initialize' may cause serious problems

Any way to silence these?

@jferris
thoughtbot, inc. member
jferris commented on 289ba43 Jul 6, 2011

There's already a bug for this, and it will be fixed before the 2.0.0 stable release.

Please sign in to comment.
Something went wrong with that request. Please try again.