@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
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
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)
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)
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
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
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
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
}
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
}
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
}
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
# 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