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

Added AutomateWorkspace model #15817

Merged
merged 8 commits into from
Sep 6, 2017
Merged

Conversation

mkanoor
Copy link
Contributor

@mkanoor mkanoor commented Aug 15, 2017

Added AutomateWorkspace model which can be accessed from the REST API

@Fryguy
Copy link
Member

Fryguy commented Aug 25, 2017

I still don't agree with this approach to the problem, but we can discuss as this moves forward.

@Fryguy
Copy link
Member

Fryguy commented Aug 25, 2017

@mkanoor Do you have a design doc or picture for this. I'd like to understand all the moving parts before merging each individual gear.

@mkanoor
Copy link
Contributor Author

mkanoor commented Aug 30, 2017

@mkanoor mkanoor changed the title [WIP] Added AutomateWorkspace model Added AutomateWorkspace model Aug 30, 2017
@mkanoor
Copy link
Contributor Author

mkanoor commented Aug 30, 2017

Depends on Schema changes in ManageIQ/manageiq-schema#50

@miq-bot miq-bot removed the wip label Aug 30, 2017
@Fryguy
Copy link
Member

Fryguy commented Aug 31, 2017

Merged schema in ManageIQ/manageiq-schema#50

@Fryguy Fryguy closed this Aug 31, 2017
@Fryguy Fryguy reopened this Aug 31, 2017
raise ArgumentError, "No workspace or state_var specified for edit"
end

self[:output] = (output || {}).deep_merge(hash)
Copy link
Member

Choose a reason for hiding this comment

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

I believe it's preferable to use write_attribute over []= . @jrafanie @chrisarcand Do you know what's the preferable way to do this?

Copy link
Member

Choose a reason for hiding this comment

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

Oh duh...the preferable way is to use super 😝

Copy link
Member

Choose a reason for hiding this comment

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

Prefer output= on the parent via self.output = (output...., if that's what you meant by super, yeah 😄

end

self[:output] = (output || {}).deep_merge(hash)
save!
Copy link
Member

Choose a reason for hiding this comment

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

A setter should never call .save! directly. It's should be the caller's concern as they may choose to defer saving, or use update_attributes or whatever.

Copy link
Member

Choose a reason for hiding this comment

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

That being said, can the setter just be the setter, and deal with the validation at validation time? Doing all this on a setter seems wrong.

Copy link
Member

Choose a reason for hiding this comment

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

If you must have a method that sets and saves, then prefer creating a method like def merge_output!(hash) which is explicit in what it's doing

@mkanoor
Copy link
Contributor Author

mkanoor commented Aug 31, 2017

@Fryguy changed to merge_output! please review

@@ -0,0 +1,22 @@
describe AutomateWorkspace do
context "#output=" do
Copy link
Member

Choose a reason for hiding this comment

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

This needs to change too

validates :user, :presence => true

def merge_output!(hash)
if hash['workspace'].blank? && hash['state_vars'].blank?
Copy link
Member

Choose a reason for hiding this comment

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

Should this be an ||? Based on the error message it should fail if either one is blank. Additionally, if state_vars => {} that would technically be blank as well, so maybe this should check for nil instead?

@miq-bot
Copy link
Member

miq-bot commented Sep 6, 2017

Checked commits mkanoor/manageiq@32db7e5~...bb02c3c with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
3 files checked, 0 offenses detected
Everything looks fine. 👍

@Fryguy Fryguy merged commit 265d3eb into ManageIQ:master Sep 6, 2017
@Fryguy Fryguy added this to the Sprint 69 Ending Sep 18, 2017 milestone Sep 6, 2017
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.

5 participants