Fix basic style issues with rubocop

This commit is contained in:
Artem Chernikov 2014-07-21 14:27:32 +02:00
parent f4a22851a1
commit 763f864dc9
36 changed files with 108 additions and 143 deletions

View file

@ -11,31 +11,79 @@ Lint/DeprecatedClassMethods:
Style/NilComparison: Style/NilComparison:
Enabled: true Enabled: true
# Use one empty line between method definitions
Style/EmptyLineBetweenDefs: Style/EmptyLineBetweenDefs:
Enabled: true Enabled: true
# Offense count: 4 # There should be only one empty line in designated place
# Cop supports --auto-correct.
Style/EmptyLines: Style/EmptyLines:
Enabled: true
# Keep a blank line before and after private.
Style/EmptyLinesAroundAccessModifier:
Enabled: true
# Do not insert empty line after class definition and before closing class
Style/EmptyLinesAroundBody:
Enabled: true
# Use hash literal {} instead of Hash.new
Style/EmptyLiteral:
Enabled: true
# Prefer `each` over `for i`
Style/For:
Enabled: true
# Wrap your assignment in condition if you mean it, otherwise it is most likely equality check
Lint/AssignmentInCondition:
Enabled: true
# Align blocks of code properly
Lint/BlockAlignment:
Enabled: true
# Do not use literal in conditions. We have it enabled for now
Lint/LiteralInCondition:
Enabled: false Enabled: false
# Prefer `Kernel#loop -> break` over `begin -> while`
Lint/Loop:
Enabled: true
# do not put space before arguments when they are in parentheses
Lint/ParenthesesAsGroupedExpression:
Enabled: true
# Offense count: 13
# Cop supports --auto-correct.
Lint/RescueException:
Enabled: true
# Offense count: 1 # Offense count: 1
Style/EmptyLinesAroundAccessModifier: Lint/ShadowingOuterLocalVariable:
Enabled: false Enabled: false
# Offense count: 21 # Offense count: 5
# Cop supports --auto-correct. # Cop supports --auto-correct.
Style/EmptyLinesAroundBody: Lint/UnusedBlockArgument:
Enabled: false Enabled: false
# Offense count: 2 # Offense count: 2
# Cop supports --auto-correct. # Cop supports --auto-correct.
Style/EmptyLiteral: Lint/UnusedMethodArgument:
Enabled: false
# Offense count: 6
Lint/UselessAssignment:
Enabled: false Enabled: false
# Offense count: 1 # Offense count: 1
# Configuration parameters: Exclude. Lint/Void:
Style/FileName: Enabled: false
# Offense count: 17
Style/AccessorMethodName:
Enabled: false Enabled: false
AllCops: AllCops:

View file

@ -5,58 +5,6 @@
# Note that changes in the inspected code, or installation of new # Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again. # versions of RuboCop, may require this file to be generated again.
# Offense count: 3
# Configuration parameters: AllowSafeAssignment.
Lint/AssignmentInCondition:
Enabled: false
# Offense count: 4
Lint/BlockAlignment:
Enabled: false
# Offense count: 1
Lint/LiteralInCondition:
Enabled: false
# Offense count: 2
Lint/Loop:
Enabled: false
# Offense count: 3
Lint/ParenthesesAsGroupedExpression:
Enabled: false
# Offense count: 13
# Cop supports --auto-correct.
Lint/RescueException:
Enabled: false
# Offense count: 1
Lint/ShadowingOuterLocalVariable:
Enabled: false
# Offense count: 5
# Cop supports --auto-correct.
Lint/UnusedBlockArgument:
Enabled: false
# Offense count: 2
# Cop supports --auto-correct.
Lint/UnusedMethodArgument:
Enabled: false
# Offense count: 6
Lint/UselessAssignment:
Enabled: false
# Offense count: 1
Lint/Void:
Enabled: false
# Offense count: 17
Style/AccessorMethodName:
Enabled: false
# Offense count: 10 # Offense count: 10
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles. # Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
@ -156,41 +104,11 @@ Style/DotPosition:
Style/DoubleNegation: Style/DoubleNegation:
Enabled: false Enabled: false
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowAdjacentOneLineDefs.
Style/EmptyLineBetweenDefs:
Enabled: false
# Offense count: 4
# Cop supports --auto-correct.
Style/EmptyLines:
Enabled: false
# Offense count: 1
Style/EmptyLinesAroundAccessModifier:
Enabled: false
# Offense count: 21
# Cop supports --auto-correct.
Style/EmptyLinesAroundBody:
Enabled: false
# Offense count: 2
# Cop supports --auto-correct.
Style/EmptyLiteral:
Enabled: false
# Offense count: 1 # Offense count: 1
# Configuration parameters: Exclude. # Configuration parameters: Exclude.
Style/FileName: Style/FileName:
Enabled: false Enabled: false
# Offense count: 1
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/For:
Enabled: false
# Offense count: 8 # Offense count: 8
# Configuration parameters: MinBodyLength. # Configuration parameters: MinBodyLength.
Style/GuardClause: Style/GuardClause:

