diff --git a/app/models/miq_report_result.rb b/app/models/miq_report_result.rb index 16957e0d15e..8d430c86a12 100644 --- a/app/models/miq_report_result.rb +++ b/app/models/miq_report_result.rb @@ -11,10 +11,8 @@ class MiqReportResult < ApplicationRecord serialize :report virtual_delegate :description, :to => :miq_group, :prefix => true, :allow_nil => true - virtual_delegate :state_or_status, :to => "miq_task", :allow_nil => true - virtual_attribute :status, :string, :uses => :state_or_status + virtual_attribute :status, :string virtual_column :status_message, :type => :string, :uses => :miq_task - virtual_has_one :result_set, :class_name => "Hash" before_save do @@ -32,11 +30,15 @@ def result_set end def status - MiqTask.human_status(state_or_status) + if miq_task + miq_task.human_status + else + report_results.blank? ? "Error" : "Complete" + end end def status_message - miq_task.nil? ? _("Report results are no longer available") : miq_task.message + miq_task.nil? ? _("The task associated with this report is no longer available") : miq_task.message end def report_results diff --git a/app/models/miq_task.rb b/app/models/miq_task.rb index d90bc1915f4..1ec2c92442a 100644 --- a/app/models/miq_task.rb +++ b/app/models/miq_task.rb @@ -19,7 +19,7 @@ class MiqTask < ApplicationRecord has_one :log_file, :dependent => :destroy has_one :binary_blob, :as => :resource, :dependent => :destroy - has_one :miq_report_result, :dependent => :destroy + has_one :miq_report_result has_one :job, :dependent => :destroy belongs_to :miq_server diff --git a/spec/models/miq_report_result_spec.rb b/spec/models/miq_report_result_spec.rb index 73829c35677..709ded6419e 100644 --- a/spec/models/miq_report_result_spec.rb +++ b/spec/models/miq_report_result_spec.rb @@ -125,6 +125,35 @@ end end + describe "#status" do + let(:report_name) { "Vendor and Guest OS" } + let(:task) { FactoryGirl.create(:miq_task) } + let(:miq_report_result) do + MiqReport.seed_report(report_name) + report = MiqReport.where(:name => report_name).last + report.generate_table(:userid => "test") + task.miq_report_result = report.build_create_results({:userid => "test"}, task.id) + MiqReportResult.find_by(:miq_task_id => task.id) + end + + it "returns 'Running' if associated task exists and report not ready" do + expect(miq_report_result.status).to eq "Running" + end + + it "returns 'Complete' if report generated and associated task exists" do + task.update_status("Finished", "Ok", "Generate Report result") + expect(miq_report_result.status).to eq "Complete" + end + + it "returns 'Complete' if task ssociated with report deleted" do + expect(miq_report_result.status).to eq "Running" + task.update_status("Finished", "Ok", "Generate Report result") + task.destroy + miq_report_result.reload + expect(miq_report_result.status).to eq "Complete" + end + end + describe "serializing and deserializing report results" do it "can serialize and deserialize an MiqReport" do report = FactoryGirl.build(:miq_report)