Skip to content

Commit

Permalink
[FINE] Prefer valid_report_column? and contains_records? from MiqRepo…
Browse files Browse the repository at this point in the history
…rtResult

https://bugzilla.redhat.com/show_bug.cgi?id=1594387

Gaprindashvili Backport commit from:

    #4143

Original SHA:

   ff7ee24

Rest of original message below...

* * *

These are new methods added in:

ManageIQ/manageiq#17590

And are far more efficient for the use cases of ChargebackController and
ReportController::SavedReports.
  • Loading branch information
NickLaMuro committed Jun 25, 2018
1 parent 91f9ba5 commit 64f8b1f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
5 changes: 2 additions & 3 deletions app/controllers/chargeback_controller.rb
Expand Up @@ -349,17 +349,16 @@ def cb_rpts_fetch_saved_report(id)
@report_result_id = session[:report_result_id] = rr.id
session[:report_result_runtime] = rr.last_run_on
if rr.status.downcase == "complete"
@report = rr.report_results
session[:rpt_task_id] = nil
if @report.blank?
unless rr.valid_report_column?
@saved_reports = cb_rpts_get_all_reps(rr.miq_report_id.to_s)
rep = MiqReport.find_by_id(rr.miq_report_id)
if x_active_tree == :cb_reports_tree
self.x_node = "reports-#{rep.id}"
end
return
else
if @report.contains_records?
if rr.contains_records?
@html = report_first_page(rr) # Get the first page of the results
unless @report.graph.blank?
@zgraph = true
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/report_controller/saved_reports.rb
Expand Up @@ -26,9 +26,8 @@ def fetch_saved_report(id)
@report_result_id = session[:report_result_id] = rr.id
session[:report_result_runtime] = rr.last_run_on
if rr.status.downcase == "complete"
@report = rr.report_results
session[:rpt_task_id] = nil
if @report.blank?
unless rr.valid_report_column?
add_flash(_("Saved Report \"%{time}\" not found, Schedule may have failed") %
{:time => format_timezone(rr.created_on, Time.zone, "gtl")},
:error)
Expand All @@ -48,7 +47,7 @@ def fetch_saved_report(id)
end
return
else
if @report.contains_records?
if rr.contains_records?
@html = report_first_page(rr) # Get the first page of the results
if params[:type]
@zgraph = nil
Expand Down
3 changes: 2 additions & 1 deletion spec/controllers/chargeback_controller_spec.rb
Expand Up @@ -577,7 +577,8 @@ def convert_chargeback_rate_to_hash(rate)
miq_task.state_finished
miq_report_result.report = chargeback_report.to_hash.merge(:extras=> {:total_html_rows => 100})
miq_report_result.save
allow(controller).to receive(:report_first_page)
controller.instance_variable_set(:@sb, {})
controller.instance_variable_set(:@settings, :perpage => { :reports => 20 })
end

it "fetch existing report" do
Expand Down
9 changes: 6 additions & 3 deletions spec/controllers/miq_report_controller/trees_spec.rb
Expand Up @@ -34,9 +34,12 @@
before do
login_as user
controller.instance_variable_set(:@html, "<h1>Test</h1>")
allow(controller).to receive(:report_first_page)
allow(report).to receive(:contains_records?).and_return(true)
allow_any_instance_of(MiqReportResult).to receive(:report_results).and_return(report)
session[:settings] = {:perpage => {:reports => 20}}
report_result.report = report.to_hash.merge(:extras=> {:total_html_rows => 100})
report_result.save
# allow(controller).to receive(:report_first_page)
# allow(report).to receive(:contains_records?).and_return(true)
# allow_any_instance_of(MiqReportResult).to receive(:report_results).and_return(report)
end

it 'renders show from CI -> Reports -> Saved Reports' do
Expand Down

0 comments on commit 64f8b1f

Please sign in to comment.