Skip to content

Commit

Permalink
[frontend] Fix Rails/Present offense
Browse files Browse the repository at this point in the history
Mob-programming with @DavidKang
  • Loading branch information
bgeuken authored and David Kang committed Dec 15, 2017
1 parent 26f770e commit 724d78b
Show file tree
Hide file tree
Showing 55 changed files with 131 additions and 137 deletions.
6 changes: 0 additions & 6 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,6 @@ Rails/OutputSafety:
- 'src/api/app/helpers/webui/request_helper.rb'
- 'src/api/app/helpers/webui/webui_helper.rb'

# Offense count: 131
# Cop supports --auto-correct.
# Configuration parameters: NotNilAndNotEmpty, NotBlank, UnlessBlank.
Rails/Present:
Enabled: false

# Offense count: 11
# Cop supports --auto-correct.
# Configuration parameters: Include.
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ def get_request_path
query_string = request.query_string
if request.form_data?
# it's uncommon, but possible that we have both
query_string += "&" unless query_string.blank?
query_string += "&" if query_string.present?
query_string += request.raw_post
end
query_string = "?" + query_string unless query_string.blank?
query_string = "?" + query_string if query_string.present?
path + query_string
end

Expand Down
2 changes: 1 addition & 1 deletion src/api/app/controllers/configurations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def update
value = xml[key.to_s] || params[key.to_s]

# is it defined in options.yml
if value && !value.blank?
if value && value.present?
v = ::Configuration.map_value(key, value)
ov = ::Configuration.map_value(key, ::Configuration::OPTIONS_YML[key])
if ov != v && ov.present?
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/controllers/person_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ def internal_register
raise ErrRegisterSave, "Missing iChain header"
end
login = request.env['HTTP_X_USERNAME']
email = request.env['HTTP_X_EMAIL'] unless request.env['HTTP_X_EMAIL'].blank?
realname = request.env['HTTP_X_FIRSTNAME'] + " " + request.env['HTTP_X_LASTNAME'] unless request.env['HTTP_X_LASTNAME'].blank?
email = request.env['HTTP_X_EMAIL'] if request.env['HTTP_X_EMAIL'].present?
realname = request.env['HTTP_X_FIRSTNAME'] + " " + request.env['HTTP_X_LASTNAME'] if request.env['HTTP_X_LASTNAME'].present?
end

