Merge pull request #1420 from siaw23/master

Enable Rails/Validation Rubocop cop
This commit is contained in:
Christian Bruckmayer 2017-03-29 08:56:38 +02:00 committed by GitHub
commit 6ea0752ef7
11 changed files with 33 additions and 46 deletions

View file

@ -160,6 +160,10 @@ Lint/Void:
#################### Rails ############################### #################### Rails ###############################
# Enforce Rails specific style # Enforce Rails specific style
Rails: Rails:
Enabled: true Enabled: true
# Avoid use of old-style attribute validation
Rails/Validation:
Enabled: true

View file

@ -141,23 +141,6 @@ Rails/TimeZone:
- 'spec/models/campaign_spec.rb' - 'spec/models/campaign_spec.rb'
- 'spec/models/conference_spec.rb' - 'spec/models/conference_spec.rb'
# Offense count: 16
# Configuration parameters: Include.
# Include: app/models/**/*.rb
Rails/Validation:
Exclude:
- 'app/models/call_for_paper.rb'
- 'app/models/comment.rb'
- 'app/models/conference.rb'
- 'app/models/photo.rb'
- 'app/models/registration.rb'
- 'app/models/sponsor.rb'
- 'app/models/sponsorship_level.rb'
- 'app/models/subscription.rb'
- 'app/models/ticket.rb'
- 'app/models/ticket_purchase.rb'
- 'app/models/vposition.rb'
# Offense count: 18 # Offense count: 18
Style/AccessorMethodName: Style/AccessorMethodName:
Exclude: Exclude:

View file

@ -1,7 +1,7 @@
class Comment < ActiveRecord::Base class Comment < ActiveRecord::Base
acts_as_nested_set scope: [:commentable_id, :commentable_type] acts_as_nested_set scope: %i(commentable_id commentable_type)
validates_presence_of :body validates :body, presence: true
validates_presence_of :user validates :user, presence: true
after_create :send_notification after_create :send_notification
# NOTE: install the acts_as_votable plugin if you # NOTE: install the acts_as_votable plugin if you
@ -13,7 +13,7 @@ class Comment < ActiveRecord::Base
# NOTE: Comments belong to a user # NOTE: Comments belong to a user
belongs_to :user belongs_to :user
has_paper_trail on: [:create, :destroy], meta: { conference_id: :conference_id } has_paper_trail on: %i(create destroy), meta: { conference_id: :conference_id }
# Helper class method that allows you to build a comment # Helper class method that allows you to build a comment
# by passing a commentable object, a user_id, and comment text # by passing a commentable object, a user_id, and comment text

View file

@ -7,7 +7,7 @@ class Conference < ActiveRecord::Base
default_scope { order('start_date DESC') } default_scope { order('start_date DESC') }
has_paper_trail ignore: [:updated_at, :guid, :revision, :events_per_week], meta: { conference_id: :id } has_paper_trail ignore: %i(updated_at guid revision events_per_week), meta: { conference_id: :id }
has_and_belongs_to_many :questions has_and_belongs_to_many :questions
@ -48,15 +48,15 @@ class Conference < ActiveRecord::Base
mount_uploader :picture, PictureUploader, mount_on: :logo_file_name mount_uploader :picture, PictureUploader, mount_on: :logo_file_name
validates_presence_of :title, validates :title,
:short_title, :short_title,
:start_date, :start_date,
:end_date, :end_date,
:start_hour, :start_hour,
:end_hour :end_hour, presence: true
validates_uniqueness_of :short_title validates :short_title, uniqueness: true
validates_format_of :short_title, with: /\A[a-zA-Z0-9_-]*\z/ validates :short_title, format: { with: /\A[a-zA-Z0-9_-]*\z/ }
validates :registration_limit, numericality: { only_integer: true, greater_than_or_equal_to: 0 } validates :registration_limit, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
# This validation is needed since a conference with a start date greater than the end date is not possible # This validation is needed since a conference with a start date greater than the end date is not possible
@ -559,7 +559,7 @@ class Conference < ActiveRecord::Base
# do not notify unless one of the dates changed # do not notify unless one of the dates changed
return false unless start_date_changed? || end_date_changed? return false unless start_date_changed? || end_date_changed?
# do not notify unless the mail content is set up # do not notify unless the mail content is set up
(!email_settings.conference_dates_updated_subject.blank? && !email_settings.conference_dates_updated_body.blank?) (email_settings.conference_dates_updated_subject.present? && email_settings.conference_dates_updated_body.present?)
end end
## ##
@ -575,7 +575,7 @@ class Conference < ActiveRecord::Base
# do not notify unless one of the dates changed # do not notify unless one of the dates changed
return false unless registration_period.start_date_changed? || registration_period.end_date_changed? return false unless registration_period.start_date_changed? || registration_period.end_date_changed?
# do not notify unless the mail content is set up # do not notify unless the mail content is set up
(!email_settings.conference_registration_dates_updated_subject.blank? && !email_settings.conference_registration_dates_updated_body.blank?) (email_settings.conference_registration_dates_updated_subject.present? && email_settings.conference_registration_dates_updated_body.present?)
end end
def registration_limit_exceeded? def registration_limit_exceeded?
@ -699,7 +699,7 @@ class Conference < ActiveRecord::Base
# Completed weeks # Completed weeks
events_per_week.each do |week, values| events_per_week.each do |week, values|
values.each do |state, value| values.each do |state, value|
if [:confirmed, :unconfirmed].include?(state) if %i(confirmed unconfirmed).include?(state)
unless result[state.to_s.capitalize] unless result[state.to_s.capitalize]
result[state.to_s.capitalize] = {} result[state.to_s.capitalize] = {}
end end