View file

@ -128,3 +128,7 @@ group :test do
# Extracted from RSpec 3 stub_model and mock_model # Extracted from RSpec 3 stub_model and mock_model
gem 'rspec-activemodel-mocks' gem 'rspec-activemodel-mocks'
end end
group :development, :test do
gem 'debugger'
end

View file

@ -90,6 +90,7 @@ GEM
coffee-script-source coffee-script-source
execjs execjs
coffee-script-source (1.7.0) coffee-script-source (1.7.0)
columnize (0.8.9)
coveralls (0.7.0) coveralls (0.7.0)
multi_json (~> 1.3) multi_json (~> 1.3)
rest-client rest-client
@ -99,6 +100,12 @@ GEM
d3_rails (3.4.6) d3_rails (3.4.6)
railties (>= 3.1.0) railties (>= 3.1.0)
database_cleaner (1.3.0) database_cleaner (1.3.0)
debugger (1.6.8)
columnize (>= 0.3.1)
debugger-linecache (~> 1.2.0)
debugger-ruby_core_source (~> 1.3.5)
debugger-linecache (1.2.0)
debugger-ruby_core_source (1.3.5)
devise (3.2.4) devise (3.2.4)
bcrypt (~> 3.0) bcrypt (~> 3.0)
orm_adapter (~> 0.1) orm_adapter (~> 0.1)
@ -399,6 +406,7 @@ DEPENDENCIES
coveralls coveralls
d3_rails d3_rails
database_cleaner database_cleaner
debugger
devise devise
factory_girl_rails factory_girl_rails
font-awesome-rails font-awesome-rails

View file

@ -25,6 +25,5 @@ class Admin::DifficultyLevelsController < ApplicationController
flash[:error] = "Difficulty Levels update failed." flash[:error] = "Difficulty Levels update failed."
redirect_to(admin_conference_difficulty_levels_path(:conference_id => @conference.short_title)) redirect_to(admin_conference_difficulty_levels_path(:conference_id => @conference.short_title))
end end
end end
end end

View file

@ -18,7 +18,7 @@ module Admin
@mystates = [] @mystates = []
@mytypes = [] @mytypes = []
@eventstats = Hash.new @eventstats = {}
@totallength = 0 @totallength = 0
@machine_states.each do |mystate| @machine_states.each do |mystate|
@ -50,7 +50,7 @@ module Admin
@totallength += myevent.event_type.length @totallength += myevent.event_type.length
end end
if @eventstats[mytype.title] == nil if @eventstats[mytype.title].nil?
@eventstats[mytype.title] = { 'count' => events_mytype.count, @eventstats[mytype.title] = { 'count' => events_mytype.count,
'length' => events_mytype.count * mytype.length } 'length' => events_mytype.count * mytype.length }
end end
@ -150,7 +150,7 @@ module Admin
@event = Event.find(params[:id]) @event = Event.find(params[:id])
@ratings = @event.votes.includes(:user) @ratings = @event.votes.includes(:user)
if votes = current_user.votes.find_by_event_id(params[:id]) if (votes = current_user.votes.find_by_event_id(params[:id]))
votes.update_attributes(rating: params[:rating]) votes.update_attributes(rating: params[:rating])
else else
@myvote = @event.votes.build @myvote = @event.votes.build

View file

@ -79,7 +79,7 @@ class Admin::QuestionsController < ApplicationController
a.delete a.delete
end end
flash[:notice] = "Deleted question: #{@question.title} and its answers: #{@question.answers.map {|a| a.title}.join ','}" flash[:notice] = "Deleted question: #{@question.title} and its answers: #{@question.answers.map {|a| a.title}.join ','}"
end end
rescue ActiveRecord::RecordInvalid rescue ActiveRecord::RecordInvalid
flash[:error] = "Could not delete question." flash[:error] = "Could not delete question."
end end

View file

