From 4c610b285ec109d13d35d7d60a62f9d133b7ba6d Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Fri, 3 Nov 2017 13:18:56 -0400 Subject: [PATCH] settings_for_resource shouldn't blow up if the instance isn't saved yet It should return the settings from the parent resource instead. Only attempt to reload the record if the record is persisted https://bugzilla.redhat.com/show_bug.cgi?id=1509172 --- lib/vmdb/settings/database_source.rb | 4 +++- spec/lib/vmdb/settings_spec.rb | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/vmdb/settings/database_source.rb b/lib/vmdb/settings/database_source.rb index c9828649a6a..5fcb0fee499 100644 --- a/lib/vmdb/settings/database_source.rb +++ b/lib/vmdb/settings/database_source.rb @@ -36,7 +36,9 @@ def self.parent_sources_for(resource) end def resource - @resource_instance == :my_server ? my_server : @resource_instance.reload + return my_server if @resource_instance == :my_server + @resource_instance.reload if @resource_instance.persisted? + @resource_instance end def load diff --git a/spec/lib/vmdb/settings_spec.rb b/spec/lib/vmdb/settings_spec.rb index 7967597472f..0b00e90fcf6 100644 --- a/spec/lib/vmdb/settings_spec.rb +++ b/spec/lib/vmdb/settings_spec.rb @@ -355,7 +355,7 @@ expect(settings.api.token_ttl).to eq "3.hour" end - it "applied settings from hierarchy Region -> Zone -> Server" do + it "applies settings from up the hierarchy: Region -> Zone -> Server" do MiqRegion.seed described_class.save!(server.zone.miq_region, :api => {:token_ttl => "3.hour"}) @@ -369,6 +369,9 @@ described_class.save!(server, :api => {:token_ttl => "5.hour"}) settings = Vmdb::Settings.for_resource(server) expect(settings.api.token_ttl).to eq "5.hour" + + settings = Vmdb::Settings.for_resource(MiqServer.new(:zone => server.zone)) + expect(settings.api.token_ttl).to eq "4.hour" end end