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

ApplicationController: fix rubocop warnings #4658

Conversation

mzazrivec
Copy link
Contributor

No description provided.

@mzazrivec mzazrivec force-pushed the fix_rubocop_warnings_in_application_controller branch from cc4c7b3 to efa3fc3 Compare September 13, 2018 15:36
@@ -650,14 +651,14 @@ def build_ae_tree(type = :ae, name = :ae_tree)

# moved this method here so it can be accessed from pxe_server controller as well
def log_depot_set_verify_status
if (@edit[:new][:log_password] == @edit[:new][:log_verify]) && @edit[:new][:uri_prefix] != "nfs" &&
Copy link
Member

@romanblanco romanblanco Sep 13, 2018

Choose a reason for hiding this comment

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

@mzazrivec I would use extra variables to improve readability here:

- @edit[:log_verify_status] = if (@edit[:new][:log_password] == @edit[:new][:log_verify]) && @edit[:new][:uri_prefix] != "nfs" &&
-                                (@edit[:new][:uri].present? && @edit[:new][:log_userid].present? && @edit[:new][:log_password].present? && @edit[:new][:log_verify].present?)
-                               true
-                             elsif @edit[:new][:uri_prefix] == "nfs" && @edit[:new][:uri].present?
-                               true
-                             else
-                               false
-                             end
+ uri_filled = @edit[:new][:uri].present?
+ nfs_prefix = (@edit[:new][:uri_prefix] == "nfs")
+ passwords_match = (@edit[:new][:log_password] == @edit[:new][:log_verify])
+ authentication_credentials_filled = (
+  uri_filled &&
+  @edit[:new][:log_userid].present? &&
+  @edit[:new][:log_password].present? &&
+  @edit[:new][:log_verify].present?
+ )
+
+ @edit[:log_verify_status] = (
+   (nfs_prefix && uri_filled) ||
+   (!nfs_prefix && authentication_credentials_filled && passwords_match)
+ )

...what do you think?

Maybe in a separate PR.

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 simplified the condition inside that routine and also moved the routine to PxeController, since it's used only in that controller.

- rename the method to log_depot_verify_status()
- don't set @edit[:log_verify_status] inside the routine
- simplify the condition inside the routine
@miq-bot
Copy link
Member

miq-bot commented Sep 14, 2018

Checked commits mzazrivec/manageiq-ui-classic@efa3fc3~...63b6e72 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 1 offense detected

app/controllers/application_controller.rb

end
next if current.present? && (new[k][hk] == current[k][hk])
msg_arr << if password_field?(hk) # Asterisk out password fields
"#{hk}:[*]#{' to [*]' unless current.nil?}"
Copy link
Contributor

Choose a reason for hiding this comment

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

unless used inside a string interpolation 🤢

Probably a separate PR, right?

$ ag '"[^"]*#{[^}]*\b(unless|if)'
app/controllers/application_controller.rb
700:          msg_arr << "#{k}:[*]#{' to [*]' unless current.nil?}"
708:                msg_arr << "#{hk}:[*]#{' to [*]' unless current.nil?}"

app/controllers/report_controller/reports/editor.rb
811:            (suffix ? " (#{MiqReport.date_time_break_suffixes.collect { |s| s.first i  s.last == suffix }.compact.join})" : "") +

app/helpers/vm_helper/textual_summary.rb
259:         :value => "#{s.name}#{" (main)" if s == main}",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'd rather address that in a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here: #4671

@himdel himdel self-assigned this Sep 17, 2018
@himdel himdel added this to the Sprint 95 Ending Sep 24, 2018 milestone Sep 17, 2018
@himdel himdel merged commit 07dbfda into ManageIQ:master Sep 17, 2018
@mzazrivec mzazrivec deleted the fix_rubocop_warnings_in_application_controller branch September 17, 2018 13:12
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.

4 participants