From 45de06af4f889af5c080734464d9b7c045233280 Mon Sep 17 00:00:00 2001 From: Jeremy Green Date: Tue, 5 Sep 2023 16:03:41 -0500 Subject: [PATCH] Remove remnants of resetting tables --- .../lib/bullet_train/api/example_bot.rb | 55 +------------------ 1 file changed, 2 insertions(+), 53 deletions(-) diff --git a/bullet_train-api/lib/bullet_train/api/example_bot.rb b/bullet_train-api/lib/bullet_train/api/example_bot.rb index 1075172a1..7a6bc6e6f 100644 --- a/bullet_train-api/lib/bullet_train/api/example_bot.rb +++ b/bullet_train-api/lib/bullet_train/api/example_bot.rb @@ -2,26 +2,12 @@ module FactoryBot module ExampleBot - attr_accessor :tables_to_reset - def example(model, **) - @tables_to_reset = [model.to_s.pluralize] - - object = FactoryBot.build(factory(model), **) - - object - ensure - reset_tables! + FactoryBot.build(factory(model), **) end def example_list(model, quantity, **) - @tables_to_reset = [model.to_s.pluralize] - - objects = FactoryBot.build_list(factory(model), quantity, **) - - objects - ensure - reset_tables! + FactoryBot.build_list(factory(model), quantity, **) end REST_METHODS = %i[get_examples get_example post_example post_parameters put_example put_parameters patch_example patch_parameters] @@ -39,43 +25,6 @@ def factory(model) factories.include?("#{model}_example") ? "#{model}_example".to_sym : model end - def reset_tables! - # This is only available for postgres - return unless @tables_to_reset.present? - - return unless ActiveRecord::Base.connection.respond_to?(:reset_pk_sequence!) - - @tables_to_reset.each do |name| - ActiveRecord::Base.connection.reset_pk_sequence!(name) if ActiveRecord::Base.connection.table_exists?(name) - end - end - - def deep_clone(instance) - clone = instance.clone - - instance.class.reflections.each do |name, reflection| - if reflection.macro == :has_many - associations = instance.send(name).map { |association| association.clone } - clone.send("#{name}=", associations) - @tables_to_reset << name - elsif %i[belongs_to has_one].include?(reflection.macro) - # Calling e.g. address.team= throws an error, - # if address has_one team through person - # and person has_one team through company - # and company belongs_to team - # so the resulting error will be caught here and a warning logged. - begin - clone.send("#{name}=", instance.send(name).clone) - @tables_to_reset << name.pluralize - rescue ActiveRecord::HasOneThroughNestedAssociationsAreReadonly - Rails.logger.warn("ExampleBot.deep_clone ignored setting #{name} of #{instance}") - end - end - end - - clone - end - include ::Api::OpenApiHelper def _path_examples(method, model, **options) version = options.delete(:version) || "v1"