Skip to content

Commit

Permalink
Undefine most private methods on DefinitionProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
jferris committed Jul 5, 2011
1 parent 3f15c23 commit 289ba43
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions 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
Expand Down
5 changes: 5 additions & 0 deletions spec/factory_girl/definition_proxy_spec.rb
Expand Up @@ -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 == [] }

Expand Down

0 comments on commit 289ba43

Please sign in to comment.