Skip to content

Commit

Permalink
reports separate includes from preloads
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrock committed Jan 31, 2020
1 parent 0d1f966 commit 745352d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
6 changes: 5 additions & 1 deletion app/models/miq_report/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,14 @@ def table2class(table)
@table2class[table]
end

# models that are preloaded for later use
def get_include_for_find
get_include.deep_merge(include_for_find || {}).presence
include_for_find.presence
end

# models that are necessary / in the SELECT, WHERE, or ORDER clause
#
# get from include hash or derive from col_order)
def get_include
include_as_hash(include.presence || invent_report_includes)
end
Expand Down
26 changes: 4 additions & 22 deletions spec/models/miq_report/generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@
expect(rpt.get_include_for_find).to be_nil
end

it "includes virtual_includes from virtual_attributes that are not sql friendly" do
it "does not includes virtual_includes from virtual_attributes that are not sql friendly" do
rpt = MiqReport.new(:db => "VmOrTemplate",
:cols => %w(name platform))
expect(rpt.get_include_for_find).to eq(:platform => {})
expect(rpt.get_include_for_find).to be_nil
end

it "does not include sql friendly virtual_attributes" do
Expand All @@ -177,30 +177,12 @@
expect(rpt.get_include_for_find).to be_nil
end

it "uses include and include_as_hash" do
it "uses only include_for_find" do
rpt = MiqReport.new(:db => "VmOrTemplate",
:cols => %w(name platform),
:include => {:host => {:columns => %w(name)}, :storage => {:columns => %w(name)}},
:include_for_find => {:snapshots => {}})
expect(rpt.get_include_for_find).to eq(:platform => {}, :host => {}, :storage => {}, :snapshots => {})
end

it "uses col, col_order, and virtual attributes and ignores empty include" do
# it also allows cols to override col_order for requesting extra columns
rpt = MiqReport.new(:db => "VmOrTemplate",
:include => {},
:cols => %w[name v_datastore_path],
:col_order => %w(name host.name storage.name),
:include_for_find => {:snapshots => {}})
expect(rpt.get_include_for_find).to eq(:v_datastore_path => {}, :host => {}, :storage => {}, :snapshots => {})
end

it "uses col_order and virtual attributes" do
rpt = MiqReport.new(:db => "VmOrTemplate",
:include => {},
:col_order => %w[name v_datastore_path host.name storage.name],
:include_for_find => {:snapshots => {}})
expect(rpt.get_include_for_find).to eq(:v_datastore_path => {}, :host => {}, :storage => {}, :snapshots => {})
expect(rpt.get_include_for_find).to eq(:snapshots => {})
end
end

Expand Down

0 comments on commit 745352d

Please sign in to comment.