1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00

Fix FactoryGirl::Decorator#send to pass blocks

Why?

When the decorated @component is also a decorated object, and
FactoryGirl::Decorator#method_missing calls @component#send and a block
is present, the block needs to be sent appropriately.

Closes #816
This commit is contained in:
Joshua Clayton 2016-02-06 00:31:26 -05:00
parent ad646723e4
commit ee6caa2a6b
2 changed files with 22 additions and 2 deletions

View file

@ -10,8 +10,8 @@ module FactoryGirl
@component.send(name, *args, &block)
end
def send(symbol, *args)
__send__(symbol, *args)
def send(symbol, *args, &block)
__send__(symbol, *args, &block)
end
def self.const_missing(name)

View file

@ -215,3 +215,23 @@ describe "initialize_with has access to all attributes for construction" do
expect(user_with_attributes.ignored).to be_nil
end
end
describe "initialize_with for a constructor that requires a block" do
it "executes the block correctly" do
define_class("Awesome") do
attr_reader :output
def initialize(&block)
@output = instance_exec(&block)
end
end
FactoryGirl.define do
factory :awesome do
initialize_with { new { "Output" } }
end
end
expect(FactoryGirl.build(:awesome).output).to eq "Output"
end
end