UnregisteredUser.register(login: login, realname: realname, email:
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/controllers/public_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def binary_packages
# do not support it (exception zypp via ymp files)
dist = Distribution.find_by_project_and_repository(pe.link.project.name, pe.link.name)
next unless dist
unless binary_map[repo.name].blank?
if binary_map[repo.name].present?
dist_id = dist.id
@binary_links[dist_id] ||= {}
binary = binary_map[repo.name].select { |bin| bin.value(:name) == @pkg.name }.first
Expand Down
6 changes: 3 additions & 3 deletions src/api/app/controllers/request_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ def request_create
xml = nil
BsRequest.transaction do
@req = BsRequest.new_from_xml(request.raw_post.to_s)
@req.set_add_revision unless params[:addrevision].blank?
@req.set_ignore_build_state unless params[:ignore_build_state].blank?
@req.set_add_revision if params[:addrevision].present?
@req.set_ignore_build_state if params[:ignore_build_state].present?
@req.save!

xml = @req.render_xml
Expand Down Expand Up @@ -213,7 +213,7 @@ def request_command_setincident
end

def request_command_setacceptat
time = DateTime.parse(params[:time]) unless params[:time].blank?
time = DateTime.parse(params[:time]) if params[:time].present?
@req.set_accept_at!(time)
render_ok
end
Expand Down
6 changes: 3 additions & 3 deletions src/api/app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def owner
Backend::Test.start if Rails.env.test?

obj = nil
obj = params[:binary] unless params[:binary].blank?
obj = User.find_by_login!(params[:user]) unless params[:user].blank?
obj = Group.find_by_title!(params[:group]) unless params[:group].blank?
obj = params[:binary] if params[:binary].present?
obj = User.find_by_login!(params[:user]) if params[:user].present?
obj = Group.find_by_title!(params[:group]) if params[:group].present?
obj = Package.get_by_project_and_name(params[:project], params[:package]) unless params[:project].blank? || params[:package].blank?
obj = Project.get_by_name(params[:project]) if obj.nil? && params[:project].present?

Expand Down
2 changes: 1 addition & 1 deletion src/api/app/controllers/source_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ def project_command_move
commit = { login: User.current.login,
lowprio: 1,
comment: "Project move from #{params[:oproject]} to #{params[:project]}" }
commit[:comment] = params[:comment] unless params[:comment].blank?
commit[:comment] = params[:comment] if params[:comment].present?
Backend::Api::Sources::Project.move(params[:oproject], params[:project])
project.name = params[:project]
project.store(commit)
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/controllers/webui/feeds_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def commits
redirect_to '/403.html', status: :forbidden
return
end
unless params[:starting_at].blank?
if params[:starting_at].present?
@start = (begin
Time.zone.parse(params[:starting_at])
rescue
Expand All @@ -27,7 +27,7 @@ def commits
end
@start ||= 7.days.ago
@finish = nil
unless params[:ending_at].blank?
if params[:ending_at].present?
@finish = (begin
Time.zone.parse(params[:ending_at])
rescue
Expand Down
8 changes: 4 additions & 4 deletions src/api/app/controllers/webui/package_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def statistics
rescue ActiveXML::Transport::ForbiddenError
end

return unless @statistics.blank?
return if @statistics.present?
flash[:error] = "No statistics of a successful build could be found in #{@repository}/#{@arch}"
redirect_to controller: 'package', action: :binaries, project: @project,
package: @package, repository: @repository, nextstatus: 404
Expand Down Expand Up @@ -453,7 +453,7 @@ def rdiff

options = {}
[:orev, :opackage, :oproject, :linkrev, :olinkrev].each do |k|
options[k] = params[k] unless params[k].blank?
options[k] = params[k] if params[k].present?
end
options[:rev] = @rev if @rev
return unless get_diff(@project.name, @package.name, options)
Expand Down Expand Up @@ -755,12 +755,12 @@ def set_job_status

begin
jobstatus = get_job_status(@project, @package, @repo, @arch)
unless jobstatus.blank?
if jobstatus.present?
js = Xmlhash.parse(jobstatus)
@workerid = js.get('workerid')
@buildtime = Time.now.to_i - js.get('starttime').to_i
ld = js.get('lastduration')
@percent = (@buildtime * 100) / ld.to_i unless ld.blank?
@percent = (@buildtime * 100) / ld.to_i if ld.present?
end
rescue
@workerid = nil
Expand Down
6 changes: 3 additions & 3 deletions src/api/app/controllers/webui/patchinfo_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ def save
}
xml = node.patchinfo(attrs) do
params[:selected_binaries].to_a.each do |binary|
unless binary.blank?
if binary.present?
node.binary(binary)
end
end
node.name params[:name] unless params[:name].blank?
node.name params[:name] if params[:name].present?
node.packager params[:packager]
issues.to_a.each do |issue|
unless IssueTracker.find_by_name(issue[1])
Expand Down Expand Up @@ -312,7 +312,7 @@ def get_binaries
end

def require_exists
unless params[:package].blank?
if params[:package].present?
begin
@package = Package.get_by_project_and_name(params[:project], params[:package], use_source: false)
rescue Package::UnknownObjectError
Expand Down
6 changes: 3 additions & 3 deletions src/api/app/controllers/webui/project_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def monitor

find_opt = { project: @project, view: 'status', code: @status_filter,
arch: @arch_filter, repo: @repo_filter }
find_opt[:lastbuild] = 1 unless @lastbuild_switch.blank?
find_opt[:lastbuild] = 1 if @lastbuild_switch.present?

@buildresult = Buildresult.find(find_opt)
unless @buildresult
Expand Down Expand Up @@ -959,7 +959,7 @@ def status_check_package(p)
end

currentpack['name'] = pname
currentpack['failedcomment'] = p.failed_comment unless p.failed_comment.blank?
currentpack['failedcomment'] = p.failed_comment if p.failed_comment.present?

newest = 0

Expand Down Expand Up @@ -1037,7 +1037,7 @@ def check_devel_package_status(currentpack, p)
end

def status_filter_packages
filter_for_user = User.find_by_login!(@filter_for_user) unless @filter_for_user.blank?
filter_for_user = User.find_by_login!(@filter_for_user) if @filter_for_user.present?
current_develproject = @filter || @all_projects
@develprojects = Hash.new
packages_to_filter_for = nil
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/controllers/webui/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def create_flag

@flag = @main_object.flags.new(status: params[:status], flag: params[:flag])
@flag.architecture = Architecture.find_by_name(params[:architecture])
@flag.repo = params[:repository] unless params[:repository].blank?
@flag.repo = params[:repository] if params[:repository].present?

respond_to do |format|
if @flag.save
Expand Down
8 changes: 4 additions & 4 deletions src/api/app/controllers/webui/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ def search
#
def set_parameters
@search_attrib_type_id = nil
@search_attrib_type_id = params[:attrib_type_id] unless params[:attrib_type_id].blank?
@search_attrib_type_id = params[:attrib_type_id] if params[:attrib_type_id].present?

@search_issue = nil
@search_issue = params[:issue].strip unless params[:issue].blank?
@search_issue = params[:issue].strip if params[:issue].present?

@search_tracker = nil
@search_tracker = params[:issue_tracker] unless params[:issue_tracker].blank?
@search_tracker = params[:issue_tracker] if params[:issue_tracker].present?

@search_text = ""
@search_text = params[:search_text].strip unless params[:search_text].blank?
@search_text = params[:search_text].strip if params[:search_text].present?
@search_text = @search_text.delete("'[]\n")

@search_what = []
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/controllers/webui/webui_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def require_package
required_parameters :package
params[:rev], params[:package] = params[:pkgrev].split('-', 2) if params[:pkgrev]
@project ||= params[:project]
unless params[:package].blank?
if params[:package].present?
begin
@package = Package.get_by_project_and_name(@project.to_param, params[:package],
{ use_source: false, follow_project_links: true, follow_multibuild: true })
Expand Down
6 changes: 3 additions & 3 deletions src/api/app/helpers/flag_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def remove_flag(flag, repository, arch = nil)

flags_to_remove = Array.new
flaglist.each do |f|
next if !repository.blank? && f.repo != repository
next if repository.blank? && !f.repo.blank?
next if !arch.blank? && f.architecture != arch
next if repository.present? && f.repo != repository
next if repository.blank? && f.repo.present?
next if arch.present? && f.architecture != arch
next if arch.blank? && !f.architecture.nil?
flags_to_remove << f
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/helpers/maintenance_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def copy_binaries_to_repository(source_repository, source_package, target_repo,
multibuild_container, setrelease)
u_id = get_updateinfo_id(source_package, target_repo)
source_package_name = source_package.name
unless multibuild_container.blank?
if multibuild_container.present?
source_package_name << ":" << multibuild_container
target_package_name = target_package_name.gsub(/:.*/, '') << ":" << multibuild_container
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/helpers/webui/buildresult_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def arch_repo_table_cell(repo, arch, package_name, status = nil, enable_help = t
code = status['code']
theclass = 'status_' + code.gsub(/[- ]/, '_')
# special case for scheduled jobs with constraints limiting the workers a lot
theclass = "status_scheduled_warning" if code == "scheduled" && !link_title.blank?
theclass = "status_scheduled_warning" if code == "scheduled" && link_title.present?
else
code = ''
theclass = ' '
Expand Down
6 changes: 3 additions & 3 deletions src/api/app/jobs/consistency_check_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def perform(fix = nil)
@errors << package_existence_consistency_check(project, fix)
@errors << project_meta_check(project, fix)
end
unless @errors.blank?
if @errors.present?
@errors = "FIXING the following errors:\n" << @errors if fix
Rails.logger.error("Detected problems during consistency check")
Rails.logger.error(@errors)
Expand Down Expand Up @@ -49,7 +49,7 @@ def check_project(fix = nil)
rescue Project::UnknownObjectError
# specified but does not exist in api. does it also not exist in backend?
answer = import_project_from_backend(ENV['project'])
unless answer.blank?
if answer.present?
@errors << answer
return
end
Expand All @@ -64,7 +64,7 @@ def check_project(fix = nil)
project.destroy if fix
end
@errors << package_existence_consistency_check(project, fix)
puts @errors unless @errors.blank?
puts @errors if @errors.present?
end

private
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/mixins/has_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def render_main_attributes(builder, params)
p[:namespace] = attr.attrib_type.attrib_namespace.name
p[:binary] = attr.binary if attr.binary
builder.attribute(p) do
unless attr.issues.blank?
if attr.issues.present?
attr.issues.each do |ai|
builder.issue(name: ai.name, tracker: ai.issue_tracker.name)
end
Expand Down
8 changes: 4 additions & 4 deletions src/api/app/models/bs_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ def self.new_from_xml(xml)
str = state.delete('when')
request.updated_when = Time.zone.parse(str) if str
str = state.delete('superseded_by') || ''
request.superseded_by = Integer(str) unless str.blank?
raise ArgumentError, "too much information #{state.inspect}" unless state.blank?
request.superseded_by = Integer(str) if str.present?
raise ArgumentError, "too much information #{state.inspect}" if state.present?

request.description = hashed.value('description')
hashed.delete('description')
Expand All @@ -229,7 +229,7 @@ def self.new_from_xml(xml)
request.reviews << Review.new_from_xml_hash(r)
end if reviews

raise ArgumentError, "too much information #{hashed.inspect}" unless hashed.blank?
raise ArgumentError, "too much information #{hashed.inspect}" if hashed.present?

request.updated_at ||= Time.now
end
Expand Down Expand Up @@ -365,7 +365,7 @@ def render_xml(opts = {})
builder.history(attributes) do
# request description is on purpose the comment in history:
builder.description! "Request created"
builder.comment! description unless description.blank?
builder.comment! description if description.present?
end
end
if opts[:withfullhistory]
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/bs_request/find_for/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def all

# include all groups of user
usergroups = user.groups.map { |group| "'#{group.title}'" }
or_in_and << "reviews.by_group in (#{usergroups.join(',')})" unless usergroups.blank?
or_in_and << "reviews.by_group in (#{usergroups.join(',')})" if usergroups.present?

@relation, inner_or = extend_query_for_involved_reviews(user, or_in_and, @relation, review_states, inner_or)
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/bs_request/find_for/user_group_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def extend_query_for_involved_reviews(obj, or_in_and, requests, review_states, i
review_states.each do |review_state|
# find requests where obj is maintainer in target project
projects = obj.involved_projects.pluck('projects.name').map { |project| quote(project) }
or_in_and << "reviews.by_project in (#{projects.join(',')})" unless projects.blank?
or_in_and << "reviews.by_project in (#{projects.join(',')})" if projects.present?

## find request where user is maintainer in target package, except we have to project already
obj.involved_packages.includes(:project).pluck('packages.name, projects.name').each do |ip|
Expand Down
Loading

0 comments on commit 724d78b

Please sign in to comment.