@ -11,7 +11,5 @@ class Admin::SocialEventsController < ApplicationController
else else
redirect_to(admin_conference_social_events_path(:conference_id => @conference.short_title), :notice => 'Social events update failed.') redirect_to(admin_conference_social_events_path(:conference_id => @conference.short_title), :notice => 'Social events update failed.')
end end
end end
end end

View file

@ -48,7 +48,7 @@ module Admin
if @events.count > 0 if @events.count > 0
start_date = @events.minimum('created_at').strftime('%Y-%m-%d') start_date = @events.minimum('created_at').strftime('%Y-%m-%d')
end_date = @events.maximum('created_at').strftime('%Y-%m-%d') end_date = @events.maximum('created_at').strftime('%Y-%m-%d')
unless start_date == nil || end_date == nil unless start_date.nil? || end_date.nil?
@events_time = var_time(start_date, end_date, @events, 'created_at') @events_time = var_time(start_date, end_date, @events, 'created_at')
end end
end end
@ -87,7 +87,7 @@ module Admin
typelength += myevent.event_type.length typelength += myevent.event_type.length
@totallength += myevent.event_type.length @totallength += myevent.event_type.length
end end
if @eventstats[mytype.title] == nil if @eventstats[mytype.title].nil?
@eventstats[mytype.title] = { 'count' => events_mytype.count, @eventstats[mytype.title] = { 'count' => events_mytype.count,
'length' => events_mytype.count * mytype.length } 'length' => events_mytype.count * mytype.length }
end end

View file

@ -19,5 +19,4 @@ class Admin::VenueController < ApplicationController
@venue = @conference.venue @venue = @conference.venue
render :venue_info render :venue_info
end end
end end

View file

@ -71,8 +71,10 @@ class EventAttachmentsController < ApplicationController
:content_type => 'text/html', :content_type => 'text/html',
:layout => false :layout => false
} }
format.json { render json: [@upload.to_jq_upload].to_json, status: :created, format.json do
location: conference_proposal_event_attachment_path(@upload.event.conference.short_title, @upload.event, @upload) } render json: [@upload.to_jq_upload].to_json, status: :created,
location: conference_proposal_event_attachment_path(@upload.event.conference.short_title, @upload.event, @upload)
end
else else
format.html { render action: "new" } format.html { render action: "new" }
format.json { render json: @upload.errors, status: :unprocessable_entity } format.json { render json: @upload.errors, status: :unprocessable_entity }

View file

@ -1,5 +1,4 @@
class ScheduleController < ApplicationController class ScheduleController < ApplicationController
layout "application" layout "application"
def index def index
@ -14,5 +13,4 @@ class ScheduleController < ApplicationController
@today = @conference.start_date.strftime("%Y-%m-%d") @today = @conference.start_date.strftime("%Y-%m-%d")
end end
end end
end end

View file

@ -13,7 +13,7 @@ module Users
openid = Openid.find_for_oauth(auth_hash) # Get or create openid openid = Openid.find_for_oauth(auth_hash) # Get or create openid
# If openid exists and is associated with a user, sign in with associated user, # If openid exists and is associated with a user, sign in with associated user,
# even if the email of the associated user and the email of the provided openid are different # even if the email of the associated user and the email of the provided openid are different
unless user = openid.user unless (user = openid.user)
user = User.find_for_auth(auth_hash, current_user) # Get or create users user = User.find_for_auth(auth_hash, current_user) # Get or create users
end end

View file

@ -6,7 +6,6 @@ class Mailbot < ActionMailer::Base
person.email, person.email,
conference.email_settings.registration_subject, conference.email_settings.registration_subject,
conference.email_settings.generate_registration_email(conference, person)) conference.email_settings.generate_registration_email(conference, person))
end end
def acceptance_mail(event) def acceptance_mail(event)
@ -16,7 +15,6 @@ class Mailbot < ActionMailer::Base
person.email, person.email,
conference.email_settings.accepted_subject, conference.email_settings.accepted_subject,
conference.email_settings.generate_accepted_email(event)) conference.email_settings.generate_accepted_email(event))
end end
def rejection_mail(event) def rejection_mail(event)
@ -63,5 +61,4 @@ class Mailbot < ActionMailer::Base
:subject => subject, :subject => subject,
:body => body) :body => body)
end end
end end

View file

@ -102,7 +102,6 @@ class Conference < ActiveRecord::Base
return media_types return media_types
end end
## ##
# Checks if the user is registered to the conference # Checks if the user is registered to the conference
# #

View file

@ -18,7 +18,6 @@ class Datatable
} }
end end
def data def data
[] []
end end

View file

