From 65e1dbb4a69cf5251c638e50e480aee3b77bca50 Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 12 Jul 2017 11:49:23 +0100 Subject: [PATCH] Rubocop autofixes. --- app/controllers/issues_controller.rb | 26 +++++++++++----------- app/models/issue.rb | 6 ++--- test/controllers/issues_controller_test.rb | 12 +++++----- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index d1267fa4d..ffce14774 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -22,8 +22,8 @@ class IssuesController < ApplicationController @issues = Issue.where(:issue_type => @user_role).order(sort_column + " " + sort_direction) # If search - if params[:search_by_user] && !params[:search_by_user].blank? - @find_user = User.find_by_display_name(params[:search_by_user]) + if params[:search_by_user] && params[:search_by_user].present? + @find_user = User.find_by(:display_name => params[:search_by_user]) if @find_user @issues = @issues.where(:reported_user_id => @find_user.id) else @@ -31,23 +31,23 @@ class IssuesController < ApplicationController end end - if params[:status] && !params[:status][0].blank? + if params[:status] && params[:status][0].present? @issues = @issues.where(:status => params[:status][0].to_i) end - if params[:issue_type] && !params[:issue_type][0].blank? + if params[:issue_type] && params[:issue_type][0].present? @issues = @issues.where(:reportable_type => params[:issue_type][0]) end # If last_updated_by - if params[:last_updated_by] && !params[:last_updated_by][0].blank? + if params[:last_updated_by] && params[:last_updated_by][0].present? last_updated_by = params[:last_updated_by][0].to_s == "nil" ? nil : params[:last_updated_by][0].to_i @issues = @issues.where(:updated_by => last_updated_by) end notice = t("issues.index.search.issues_not_found") if @issues.first.nil? - if params[:last_reported_by] && !params[:last_reported_by][0].blank? + if params[:last_reported_by] && params[:last_reported_by][0].present? last_reported_by = params[:last_reported_by][0].to_s == "nil" ? nil : params[:last_reported_by][0].to_i @issues = @issues.where(:updated_by => last_reported_by) end @@ -65,7 +65,7 @@ class IssuesController < ApplicationController end def new - unless create_new_issue_params.blank? + if create_new_issue_params.present? @issue = Issue.find_or_initialize_by(create_new_issue_params) path = "issues.report_strings." + @issue.reportable.class.name.to_s @report_strings_yaml = t(path) @@ -73,7 +73,7 @@ class IssuesController < ApplicationController end def create - @issue = Issue.find_by_reportable_id_and_reportable_type(params[:reportable_id], params[:reportable_type]) + @issue = Issue.find_by(:reportable_id => params[:reportable_id], :reportable_type => params[:reportable_type]) # Check if Issue already exists unless @issue @issue = Issue.find_or_initialize_by(issue_params) @@ -212,8 +212,8 @@ class IssuesController < ApplicationController end def set_issues - @admin_issues = %w(DiaryEntry DiaryComment User) - @moderator_issues = %w(Changeset Note) + @admin_issues = %w[DiaryEntry DiaryComment User] + @moderator_issues = %w[Changeset Note] end def setup_user_role @@ -223,9 +223,9 @@ class IssuesController < ApplicationController def check_if_updated if @issue.reportable && (@issue.ignored? || @issue.resolved?) && @issue.reportable.has_attribute?(:updated_by) && @issue.reportable.updated_at > @last_report.updated_at - return true + true else - return false + false end end @@ -269,7 +269,7 @@ class IssuesController < ApplicationController end def sort_direction - %w(asc desc).include?(params[:direction]) ? params[:direction] : "asc" + %w[asc desc].include?(params[:direction]) ? params[:direction] : "asc" end # back-port of ActionController#redirect_back from rails 5 diff --git a/app/models/issue.rb b/app/models/issue.rb index b6a531824..40e0bb82a 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -10,10 +10,10 @@ class Issue < ActiveRecord::Base validates :reported_user_id, :presence => true # Check if more statuses are needed - enum :status => %w(open ignored resolved) - enum :type => %w(administrator moderator) + enum :status => %w[open ignored resolved] + enum :type => %w[administrator moderator] - scope :with_status, -> (issue_status) { where(:status => statuses[issue_status]) } + scope :with_status, ->(issue_status) { where(:status => statuses[issue_status]) } def read_reports resolved_at.present? ? reports.where("updated_at < ?", resolved_at) : nil diff --git a/test/controllers/issues_controller_test.rb b/test/controllers/issues_controller_test.rb index 602c6eb53..161fd6d4c 100644 --- a/test/controllers/issues_controller_test.rb +++ b/test/controllers/issues_controller_test.rb @@ -104,7 +104,7 @@ class IssuesControllerTest < ActionController::TestCase } end assert_response :redirect - assert_equal Issue.find_by_reportable_id_and_reportable_type(target_user.id, "User").reports.count, 1 + assert_equal Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").reports.count, 1 # Report without details assert_no_difference "Issue.count" do @@ -115,7 +115,7 @@ class IssuesControllerTest < ActionController::TestCase } end assert_response :redirect - assert_equal Issue.find_by_reportable_id_and_reportable_type(target_user.id, "User").reports.count, 1 + assert_equal Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").reports.count, 1 end def test_new_report_with_complete_details @@ -156,7 +156,7 @@ class IssuesControllerTest < ActionController::TestCase } end assert_response :redirect - report_count = Issue.find_by_reportable_id_and_reportable_type(target_user.id, "User").reports.count + report_count = Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").reports.count assert_equal report_count, 2 end @@ -184,17 +184,17 @@ class IssuesControllerTest < ActionController::TestCase # Test 'Resolved' get :resolve, :params => { :id => issue.id } - assert_equal Issue.find_by_reportable_id_and_reportable_type(target_user.id, "User").resolved?, true + assert_equal Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").resolved?, true assert_response :redirect # Test 'Reopen' get :reopen, :params => { :id => issue.id } - assert_equal Issue.find_by_reportable_id_and_reportable_type(target_user.id, "User").open?, true + assert_equal Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").open?, true assert_response :redirect # Test 'Ignored' get :ignore, :params => { :id => issue.id } - assert_equal Issue.find_by_reportable_id_and_reportable_type(target_user, "User").ignored?, true + assert_equal Issue.find_by(:reportable_id => target_user, :reportable_type => "User").ignored?, true assert_response :redirect end -- 2.39.5