diff --git a/.rubocop.yml b/.rubocop.yml index f53998790f..de129467b9 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 bed672e1ae..71f22cfb3e 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -20,7 +20,7 @@ def not_signed_in 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 f0001ed38b..137d94f4fb 100644 --- a/app/models/cfp.rb +++ b/app/models/cfp.rb @@ -108,14 +108,18 @@ def self.for_booths 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 6b961592e0..95d6394147 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -154,7 +154,7 @@ def registration_dates_given? 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 @@ def get_submissions_per_week # * +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 @@ def get_tickets_data 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 @@ def get_status 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 45a37c437e..d6a163dd96 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -312,7 +312,7 @@ def set_week 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 @@ def conference_id # 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 99671733d3..66f02fe0a4 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 6afd43b252..59a7c632b5 100644 --- a/app/models/track.rb +++ b/app/models/track.rb @@ -115,10 +115,8 @@ def assign_role_to_submitter 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 574ef86b56..5c9c5209ac 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -133,7 +133,7 @@ def supports? conference 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 c46f52ab20..b55723a55e 100644 --- a/app/models/venue.rb +++ b/app/models/venue.rb @@ -21,7 +21,7 @@ def address 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 9c669b8622..1b6385dd0f 100644 --- a/app/uploaders/picture_uploader.rb +++ b/app/uploaders/picture_uploader.rb @@ -44,7 +44,7 @@ def extra_store_dir # 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 6d0390b625..a90b5c5306 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 @@ def up 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!