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

[FINE] Fix displaying report result #1632

Merged
merged 7 commits into from
Jul 7, 2017
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
3 changes: 2 additions & 1 deletion app/controllers/report_controller/saved_reports.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def fetch_saved_report(id)
{:name => "#{rr.name} - #{format_timezone(rr.created_on, Time.zone, "gt")}"}
if admin_user? || current_user.miq_group_ids.include?(rr.miq_group_id)
@report_result_id = session[:report_result_id] = rr.id
@report_result = rr
session[:report_result_runtime] = rr.last_run_on
if rr.status.downcase == "complete"
@report = rr.report_results
Expand Down Expand Up @@ -77,6 +76,8 @@ def fetch_saved_report(id)
add_flash(_("No records found for this report"), :warning)
end
end
else
@report_result = rr
end
else
add_flash(_("Report is not authorized for the logged in user"), :error)
Expand Down
36 changes: 21 additions & 15 deletions spec/controllers/miq_report_controller/trees_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,34 @@
expect(response).to render_template('report/_savedreports_list')
end

it 'renders show' do
user = FactoryGirl.create(:user_with_group)
let(:user) { FactoryGirl.create(:user_with_group) }
let(:report) { FactoryGirl.create(:miq_report_with_results) }
let(:task) { FactoryGirl.create(:miq_task, :state => "Finished") }
let(:report_result) { FactoryGirl.create(:miq_report_result, :miq_group_id => user.current_group.id, :miq_task_id => task.id) }
let(:binary_blob) { FactoryGirl.create(:binary_blob, :resource_type => "MiqReportResult", :resource_id => report_result.id) }
let!(:binary_blob_part) do
FactoryGirl.create(:binary_blob_part,
:data => "--- Quota \xE2\x80\x93 Max CPUs\n...\n",
:binary_blob_id => binary_blob.id)
end

before do
login_as user
controller.instance_variable_set(:@html, "<h1>Test</h1>")
allow(controller).to receive(:report_first_page)
report = FactoryGirl.create(:miq_report_with_results)
allow(report).to receive(:contains_records?).and_return(true)
task = FactoryGirl.create(:miq_task)
task.update_attributes(:state => "Finished")
task.reload
report_result = FactoryGirl.create(:miq_report_result,
:miq_group_id => user.current_group.id,
:miq_task_id => task.id)
allow_any_instance_of(MiqReportResult).to receive(:report_results).and_return(report)
binary_blob = FactoryGirl.create(:binary_blob,
:resource_type => "MiqReportResult",
:resource_id => report_result.id)
FactoryGirl.create(:binary_blob_part,
:data => "--- Quota \xE2\x80\x93 Max CPUs\n...\n",
:binary_blob_id => binary_blob.id)
end

it 'renders show from CI -> Reports -> Saved Reports' do
post :tree_select, :params => { :id => "rr-#{report_result.id}", :format => :js, :accord => 'savedreports' }
expect(controller.instance_variable_get(:@report_result)).to be_nil
expect(response).to render_template('shared/_report_chart_and_html')
end

it 'renders show from CI -> Reports -> Reports -> Any Report' do
post :tree_select, :params => { :id => "xx-11_xx-11-0_rep-145_rr-#{report_result.id}", :format => :js, :accord => 'savedreports' }
expect(controller.instance_variable_get(:@report_result)).to be_nil
expect(response).to render_template('shared/_report_chart_and_html')
end
end
Expand Down
3 changes: 3 additions & 0 deletions spec/helpers/report_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ def create_and_generate_report_for_user(report_name, user_id)
@rpt = MiqReport.where(:name => report_name).last
@rpt.generate_table(:userid => user_id)
report_result = @rpt.build_create_results(:userid => user_id)
miq_task = FactoryGirl.create(:miq_task)
miq_report_result = @rpt.miq_report_results.first
miq_report_result.update_attributes!(:miq_task => miq_task)
report_result.reload
@rpt
end
Expand Down