]> git.openstreetmap.org Git - rails.git/commitdiff
Rubocop autofixes.
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 12 Jul 2017 10:49:23 +0000 (11:49 +0100)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 12 Jul 2017 10:49:23 +0000 (11:49 +0100)
app/controllers/issues_controller.rb
app/models/issue.rb
test/controllers/issues_controller_test.rb

index d1267fa4dbdd4082135e2c43ec33799fc6ea5559..ffce14774b65fe2151db1055849669e386d23441 100644 (file)
@@ -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
index b6a5318249ddb3dbb5e48b718fb5c1a01382ca18..40e0bb82aa9eb92a9bcc0f5ffcd3a2d1fe721b6b 100644 (file)
@@ -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
index 602c6eb53c135dc3ea0cdd148035a5337560f21a..161fd6d4c7cf6b7c33b5e98c0682ab5250df3364 100644 (file)
@@ -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