-
Notifications
You must be signed in to change notification settings - Fork 898
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert last_scan_on to a sql friendly delegate
This makes the drift state columns virtual This is used by the Host-host.yml and 21 screen views
- Loading branch information
Showing
4 changed files
with
100 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
describe DriftStateMixin do | ||
include Spec::Support::ArelHelper | ||
|
||
let(:host) { FactoryGirl.create(:host) } | ||
|
||
let(:drift_states) do | ||
[ | ||
FactoryGirl.create(:drift_state, :resource => host, :timestamp => recent_timestamp, :data => "bogus"), | ||
FactoryGirl.create(:drift_state, :resource => host, :timestamp => old_timestamp, :data => "bogus") | ||
] | ||
end | ||
|
||
let(:recent_timestamp) { 2.months.ago.change(:usec => 0) } | ||
let(:old_timestamp) { 4.months.ago.change(:usec => 0) } | ||
|
||
describe "#first_drift_state" do | ||
it "uses the most recent value" do | ||
drift_states | ||
expect(host.last_drift_state.timestamp).to eq(recent_timestamp) | ||
end | ||
end | ||
|
||
describe "#last_drift_state" do | ||
it "uses the least recent value" do | ||
drift_states | ||
expect(host.first_drift_state.timestamp).to eq(old_timestamp) | ||
end | ||
end | ||
|
||
describe "#last_drift_state_timestamp" do | ||
describe "with no timestamps" do | ||
before { host } | ||
it "has nil with sql" do | ||
expect(virtual_column_sql_value(Host, "last_drift_state_timestamp")).to be_nil | ||
end | ||
|
||
it "has nil with ruby" do | ||
expect(host.last_drift_state_timestamp).to be_nil | ||
end | ||
end | ||
|
||
describe "with no timestamps" do | ||
before { drift_states } | ||
|
||
it "has the most recent timestamp with sql" do | ||
h = Host.select(:id, :last_drift_state_timestamp).first | ||
expect do | ||
expect(h.last_drift_state_timestamp).to eq(recent_timestamp) | ||
end.to match_query_limit_of(0) | ||
expect(h.association(:last_drift_state)).not_to be_loaded | ||
expect(h.association(:last_drift_state_timestamp_rec)).not_to be_loaded | ||
end | ||
|
||
it "has the most recent timestamp with ruby" do | ||
h = Host.first # want a clean host record | ||
expect(h.last_drift_state_timestamp).to eq(recent_timestamp) | ||
expect(h.association(:last_drift_state)).not_to be_loaded | ||
expect(h.association(:last_drift_state_timestamp_rec)).to be_loaded | ||
end | ||
end | ||
end | ||
|
||
# ems_cluster and host specific | ||
describe "#last_scan_on" do | ||
describe "with no timestamps" do | ||
before { host } | ||
it "has nil with sql" do | ||
expect(virtual_column_sql_value(Host, "last_scan_on")).to be_nil | ||
end | ||
|
||
it "has nil with ruby" do | ||
expect(host.last_scan_on).to be_nil | ||
end | ||
end | ||
|
||
describe "with no timestamps" do | ||
before { drift_states } | ||
|
||
it "has the most recent timestamp with sql" do | ||
h = Host.select(:id, :last_scan_on).first | ||
expect do | ||
expect(h.last_scan_on).to eq(recent_timestamp) | ||
end.to match_query_limit_of(0) | ||
expect(h.association(:last_drift_state)).not_to be_loaded | ||
expect(h.association(:last_drift_state_timestamp_rec)).not_to be_loaded | ||
end | ||
|
||
it "has the most recent timestamp with ruby" do | ||
h = Host.first # want a clean host record | ||
expect(h.last_scan_on).to eq(recent_timestamp) | ||
expect(h.association(:last_drift_state)).not_to be_loaded | ||
expect(h.association(:last_drift_state_timestamp_rec)).to be_loaded | ||
end | ||
end | ||
end | ||
end |