View file

@ -9,7 +9,7 @@ class Registration < ActiveRecord::Base
has_many :events_registrations has_many :events_registrations
has_many :events, through: :events_registrations, dependent: :destroy has_many :events, through: :events_registrations, dependent: :destroy
has_paper_trail ignore: [:updated_at, :week], meta: { conference_id: :conference_id } has_paper_trail ignore: %i(updated_at week), meta: { conference_id: :conference_id }
accepts_nested_attributes_for :user accepts_nested_attributes_for :user
accepts_nested_attributes_for :qanswers accepts_nested_attributes_for :qanswers
@ -24,7 +24,7 @@ class Registration < ActiveRecord::Base
validates :user, presence: true validates :user, presence: true
validates_uniqueness_of :user_id, scope: :conference_id, message: 'already Registered!' validates :user_id, uniqueness: { scope: :conference_id, message: 'already Registered!' }
validate :registration_limit_not_exceed, on: :create validate :registration_limit_not_exceed, on: :create
validate :registration_to_events_only_if_present validate :registration_to_events_only_if_present

View file

@ -6,5 +6,5 @@ class Sponsor < ActiveRecord::Base
mount_uploader :picture, PictureUploader, mount_on: :logo_file_name mount_uploader :picture, PictureUploader, mount_on: :logo_file_name
validates_presence_of :name, :website_url, :sponsorship_level validates :name, :website_url, :sponsorship_level, presence: true
end end

View file

@ -1,5 +1,5 @@
class SponsorshipLevel < ActiveRecord::Base class SponsorshipLevel < ActiveRecord::Base
validates_presence_of :title validates :title, presence: true
belongs_to :conference belongs_to :conference
acts_as_list scope: :conference acts_as_list scope: :conference
has_many :sponsors has_many :sponsors

View file

@ -1,9 +1,9 @@
class Subscription < ActiveRecord::Base class Subscription < ActiveRecord::Base
validates_uniqueness_of :user_id, scope: [:conference_id] validates :user_id, uniqueness: { scope: [:conference_id] }
belongs_to :conference belongs_to :conference
belongs_to :user belongs_to :user
has_paper_trail on: [:create, :destroy], ignore: [:updated_at], meta: { conference_id: :conference_id } has_paper_trail on: %i(create destroy), ignore: [:updated_at], meta: { conference_id: :conference_id }
validates_uniqueness_of :user_id, scope: :conference_id, message: 'already subscribed!' validates :user_id, uniqueness: { scope: :conference_id, message: 'already subscribed!' }
end end

View file

@ -13,7 +13,7 @@ class Ticket < ActiveRecord::Base
validates :price_cents, :price_currency, :title, presence: true validates :price_cents, :price_currency, :title, presence: true
validates_numericality_of :price_cents, greater_than_or_equal_to: 0 validates :price_cents, numericality: { greater_than_or_equal_to: 0 }
def bought?(user) def bought?(user)
buyers.include?(user) buyers.include?(user)

View file

@ -5,7 +5,7 @@ class TicketPurchase < ActiveRecord::Base
validates :ticket_id, :user_id, :conference_id, :quantity, presence: true validates :ticket_id, :user_id, :conference_id, :quantity, presence: true
validates_numericality_of :quantity, greater_than: 0 validates :quantity, numericality: { greater_than: 0 }
delegate :title, to: :ticket delegate :title, to: :ticket
delegate :description, to: :ticket delegate :description, to: :ticket
@ -15,8 +15,8 @@ class TicketPurchase < ActiveRecord::Base
scope :paid, -> { where(paid: true) } scope :paid, -> { where(paid: true) }
scope :unpaid, -> { where(paid: false) } scope :unpaid, -> { where(paid: false) }
scope :by_conference, -> (conference) { where(conference_id: conference.id) } scope :by_conference, ->(conference) { where(conference_id: conference.id) }
scope :by_user, -> (user) { where(user_id: user.id) } scope :by_user, ->(user) { where(user_id: user.id) }
def self.purchase(conference, user, purchases) def self.purchase(conference, user, purchases)
errors = [] errors = []

View file

@ -4,5 +4,5 @@ class Vposition < ActiveRecord::Base
has_many :vchoices has_many :vchoices
has_many :vdays, through: :vchoices has_many :vdays, through: :vchoices
validates_presence_of :title, :vdays validates :title, :vdays, presence: true
end end