Class: Believer::Test::TestRunLifeCycle::Destructor
- Inherits:
-
Object
- Object
- Believer::Test::TestRunLifeCycle::Destructor
- Includes:
- Singleton
- Defined in:
- lib/believer/test/test_run_life_cycle.rb
Overview
Detroys all CqlRecord::Base instances created
Instance Method Summary collapse
- #after_save(model) ⇒ Object
- #cleanup ⇒ Object
- #counters_action ⇒ Object
- #observed_models ⇒ Object
- #should_destroy?(model) ⇒ Boolean
Instance Method Details
#after_save(model) ⇒ Object
64 65 66 67 |
# File 'lib/believer/test/test_run_life_cycle.rb', line 64 def after_save(model) @observed_models ||= Set.new @observed_models << model end |
#cleanup ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/believer/test/test_run_life_cycle.rb', line 38 def cleanup @observed_models.each do |model| begin if model.is_counter_instance? case counters_action when :destroy model.destroy if should_destroy?(model) when :reset model.reset_counters! when :retain end else model.destroy if should_destroy?(model) end rescue Exception => e puts "Could not destroy model #{model}: #{e}\n#{e.backtrace.join("\n")}" end end unless @observed_models.nil? || @observed_models.empty? @observed_models = nil end |
#counters_action ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/believer/test/test_run_life_cycle.rb', line 22 def counters_action if @counters_action.nil? begin @counters_action = Believer::Base.environment.believer_configuration[:test][:life_cycle][:counters].to_sym rescue @counters_action = :destroy end end @counters_action end |
#observed_models ⇒ Object
59 60 61 62 |
# File 'lib/believer/test/test_run_life_cycle.rb', line 59 def observed_models return @observed_models.dup.to_a unless @observed_models.nil? [] end |
#should_destroy?(model) ⇒ Boolean
33 34 35 36 |
# File 'lib/believer/test/test_run_life_cycle.rb', line 33 def should_destroy?(model) #return false if model.is_counter_instance? && retain_counter_models? true end |