Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/factory_bot/definition_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def method_missing(name, *args, &block) # rubocop:disable Style/MissingRespondTo
if association_options.nil?
__declare_attribute__(name, block)
elsif __valid_association_options?(association_options)
association(name, association_options)
association(name, association_options, &block)
else
raise NoMethodError.new(<<~MSG)
undefined method '#{name}' in '#{@definition.name}' factory
Expand Down
13 changes: 13 additions & 0 deletions spec/factory_bot/definition_proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@
"Did you mean? 'static_attributes_are_gone { \"true\" }'\n"
)
end

it "raises an AssociationDefinitionError when called with a `:factory`-key and providing a block" do
definition = FactoryBot::Definition.new(:user)
proxy = FactoryBot::DefinitionProxy.new(definition)
invalid_call = lambda do
proxy.author(factory: :user) { :this_should_raise_an_error }
end

expect(invalid_call).to raise_error(
FactoryBot::AssociationDefinitionError,
"Unexpected block passed to 'author' association in 'user' factory"
)
end
end

describe FactoryBot::DefinitionProxy, "#sequence" do
Expand Down