Skip to content

Commit

Permalink
Rubocop Fixes (#433)
Browse files Browse the repository at this point in the history
* Working on some rubocop cleanup.

* Ran the auto-correct (should have done this in the first place)

* Rubocop fixes

* rubocop fixes
  • Loading branch information
seanmarcia authored Jun 15, 2018
1 parent b383867 commit 0683743
Show file tree
Hide file tree
Showing 112 changed files with 999 additions and 2,106 deletions.
1,046 changes: 13 additions & 1,033 deletions .rubocop_todo.yml

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions Capfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ require "capistrano/deploy"
# https://github.com/capistrano/passenger
#
# require 'capistrano/rvm'
require 'capistrano/rbenv'
require "capistrano/rbenv"
# require 'capistrano/chruby'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano/puma'
require 'capistrano/rails/console'
require "capistrano/bundler"
require "capistrano/rails/assets"
require "capistrano/rails/migrations"
require "capistrano/puma"
require "capistrano/rails/console"
require "capistrano/scm/git"

install_plugin Capistrano::SCM::Git
install_plugin Capistrano::Puma # Default puma tasks
install_plugin Capistrano::Puma::Workers # if you want to control the workers (in cluster mode)
install_plugin Capistrano::Puma::Nginx # if you want to upload a nginx site template
install_plugin Capistrano::Puma # Default puma tasks
install_plugin Capistrano::Puma::Workers # if you want to control the workers (in cluster mode)
install_plugin Capistrano::Puma::Nginx # if you want to upload a nginx site template

# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
122 changes: 61 additions & 61 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,78 +1,78 @@
source 'https://rubygems.org'
source "https://rubygems.org"

git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end

gem 'api-auth', '~> 1.5'
gem 'bootstrap-sass'
gem 'bugsnag'
gem 'chartkick'
gem 'cocoon'
gem 'coffee-rails'
gem 'devise'
gem 'devise_invitable'
gem 'dotenv-rails'
gem 'font-awesome-rails'
gem 'font-ionicons-rails'
gem 'groupdate', '~> 3.2'
gem 'jbuilder'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'newrelic_rpm'
gem 'paperclip'
gem 'pg', '~> 0.2'
gem 'prawn-rails'
gem 'puma'
gem 'rails', '~> 5.2.0'
gem 'react-rails', '~> 2.3.0'
gem 'sass-rails'
gem 'simple_form'
gem 'skylight'
gem 'uglifier', '>= 1.3.0'
gem 'therubyracer', '~> 0.12', platforms: :ruby
gem 'yajl-ruby'
gem 'toastr-rails'
gem "api-auth", "~> 1.5"
gem "bootstrap-sass"
gem "bugsnag"
gem "chartkick"
gem "cocoon"
gem "coffee-rails"
gem "devise"
gem "devise_invitable"
gem "dotenv-rails"
gem "font-awesome-rails"
gem "font-ionicons-rails"
gem "groupdate", "~> 3.2"
gem "jbuilder"
gem "jquery-rails"
gem "jquery-ui-rails"
gem "newrelic_rpm"
gem "paperclip"
gem "pg", "~> 0.2"
gem "prawn-rails"
gem "puma"
gem "rails", "~> 5.2.0"
gem "react-rails", "~> 2.3.0"
gem "sass-rails"
gem "simple_form"
gem "skylight"
gem "uglifier", ">= 1.3.0"
gem "therubyracer", "~> 0.12", platforms: :ruby
gem "yajl-ruby"
gem "toastr-rails"

group :development, :test do
gem 'awesome_print'
gem 'byebug', '~> 9.0', platform: :mri
gem 'guard-rspec'
gem 'pry'
gem 'rspec-rails', '~> 3.5'
gem 'terminal-notifier-guard'
gem 'terminal-notifier'
gem 'rubocop'
gem "awesome_print"
gem "byebug", "~> 9.0", platform: :mri
gem "guard-rspec"
gem "pry"
gem "rspec-rails", "~> 3.5"
gem "terminal-notifier-guard"
gem "terminal-notifier"
gem "rubocop"
end

group :development do
gem 'annotate'
gem 'binding_of_caller'
gem 'better_errors'
gem 'capistrano-rails'
gem 'capistrano-rbenv'
gem 'capistrano-bundler'
gem 'capistrano3-puma'
gem 'capistrano-rails-console', require: false
gem 'listen', '~> 3.0.5'
gem 'rails-erd'
gem 'spring'
gem 'spring-watcher-listen'
gem 'web-console'
gem "annotate"
gem "binding_of_caller"
gem "better_errors"
gem "capistrano-rails"
gem "capistrano-rbenv"
gem "capistrano-bundler"
gem "capistrano3-puma"
gem "capistrano-rails-console", require: false
gem "listen", "~> 3.0.5"
gem "rails-erd"
gem "spring"
gem "spring-watcher-listen"
gem "web-console"
end

group :test do
gem 'capybara', '~> 2.18'
gem 'capybara-screenshot'
gem 'database_cleaner'
gem 'factory_bot_rails'
gem 'launchy'
gem 'chromedriver-helper'
gem 'selenium-webdriver'
gem 'rails-controller-testing'
gem 'webmock', '~> 2.1'
gem "capybara", "~> 2.18"
gem "capybara-screenshot"
gem "database_cleaner"
gem "factory_bot_rails"
gem "launchy"
gem "chromedriver-helper"
gem "selenium-webdriver"
gem "rails-controller-testing"
gem "webmock", "~> 2.1"
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', '~> 1.2', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem "tzinfo-data", "~> 1.2", platforms: %i(mingw mswin x64_mingw jruby)
15 changes: 7 additions & 8 deletions app/controllers/adjustments_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class AdjustmentsController < ApplicationController
before_action :set_adjustment, only: [:show, :destroy]
before_action :set_adjustment, only: %i(show destroy)

# GET /adjustments
# GET /adjustments.json
Expand All @@ -12,8 +12,7 @@ def index

# GET /adjustments/1
# GET /adjustments/1.json
def show
end
def show; end

# GET /adjustments/new
def new
Expand All @@ -33,13 +32,13 @@ def create
@adjustment.storage_location.adjust!(@adjustment)

if @adjustment.save
redirect_to adjustment_path(@adjustment), notice: 'Adjustment was successfully created.'
redirect_to adjustment_path(@adjustment), notice: "Adjustment was successfully created."
else
flash[:error] = @adjustment.errors.collect { |model,message| "#{model}: " + message }.join("<br />".html_safe)
flash[:error] = @adjustment.errors.collect { |model, message| "#{model}: " + message }.join("<br />".html_safe)
render :new
end
else
flash[:error] = @adjustment.errors.collect { |model,message| "#{model}: " + message }.join("<br />".html_safe)
flash[:error] = @adjustment.errors.collect { |model, message| "#{model}: " + message }.join("<br />".html_safe)
render :new
end
rescue Errors::InsufficientAllotment => ex
Expand All @@ -55,11 +54,11 @@ def set_adjustment

def adjustment_params
params.require(:adjustment).permit(:organization_id, :storage_location_id, :comment,
line_items_attributes: [:item_id, :quantity, :_destroy])
line_items_attributes: %i(item_id quantity _destroy))
end

