File: generate.rb

package info (click to toggle)
ruby-activerecord-import 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 840 kB
  • sloc: ruby: 4,698; makefile: 7
file content (31 lines) | stat: -rw-r--r-- 913 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

class ActiveSupport::TestCase
  def Build(*args) # rubocop:disable Naming/MethodName
    n = args.shift if args.first.is_a?(Numeric)
    factory = args.shift
    factory_bot_args = args.shift || {}

    if n
      [].tap do |collection|
        n.times.each { collection << FactoryBot.build(factory.to_s.singularize.to_sym, factory_bot_args) }
      end
    else
      FactoryBot.build(factory.to_s.singularize.to_sym, factory_bot_args)
    end
  end

  def Generate(*args) # rubocop:disable Naming/MethodName
    n = args.shift if args.first.is_a?(Numeric)
    factory = args.shift
    factory_bot_args = args.shift || {}

    if n
      [].tap do |collection|
        n.times.each { collection << FactoryBot.create(factory.to_s.singularize.to_sym, factory_bot_args) }
      end
    else
      FactoryBot.create(factory.to_s.singularize.to_sym, factory_bot_args)
    end
  end
end