Skip to content

Commit

Permalink
host#v_total_storages is now arel friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrock committed Feb 9, 2018
1 parent a0825f4 commit f0e6634
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/models/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 9 additions & 7 deletions spec/lib/extensions/virtual_total_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion spec/models/host_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit f0e6634

Please sign in to comment.