diff --git a/.rubocop.yml b/.rubocop.yml index f5399879..de129467 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -17,8 +17,6 @@ AllCops: #################### Metrics ############################### # Start with cops for Ruby >= 2.3 disabled -Style/SafeNavigation: - Enabled: false Style/NumericPredicate: Enabled: false diff --git a/app/models/ability.rb b/app/models/ability.rb index bed672e1..71f22cfb 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -20,7 +20,7 @@ class Ability can [:index, :conferences, :code_of_conduct], Organization can [:index], Conference can [:show], Conference do |conference| - conference.splashpage && conference.splashpage.public == true + conference.splashpage&.public == true end # Can view the schedule can [:schedule, :events], Conference do |conference| diff --git a/app/models/cfp.rb b/app/models/cfp.rb index f0001ed3..137d94f4 100644 --- a/app/models/cfp.rb +++ b/app/models/cfp.rb @@ -108,14 +108,18 @@ class Cfp < ApplicationRecord private def before_end_of_conference - if program && program.conference && program.conference.end_date && end_date && (end_date > program.conference.end_date) - errors - .add(:end_date, "can't be after the conference end date (#{program.conference.end_date})") + if program&.conference&.end_date && end_date && (end_date > program.conference.end_date) + errors.add( + :end_date, + "can't be after the conference end date (#{program.conference.end_date})" + ) end - if program && program.conference && program.conference.end_date && start_date && (start_date > program.conference.end_date) - errors - .add(:start_date, "can't be after the conference end date (#{program.conference.end_date})") + if program&.conference&.end_date && start_date && (start_date > program.conference.end_date) + errors.add( + :start_date, + "can't be after the conference end date (#{program.conference.end_date})" + ) end end diff --git a/app/models/conference.rb b/app/models/conference.rb index 6b961592..95d63941 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -154,7 +154,7 @@ class Conference < ApplicationRecord def get_submissions_per_week result = [] - if program && program.cfp && program.events + if program&.cfp && program&.events submissions = program.events.select(:week).group(:week).order(:week).count start_week = program.cfp.start_week weeks = program.cfp.weeks @@ -171,7 +171,7 @@ class Conference < ApplicationRecord # * +Array+ -> e.g. 'Submitted' => [0, 3, 3, 5] -> first week 0 events, second week 3 events. def get_submissions_data result = {} - if program && program.cfp && program.events + if program&.cfp && program&.events result = get_events_per_week_by_state start_week = program.cfp.start_week @@ -272,9 +272,8 @@ class Conference < ApplicationRecord def registration_weeks result = 0 weeks = 0 - if registration_period && - registration_period.start_date && - registration_period.end_date + if registration_period&.start_date && + registration_period&.end_date weeks = Date.new(registration_period.start_date.year, 12, 31) .strftime('%W').to_i @@ -346,7 +345,7 @@ class Conference < ApplicationRecord tracks: tracks_set?, event_types: event_types_set?, difficulty_levels: difficulty_levels_set?, - splashpage: splashpage && splashpage.public? + splashpage: splashpage&.public? } result.update( diff --git a/app/models/event.rb b/app/models/event.rb index 45a37c43..d6a163dd 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -312,7 +312,7 @@ class Event < ApplicationRecord def before_end_of_conference errors - .add(:created_at, "can't be after the conference end date!") if program.conference && program.conference.end_date && + .add(:created_at, "can't be after the conference end date!") if program.conference&.end_date && (Date.today > program.conference.end_date) end @@ -324,7 +324,7 @@ class Event < ApplicationRecord # Allow only confirmed tracks that belong to the same program as the event # def valid_track - return unless track && track.program && program + return unless track&.program && program errors.add(:track, 'is invalid') unless track.confirmed? && track.program == program end diff --git a/app/models/registration_period.rb b/app/models/registration_period.rb index 99671733..66f02fe0 100644 --- a/app/models/registration_period.rb +++ b/app/models/registration_period.rb @@ -13,10 +13,10 @@ class RegistrationPeriod < ApplicationRecord def before_end_of_conference errors - .add(:start_date, "can't be after the conference end date (#{conference.end_date})") if conference && conference.end_date && start_date && (start_date > conference.end_date) + .add(:start_date, "can't be after the conference end date (#{conference.end_date})") if conference&.end_date && start_date && (start_date > conference.end_date) errors - .add(:end_date, "can't be after the conference end date (#{conference.end_date})") if conference && conference.end_date && end_date && (end_date > conference.end_date) + .add(:end_date, "can't be after the conference end date (#{conference.end_date})") if conference&.end_date && end_date && (end_date > conference.end_date) end def start_date_before_end_date diff --git a/app/models/track.rb b/app/models/track.rb index 6afd43b2..59a7c632 100644 --- a/app/models/track.rb +++ b/app/models/track.rb @@ -115,10 +115,8 @@ class Track < ApplicationRecord def revoke_role_and_cleanup role = Role.find_by(name: 'track_organizer', resource: self) - if role - role.users.each do |user| - user.remove_role 'track_organizer', self - end + role&.users&.each do |user| + user.remove_role 'track_organizer', self end self.selected_schedule_id = nil diff --git a/app/models/user.rb b/app/models/user.rb index 574ef86b..5c9c5209 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -133,7 +133,7 @@ class User < ApplicationRecord def self.for_ichain_username(username, attributes) user = find_by(username: username) - raise UserDisabled if user && user.is_disabled + raise UserDisabled if user&.is_disabled if user user.update_attributes(email: attributes[:email], diff --git a/app/models/venue.rb b/app/models/venue.rb index c46f52ab..b55723a5 100644 --- a/app/models/venue.rb +++ b/app/models/venue.rb @@ -21,7 +21,7 @@ class Venue < ApplicationRecord def country_name name = ISO3166::Country[country] - name.name if name + name&.name end def location? diff --git a/app/uploaders/picture_uploader.rb b/app/uploaders/picture_uploader.rb index 9c669b86..1b6385dd 100644 --- a/app/uploaders/picture_uploader.rb +++ b/app/uploaders/picture_uploader.rb @@ -44,7 +44,7 @@ class PictureUploader < CarrierWave::Uploader::Base # Returns the id of the instance in a split path form. e.g. returns # 000/001/234 for an id of 1234. Stolen from paperclip... def id_partition - ('%09d'.freeze % model.id).scan(/\d{3}/).join('/'.freeze) + format('%09d', model.id).scan(/\d{3}/).join('/') end # Override the directory where uploaded files will be stored. diff --git a/db/migrate/20141128073306_migrate_data_remove_column_include_cfp_in_splash_add_column_include_cfp.rb b/db/migrate/20141128073306_migrate_data_remove_column_include_cfp_in_splash_add_column_include_cfp.rb index 6d0390b6..a90b5c53 100644 --- a/db/migrate/20141128073306_migrate_data_remove_column_include_cfp_in_splash_add_column_include_cfp.rb +++ b/db/migrate/20141128073306_migrate_data_remove_column_include_cfp_in_splash_add_column_include_cfp.rb @@ -19,7 +19,7 @@ class MigrateDataRemoveColumnIncludeCfpInSplashAddColumnIncludeCfp < ActiveRecor TempConference.all.each do |conference| cfp = TempCallForPaper.find_by(conference_id: conference.id) - if cfp && cfp.include_cfp_in_splash + if cfp&.include_cfp_in_splash splashpage = TempSplashpage.find_or_initialize_by(conference_id: conference.id) splashpage.include_cfp = cfp.include_cfp_in_splash # true splashpage.save!