Skip to content

Commit

Permalink
Fixes rubocop errors
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwessman committed Oct 17, 2021
1 parent a12152a commit 11e88ca
Show file tree
Hide file tree
Showing 39 changed files with 65 additions and 246 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/mail_aliases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def update
@aliases = MailAlias.insert_aliases! mail_alias_params[:username],
mail_alias_params[:domain],
mail_alias_params[:targets] || []
rescue ActiveRecord::RecordInvalid => ex
rescue ActiveRecord::RecordInvalid
render nothing: true, status: :unprocessable_entity
return
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/adventures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ def set_mission_variables(adventure)
@group = current_user.groups.regular.last

@adventure_missions.each do |am|
@group_points_sum += am.points(@group)
@group_points_sum += am.points_per_group(@group)
end

@adventure_missions.map do |am|
am.finished = am.finished?(@group)
am.points = am.points(@group)
am.points = am.points_per_group(@group)
end

@grid = initialize_grid(@adventure_missions, locale: :sv, order: "adventure_missions.index")
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/push_devices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def create
def destroy
@push_device = current_user.push_devices.find_by(token: params[:token])

if @push_device && @push_device.destroy
if @push_device&.destroy
render json: {}, status: :ok
else
render json: {errors: "Failed to destroy push device"}, status: 422
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/cafe_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def competition
def ladybug
authorize_admin!(:ladybug, :cafe)

@date = if date = ladybug_date
@date = if (date = ladybug_date)
Time.zone.parse(date)
else
Time.zone.now
Expand Down
1 change: 0 additions & 1 deletion app/helpers/notification_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ def notification_context(notification, data)
end

def notification_icon(notification)
icon = ""
if notification.notifyable_type == "EventUser"
if notification.mode == "position"
icon("fas", "check")
Expand Down
2 changes: 1 addition & 1 deletion app/models/adventures/adventure_mission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def accepted?(group)
finished?(group) && adventure_mission_groups.by_group(group).first.pending == false
end

def points(group)
def points_per_group(group)
# Points only rewarded once mission is accepted
if accepted?(group)
adventure_mission_groups.by_group(group).first.points.to_i
Expand Down
2 changes: 1 addition & 1 deletion app/models/cars/rent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def p_time

# Requests route-helper to print url and path
def p_url
Rails.application.routes.url_helpers.rent_url(id, host: PUBLIC_URL)
Rails.application.routes.url_helpers.rent_url(id, host: Rails.application.config.public_url)
end

def p_path
Expand Down
2 changes: 1 addition & 1 deletion app/models/constant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ class Constant < ApplicationRecord

def self.get(name)
c = Constant.where(name: name).first
c && c.value || ""
c&.value.presence || ""
end
end
2 changes: 1 addition & 1 deletion app/models/council.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def to_param
end

def p_url
Rails.application.routes.url_helpers.council_url(id, host: PUBLIC_URL)
Rails.application.routes.url_helpers.council_url(id, host: Rails.application.config.public_url)
end

def p_path
Expand Down
2 changes: 0 additions & 2 deletions app/models/introduction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class Introduction < ApplicationRecord
globalize_accessors(locales: [:en, :sv],
attributes: [:title, :description])

attr_reader :dates, :events_by_day, :dates_by_week

has_many :groups, dependent: :destroy
has_many :group_users, through: :groups
has_many :users, through: :groups
Expand Down
2 changes: 1 addition & 1 deletion app/models/messages/message_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def self.add(user_id)
expires = 30.seconds.from_now.to_i
redis.expireat(KEY_BASE + token, expires)

data = {token: token, expires: expires}
{token: token, expires: expires}
end

# Finds the user_id for a token and removes the token
Expand Down
2 changes: 1 addition & 1 deletion app/models/nomination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Nomination < ApplicationRecord

def candidate_url
Rails.application.routes.url_helpers.new_candidate_url(post: post,
host: PUBLIC_URL)
host: Rails.application.config.public_url)
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/models/notifications/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ def valid_notifyable
end

def allowed_class?(notifyable)
ALLOWED.keys.include?(notifyable.class.name)
ALLOWED.key?(notifyable.class.name)
end

def allowed_mode?(notifyable, mode)
ALLOWED[notifyable.class.name].keys.include?(mode)
ALLOWED[notifyable.class.name].key?(mode)
end

def update_counter_cache
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def program_year
str = "F" if program == PHYSICS
str = "Pi" if program == MATH
str = "N" if program == NANO
str += start_year.to_s.split("").last(2).join if start_year.present?
str += start_year.to_s.chars.last(2).join if start_year.present?
str
end

Expand Down
2 changes: 1 addition & 1 deletion app/serializers/api/cafe_shift_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def isme
def councils
councils = object.cafe_worker&.councils

council_map = {
{
chosen: councils&.map { |c| [c.title, c.id] }.to_h,
available: @instance_options[:current_user].councils.map { |c| [c.title, c.id] }.to_h
}
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/api/news_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def content
end

def image
PUBLIC_URL + object.image.large.url if object.image.present?
Rails.application.config.public_url + object.image.large.url if object.image.present?
end

class Api::UserSerializer < ActiveModel::Serializer
Expand Down
4 changes: 2 additions & 2 deletions app/serializers/message_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def updated_at
def image_url
if object.image.present?
# scope is group_id
"#{PUBLIC_URL}#{download_image_group_message_path(group_id: scope, id: object.id)}"
"#{Rails.application.config.public_url}#{download_image_group_message_path(group_id: scope, id: object.id)}"
end
end

Expand All @@ -25,6 +25,6 @@ def image_url
attribute(:avatar)

def avatar
PUBLIC_URL + object.user.thumb_avatar if object.user.thumb_avatar
Rails.application.config.public_url + object.user.thumb_avatar if object.user.thumb_avatar
end
end
4 changes: 1 addition & 3 deletions app/services/cafe_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ def self.group_cafe_shifts(date_start, date_end, shifts)
month = shift.start.month
day_name = I18n.t("date.day_names")[week_day].capitalize
month_name = I18n.t("date.month_names")[month].capitalize
unless h[:years][shift.start.year][:months][month_name][:days]["#{day_name} - #{shift.start.day}/#{shift.start.month}"].nil?
h[:years][shift.start.year][:months][month_name][:days]["#{day_name} - #{shift.start.day}/#{shift.start.month}"].push(Api::CafeShiftSerializer::Index.new(shift).as_json)
end
h[:years][shift.start.year][:months][month_name][:days]["#{day_name} - #{shift.start.day}/#{shift.start.month}"]&.push(Api::CafeShiftSerializer::Index.new(shift).as_json)
end
end
end
2 changes: 1 addition & 1 deletion app/services/calendar_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def self.event(resource, locale: "sv")
ical_event.created = date_time(resource.created_at.utc, tzid: "UTC")
ical_event.last_modified = date_time(resource.updated_at.utc, tzid: "UTC")
ical_event.url = Rails.application.routes.url_helpers.event_url(resource.id,
host: PUBLIC_URL)
host: Rails.application.config.public_url)
ical_event.ip_class = "PUBLIC"
ical_event
end
Expand Down
4 changes: 1 addition & 3 deletions app/services/meeting_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ def self.create_recurring_meeting(meeting_params, old_recurring = nil)
begin
RecurringMeeting.transaction do
# If old recurring is specified destroy it
if !old_recurring.nil?
old_recurring.destroy!
end
old_recurring&.destroy!
recurring_meeting = RecurringMeeting.new(every: every)
recurring_meeting.save!
meetings.each do |meeting|
Expand Down
2 changes: 1 addition & 1 deletion app/view_objects/cafe_competition.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class CafeCompetition
attr_accessor :cafe_workers, :lp, :users, :lps, :year, :years, :amount
attr_accessor :cafe_workers, :lp, :users, :lps, :year, :amount
def initialize(lp:, year:, amount:)
@cafe_workers = CafeQueries.cafe_workers(lp, year)
@lp = lp
Expand Down
2 changes: 1 addition & 1 deletion app/view_objects/election_view.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ElectionView
attr_reader :election, :post_count
attr_reader :election
attr_accessor :rest_grid, :grid, :candidate, :user, :nomination

def initialize(election, candidate: nil)
Expand Down
2 changes: 1 addition & 1 deletion app/views/election_mailer/candidate_email.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
date: l(@candidate.election.post_closing(@candidate.post)))) %>
<br>

<%= link_to(t('.show_your_candidacies'), candidates_url(host: PUBLIC_URL), class: 'btn') %>
<%= link_to(t('.show_your_candidacies'), candidates_url(host: Rails.application.config.public_url), class: 'btn') %>
<br>
<br>

Expand Down
13 changes: 7 additions & 6 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Fsek::Application.configure do
PUBLIC_URL = "http://localhost:3000".freeze
config.public_url = "http://localhost:3000".freeze

# Settings specified here will take precedence over those in config/application.rb.

# In the development environment your application's code is reloaded on
Expand Down Expand Up @@ -29,7 +30,7 @@
# Don't care if the mailer can't send.
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
config.action_mailer.default_url_options = {host: PUBLIC_URL}
config.action_mailer.default_url_options = {host: config.public_url}
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
Expand All @@ -39,7 +40,7 @@
config.action_mailer.smtp_settings = {
address: "127.0.0.1",
port: 1025,
domain: PUBLIC_URL,
domain: config.public_url,
authentication: "plain",
enable_starttls_auto: false
}
Expand All @@ -58,8 +59,8 @@
config.assets.digest = false

# Assets for mailers
config.action_controller.asset_host = PUBLIC_URL
config.action_mailer.asset_host = PUBLIC_URL
config.action_controller.asset_host = config.public_url
config.action_mailer.asset_host = config.public_url

config.action_view.raise_on_missing_translations = true

Expand All @@ -75,7 +76,7 @@
Bullet.add_footer = true
end

config.action_cable.allowed_request_origins = [PUBLIC_URL, "file://", "file:///"]
config.action_cable.allowed_request_origins = [config.public_url, "file://", "file:///"]

# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
Expand Down
8 changes: 4 additions & 4 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Rails.application.configure do
PUBLIC_URL = "https://fsektionen.se".freeze
config.public_url = "https://fsektionen.se".freeze
# Settings specified here will take precedence over those in config/application.rb.

# Code is not reloaded between requests.
Expand Down Expand Up @@ -73,9 +73,9 @@
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :notify
config.action_mailer.asset_host = PUBLIC_URL
config.action_mailer.asset_host = config.public_url
config.action_mailer.default charset: "utf-8"
config.action_mailer.default_url_options = {host: PUBLIC_URL}
config.action_mailer.default_url_options = {host: config.public_url}
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
Expand Down Expand Up @@ -106,5 +106,5 @@
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false

config.action_cable.allowed_request_origins = [PUBLIC_URL, "file://", "file:///"]
config.action_cable.allowed_request_origins = [config.public_url, "file://", "file:///"]
end
8 changes: 4 additions & 4 deletions config/environments/staging.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Rails.application.configure do
PUBLIC_URL = "https://stage.fsektionen.se".freeze
config.public_url = "https://stage.fsektionen.se".freeze
# Settings specified here will take precedence over those in config/application.rb.

# Code is not reloaded between requests.
Expand Down Expand Up @@ -60,9 +60,9 @@
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :notify
config.action_mailer.asset_host = PUBLIC_URL
config.action_mailer.asset_host = config.public_url
config.action_mailer.default charset: "utf-8"
config.action_mailer.default_url_options = {host: PUBLIC_URL}
config.action_mailer.default_url_options = {host: config.public_url}
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
Expand Down Expand Up @@ -93,5 +93,5 @@
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false

config.action_cable.allowed_request_origins = [PUBLIC_URL, "file://", "file:///"]
config.action_cable.allowed_request_origins = [config.public_url, "file://", "file:///"]
end
8 changes: 4 additions & 4 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Fsek::Application.configure do
PUBLIC_URL = "http://localhost:3000".freeze
config.public_url = "https://fsektionen.se".freeze
# Settings specified here will take precedence over those in config/application.rb.

# The test environment is used exclusively to run your application's
Expand Down Expand Up @@ -38,9 +38,9 @@
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr

config.action_controller.asset_host = PUBLIC_URL
config.action_mailer.default_url_options = {host: PUBLIC_URL}
config.action_mailer.asset_host = PUBLIC_URL
config.action_controller.asset_host = config.public_url
config.action_mailer.default_url_options = {host: config.public_url}
config.action_mailer.asset_host = config.public_url

config.action_view.raise_on_missing_translations = true
end
3 changes: 2 additions & 1 deletion config/initializers/action_cable_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module ActionCableConfig
def self.[](key)
unless @config
template = ERB.new(File.read(Rails.root + "config/cable.yml"))
@config = YAML.load(template.result(binding))[Rails.env].symbolize_keys
# TODO: Use safe_load switched to ruby 2.6
@config = YAML.load(template.result(binding))[Rails.env].symbolize_keys # rubocop:disable Security/YAMLLoad
end

@config[key]
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/carrierwave.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
config.enable_processing = false
end

# rubocop:disable Lint/Void
AttachedImageUploader
DocumentUploader
ImageUploader
# rubocop:enable Lint/Void

CarrierWave::Uploader::Base.descendants.each do |klass|
next if klass.anonymous?
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/rpush.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# Path to log file. Relative to current directory unless absolute.
config.log_file = "log/rpush.log"

config.log_level = defined?(Rails) && Rails.logger ? Rails.logger.level : ::Logger::Severity::INFO
config.log_level = defined?(Rails) && Rails.logger ? Rails.logger.level : ::Logger::Severity::INFO # rubocop:disable Lint/RequireParentheses

# Define a custom logger.
# config.logger = MyLogger.new
Expand Down
6 changes: 3 additions & 3 deletions config/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads_count = ENV.fetch("RAILS_MAX_THREADS", 5)
threads threads_count, threads_count

# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port ENV.fetch("PORT") { 3000 }
port ENV.fetch("PORT", 3000)

# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "development" }
environment ENV.fetch("RAILS_ENV", "development")

# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked webserver processes. If using threads and workers together
Expand Down
Loading

0 comments on commit 11e88ca

Please sign in to comment.