@ -3,5 +3,4 @@ class DietaryChoice < ActiveRecord::Base
belongs_to :conference belongs_to :conference
has_many :registrations has_many :registrations
end end

View file

@ -197,11 +197,15 @@ class Event < ActiveRecord::Base
errors.add(:user_biography, 'must be filled out') if submitter.biography_word_count == 0 errors.add(:user_biography, 'must be filled out') if submitter.biography_word_count == 0
end end
# TODO: create a module to be mixed into model to perform same operation
# venue.rb has same functionality which can be shared
# TODO: rename guid to UUID as guid is specifically Microsoft term
def generate_guid def generate_guid
begin loop do
guid = SecureRandom.urlsafe_base64 @guid = SecureRandom.urlsafe_base64
end while self.class.where(guid: guid).exists? break if !self.class.where(guid: guid).any?
self.guid = guid end
self.guid = @guid
end end
def set_week def set_week

View file

@ -18,12 +18,9 @@ class EventAttachment < ActiveRecord::Base
"delete_url" => conference_proposal_event_attachment_path(self.event.conference.short_title, self.event_id, self.id), "delete_url" => conference_proposal_event_attachment_path(self.event.conference.short_title, self.event_id, self.id),
"delete_type" => "DELETE" "delete_type" => "DELETE"
} }
end end
#:path => ":rails_root/public/system/:attachment/:id/:style/:filename", #:path => ":rails_root/public/system/:attachment/:id/:style/:filename",
# :url => "/system/:attachment/:id/:style/:filename" # :url => "/system/:attachment/:id/:style/:filename"
#has_paper_trail :meta => {:associated_id => :event_id, :associated_type => "Event"} #has_paper_trail :meta => {:associated_id => :event_id, :associated_type => "Event"}
end end

View file

@ -11,7 +11,7 @@ class Openid < ActiveRecord::Base
if openid.new_record? if openid.new_record?
openid.email = auth.info.email openid.email = auth.info.email
if existing_openid = Openid.where(email: openid.email).first if (existing_openid = Openid.where(email: openid.email).first)
openid.user_id = existing_openid.user_id openid.user_id = existing_openid.user_id
end end
end end

View file

@ -15,5 +15,4 @@ class Room < ActiveRecord::Base
# end while Person.where(:guid => guid).exists? # end while Person.where(:guid => guid).exists?
self.guid = guid self.guid = guid
end end
end end

View file

@ -14,5 +14,4 @@ class Track < ActiveRecord::Base
# end while Person.where(:guid => guid).exists? # end while Person.where(:guid => guid).exists?
self.guid = guid self.guid = guid
end end
end end

View file

@ -11,13 +11,17 @@ class Venue < ActiveRecord::Base
content_type: [/jpg/, /jpeg/, /png/, /gif/], content_type: [/jpg/, /jpeg/, /png/, /gif/],
size: { in: 0..500.kilobytes } size: { in: 0..500.kilobytes }
accepts_nested_attributes_for :lodgings, allow_destroy: true accepts_nested_attributes_for :lodgings, allow_destroy: true
private private
# TODO: create a module to be mixed into model to perform same operation
# event.rb has same functionality which can be shared
# TODO: rename guid to UUID as guid is specifically Microsoft term
def generate_guid def generate_guid
begin loop do
guid = SecureRandom.urlsafe_base64 @guid = SecureRandom.urlsafe_base64
end while Venue.where(:guid => guid).exists? break if !Venue.where(:guid => guid).any?
self.guid = guid end
self.guid = @guid
end end
end end

View file

@ -4,5 +4,4 @@ class Vote < ActiveRecord::Base
belongs_to :user belongs_to :user
belongs_to :event belongs_to :event
delegate :name, to: :user delegate :name, to: :user
end end

View file

@ -3,4 +3,4 @@ require 'rubygems'
# Set up gems listed in the Gemfile. # Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])

View file

@ -7,7 +7,7 @@ begin
CONFIG = YAML.load_file(path)[Rails.env] CONFIG = YAML.load_file(path)[Rails.env]
rescue Exception rescue Exception
puts "Error while parsing config file #{path}" puts "Error while parsing config file #{path}"
CONFIG = Hash.new CONFIG = {}
end end
# Initialize the rails application # Initialize the rails application

View file

@ -15,5 +15,4 @@ class CreateVenueTable < ActiveRecord::Migration
def down def down
drop_table :venues drop_table :venues
end end
end end

View file

@ -12,7 +12,6 @@ class CreateEmailTable < ActiveRecord::Migration
t.text :confirmed_email_template t.text :confirmed_email_template
t.timestamps t.timestamps
end end
end end
def down def down

