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

Inventory task #16980

Merged
merged 5 commits into from
Feb 21, 2018
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
host#v_total_storages is now arel friendly
  • Loading branch information
kbrock committed Feb 20, 2018
commit 36a6bc825aa65712e688343e06e7d86fb62f7660
2 changes: 1 addition & 1 deletion app/models/host.rb
Original file line number Diff line number Diff line change
@@ -146,7 +146,7 @@ class Host < ApplicationRecord
virtual_has_many :event_logs, :uses => {:operating_system => :event_logs}
virtual_has_many :firewall_rules, :uses => {:operating_system => :firewall_rules}

virtual_total :v_total_storages, :storages
virtual_total :v_total_storages, :host_storages
virtual_total :v_total_vms, :vms
virtual_total :v_total_miq_templates, :miq_templates

16 changes: 9 additions & 7 deletions spec/lib/extensions/virtual_total_spec.rb
Original file line number Diff line number Diff line change
@@ -362,21 +362,23 @@ def model_with_children(count)
end
end

describe ".virtual_total (with through relation (host#v_total_storages)" do
let(:base_model) { Host }
describe ".virtual_total (with through relation (ems#total_storages)" do
let(:base_model) { ExtManagementSystem }

it "calculates totals locally" do
expect(model_with_children(0).v_total_storages).to eq(0)
expect(model_with_children(2).v_total_storages).to eq(2)
expect(model_with_children(0).total_storages).to eq(0)
expect(model_with_children(2).total_storages).to eq(2)
end

it "is not defined in sql" do
expect(base_model.attribute_supported_by_sql?(:v_total_storages)).to be(false)
expect(base_model.attribute_supported_by_sql?(:total_storages)).to be(false)
end

def model_with_children(count)
FactoryGirl.create(:host).tap do |host|
count.times { host.storages.create(FactoryGirl.attributes_for(:storage)) }
FactoryGirl.create(:ext_management_system).tap do |ems|
ems.hosts.create(FactoryGirl.attributes_for(:host)).tap do |host|
count.times { host.storages.create(FactoryGirl.attributes_for(:storage)) }
end
end.reload
end
end
1 change: 0 additions & 1 deletion spec/models/host_spec.rb
Original file line number Diff line number Diff line change
@@ -375,7 +375,6 @@ def assert_remote_credentials_validated
host = FactoryGirl.create(:host)
host.storages.create(FactoryGirl.attributes_for(:storage))
expect(host.v_total_storages).to eq(1)
expect(Host.attribute_supported_by_sql?(:v_total_storages)).to be false
end
end