Skip to content

Commit

Permalink
Use Ruby safe navigation over Rails try
Browse files Browse the repository at this point in the history
  • Loading branch information
bear454 committed Jun 1, 2018
1 parent d8bd269 commit 24396d3
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 27 deletions.
2 changes: 0 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ AllCops:
#################### Metrics ###############################

# Start with cops for Ruby >= 2.3 disabled
Style/SafeNavigation:
Enabled: false
Style/NumericPredicate:
Enabled: false

Expand Down
2 changes: 1 addition & 1 deletion app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
16 changes: 10 additions & 6 deletions app/models/cfp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 5 additions & 6 deletions app/models/conference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions app/models/registration_period.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions app/models/track.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion app/models/venue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def address

def country_name
name = ISO3166::Country[country]
name.name if name
name&.name
end

def location?
Expand Down
2 changes: 1 addition & 1 deletion app/uploaders/picture_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down

0 comments on commit 24396d3

Please sign in to comment.