Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module FactoryBot
- module Syntax
- module Methods
- def find_or_create(name, *attributes, &block)
- attributes = FactoryBot.attributes_for(name, *attributes)
- klass = FactoryBot.factory_by_name(name).build_class
- enums = klass.defined_enums
- find_attributes = attributes.clone
- find_attributes.keys.each do |key|
- find_attributes[key] = enums[key.to_s][find_attributes[key]] if enums.has_key?(key.to_s)
- end
- result = klass.find_by(find_attributes, &block)
- result || FactoryBot.create(name, attributes, &block)
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment