Skip to content

Commit

Permalink
Fix other Naming/ cops (1 still left open)
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed Dec 3, 2023
1 parent 9907630 commit 6c4f737
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 48 deletions.
2 changes: 1 addition & 1 deletion app/abilities/medium_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(user)

can [:edit, :update, :enrich, :publish, :destroy, :cancel_publication,
:add_item, :add_reference, :add_screenshot, :remove_screenshot,
:import_script_items, :import_manuscript, :get_statistics,
:import_script_items, :import_manuscript, :statistics,
:render_medium_tags, :fill_quizzable_area,
:fill_reassign_modal], Medium do |medium|
user.can_edit?(medium)
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/media.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ $(document).on 'turbolinks:load', ->

$(document).on 'click', '#showMediaStatistics', ->
mediumId = $(this).data('medium')
$.ajax Routes.get_statistics_path(mediumId),
$.ajax Routes.statistics_path(mediumId),
type: 'GET'
dataType: 'script'
return
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/main_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def current_ability

def home
cookies[:locale] = current_user.locale if user_signed_in?
get_announcements
announcements
end

def error
Expand Down Expand Up @@ -43,7 +43,7 @@ def start
:term)
.sort
end
get_announcements
announcements
@talks = current_user.talks.includes(lecture: :term)
.select { |t| t.visible_for_user?(current_user) }
.sort_by do |t|
Expand All @@ -60,7 +60,7 @@ def check_for_consent
redirect_to consent_profile_path unless current_user.consents
end

def get_announcements # rubocop:todo Naming/AccessorMethodName
def announcements
@announcements = Announcement.where(on_main_page: true, lecture: nil)
.pluck(:details)
.join('<hr class="my-3" w-100>')
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/media_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def register_download
head :ok
end

def get_statistics # rubocop:todo Naming/AccessorMethodName
def statistics
I18n.locale = @medium.locale || I18n.default_locale
medium_consumption = Consumption.where(medium_id: @medium.id)
if @medium.video.present?
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def first_course_independent?
&.first&.term_independent
end

def get_announcements # rubocop:todo Naming/AccessorMethodName
def announcements
megaphone_icon_str = '<i class="bi bi-megaphone p-2"></i>'
separator_str = "<hr class=\"my-3 w-100\">#{megaphone_icon_str}"
Announcement.active_on_main
Expand Down
4 changes: 2 additions & 2 deletions app/mailers/exception_handler/exception_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class ExceptionMailer < ActionMailer::Base
default template_path: "exception_handler/mailers"
# => http://stackoverflow.com/a/18579046/1143732

def new_exception(e) # rubocop:todo Naming/MethodParameterName
@exception = e
def new_exception(err)
@exception = err
mail to: ExceptionHandler.config.email
Rails.logger.info "Exception Sent To → #{ExceptionHandler.config.email}"
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def check_destructibility
true
end

def has_documents? # rubocop:todo Naming/PredicateName
def documents?
return false unless medium

medium.video || medium.manuscript || medium.geogebra ||
Expand Down
2 changes: 1 addition & 1 deletion app/models/mampf_matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def self.trivial_instance
"matrix([0,0],[0,0]")
end

def entry(i, j) # rubocop:todo Naming/MethodParameterName
def entry(i, j) # rubocop:disable Naming/MethodParameterName
return "0" if i > @row_count || j > @column_count

@coefficients[((i - 1) * @column_count) + (j - 1)]
Expand Down
8 changes: 4 additions & 4 deletions app/models/medium.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1061,17 +1061,17 @@ def becomes_quizzable
becomes(Remark)
end

def containingWatchlists(user) # rubocop:todo Naming/MethodName
def containing_watchlists(user)
Watchlist.where(id: WatchlistEntry.where(medium: self).pluck(:watchlist_id),
user: user)
end

def containingWatchlistsNames(user) # rubocop:todo Naming/MethodName
watchlists = containingWatchlists(user)
def containing_watchlists_names(user)
watchlists = containing_watchlists(user)
if watchlists.empty?
""
else
containingWatchlists(user).pluck(:name)
watchlists.pluck(:name)
end
end

Expand Down
4 changes: 0 additions & 4 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -650,10 +650,6 @@ def tutorials(lecture)
given_tutorials.where(lecture: lecture)
end

def has_tutorials?(lecture) # rubocop:todo Naming/PredicateName
!given_tutorials.where(lecture: lecture).empty?
end

def proper_submissions_count
submissions.proper.size
end
Expand Down
6 changes: 2 additions & 4 deletions app/models/watchlist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ class Watchlist < ApplicationRecord
validates :name, presence: true, uniqueness: { scope: :user_id }
# rubocop:enable Rails/UniqueValidationWithoutIndex

# rubocop:todo Naming/VariableName
def owned_by?(otherUser) # rubocop:todo Naming/MethodParameterName, Naming/VariableName
# rubocop:enable Naming/VariableName
user == otherUser # rubocop:todo Naming/VariableName
def owned_by?(other_user)
user == other_user
end
end
2 changes: 1 addition & 1 deletion app/views/layouts/devise.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<%# Announcements %>
<% if Announcement.active_on_main.exists? %>
<div id="announcement-box" class="landing-box">
<%= get_announcements().html_safe %>
<%= announcements().html_safe %>
</div>
<% end %>

Expand Down
8 changes: 4 additions & 4 deletions app/views/media/_medium.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@
title="<%= t('medium.waiting_for_tag') %>">
</i>
<% end %>
<% if !medium.containingWatchlists(current_user).empty? %>
<% if !medium.containing_watchlists(current_user).empty? %>
<%= link_to '',
watchlist_path(medium.containingWatchlists(current_user).first),
watchlist_path(medium.containing_watchlists(current_user).first),
class: 'fas fa-bookmark text-light me-2',
style: 'text-decoration: none;',
data: { toggle: 'tooltip',
placement: 'bottom' },
title: t('watchlist_entry.list',
count: medium.containingWatchlists(current_user).size,
watchlists: medium.containingWatchlistsNames(current_user).join(", ")) %>
count: medium.containing_watchlists(current_user).size,
watchlists: medium.containing_watchlists_names(current_user).join(", ")) %>
<% end %>
<%= link_to '',
add_medium_to_watchlist_path(medium),
Expand Down
4 changes: 2 additions & 2 deletions app/views/submissions/_card.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</div>
</div>
<% if assignment&.medium&.visible_for_user?(current_user) &&
(assignment.medium.tags.present? || assignment.has_documents?) %>
(assignment.medium.tags.present? || assignment.documents?) %>
<ul class="list-group list-group-flush">
<li class="list-group-item submissionSubHeader">
<div class="row">
Expand All @@ -44,7 +44,7 @@
<% end %>
</div>
<div class="col-12">
<% if assignment.has_documents? %>
<% if assignment.documents? %>
<div class="flexdiv mt-2">
<%= render partial: 'media/medium/buttons',
locals: { medium: assignment.medium,
Expand Down
6 changes: 3 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,9 @@
to: "media#register_download",
as: "register_download"

get "media/:id/get_statistics",
to: "media#get_statistics",
as: "get_statistics"
get "media/:id/statistics",
to: "media#statistics",
as: "statistics"

get "media/:id/show_comments",
to: "media#show_comments",
Expand Down
29 changes: 14 additions & 15 deletions spec/support/request_parse_helper.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
module RequestParsingHelper
# Parse the request body as HTML and return the number of hits
def parse_media_search(response)
# rubocop:todo Naming/VariableName
searchResults = response.body.match(/(?<=searchResults.innerHTML = ').*(?=';)/)[0].gsub('\n',
"")
# rubocop:enable Naming/VariableName
# strip whitespaces in searchResults
searchResults = searchResults.gsub(/\s+/, " ") # rubocop:todo Naming/VariableName
# fix " in searchResults
searchResults = searchResults.gsub('\\\"', '"') # rubocop:todo Naming/VariableName
# fix \/ in searchResults
searchResults = searchResults.gsub('\\/', "/") # rubocop:todo Naming/VariableName
search_results = response.body
.match(/(?<=search_results.innerHTML = ').*(?=';)/)[0]
.gsub('\n', "")
# strip whitespaces in search_results
search_results = search_results.gsub(/\s+/, " ")
# fix " in search_results
search_results = search_results.gsub('\\\"', '"')
# fix \/ in search_results
search_results = search_results.gsub('\\/', "/")

# parse searchResults as html
searchResults = Nokogiri::HTML(searchResults) # rubocop:todo Naming/VariableName
# parse search_results as html
search_results = Nokogiri::HTML(search_results)

# get text within first "col-12 col-lg-2" div
treffer = searchResults.css("div.col-12.col-lg-2").first.text # rubocop:todo Naming/VariableName
# get number in treffer
treffer.match(/\d+/)[0].to_i
matches = search_results.css("div.col-12.col-lg-2").first.text
# get number in matches
matches.match(/\d+/)[0].to_i
end
end

Expand Down

0 comments on commit 6c4f737

Please sign in to comment.