Skip to content

Commit

Permalink
Fix most of rubocop offences
Browse files Browse the repository at this point in the history
  • Loading branch information
tagliala committed Dec 26, 2015
1 parent aeaef25 commit b2045bc
Show file tree
Hide file tree
Showing 67 changed files with 785 additions and 747 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ group :development do
gem 'binding_of_caller'
gem 'meta_request'
gem 'quiet_assets'
gem 'rubocop'
gem 'spring'
gem 'spring-commands-rspec'
gem 'web-console'
Expand Down
16 changes: 16 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ GEM
airbrake-ruby (~> 1.0)
airbrake-ruby (1.0.1)
arel (6.0.3)
ast (2.2.0)
astrolabe (1.3.1)
parser (~> 2.2)
autoprefixer-rails (6.2.1)
execjs
json
Expand Down Expand Up @@ -233,6 +236,9 @@ GEM
omniauth (~> 1.2)
origin (2.1.1)
orm_adapter (0.5.0)
parser (2.2.3.0)
ast (>= 1.1, < 3.0)
powerpack (0.1.1)
pry (0.10.3)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
Expand Down Expand Up @@ -283,6 +289,7 @@ GEM
activesupport (= 4.2.5)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (2.0.0)
raindrops (0.15.0)
rake (10.4.2)
redis (3.2.2)
Expand Down Expand Up @@ -322,6 +329,14 @@ GEM
rspec-mocks (~> 3.4.0)
rspec-support (~> 3.4.0)
rspec-support (3.4.1)
rubocop (0.35.1)
astrolabe (~> 1.3)
parser (>= 2.2.3.0, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
tins (<= 1.6.0)
ruby-progressbar (1.7.5)
rubyzip (1.1.7)
safe_yaml (1.0.4)
sass (3.4.20)
Expand Down Expand Up @@ -473,6 +488,7 @@ DEPENDENCIES
rgeo
rspec
rspec-rails
rubocop
sass-rails (~> 5.0)
secure_headers
selenium-webdriver
Expand Down
8 changes: 7 additions & 1 deletion Rakefile
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

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

require File.join(Rails.root.to_s, "config", "configuration.rb")
require File.join(Rails.root.to_s, 'config', 'configuration.rb')

require 'rubocop/rake_task'

RuboCop::RakeTask.new

# task default: [:rubocop, :spec]

Rails.application.load_tasks
13 changes: 8 additions & 5 deletions app/controllers/admin/base_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
class Admin::BaseController < ApplicationController
before_action :check_admin
module Admin
class BaseController < ::ApplicationController
before_action :check_admin

private
def check_admin
redirect_to root_path, flash: { error: t('flash.errors.not_allowed') } if user_signed_in? && !current_user.admin?
private

def check_admin
redirect_to root_path, flash: { error: t('flash.errors.not_allowed') } if user_signed_in? && !current_user.admin?
end
end
end
57 changes: 30 additions & 27 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
class Admin::UsersController < Admin::BaseController
before_action :set_user, only: [:login_as, :ban, :unban]
before_action :prevent_autoban, only: [:ban, :unban]
module Admin
class UsersController < BaseController
before_action :set_user, only: [:login_as, :ban, :unban]
before_action :prevent_autoban, only: [:ban, :unban]

def index
@users = User.asc(:name).page params[:page]
end
def index
@users = User.asc(:name).page params[:page]
end

def login_as
sign_in_and_redirect :user, @user
end
def login_as
sign_in_and_redirect :user, @user
end

def ban
if @user.update_attributes(banned: true)
redirect_to admin_users_path, flash: { success: t('flash.admin.users.success.ban') }
else
redirect_to admin_users_path, flash: { error: t('flash.admin.users.error.ban') }
def ban
if @user.update_attributes(banned: true)
redirect_to admin_users_path, flash: { success: t('flash.admin.users.success.ban') }
else
redirect_to admin_users_path, flash: { error: t('flash.admin.users.error.ban') }
end
end
end

def unban
if @user.update_attributes(banned: false)
redirect_to admin_users_path, flash: { success: t('flash.admin.users.success.unban') }
else
redirect_to admin_users_path, flash: { error: t('flash.admin.users.error.unban') }
def unban
if @user.update_attributes(banned: false)
redirect_to admin_users_path, flash: { success: t('flash.admin.users.success.unban') }
else
redirect_to admin_users_path, flash: { error: t('flash.admin.users.error.unban') }
end
end
end

private
def set_user
@user = User.find params[:id]
end
private

def prevent_autoban
redirect_to admin_users_path, flash: { error: t('flash.admin.users.error.ban') } if @user == current_user
def set_user
@user = User.find params[:id]
end

def prevent_autoban
redirect_to admin_users_path, flash: { error: t('flash.admin.users.error.ban') } if @user == current_user
end
end
end
20 changes: 13 additions & 7 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,26 @@ class ApplicationController < ActionController::Base
before_action :authenticate_user!
before_action :check_banned, except: [:banned]

around_action :set_locale
around_action :set_user_time_zone, if: :user_signed_in?
around_action :set_locale_from_params
around_action :time_zone_from_user, if: :user_signed_in?

helper_method :permitted_params

protected
def set_locale(&block)

def set_locale_from_params
locale = check_locale_availability(params[:locale] || (current_user.locale if user_signed_in?)) ||
http_accept_language.preferred_language_from(I18n.available_locales) ||
http_accept_language.compatible_language_from(I18n.available_locales)
I18n.with_locale locale, &block
I18n.with_locale(locale) do
yield
end
end

def set_user_time_zone(&block)
Time.use_zone current_user.time_zone, &block
def time_zone_from_user
Time.use_zone(current_user.time_zone) do
yield
end
end

def check_banned
Expand All @@ -31,7 +36,8 @@ def find_user(param)
end

private
def after_sign_in_path_for(resource_or_scope)

def after_sign_in_path_for(_resource_or_scope)
session.delete(:redirect_to) || dashboard_path
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/conversations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class ConversationsController < ApplicationController

after_action :mark_as_read, only: [:show]

def index
Expand Down Expand Up @@ -55,6 +54,7 @@ def unread
end

private

def mark_as_read
@conversation.mark_as_read(current_user)
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/feedbacks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class FeedbacksController < ApplicationController

before_action :set_feedback, only: [:show, :edit, :update, :destroy]
before_action :check_owner_or_admin, only: [:edit, :update, :destroy]

Expand Down Expand Up @@ -36,6 +35,7 @@ def destroy
end

private

def set_feedback
@feedback = Feedback.find(params[:id])
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/itineraries_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class ItinerariesController < ApplicationController

skip_before_action :authenticate_user!, only: [:show]

before_action :set_itinerary, only: [:show]
Expand All @@ -12,7 +11,7 @@ def new
end

def index
#@itineraries = Itinerary.includes(:user).all
# @itineraries = Itinerary.includes(:user).all
end

def show
Expand Down Expand Up @@ -54,6 +53,7 @@ def search
end

protected

def check_permissions
end

Expand Down
1 change: 0 additions & 1 deletion app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class PagesController < ApplicationController

skip_before_action :authenticate_user!

def home
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/references_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class ReferencesController < ApplicationController

before_action :set_user, only: [:index, :show, :update]
before_action :check_not_myself, only: [:new, :create]

Expand Down Expand Up @@ -42,6 +41,7 @@ def update
end

private

def check_not_myself
@itinerary = Itinerary.find(params[:itinerary_id])
redirect_to root_path if @itinerary.user == current_user
Expand Down
24 changes: 14 additions & 10 deletions app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
if @user = User.from_omniauth(request.env['omniauth.auth'])
sign_in_and_redirect @user, event: :authentication # this will throw if @user is not activated
else
redirect_to root_path, flash: { error: t(APP_CONFIG.facebook.restricted_group_id ? 'flash.sessions.error.restricted' : 'flash.sessions.error.create') }
module Users
class OmniauthCallbacksController < ::Devise::OmniauthCallbacksController
def facebook
@user = User.from_omniauth(request.env['omniauth.auth'])
if @user
sign_in_and_redirect @user, event: :authentication
else
redirect_to root_path, flash: { error: t(APP_CONFIG.facebook.restricted_group_id ? 'flash.sessions.error.restricted' : 'flash.sessions.error.create') }
end
end
end

protected
def after_omniauth_failure_path_for(scope)
root_path
protected

def after_omniauth_failure_path_for(_scope)
root_path
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class UsersController < ApplicationController

before_action :set_user_as_current_user, only: [:update, :dashboard, :settings, :itineraries]

def show
Expand Down Expand Up @@ -36,6 +35,7 @@ def banned
end

private

def set_user_as_current_user
@user = current_user
end
Expand Down
7 changes: 3 additions & 4 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
module ApplicationHelper

def title(page_title)
content_for(:title) { page_title.to_s }
end

def yield_or_default(section, default = '')
content_for?(section) ? content_for(section) + (" | #{APP_CONFIG.app_name}" unless (user_signed_in? || content_for(section) == APP_CONFIG.app_name)) : default
content_for?(section) ? content_for(section) + (" | #{APP_CONFIG.app_name}" unless user_signed_in? || content_for(section) == APP_CONFIG.app_name) : default
end

def twitterized_type(type)
Expand All @@ -21,8 +20,8 @@ def transparent_gif_image_data
'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='
end

def options_for_array_collection(model, attr_name, *args)
"#{model}::#{attr_name.to_s.upcase}".safe_constantize.map { |e| [ model.human_attribute_name("#{attr_name}_#{e}"), e] }
def options_for_array_collection(model, attr_name, *_args)
"#{model}::#{attr_name.to_s.upcase}".safe_constantize.map { |e| [model.human_attribute_name("#{attr_name}_#{e}"), e] }
end

def background_jobs_available?
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/conversations_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def message_timestamp(message)
def message_readat(message)
content_tag(:small, class: 'text-muted') do
content_tag(:span, nil, class: 'fa fa-check') + ' ' +
I18n.t('conversations.messages.seen', date: l(message.read_at.in_time_zone(current_user.time_zone), format: :short))
I18n.t('conversations.messages.seen', date: l(message.read_at.in_time_zone(current_user.time_zone), format: :short))
end
end

Expand Down
14 changes: 7 additions & 7 deletions app/helpers/itineraries_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def boolean_options_for_select
end

def default_leave_date
@default_leave_date ||= ((Time.now).change(min: (Time.now.min / 10) * 10) + 10.minutes).in_time_zone
@default_leave_date ||= (Time.zone.now).change(min: (Time.zone.now.min / 10) * 10) + 10.minutes
end

def boolean_tag(value, field)
Expand All @@ -20,14 +20,14 @@ def share_on_facebook_timeline_checkbutton(form)
content_tag(:span, nil, class: 'fa fa-square-o check') + ' ' +
Itinerary.human_attribute_name(:share_on_facebook_timeline)
end) +
(unless publish_actions_permission
content_tag(:p, class: 'text-muted') do
content_tag(:small) do
content_tag(:span, nil, class: 'fa fa-ban') + ' ' +
t('.missing_publish_actions_permission', appname: APP_CONFIG.app_name)
unless publish_actions_permission
content_tag(:p, class: 'text-muted') do
content_tag(:small) do
content_tag(:span, nil, class: 'fa fa-ban') + ' ' +
t('.missing_publish_actions_permission', appname: APP_CONFIG.app_name)
end
end
end
end)
else
t('.share_on_timeline_unavailable', appname: APP_CONFIG.app_name)
end
Expand Down
3 changes: 2 additions & 1 deletion app/helpers/references_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def reference_tags(user)
end

private

def reference_radio_button(form, field, info)
form.label :rating, value: info[:value], class: 'btn btn-default' do
concat form.radio_button(:rating, info[:value])
Expand All @@ -43,6 +44,6 @@ def reference_radio_button(form, field, info)
end

def reference_tag(user, reference_type)
content_tag(:div, t("references.snippet.#{reference_type}", count: @user.references.send(reference_type).count), class: 'tag')
content_tag(:div, t("references.snippet.#{reference_type}", count: user.references.send(reference_type).count), class: 'tag')
end
end
Loading

0 comments on commit b2045bc

Please sign in to comment.