mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
Undef possible method before defining
Without these changes, factory_girl causes massive number of warnings: "warning: method redefined; discarding old ..." "warning: previous definition of ... was here"
This commit is contained in:
parent
f5e568e47e
commit
241e8e5fb4
2 changed files with 8 additions and 0 deletions
|
@ -64,6 +64,10 @@ module FactoryGirl
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.define_attribute(name, &block)
|
def self.define_attribute(name, &block)
|
||||||
|
if method_defined?(name) || private_method_defined?(name)
|
||||||
|
undef_method(name)
|
||||||
|
end
|
||||||
|
|
||||||
define_method(name) do
|
define_method(name) do
|
||||||
if @cached_attributes.key?(name)
|
if @cached_attributes.key?(name)
|
||||||
@cached_attributes[name]
|
@cached_attributes[name]
|
||||||
|
|
|
@ -39,6 +39,10 @@ module FactoryGirl
|
||||||
|
|
||||||
def define_syntax_method(name, &block)
|
def define_syntax_method(name, &block)
|
||||||
FactoryGirl::Syntax::Methods.module_exec do
|
FactoryGirl::Syntax::Methods.module_exec do
|
||||||
|
if method_defined?(name) || private_method_defined?(name)
|
||||||
|
undef_method(name)
|
||||||
|
end
|
||||||
|
|
||||||
define_method(name, &block)
|
define_method(name, &block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue