Skip to content

Commit

Permalink
Rubocop offenses may references #99 (#161)
Browse files Browse the repository at this point in the history
* regenerate rubocop_todo file to account for updates in inspected code

* Handle several rubocop syntax offenses and delete from rubocop_todo

* rebased with master and fix rubocop issue

* update each_key and each_value to single params

* fix conditional so it will not evaluate to nil
  • Loading branch information
annaroyer authored and rylanb committed May 28, 2018
1 parent 40f86c6 commit 184d2c7
Show file tree
Hide file tree
Showing 61 changed files with 309 additions and 498 deletions.
279 changes: 70 additions & 209 deletions .rubocop_todo.yml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
2.3.7

8 changes: 4 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ group :development do
gem 'better_errors'
gem 'binding_of_caller'
gem 'faker', '~> 1.7.3'
gem 'guard-rspec', require: false
gem 'rails-erd'
gem 'rubocop', require: false
gem 'rb-fsevent', '~> 0.9.0', require: false # latest 0.10.x seems to be incompatible with listen gem
gem 'guard-rspec', require: false
gem 'rubocop', require: false
end

group :development, :test do
Expand Down Expand Up @@ -89,10 +89,10 @@ gem 'jquery-datatables-rails', git: 'https://github.com/rweng/jquery-datatables-
gem 'cocoon'

# set timezone to browser timezone
gem 'browser-timezone-rails'#, '~> 0.0.9'
gem 'browser-timezone-rails' # '~> 0.0.9'
gem 'ranked-model'

#Send email when exception occurs.
# Send email when exception occurs.
gem 'exception_notification', '~> 3.0.1'
gem 'exception_notification-rake', '~> 0.0.6'

Expand Down
8 changes: 3 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)
require File.expand_path('config/application', __dir__)

Webapp::Application.load_tasks

task(:export_log_data => :environment) do

CSV.open('orgs.csv', 'wb') do |csv|
csv << %w(id name lat lng type)
Location.where('region_id = ?', 1).each{ |l|
Expand All @@ -24,8 +23,8 @@ task(:export_log_data => :environment) do
schedule_id)
ntotal = Log.where('region_id = ? AND complete', 1).count
Log.where('region_id = ? AND complete', 1).each{ |l|
lp = LogPart.select('log_parts.id,food_types.name,weight,count').where('log_id = ?', l.id).
joins('LEFT JOIN food_types ON log_parts.food_type_id=food_types.id')
lp = LogPart.select('log_parts.id,food_types.name,weight,count').where('log_id = ?', l.id)
.joins('LEFT JOIN food_types ON log_parts.food_type_id=food_types.id')
tt = l.transport_type.nil? ? '' : l.transport_type.name
st = l.scale_type.nil? ? '' : l.scale_type.name
csv << [l.id, l.when, l.volunteers.collect{ |v| v.id }.join(':'), l.donor_id, l.recipients.collect{ |r| r.id }.join(':'),
Expand All @@ -38,5 +37,4 @@ task(:export_log_data => :environment) do
end
}
end

end
7 changes: 3 additions & 4 deletions app/controllers/absences_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ def all
index(absences, 'All Absences')
end

def index(a=nil, header='Absences')
@absences = a.nil? ? Absence.where('stop_date >= ? AND volunteer_id=?', Date.today, current_volunteer.id) : a
@header = header.nil? ? 'Absences' : header
def index(absence=nil, header='Absences')
@absences = absence || Absence.where('stop_date >= ? AND volunteer_id=?', Date.today, current_volunteer.id)
@header = header || 'Absences'
respond_to do |format|
format.html { render :index } # index.html.erb
end
Expand Down Expand Up @@ -110,5 +110,4 @@ def create
def admin_only
redirect_to(root_path) unless current_volunteer.any_admin?
end

end
13 changes: 5 additions & 8 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require 'food_robot'

class ApplicationController < ActionController::Base

protect_from_forgery with: :null_session
after_filter :setup_headers
before_filter :authenticate_user_from_token!
Expand Down Expand Up @@ -69,13 +68,11 @@ def set_vars_for_form(region)
# https://gist.github.com/josevalim/fb706b1e933ef01e4fb6
def authenticate_user_from_token!
user_email = params['volunteer_email']
return if user_email.nil?

user = Volunteer.find_by_email(user_email)
token = params['volunteer_token']
return if token.nil?
if user and Devise.secure_compare(user.authentication_token, token)
sign_in user, store: false
end
return unless user_email && token

user = Volunteer.find_by_email(params['volunteer_email'])
clearance = Devise.secure_compare(user.authentication_token, token) if user
sign_in user, store: false if clearance
end
end
1 change: 0 additions & 1 deletion app/controllers/assignments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@ def knight
def admin_only
redirect_to(root_path) unless current_volunteer.any_admin?
end

end
2 changes: 1 addition & 1 deletion app/controllers/locations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class LocationsController < ApplicationController

def hud
@location = Location.find(params[:id])
if params[:key] == @location.receipt_key || (!current_volunteer.nil? && (current_volunteer.region_admin?(@location.region) || current_volunteer.super_admin?))
if params[:key] == @location.receipt_key || (current_volunteer && (current_volunteer.region_admin?(@location.region) || current_volunteer.super_admin?))
@schedules = ScheduleChain.for_location(@location)
@logs = if @location.donor?
Log.at(@location).last(500)
Expand Down
19 changes: 5 additions & 14 deletions app/controllers/logs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def stats
@transport_years << log.year unless @transport_years.include?(log.year)
@transport_per_year[log.name] = [] if @transport_per_year[log.name].nil?
end
@transport_per_year.keys.each do |key|
@transport_per_year.each_key do |key|
@transport_per_year[key] = @transport_years.collect{ |_y| 0 }
end
@transport_data.each do |log|
Expand Down Expand Up @@ -132,14 +132,8 @@ def stats_service
when 'transport'
rq = ''
wq = ''
unless params[:region_id].nil?
rq = "AND region_id=#{params[:region_id].to_i}"
end
unless params[:timespan].nil?
if params[:timespan] == 'month'
wq = "AND \"when\" > NOW() - interval '1 month'"
end
end
rq = "AND region_id=#{params[:region_id].to_i}" if params[:region_id]
wq = "AND \"when\" > NOW() - interval '1 month'" if params[:timespan] == 'month'
noncar = Log.where("complete AND transport_type_id IN (SELECT id FROM transport_types WHERE name != 'Car') #{rq} #{wq}").count.to_f
car = Log.where("complete AND transport_type_id IN (SELECT id FROM transport_types WHERE name = 'Car') #{rq} #{wq}").count.to_f
render :text => "#{100.0*noncar/(noncar+car)} #{100.0*car/(noncar+car)}"
Expand Down Expand Up @@ -176,9 +170,7 @@ def create
render :new and return
end

if @scale_types.any? && @log.scale_type_id.nil?
@log.scale_type_id = @region.scale_types.first.id
end
@log.scale_type_id ||= @region.scale_types.first.id if @scale_types.any?

authorize! :create, @log
parse_and_create_log_parts(params, @log)
Expand Down Expand Up @@ -283,7 +275,6 @@ def take
format.json { render json: { error: 0, message: flash[:notice] } }
format.html { request.env['HTTP_REFERER'].present? ? redirect_to(:back) : redirect_to(open_logs_path) }
end

end

# can be given a single id or a list of ids
Expand Down Expand Up @@ -401,7 +392,7 @@ def export

def parse_and_create_log_parts(params, log)
ret = []
params['log_parts']&.each{ |_dc, lpdata|
params['log_parts'].each_value{ |lpdata|
lpdata['weight'] = nil if lpdata['weight'].strip == ''
lpdata['count'] = nil if lpdata['count'].strip == ''
next if lpdata['id'].nil? and lpdata['weight'].nil? and lpdata['count'].nil?
Expand Down
7 changes: 3 additions & 4 deletions app/controllers/schedule_chains_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,13 @@ def take
notice += if index == (schedule.recipient_stops.length-1)
('and ' + stop.location.name + '.')
else
(stop.location.name + ', ') #oxford comma
(stop.location.name + ', ') # oxford comma
end
end
end
flash[:notice] = notice
else
flash[:error] = "Hrmph. That didn't work..."
else
flash[:error] = "Hrmph. That didn't work..."
end
end
else
Expand All @@ -245,5 +245,4 @@ def take
def admin_only
redirect_to(root_path) unless current_volunteer.any_admin?
end

end
1 change: 0 additions & 1 deletion app/controllers/transport_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ def index
format.json { render json: TransportType.all.to_json }
end
end

end
25 changes: 12 additions & 13 deletions app/controllers/volunteers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,21 +187,20 @@ def stats
@regions = current_volunteer.admin_regions
region_ids = @regions.collect{ |region| region.id }.join(',')
@logs_per_volunteer_year =
Log.joins(:log_parts, :volunteers).
select('volunteers.id, volunteers.name, sum(weight), count(DISTINCT logs.id)').
where("complete AND region_id IN (#{region_ids}) and logs.when > ?", Date.today-12.months).
group('volunteers.id, volunteers.name').order('sum DESC')
Log.joins(:log_parts, :volunteers)
.select('volunteers.id, volunteers.name, sum(weight), count(DISTINCT logs.id)')
.where("complete AND region_id IN (#{region_ids}) and logs.when > ?", Date.today-12.months)
.group('volunteers.id, volunteers.name').order('sum DESC')
@logs_per_volunteer_month =
Log.joins(:log_parts, :volunteers).
select('volunteers.id, volunteers.name, sum(weight), count(DISTINCT logs.id)').
where("complete AND region_id IN (#{region_ids}) and logs.when > ?", Date.today-1.month).
group('volunteers.id, volunteers.name').order('sum DESC')

Log.joins(:log_parts, :volunteers)
.select('volunteers.id, volunteers.name, sum(weight), count(DISTINCT logs.id)')
.where("complete AND region_id IN (#{region_ids}) and logs.when > ?", Date.today-1.month)
.group('volunteers.id, volunteers.name').order('sum DESC')
@lazy_volunteers =
Volunteer.select('volunteers.id, name, email, count(*) as count, max("when") as last_date').
joins(:logs, :log_volunteers).
where("volunteers.id=log_volunteers.volunteer_id and logs.region_id IN (#{current_volunteer.admin_region_ids.join(',')})").
group('volunteers.id, name, email')
Volunteer.select('volunteers.id, name, email, count(*) as count, max("when") as last_date')
.joins(:logs, :log_volunteers)
.where("volunteers.id=log_volunteers.volunteer_id and logs.region_id IN (#{current_volunteer.admin_region_ids.join(',')})")
.group('volunteers.id, name, email')
end

def shift_stats
Expand Down
25 changes: 10 additions & 15 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

module ApplicationHelper

def all_admin_region_volunteer_tuples(whom)
admin_rids = whom.assignments.collect{ |a| a.admin ? a.region.id : nil }.compact
Volunteer.all.collect{ |v|
Expand All @@ -10,20 +9,17 @@ def all_admin_region_volunteer_tuples(whom)
}.compact
end

def days_ago(shift_date)
return 'today' if shift_date.today?
distance = distance_of_time_in_words(Time.zone.today, shift_date)
return "#{distance} ago" if shift_date.past?
return "#{distance} from now" if shift_date.future?
end

def readable_time_until shift
ret = shift.when.strftime('%a %b %e') + ' ('
if shift.when == Time.zone.today
ret += 'today'
elsif shift.when < Time.zone.today
ret += (Time.zone.today - shift.when).to_i.to_s + ' days ago'
elsif shift.when > Time.zone.today
ret += (shift.when - Time.zone.today).to_i.to_s + ' days from now'
end
ret += ')'
unless shift.schedule_chain.nil?
ret += " <br>between #{readable_start_time(shift.schedule_chain)} and #{readable_stop_time(shift.schedule_chain)}"
end
ret.html_safe
time = "#{shift.when.strftime('%a %b %e')} (#{days_ago(shift.when)})}"
time += "\n#{readable_start_time(shift.schedule_chain)} and #{readable_stop_time(shift.schedule_chain)}" if shift.schedule_chain
time
end

def readable_start_time schedule
Expand Down Expand Up @@ -53,5 +49,4 @@ def readable_pickup_timespan schedule
str+= readable_stop_time schedule
str
end

end
2 changes: 0 additions & 2 deletions app/helpers/devise_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

module DeviseHelper

def devise_error_messages!
flash_alerts = []
error_key = 'errors.messages.not_saved'
Expand Down Expand Up @@ -35,5 +34,4 @@ def devise_error_messages!

html.html_safe
end

end
6 changes: 2 additions & 4 deletions app/helpers/locations_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

module LocationsHelper

def readable_hours location
readable_detailed_hours location
end
Expand All @@ -23,8 +22,7 @@ def readable_detailed_hours location
str.html_safe
end

def format_time t
t.to_s(:clean_time)
def format_time time
time.to_s(:clean_time)
end

end
2 changes: 0 additions & 2 deletions app/helpers/regions_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

module RegionsHelper

def region_logo_column(record)
return '' if record.logo_file_name.nil?
image_tag(record.logo(:thumb))
Expand All @@ -11,5 +10,4 @@ def region_time_zone_form_column(record, options)
time_zone_select( 'record', 'time_zone', ActiveSupport::TimeZone.us_zones,
{:default => record.time_zone}, options)
end

end
2 changes: 1 addition & 1 deletion app/mailers/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Notifier < ActionMailer::Base
add_template_helper(ApplicationHelper)
default from: '[email protected]'
#ForceTo = "[email protected]"
# ForceTo = "[email protected]"
FORCE_TO = nil

def admin_emails_for_region(region)
Expand Down
1 change: 0 additions & 1 deletion app/models/assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ def self.add_volunteer_to_region volunteer, region
volunteer.save
return true
end

end
Loading

0 comments on commit 184d2c7

Please sign in to comment.