lib/toaster/model/automation.rb in cloud-toaster-1.1.5 vs lib/toaster/model/automation.rb in cloud-toaster-1.1.6
- old
+ new
@@ -16,15 +16,16 @@
module Toaster
class Automation < ActiveRecord::Base
belongs_to :user
- has_many :tasks, nil, {:autosave => true, :dependent => :delete_all}
- has_many :automation_attributes, nil, {:autosave => true, :dependent => :delete_all}
- has_many :ignore_properties, nil, {:class_name => IgnoreProperty, :autosave => true, :dependent => :delete_all}
- has_many :additional_properties, nil, {:class_name => AdditionalProperty, :autosave => true, :dependent => :delete_all}
- has_many :automation_runs, nil, {:autosave => true, :dependent => :delete_all}
+ has_many :tasks, :autosave => true, :dependent => :destroy
+ has_many :test_suites, :autosave => true, :dependent => :destroy
+ has_many :automation_attributes, :autosave => true, :dependent => :destroy
+ has_many :ignore_properties, :autosave => true, :dependent => :destroy
+ has_many :additional_properties, :autosave => true, :dependent => :destroy
+ has_many :automation_runs, :autosave => true, :dependent => :destroy
#attr_accessor :tasks, :attributes,
attr_accessor :chef_run_list, :additional_state_configs, :version
def initialize(attr_hash)
@@ -41,10 +42,23 @@
distinct()
return exec_tasks if !exec_tasks.empty?
return tasks
end
+ # collect the executed state transitions of
+ # all tasks contained in this automation
+ def global_state_transitions()
+ result = Set.new
+ get_globally_executed_tasks().each do |task|
+ result += task.global_state_transitions
+ end
+ return result
+ end
+ def num_global_state_transitions()
+ global_state_transitions().size
+ end
+
#
# return a map AutomationRun -> (list of TaskExecution)
#
def get_task_execs_by_run()
result = {}
@@ -54,10 +68,15 @@
result[exe.automation_run] << exe
end
return result
end
+ def get_all_test_cases()
+ TestCase.joins(:automation_run => :automation).where(
+ "automations.id = #{self.id}")
+ end
+
def is_chef?
"#{language}".casecmp("chef") == 0
end
def short_name()
@@ -135,15 +154,15 @@
end
def get_task(task_id, check_automation_runs=false)
task_id = task_id.to_s
tasks.each do |t|
- return t if t.id.to_s == task_id || t.uuid.to_s == task_id
+ return t if (t.id.to_s == task_id || t.uuid.to_s == task_id)
end
if check_automation_runs
automation_runs().each do |r|
r.task_executions().each do |exe|
- if exe.task && exe.task.uuid.to_s == task_id || exe.task.uuid.to_s == task_id
+ if exe.task && (exe.task.id.to_s == task_id || exe.task.uuid == task_id)
return exe.task
end
end
end
end