Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/controllers/hangar/records_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
module Hangar
class RecordsController < ActionController::Base
def delete
DatabaseCleaner.clean_with Hangar.clean_strategy, except: Hangar.do_not_delete
head :no_content, content_type: "text/html"
Hangar.created_data.each do |key, value|
value.constantize.delete(key)
end
Hangar.created_data.clear
render json: {"delete": "success"}.to_json, status: 200
end
end
end
1 change: 1 addition & 0 deletions app/controllers/hangar/resources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class ResourcesController < ActionController::Base

def create
created = FactoryBot.create resource, *traits, resource_attributes
Hangar.created_data[created.id.to_s] = created.model_name.to_s
render json: created.as_json(include: includes)
end

Expand Down
5 changes: 3 additions & 2 deletions lib/hangar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ module Hangar
BadEnvironmentError = Class.new(StandardError)

mattr_writer :do_not_delete, :route_namespace
mattr_accessor :clean_strategy
mattr_accessor :clean_strategy, :created_data

self.clean_strategy = :deletion
self.route_namespace = nil
self.created_data = Hash.new

def self.do_not_delete
Array.wrap(@@do_not_delete)
Expand All @@ -28,7 +29,7 @@ def self.route_namespace
end

def validate_environment
Rails.env.test? or raise BadEnvironmentError, "Hangar should not be used in the #{Rails.env} environment"
Rails.env.test? || Rails.env.development? or raise BadEnvironmentError, "Hangar should not be used in the #{Rails.env} environment"
end
module_function :validate_environment
end
Expand Down