Module: FactoryBot::ExampleBot

Includes:
Api::OpenApiHelper
Included in:
FactoryBot
Defined in:
lib/bullet_train/api/example_bot.rb

Constant Summary collapse

REST_METHODS =
%i[get_examples get_example post_example post_parameters put_example put_parameters patch_example patch_parameters]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Api::OpenApiHelper

#automatic_components_for, #automatic_paths_for, #current_model, #for_model, #gem_paths, #indent, #paths_for

Instance Attribute Details

#tables_to_resetObject

Returns the value of attribute tables_to_reset.



5
6
7
# File 'lib/bullet_train/api/example_bot.rb', line 5

def tables_to_reset
  @tables_to_reset
end

Instance Method Details

#example(model) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/bullet_train/api/example_bot.rb', line 7

def example(model, **)
  @tables_to_reset = [model.to_s.pluralize]

  object = nil

  ActiveRecord::Base.transaction do
    instance = FactoryBot.create(factory(model), **)
    object = deep_clone(instance)

    raise ActiveRecord::Rollback
  end

  object
ensure
  reset_tables!
end

#example_list(model, quantity) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bullet_train/api/example_bot.rb', line 24

def example_list(model, quantity, **)
  @tables_to_reset = [model.to_s.pluralize]

  objects = []

  ActiveRecord::Base.transaction do
    instances = FactoryBot.create_list(factory(model), quantity, **)

    instances.each do |instance|
      objects << deep_clone(instance)
    end

    raise ActiveRecord::Rollback
  end

  objects
ensure
  reset_tables!
end