Skip to content

Commit c32fef6

Browse files
committed
Wrap MemberPresenter#attending_workshops safely
This now checks if the object passed to the Presenter is `nil` and responds accordingly. I've updated the logic in the dashboard_controller.rb to reflect the change Signed-off-by: jonathan.kerr <3410350+jonodrew@users.noreply.github.com>
1 parent 7df6ae6 commit c32fef6

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

app/controllers/dashboard_controller.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ class DashboardController < ApplicationController
44

55
DEFAULT_UPCOMING_EVENTS = 5
66

7-
helper_method :year_param, :attending_workshops
7+
helper_method :year_param
88

99
def show
1010
@chapters = Chapter.active.all.order(:created_at)
11-
@user = current_user ? MemberPresenter.new(current_user) : nil
11+
@user = MemberPresenter.new(current_user)
1212
@upcoming_workshops = upcoming_events.map.inject({}) do |hash, (key, value)|
1313
hash[key] = EventPresenter.decorate_collection(value)
1414
hash
1515
end
16-
@attending_ids = attending_workshops
16+
@attending_ids = @user.attending_workshops
1717
@testimonials = Testimonial.order(Arel.sql('RANDOM()')).limit(5).includes(:member)
1818
end
1919

@@ -84,8 +84,4 @@ def all_events(workshops)
8484

8585
[*workshops, *events, meeting].uniq.compact
8686
end
87-
88-
def attending_workshops
89-
current_user.nil? ? Set.new : current_user.workshop_invitations.accepted.pluck(:id).to_set
90-
end
9187
end

app/presenters/member_presenter.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
class MemberPresenter < BasePresenter
2+
3+
def initialize(current_user)
4+
@member = current_user
5+
super
6+
end
27
def organiser?
38
has_role? :organiser, :any
49
end
@@ -23,6 +28,10 @@ def pairing_details_array(role, tutorial, note)
2328
role.eql?('Coach') ? coach_pairing_details(note) : student_pairing_details(tutorial, note)
2429
end
2530

31+
def attending_workshops
32+
@member.nil? ? Set.new : workshop_invitations.accepted.pluck(:id).to_set
33+
end
34+
2635
private
2736

2837
def coach_pairing_details(note)

0 commit comments

Comments
 (0)