-
Notifications
You must be signed in to change notification settings - Fork 356
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
Display flash message on import/export custom report #125
Display flash message on import/export custom report #125
Conversation
@@ -178,6 +178,10 @@ def x_show | |||
def tree_select | |||
@edit = nil | |||
@sb[:select_node] = false | |||
if @sb.try(:[], :flash_msg) |
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.
This line should better read if @sb.key?(:flash_msg)
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.
what if @sb is nil ? this approach doesn't need to test that ;-) but if you insist on that I can replace it ofc.
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.
if @sb
is nil, then the line above that would fail as well, right?
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 can imagine that someone will delete the line or change the lines order ;-)
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.
@sb
is being set in ApplicationController
before every action either to an empty hash or to whatever
the sandbox for the given controller contained before. I haven't seen this @sb.try(:[], ...)
construct anywhere
in our code, I consider it a bad coding practice and I won't merge this PR looking like this.
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.
btw. not sure what version of ruby, we support right now, but the best is using safe navigation operator .& ...
I haven't seen this @sb.try(:[], ...) construct anywhere
in our code, I consider it a bad coding practice and I won't merge this PR looking like this.
$ grep -rn \\.try app/ | wc -l
458
vs.
$ grep -rn \\.key? app/ | wc -l
259
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.
FYI above numbers are for manageiq repo, for manageiq-ui-classic the numbers are:
$ grep -rn \\.try app/ | wc -l
330
$ grep -rn \\.key? app/ | wc -l
206
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.
So looking at this, I think .try
has its place, but perhaps not here. This is because @sb.try
will not fail if @sb
is nil, which in this case is bad. So, to me, I would prefer we use .key?
and blow up with a nil error here, which would fail any test that runs this code and we would know that somehow we ended up here without our sandbox object in place. Anyplace we address @sb
, except where we initialize it, we'd probably want it to fail if it's nil.
cee650b
to
3a0eb1a
Compare
3a0eb1a
to
1b92982
Compare
Checked commit jzigmund@1b92982 with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1 |
Euwe backport (to manageiq repo) details:
|
The PR is recreated after the UI split, original PR ManageIQ/manageiq#13246
https://bugzilla.redhat.com/show_bug.cgi?id=1393244