Skip to content
Browse files

Undefine most private methods on Evaluator

When method_missing is used with Evaluator, certain methods (namely
private methods from Object) may register as being defined, which we
don't want.

Closes #279, #285
  • Loading branch information...
1 parent 0d67a42 commit 5f95b967900c8c5bd03ecedfe222edb5b06e2c82 @joshuaclayton joshuaclayton committed
Showing with 14 additions and 5 deletions.
  1. +5 −0 lib/factory_girl/evaluator.rb
  2. +9 −5 spec/acceptance/attribute_existing_on_object_spec.rb
View
5 lib/factory_girl/evaluator.rb
@@ -11,6 +11,11 @@ def self.attribute_list
end
end
end
+
+ private_instance_methods.each do |method|
+ undef_method(method) unless method =~ /^__|initialize/
+ end
+
undef_method(:id) if method_defined?(:id)
def initialize(build_strategy, overrides = {})
View
14 spec/acceptance/attribute_existing_on_object_spec.rb
@@ -2,20 +2,24 @@
describe "declaring attributes on a Factory that are private methods on Object" do
before do
- define_model("Website", :system => :boolean, :link => :string, :sleep => :integer)
+ define_model("Website", :system => :boolean, :link => :string, :sleep => :integer, :format => :string, :y => :integer, :more_format => :string)
FactoryGirl.define do
factory :website do
system false
link "http://example.com"
sleep 15
+ more_format { "format: #{format}" }
end
end
end
- subject { FactoryGirl.build(:website, :sleep => -5) }
+ subject { FactoryGirl.build(:website, :sleep => -5, :format => "Great", :y => 12345) }
- its(:system) { should == false }
- its(:link) { should == "http://example.com" }
- its(:sleep) { should == -5 }
+ its(:system) { should == false }
+ its(:link) { should == "http://example.com" }
+ its(:sleep) { should == -5 }
+ its(:format) { should == "Great" }
+ its(:y) { should == 12345 }
+ its(:more_format) { should == "format: Great" }
end

0 comments on commit 5f95b96

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