mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
7722017bc7
Uses a block-based helper so we can remove a global around hook.
14 lines
407 B
Ruby
14 lines
407 B
Ruby
module TemporaryAssignment
|
|
def with_temporary_assignment(assignee, attribute, temporary_value)
|
|
original_value = assignee.public_send(attribute)
|
|
attribute_setter = "#{attribute}="
|
|
assignee.public_send(attribute_setter, temporary_value)
|
|
yield
|
|
ensure
|
|
assignee.public_send(attribute_setter, original_value)
|
|
end
|
|
end
|
|
|
|
RSpec.configure do |config|
|
|
config.include TemporaryAssignment
|
|
end
|