def filter_params
return {} unless params.has_key?(:filters)
return {} unless params.key?(:filters)
params.require(:filters).slice(:at_location)
end
end
8 changes: 4 additions & 4 deletions app/controllers/admins_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ def edit

def update
@organization = Organization.find(params[:id])
if @organization.update_attributes(organization_params)
redirect_to admins_path, notice: 'Updated organization!'
if @organization.update(organization_params)
redirect_to admins_path, notice: "Updated organization!"
else
flash[:error] = 'Failed to update this organization.'
flash[:error] = "Failed to update this organization."
render :edit
end
end
Expand All @@ -21,7 +21,7 @@ def index

def invite_user
User.invite!(email: params[:email], name: params[:name], organization_id: params[:org])
redirect_to admins_path, notice: 'User invited to organization!'
redirect_to admins_path, notice: "User invited to organization!"
end

def new
Expand Down
31 changes: 15 additions & 16 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ def current_organization
end
helper_method :current_organization

def organization_url_options(options={})
def organization_url_options(options = {})
options.merge(organization_id: current_organization.to_param)
end
helper_method :organization_url_options

# override Rails' default_url_options to ensure organization_id is added to
# each URL generated
def default_url_options(options = {})
if current_organization.present? && !options.has_key?(:organization_id)
if current_organization.present? && !options.key?(:organization_id)
options[:organization_id] = current_organization.to_param
elsif current_user && !current_user.is_superadmin? && current_user.organization.present?
options[:organization_id] = current_user.organization.to_param
Expand All @@ -31,46 +31,45 @@ def default_url_options(options = {})
end

def authorize_user
verboten! unless (params[:controller].include?("devise") || current_organization.id == current_user.organization_id)
verboten! unless params[:controller].include?("devise") || current_organization.id == current_user.organization_id
end

def not_found!
respond_to do |format|
format.html { render template: "errors/404", layout: "layouts/application", status: 404 }
format.json { render body: nil, status: 404 }
format.html { render template: "errors/404", layout: "layouts/application", status: :not_found }
format.json { render body: nil, status: :not_found }
end
end

def verboten!
respond_to do |format|
format.html { redirect_to dashboard_path, flash: { error: "Access Denied." } }
format.json { render body: nil, status: 403 }
format.json { render body: nil, status: :forbidden }
end
end

def omgwtfbbq!
respond_to do |format|
format.html { render template: 'errors/500', layout: 'layouts/error', status: 500 }
format.json { render nothing: true, status: 500 }
format.html { render template: "errors/500", layout: "layouts/error", status: :internal_server_error }
format.json { render nothing: true, status: :internal_server_error }
end
end

# rescue_from CanCan::AccessDenied do |exception|
# respond_to do |format|
# format.json { head :forbidden, content_type: 'text/html' }
# format.html { redirect_to main_app.root_url, notice: exception.message }
# format.js { head :forbidden, content_type: 'text/html' }
# end
# respond_to do |format|
# format.json { head :forbidden, content_type: 'text/html' }
# format.html { redirect_to main_app.root_url, notice: exception.message }
# format.js { head :forbidden, content_type: 'text/html' }
# end
# end

def swaddled
response.headers['swaddled-by'] = 'rubyforgood'
response.headers["swaddled-by"] = "rubyforgood"
end

protected
protected

def configure_permitted_parameters
devise_parameter_sanitizer.permit(:account_update, keys: [:name])
end

end
11 changes: 6 additions & 5 deletions app/controllers/barcode_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def find

def update
@barcode_item = current_organization.barcode_items.find(params[:id])
if @barcode_item.update_attributes(barcode_item_params)
redirect_to barcode_items_path, notice: "Barcode updated!"
if @barcode_item.update(barcode_item_params)
redirect_to barcode_items_path, notice: "Barcode updated!"
else
flash[:error] = "Something didn't work quite right -- try again?"
render action: :edit
Expand All @@ -58,7 +58,7 @@ def update
def destroy
begin
# If the user is a superadmin, they can delete any Barcode
if (current_user.is_superadmin?)
if current_user.is_superadmin?
barcode = BarcodeItem.find(params[:id])
# Otherwise it has to be non-global in their organization
else
Expand All @@ -72,13 +72,14 @@ def destroy
redirect_to barcode_items_path
end

private
private

def barcode_item_params
params.require(:barcode_item).permit(:value, :barcodeable_id, :quantity, :global).merge(organization_id: current_organization.id)
end

def filter_params
return {} unless params.has_key?(:filters)
return {} unless params.key?(:filters)
params.require(:filters).slice(:barcodeable_id, :less_than_quantity, :greater_than_quantity, :equal_to_quantity, :include_global, :canonical_item_id)
end
end
16 changes: 8 additions & 8 deletions app/controllers/diaper_drive_participants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ def index
def create
@diaper_drive_participant = current_organization.diaper_drive_participants.new(diaper_drive_participant_params.merge(organization: current_organization))
respond_to do |format|
if (@diaper_drive_participant.save)
format.html {redirect_to diaper_drive_participants_path, notice: "New diaper drive participant added!"}
if @diaper_drive_participant.save
format.html { redirect_to diaper_drive_participants_path, notice: "New diaper drive participant added!" }
format.js
else
flash[:error] = "Something didn't work quite right -- try again?"
format.html {render action: :new}
format.js {render template: "diaper_drive_participants/new_modal.js.erb"}
format.html { render action: :new }
format.js { render template: "diaper_drive_participants/new_modal.js.erb" }
end
end
end
Expand All @@ -36,8 +36,8 @@ def show

def update
@diaper_drive_participant = current_organization.diaper_drive_participants.find(params[:id])
if @diaper_drive_participant.update_attributes(diaper_drive_participant_params)
redirect_to diaper_drive_participants_path, notice: "#{@diaper_drive_participant.name} updated!"
if @diaper_drive_participant.update(diaper_drive_participant_params)
redirect_to diaper_drive_participants_path, notice: "#{@diaper_drive_participant.name} updated!"
else
flash[:error] = "Something didn't work quite right -- try again?"
render action: :edit
Expand All @@ -56,10 +56,10 @@ def import_csv
end
end

private
private

def diaper_drive_participant_params
params.require(:diaper_drive_participant)
.permit(:name, :phone, :email, :business_name, :address)
.permit(:name, :phone, :email, :business_name, :address)
end
end
Loading

0 comments on commit 0683743

Please sign in to comment.