Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not delete report if task associated with this report deleted #15134

Merged
Merged
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
12 changes: 7 additions & 5 deletions app/models/miq_report_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't tell, is this required for this PR? How do you know it's unused? Can you locate the last caller or why it's unused?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Search for string state_or_statusacross all projects: found only in MiqTask and it is not invocation of MiqTaskResult.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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/miq_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions spec/models/miq_report_result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down