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

Move ResourceGroup relationship into VmOrTemplate model #14948

Merged
merged 1 commit into from
Jun 2, 2017
Merged

Move ResourceGroup relationship into VmOrTemplate model #14948

merged 1 commit into from
Jun 2, 2017

Conversation

djberg96
Copy link
Contributor

This is a followup to #14000.

Originally I put the resource group relationship in the cloud_manager/vm.rb. Unfortunately, this left templates out. So, I've set the relationship in the VmOrTemplate model instead.

For backwards compatibility (and general handiness) I've created a vms method, as well as a templates method (and an :images alias). I've also updated the specs.

end

it "has many vms_or_templates" do
expect(resource_group).to respond_to(:vm_or_templates)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like the expectation on respond_to is unnecessary if the method is called on the next line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know people disagree with me on tests like this, but I like them because they're good for sanity checking. At worst, it's harmless.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, these tests appear to testing rails itself.

@@ -335,6 +335,19 @@
end
end

context "#resource_group" do
before do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the context, @variables and a before block if there is only one test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case I add more tests later.

@@ -335,6 +335,19 @@
end
end

context "#resource_group" do
before do
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member

@kbrock kbrock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (with or without minor tweak request)

@@ -79,6 +79,8 @@ class VmOrTemplate < ApplicationRecord
has_many :guest_applications, :dependent => :destroy
has_many :patches, :dependent => :destroy

belongs_to :resource_group
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


has_many :vm_or_templates

has_many :vms, -> { where(:template => false) }, :class_name => 'VmOrTemplate'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to use :class_name => 'Vm' and :class_name => 'Template'?

Copy link
Contributor Author

@djberg96 djberg96 May 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without changing the tests, if I do that I get: uninitialized constant ResourceGroup::Template. There is a "Vm" class, but no "Template" class.

@kbrock
Copy link
Member

kbrock commented May 24, 2017

Also, due to architectural limitations, moving relations up to a parent makes life simpler

@@ -1,3 +1,8 @@
class ResourceGroup < ApplicationRecord
has_many :vms
alias_attribute :images, :templates
Copy link
Member

@kbrock kbrock May 24, 2017

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?

Copy link
Contributor Author

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. :)

@djberg96
Copy link
Contributor Author

@kbrock @bdunne I've removed the tests that you felt were redundant. I've also modified the vms method to rely on the default scope. I could not do that for the templates method however since there is no Template class.

@bdunne
Copy link
Member

bdunne commented May 24, 2017

@djberg96 The class is MiqTemplate

Modified vms method, added templates method.

Added resource_group specs.

Updated ResourceGroup specs to reflect model changes.

Rely on default scope for vms method.

Remove tests that were only testing Rails.

Update templates association and specs.
@djberg96
Copy link
Contributor Author

@bdunne Thanks, updated.

@miq-bot
Copy link
Member

miq-bot commented May 24, 2017

Checked commit https://github.com/djberg96/manageiq/commit/00d261489dfc201db48eee38a7b68a7a88ead5bd with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
5 files checked, 0 offenses detected
Everything looks fine. 👍

@chessbyte
Copy link
Member

@bdunne @blomquisg bump

@bdunne bdunne merged commit ab781a8 into ManageIQ:master Jun 2, 2017
@bdunne bdunne assigned bdunne and unassigned blomquisg Jun 2, 2017
@bdunne bdunne added this to the Sprint 62 Ending Jun 5, 2017 milestone Jun 2, 2017
@djberg96 djberg96 deleted the resource_group branch July 17, 2017 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants