Skip to content

Commit

Permalink
do not delete report when linked MiqTask deleted
Browse files Browse the repository at this point in the history
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1450272
Changes:
- removed :dependent => :destroy on miq_report_result association in MiqTask
- refactor MiqReportResult#status to return 'Complete' if task asociated with report deleted
- added test coverage for MiqReportResult#status
- remove not used virtual_delegate to MiqTask#state_or_status
  • Loading branch information
yrudman committed Jun 1, 2017
1 parent 86e8752 commit fa4ebc6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
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
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

0 comments on commit fa4ebc6

Please sign in to comment.