mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-15 20:54:03 +00:00
Merge pull request #1420 from siaw23/master
Enable Rails/Validation Rubocop cop
This commit is contained in:
commit
6ea0752ef7
11 changed files with 33 additions and 46 deletions
|
|
@ -160,6 +160,10 @@ Lint/Void:
|
|||
|
||||
#################### Rails ###############################
|
||||
|
||||
# Enforce Rails specific style
|
||||
# Enforce Rails specific style
|
||||
Rails:
|
||||
Enabled: true
|
||||
|
||||
# Avoid use of old-style attribute validation
|
||||
Rails/Validation:
|
||||
Enabled: true
|
||||
|
|
|
|||
|
|
@ -141,23 +141,6 @@ Rails/TimeZone:
|
|||
- 'spec/models/campaign_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
|
||||
Style/AccessorMethodName:
|
||||
Exclude:
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
class Comment < ActiveRecord::Base
|
||||
acts_as_nested_set scope: [:commentable_id, :commentable_type]
|
||||
validates_presence_of :body
|
||||
validates_presence_of :user
|
||||
acts_as_nested_set scope: %i(commentable_id commentable_type)
|
||||
validates :body, presence: true
|
||||
validates :user, presence: true
|
||||
after_create :send_notification
|
||||
|
||||
# NOTE: install the acts_as_votable plugin if you
|
||||
|
|
@ -13,7 +13,7 @@ class Comment < ActiveRecord::Base
|
|||
# NOTE: Comments belong to a 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
|
||||
# by passing a commentable object, a user_id, and comment text
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ class Conference < ActiveRecord::Base
|
|||
|
||||
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
|
||||
|
||||
|
|
@ -48,15 +48,15 @@ class Conference < ActiveRecord::Base
|
|||
|
||||
mount_uploader :picture, PictureUploader, mount_on: :logo_file_name
|
||||
|
||||
validates_presence_of :title,
|
||||
:short_title,
|
||||
:start_date,
|
||||
:end_date,
|
||||
:start_hour,
|
||||
:end_hour
|
||||
validates :title,
|
||||
:short_title,
|
||||
:start_date,
|
||||
:end_date,
|
||||
:start_hour,
|
||||
:end_hour, presence: true
|
||||
|
||||
validates_uniqueness_of :short_title
|
||||
validates_format_of :short_title, with: /\A[a-zA-Z0-9_-]*\z/
|
||||
validates :short_title, uniqueness: true
|
||||
validates :short_title, format: { with: /\A[a-zA-Z0-9_-]*\z/ }
|
||||
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
|
||||
|
|
@ -559,7 +559,7 @@ class Conference < ActiveRecord::Base
|
|||
# do not notify unless one of the dates changed
|
||||
return false unless start_date_changed? || end_date_changed?
|
||||
# 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
|
||||
|
||||
##
|
||||
|
|
@ -575,7 +575,7 @@ class Conference < ActiveRecord::Base
|
|||
# do not notify unless one of the dates changed
|
||||
return false unless registration_period.start_date_changed? || registration_period.end_date_changed?
|
||||
# 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
|
||||
|
||||
def registration_limit_exceeded?
|
||||
|
|
@ -699,7 +699,7 @@ class Conference < ActiveRecord::Base
|
|||
# Completed weeks
|
||||
events_per_week.each do |week, values|
|
||||
values.each do |state, value|
|
||||
if [:confirmed, :unconfirmed].include?(state)
|
||||
if %i(confirmed unconfirmed).include?(state)
|
||||
unless result[state.to_s.capitalize]
|
||||
result[state.to_s.capitalize] = {}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ class Registration < ActiveRecord::Base
|
|||
has_many :events_registrations
|
||||
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 :qanswers
|
||||
|
|
@ -24,7 +24,7 @@ class Registration < ActiveRecord::Base
|
|||
|
||||
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_to_events_only_if_present
|
||||
|
||||
|
|
|
|||
|
|
@ -6,5 +6,5 @@ class Sponsor < ActiveRecord::Base
|
|||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class SponsorshipLevel < ActiveRecord::Base
|
||||
validates_presence_of :title
|
||||
validates :title, presence: true
|
||||
belongs_to :conference
|
||||
acts_as_list scope: :conference
|
||||
has_many :sponsors
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
class Subscription < ActiveRecord::Base
|
||||
validates_uniqueness_of :user_id, scope: [:conference_id]
|
||||
validates :user_id, uniqueness: { scope: [:conference_id] }
|
||||
belongs_to :conference
|
||||
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
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class Ticket < ActiveRecord::Base
|
|||
|
||||
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)
|
||||
buyers.include?(user)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ class TicketPurchase < ActiveRecord::Base
|
|||
|
||||
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 :description, to: :ticket
|
||||
|
|
@ -15,8 +15,8 @@ class TicketPurchase < ActiveRecord::Base
|
|||
|
||||
scope :paid, -> { where(paid: true) }
|
||||
scope :unpaid, -> { where(paid: false) }
|
||||
scope :by_conference, -> (conference) { where(conference_id: conference.id) }
|
||||
scope :by_user, -> (user) { where(user_id: user.id) }
|
||||
scope :by_conference, ->(conference) { where(conference_id: conference.id) }
|
||||
scope :by_user, ->(user) { where(user_id: user.id) }
|
||||
|
||||
def self.purchase(conference, user, purchases)
|
||||
errors = []
|
||||
|
|
|
|||
|
|
@ -4,5 +4,5 @@ class Vposition < ActiveRecord::Base
|
|||
has_many :vchoices
|
||||
has_many :vdays, through: :vchoices
|
||||
|
||||
validates_presence_of :title, :vdays
|
||||
validates :title, :vdays, presence: true
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue