module FactoryGirl
  def self.find_or_create(resource_name, attributes = {}, &block)
    clazz = resource_name.to_s.classify.constantize

    model = clazz.find_by(attributes) || FactoryGirl.build(resource_name, attributes)

    yield(model) if block_given? && model.new_record?

    model.tap(&:save)
  end
end