Merge pull request #349 from openSUSE/review_140721_basic_rubocop_rules

[Review] Request from 'KalabiYau' @ 'openSUSE/osem/review_140721_basic_rubocop_rules'
This commit is contained in:
Artem Chernikov 2014-07-23 11:00:30 +02:00
commit d9d72eae07
103 changed files with 686 additions and 260 deletions

View file

@ -1,7 +1,7 @@
class Ability
include CanCan::Ability
def initialize(user)
def initialize(user) # rubocop:disable Lint/UnusedMethodArgument
# Define abilities for the passed in user here. For example:
#
# user ||= User.new # guest user (not logged in)

View file

@ -2,7 +2,7 @@ class Answer < ActiveRecord::Base
attr_accessible :title
has_many :qanswers
has_many :questions, :through => :qanswers
has_many :questions, through: :qanswers
validates :title, :presence => true
validates :title, presence: true
end

View file

@ -5,7 +5,7 @@ class CallForPapers < ActiveRecord::Base
belongs_to :conference
validates_presence_of :start_date, :end_date
validates :rating, :numericality => { :greater_than_or_equal_to => 0, :less_than_or_equal_to => 10 }
validates :rating, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 10 }
##
# Calculates how many weeks the call for paper is.

View file

@ -1,5 +1,5 @@
class Comment < ActiveRecord::Base
acts_as_nested_set :scope => [:commentable_id, :commentable_type]
acts_as_nested_set scope: [:commentable_id, :commentable_type]
attr_accessible :commentable, :body, :user_id
validates_presence_of :body
validates_presence_of :user
@ -8,7 +8,7 @@ class Comment < ActiveRecord::Base
# want user to vote on the quality of comments.
#acts_as_votable
belongs_to :commentable, :polymorphic => true
belongs_to :commentable, polymorphic: true
# NOTE: Comments belong to a user
belongs_to :user
@ -18,9 +18,9 @@ class Comment < ActiveRecord::Base
# example in readme
def self.build_from(obj, user_id, comment)
new \
:commentable => obj,
:body => comment,
:user_id => user_id
commentable: obj,
body: comment,
user_id: user_id
end
#helper method to check if a comment has children
@ -31,13 +31,13 @@ class Comment < ActiveRecord::Base
# Helper class method to lookup all comments assigned
# to all commentable types for a given user.
scope :find_comments_by_user, lambda { |user|
where(:user_id => user.id).order('created_at DESC')
where(user_id: user.id).order('created_at DESC')
}
# Helper class method to look up all comments for
# commentable class name and commentable id.
scope :find_comments_for_commentable, lambda { |commentable_str, commentable_id|
where(:commentable_type => commentable_str.to_s, :commentable_id => commentable_id).order('created_at DESC')
where(commentable_type: commentable_str.to_s, commentable_id: commentable_id).order('created_at DESC')
}
# Helper class method to look up a commentable object

View file

@ -89,7 +89,7 @@ class Conference < ActiveRecord::Base
format: URI::regexp(%w(http https)), allow_blank: true
validates_uniqueness_of :short_title
validates_format_of :short_title, :with => /\A[a-zA-Z0-9_-]*\z/
validates_format_of :short_title, with: /\A[a-zA-Z0-9_-]*\z/
before_create :generate_guid
before_create :create_venue
before_create :create_event_types
@ -102,7 +102,6 @@ class Conference < ActiveRecord::Base
return media_types
end
##
# Checks if the user is registered to the conference
#
@ -640,7 +639,7 @@ class Conference < ActiveRecord::Base
# ====Returns
# * +Fixnum+ -> Progress in Percent
def calculate_setup_progress(result)
(result.select { |k, v| v }.length / result.length.to_f * 100).round(0).to_s
(result.select { |_k, v| v }.length / result.length.to_f * 100).round(0).to_s
end
##

View file

@ -9,7 +9,7 @@ class Datatable
@view = view
end
def as_json(options = {})
def as_json
{
sEcho: params[:sEcho].to_i,
iTotalRecords: @klass.count,
@ -18,7 +18,6 @@ class Datatable
}
end
def data
[]
end
@ -56,10 +55,10 @@ class Datatable
search_for = params[:sSearch].split(' ')
terms = {}
which_one = -1
criteria = search_for.inject([]) do |criteria,atom|
criteria = search_for.inject([]) do |mem, atom|
which_one += 1
terms["search#{which_one}".to_sym] = "%#{atom}%"
criteria << "(#{search_cols.map{|col| "#{col} like :search#{which_one}"}.join(' or ')})"
mem << "(#{search_cols.map{|col| "#{col} like :search#{which_one}"}.join(' or ')})"
end.join(' and ')
[criteria, terms]
end

View file

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

View file

@ -4,5 +4,5 @@ class DifficultyLevel < ActiveRecord::Base
belongs_to :conference
has_many :events
validates :title, :presence => true
validates :title, presence: true
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

@ -4,7 +4,7 @@ class EventAttachment < ActiveRecord::Base
belongs_to :event
attr_accessible :public, :attachment, :event_id, :title
has_attached_file :attachment, :path => ":rails_root/storage/:rails_env/attachments/:id/:style/:basename.:extension"
has_attached_file :attachment, path: ":rails_root/storage/:rails_env/attachments/:id/:style/:basename.:extension"
include Rails.application.routes.url_helpers
def to_jq_upload
@ -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

@ -4,7 +4,7 @@ class EventType < ActiveRecord::Base
belongs_to :conference
validates :title, presence: true
validates :length, :numericality => {:greater_than => 0}
validates :length, numericality: {greater_than: 0}
validates :minimum_abstract_length, presence: true
validates :maximum_abstract_length, presence: true

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

@ -2,7 +2,7 @@ class Qanswer < ActiveRecord::Base
attr_accessible :question_id, :answer_id
belongs_to :question
belongs_to :answer, :dependent => :delete
belongs_to :answer, dependent: :delete
has_and_belongs_to_many :registrations
end

View file

@ -4,11 +4,11 @@ class Question < ActiveRecord::Base
belongs_to :question_type
has_and_belongs_to_many :conferences
has_many :qanswers, :dependent => :delete_all
has_many :answers, :through => :qanswers, :dependent => :delete_all
has_many :qanswers, dependent: :delete_all
has_many :answers, through: :qanswers, dependent: :delete_all
validates :title, :presence => true
validates :answers, :presence => true
validates :title, presence: true
validates :answers, presence: true
accepts_nested_attributes_for :answers, :allow_destroy => true
accepts_nested_attributes_for :answers, allow_destroy: true
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

@ -4,5 +4,5 @@ class Vday < ActiveRecord::Base
belongs_to :conference
has_many :vchoices
has_many :vpositions, :through => :vchoices, :dependent => :destroy
has_many :vpositions, through: :vchoices, dependent: :destroy
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

@ -4,7 +4,7 @@ class Vposition < ActiveRecord::Base
belongs_to :conference
has_many :vchoices
has_many :vdays, :through => :vchoices
has_many :vdays, through: :vchoices
validates_presence_of :title, :vdays
end