-
Notifications
You must be signed in to change notification settings - Fork 898
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
Move ResourceGroup relationship into VmOrTemplate model #14948
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
class ResourceGroup < ApplicationRecord | ||
has_many :vms | ||
alias_attribute :images, :templates | ||
|
||
has_many :vm_or_templates | ||
|
||
# Rely on default scopes to get expected information | ||
has_many :vms, :class_name => 'Vm' | ||
has_many :templates, :class_name => 'MiqTemplate' | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,8 @@ class VmOrTemplate < ApplicationRecord | |
has_many :guest_applications, :dependent => :destroy | ||
has_many :patches, :dependent => :destroy | ||
|
||
belongs_to :resource_group | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
# Accounts - Users and Groups | ||
has_many :accounts, :dependent => :destroy | ||
has_many :users, -> { where(:accttype => 'user') }, :class_name => "Account" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -335,6 +335,19 @@ | |
end | ||
end | ||
|
||
context "#resource_group" do | ||
before do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case I add more tests later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On second thought... Do we even need this test? It feels like we're testing rails here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, sanity testing in case someone adds scopes/filters/whatever that conflict with what I'm expecting. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is a regular activerecord has_one, I don't understand why we'd need to test that. They're usually helpful when you're developing and want to make sure you did both sides of the association correctly but aren't really needed after that. |
||
@resource_group = FactoryGirl.create(:resource_group) | ||
@vm_with_rg = FactoryGirl.create(:vm_amazon, :resource_group => @resource_group) | ||
@vm_without_rg = FactoryGirl.create(:vm_amazon) | ||
end | ||
|
||
it "has a has_one association with resource groups" do | ||
expect(@vm_with_rg.resource_group).to eql(@resource_group) | ||
expect(@vm_without_rg.resource_group).to be_nil | ||
end | ||
end | ||
|
||
context "#scan_profile_categories" do | ||
before do | ||
@vm = FactoryGirl.create(:vm_vmware) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need
images
alias?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just thought it would be a handy alias. :)