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:
Enabled: true
# Use one empty line between method definitions
Style/EmptyLineBetweenDefs:
Enabled: true
# Offense count: 4
# Cop supports --auto-correct.
# There should be only one empty line in designated place
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
# 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
Style/EmptyLinesAroundAccessModifier:
Lint/ShadowingOuterLocalVariable:
Enabled: false
# Offense count: 21
# Offense count: 5
# Cop supports --auto-correct.
Style/EmptyLinesAroundBody:
Lint/UnusedBlockArgument:
Enabled: false
# Offense count: 2
# Cop supports --auto-correct.
Style/EmptyLiteral:
Lint/UnusedMethodArgument:
Enabled: false
# Offense count: 6
Lint/UselessAssignment:
Enabled: false
# Offense count: 1
# Configuration parameters: Exclude.
Style/FileName:
Lint/Void:
Enabled: false
# Offense count: 17
Style/AccessorMethodName:
Enabled: false
AllCops:

View file

@ -5,58 +5,6 @@
# Note that changes in the inspected code, or installation of new
# 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
# Cop supports --auto-correct.
# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
@ -156,41 +104,11 @@ Style/DotPosition:
Style/DoubleNegation:
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
# Configuration parameters: Exclude.
Style/FileName:
Enabled: false
# Offense count: 1
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/For:
Enabled: false
# Offense count: 8
# Configuration parameters: MinBodyLength.
Style/GuardClause:

View file

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

View file

@ -90,6 +90,7 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.7.0)
columnize (0.8.9)
coveralls (0.7.0)
multi_json (~> 1.3)
rest-client
@ -99,6 +100,12 @@ GEM
d3_rails (3.4.6)
railties (>= 3.1.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)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
@ -399,6 +406,7 @@ DEPENDENCIES
coveralls
d3_rails
database_cleaner
debugger
devise
factory_girl_rails
font-awesome-rails

View file

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

View file

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

View file

@ -79,7 +79,7 @@ class Admin::QuestionsController < ApplicationController
a.delete
end
flash[:notice] = "Deleted question: #{@question.title} and its answers: #{@question.answers.map {|a| a.title}.join ','}"
end
end
rescue ActiveRecord::RecordInvalid
flash[:error] = "Could not delete question."
end
@ -91,6 +91,6 @@ class Admin::QuestionsController < ApplicationController
end
@questions = Question.where(:global => true).all | Question.where(:conference_id => @conference.id)
@questions_conference = @conference.questions
@questions_conference = @conference.questions
end
end

View file

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

View file

@ -48,7 +48,7 @@ module Admin
if @events.count > 0
start_date = @events.minimum('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')
end
end
@ -87,7 +87,7 @@ module Admin
typelength += myevent.event_type.length
@totallength += myevent.event_type.length
end
if @eventstats[mytype.title] == nil
if @eventstats[mytype.title].nil?
@eventstats[mytype.title] = { 'count' => events_mytype.count,
'length' => events_mytype.count * mytype.length }
end

View file

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

View file

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

View file

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

View file

@ -13,7 +13,7 @@ module Users
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,
# 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
end

View file

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

View file

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

View file

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

View file

@ -3,5 +3,4 @@ class DietaryChoice < ActiveRecord::Base
belongs_to :conference
has_many :registrations
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
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
begin
guid = SecureRandom.urlsafe_base64
end while self.class.where(guid: guid).exists?
self.guid = guid
loop do
@guid = SecureRandom.urlsafe_base64
break if !self.class.where(guid: guid).any?
end
self.guid = @guid
end
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_type" => "DELETE"
}
end
#:path => ":rails_root/public/system/:attachment/:id/:style/:filename",
# :url => "/system/:attachment/:id/:style/:filename"
#has_paper_trail :meta => {:associated_id => :event_id, :associated_type => "Event"}
end

View file

@ -11,7 +11,7 @@ class Openid < ActiveRecord::Base
if openid.new_record?
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
end
end

View file

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

View file

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

View file

@ -11,13 +11,17 @@ class Venue < ActiveRecord::Base
content_type: [/jpg/, /jpeg/, /png/, /gif/],
size: { in: 0..500.kilobytes }
accepts_nested_attributes_for :lodgings, allow_destroy: true
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
begin
guid = SecureRandom.urlsafe_base64
end while Venue.where(:guid => guid).exists?
self.guid = guid
loop do
@guid = SecureRandom.urlsafe_base64
break if !Venue.where(:guid => guid).any?
end
self.guid = @guid
end
end

View file

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

View file

@ -3,4 +3,4 @@ require 'rubygems'
# Set up gems listed in the Gemfile.
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]
rescue Exception
puts "Error while parsing config file #{path}"
CONFIG = Hash.new
CONFIG = {}
end
# Initialize the rails application

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -65,10 +65,9 @@ class AddEventsPerWeekToConference < ActiveRecord::Migration
conference.save
end
# Cumulate the previous weeks to get a snapshot
TempConference.all.each do |conference|
hash = conference.events_per_week.sort.to_h
hash = conference.events_per_week.sort.to_hash
previous = nil
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?"]
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)
Qanswer.create(:question_id => q.id, :answer_id => answer_no.id)

View file

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

View file

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

View file

@ -1,7 +1,7 @@
require 'spec_helper'
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")
assign(:current, [create(:conference), create(:conference)])
render