Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ def sponsorship_level_title(level)
end

# Admin-page subject of a member activity: the entity the action was about.
# Returns nil when the subject is the member themselves (e.g. logins, bans).
# Returns nil when the subject is the member themselves (e.g. logins).
# Ban and MemberNote records have no admin show route, so link their member.
def activity_subject(activity)
case (trackable = activity.trackable)
when WorkshopInvitation then trackable.workshop
when Invitation then trackable.event
when MeetingInvitation then trackable.meeting
when Member then nil
when Ban, MemberNote then trackable.member
else trackable
end
end
Expand Down
21 changes: 21 additions & 0 deletions spec/controllers/admin/members_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,27 @@

expect(response.body).to include("href=\"#{admin_event_path(invitation.event)}\"")
end

it 'links the banned member for a ban activity' do
banned = Fabricate(:member)
ban = Fabricate(:ban, member: banned)
MemberActivityRecorder.record(actor: member, key: 'member.banned',
trackable: ban, recipient: banned)

get :show, params: { id: member.id }

expect(response.body).to include("href=\"#{admin_member_path(banned)}\"")
end

it 'links the noted member for a member-note activity' do
note = Fabricate(:member_note, author: member)
MemberActivityRecorder.record(actor: member, key: 'member_note.created',
trackable: note, recipient: note.member)

get :show, params: { id: member.id }

expect(response.body).to include("href=\"#{admin_member_path(note.member)}\"")
end
end
end

Expand Down
24 changes: 24 additions & 0 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,30 @@
end
end

describe '#activity_subject' do
def activity_with(trackable)
PublicActivity::Activity.new(key: 'test', trackable:)
end

it 'returns the banned member for a ban, since bans have no admin route' do
ban = Fabricate(:ban, member: Fabricate(:member))

expect(helper.activity_subject(activity_with(ban))).to eq(ban.member)
end

it 'returns the noted member for a member note, since notes have no admin route' do
note = Fabricate(:member_note)

expect(helper.activity_subject(activity_with(note))).to eq(note.member)
end

it 'returns nil when the trackable is the member themselves' do
member = Fabricate(:member)

expect(helper.activity_subject(activity_with(member))).to be_nil
end
end

describe '#stylesheet_link_tag and #javascript_include_tag' do
around do |example|
ApplicationHelper::HEAD_ASSET_TAG_CACHE.clear
Expand Down
Loading