View file

@ -2,6 +2,7 @@ class ChangeAttachmentDefault < ActiveRecord::Migration
def up def up
change_column_default(:event_attachments, :public, true) change_column_default(:event_attachments, :public, true)
end end
def down def down
change_column_default(:event_attachments, :public, nil) change_column_default(:event_attachments, :public, nil)
end end

View file

@ -1,6 +1,6 @@
class RegistrationsVchoices < ActiveRecord::Migration class RegistrationsVchoices < ActiveRecord::Migration
def up def up
create_table :registrations_vchoices, :id => false do |t| create_table :registrations_vchoices, :id => false do |t|
t.references :registration, :vchoice t.references :registration, :vchoice
end end
end end

View file

@ -30,6 +30,5 @@ class CreateEventUsers < ActiveRecord::Migration
record.comment = ep.comment record.comment = ep.comment
record.save! record.save!
end end
end end
end end

View file

@ -65,10 +65,9 @@ class AddEventsPerWeekToConference < ActiveRecord::Migration
conference.save conference.save
end end
# Cumulate the previous weeks to get a snapshot # Cumulate the previous weeks to get a snapshot
TempConference.all.each do |conference| TempConference.all.each do |conference|
hash = conference.events_per_week.sort.to_h hash = conference.events_per_week.sort.to_hash
previous = nil previous = nil
hash.each do |week, values| hash.each do |week, values|

View file

@ -18,7 +18,7 @@ answer_no = Answer.create(:title => "No")
questions_yes_no = ["Do you need handicapped access to the venue?", "Are you attending with partner?", "Will you attend the social event(s)?", "Will you stay at suggested hotel?"] questions_yes_no = ["Do you need handicapped access to the venue?", "Are you attending with partner?", "Will you attend the social event(s)?", "Will you stay at suggested hotel?"]
for i in questions_yes_no do questions_yes_no.each do |i|
q = Question.create(:title => i, :question_type_id => qtype_yesno.id, :global => true) q = Question.create(:title => i, :question_type_id => qtype_yesno.id, :global => true)
Qanswer.create(:question_id => q.id, :answer_id => answer_no.id) Qanswer.create(:question_id => q.id, :answer_id => answer_no.id)

View file

@ -406,7 +406,7 @@ describe Conference do
end end
describe '#difficulty_levels' do describe '#difficulty_levels' do
before (:each) do before do
subject.email_settings = create(:email_settings) subject.email_settings = create(:email_settings)
@easy = create(:difficulty_level, title: 'Easy', color: '#000000') @easy = create(:difficulty_level, title: 'Easy', color: '#000000')
@hard = create(:difficulty_level, title: 'Hard', color: '#ffffff') @hard = create(:difficulty_level, title: 'Hard', color: '#ffffff')
@ -503,7 +503,7 @@ describe Conference do
end end
describe 'event type distribution' do describe 'event type distribution' do
before (:each) do before do
subject.email_settings = create(:email_settings) subject.email_settings = create(:email_settings)
@workshop = create(:event_type, title: 'Workshop', color: '#000000') @workshop = create(:event_type, title: 'Workshop', color: '#000000')
@lecture = create(:event_type, title: 'Lecture', color: '#ffffff') @lecture = create(:event_type, title: 'Lecture', color: '#ffffff')
@ -599,7 +599,7 @@ describe Conference do
end end
describe 'tracks_distribution' do describe 'tracks_distribution' do
before (:each) do before do
subject.email_settings = create(:email_settings) subject.email_settings = create(:email_settings)
@track_one = create(:track, name: 'Track One', color: '#000000') @track_one = create(:track, name: 'Track One', color: '#000000')
@track_two = create(:track, name: 'Track Two', color: '#ffffff') @track_two = create(:track, name: 'Track Two', color: '#ffffff')

View file

@ -1,5 +1,4 @@
module LoginMacros module LoginMacros
include Warden::Test::Helpers include Warden::Test::Helpers
Warden.test_mode! Warden.test_mode!
@ -10,5 +9,4 @@ module LoginMacros
def sign_out def sign_out
logout(:user) logout(:user)
end end
end end

View file

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe 'home/index' do describe 'home/index' do
it "renders _conference partial for each conference" do it "renders _conference partial for each conference" do
allow(view).to receive(:date_string).and_return("January 17 - 21 2014") allow(view).to receive(:date_string).and_return("January 17 - 21 2014")
assign(:current, [create(:conference), create(:conference)]) assign(:current, [create(:conference), create(:conference)])
render render