Skip to content

Commit

Permalink
Undef possible method before defining
Browse files Browse the repository at this point in the history
Without these changes, factory_girl causes massive number of warnings:
"warning: method redefined; discarding old ..."
"warning: previous definition of ... was here"
  • Loading branch information
amatsuda authored and joshuaclayton committed Dec 12, 2015
1 parent f5e568e commit 241e8e5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/factory_girl/evaluator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ def self.attribute_list
end

def self.define_attribute(name, &block)
if method_defined?(name) || private_method_defined?(name)
undef_method(name)
end

define_method(name) do
if @cached_attributes.key?(name)
@cached_attributes[name]
Expand Down
4 changes: 4 additions & 0 deletions lib/factory_girl/strategy_syntax_method_registrar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def define_pair_strategy_method

def define_syntax_method(name, &block)
FactoryGirl::Syntax::Methods.module_exec do
if method_defined?(name) || private_method_defined?(name)
undef_method(name)
end

define_method(name, &block)
end
end
Expand Down

0 comments on commit 241e8e5

Please sign in to comment.