From 7d27ee9276e9752e3141cea93aed9b28a571617f Mon Sep 17 00:00:00 2001 From: Vivian Canales Date: Wed, 15 Jan 2025 17:23:21 -0600 Subject: [PATCH 1/6] updated null objects --- app/null_objects/null_account.rb | 8 ++++++++ app/null_objects/null_chapterable.rb | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/null_objects/null_account.rb b/app/null_objects/null_account.rb index 0153ba6409..981555d966 100644 --- a/app/null_objects/null_account.rb +++ b/app/null_objects/null_account.rb @@ -9,6 +9,10 @@ def name "null account" end + def scope_name + nil + end + def mentor_profile ::NullProfile.new end @@ -37,6 +41,10 @@ def authenticated? false end + def profile_image_url + nil + end + def current_chapter NullChapter.new end diff --git a/app/null_objects/null_chapterable.rb b/app/null_objects/null_chapterable.rb index 288fac85a9..200c040984 100644 --- a/app/null_objects/null_chapterable.rb +++ b/app/null_objects/null_chapterable.rb @@ -1,5 +1,5 @@ class NullChapterable < NullObject def primary_contact - nil + NullAccount.new end end From 4575d5bbe587f0d37a411c22067f35ab16c71c32 Mon Sep 17 00:00:00 2001 From: Vivian Canales Date: Wed, 15 Jan 2025 17:34:12 -0600 Subject: [PATCH 2/6] merge conflict --- app/models/club.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/models/club.rb b/app/models/club.rb index a8630ddeb6..1459bfc9d6 100644 --- a/app/models/club.rb +++ b/app/models/club.rb @@ -16,6 +16,9 @@ class Club < ActiveRecord::Base after_update :update_onboarding_status + has_many :club_account_assignments, as: :chapterable, class_name: "ChapterableAccountAssignment" + has_many :accounts, through: :club_account_assignments + def assign_address_details(geocoded) self.city = geocoded.city self.state_province = geocoded.state_code From 868159b0b7dd98c9f3a9bca119eda80a018759a8 Mon Sep 17 00:00:00 2001 From: Vivian Canales Date: Wed, 15 Jan 2025 17:35:51 -0600 Subject: [PATCH 3/6] updated mentor invite/join flows to assign mentors to student's primary club or chapter --- app/controllers/mentor/mentor_invites_controller.rb | 9 +++++---- app/controllers/mentor/team_member_invites_controller.rb | 9 +++++---- app/technovation/join_request_approved.rb | 9 +++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/controllers/mentor/mentor_invites_controller.rb b/app/controllers/mentor/mentor_invites_controller.rb index f67b80e5ed..7cddbc270e 100644 --- a/app/controllers/mentor/mentor_invites_controller.rb +++ b/app/controllers/mentor/mentor_invites_controller.rb @@ -28,11 +28,12 @@ def update invite.update(invite_params) - student_chapters = invite.team.students.flat_map { |s| s.account.current_chapter }.uniq + student_chapterables = invite.team.students.flat_map { |s| s.account.current_chapterable_assignment&.chapterable }.uniq - student_chapters.each do |chapter| - if chapter.present? - chapter.chapter_account_assignments.create( + student_chapterables.each do |chapterable| + if chapterable.present? + chapterable_type = chapterable.is_a?(Club) ? "club" : "chapter" + chapterable.send("#{chapterable_type}_account_assignments").create( profile: current_mentor, account: current_mentor.account, season: Season.current.year, diff --git a/app/controllers/mentor/team_member_invites_controller.rb b/app/controllers/mentor/team_member_invites_controller.rb index 5046f9018c..35f6334583 100644 --- a/app/controllers/mentor/team_member_invites_controller.rb +++ b/app/controllers/mentor/team_member_invites_controller.rb @@ -11,11 +11,12 @@ def update ) invite.update(invite_params) - student_chapters = invite.team.students.flat_map { |s| s.account.current_chapter }.uniq + student_chapterables = invite.team.students.flat_map { |s| s.account.current_chapterable_assignment&.chapterable }.uniq - student_chapters.each do |chapter| - if chapter.present? - chapter.chapter_account_assignments.create( + student_chapterables.each do |chapterable| + if chapterable.present? + chapterable_type = chapterable.is_a?(Club) ? "club" : "chapter" + chapterable.send("#{chapterable_type}_account_assignments").create( profile: current_mentor, account: current_mentor.account, season: Season.current.year, diff --git a/app/technovation/join_request_approved.rb b/app/technovation/join_request_approved.rb index 410fb89185..18e66253d1 100644 --- a/app/technovation/join_request_approved.rb +++ b/app/technovation/join_request_approved.rb @@ -10,11 +10,12 @@ def self.call(join_request) TeamRosterManaging.add(join_request.team, join_request.requestor) if join_request.requestor_scope_name == "mentor" - student_chapters = join_request.team.students.flat_map { |s| s.account.current_chapter }.uniq + student_chapterables = join_request.team.students.flat_map { |s| s.account.current_chapterable_assignment&.chapterable }.uniq - student_chapters.each do |chapter| - if chapter.present? - chapter.chapter_account_assignments.create( + student_chapterables.each do |chapterable| + if chapterable.present? + chapterable_type = chapterable.is_a?(Club) ? "club" : "chapter" + chapterable.send("#{chapterable_type}_account_assignments").create( profile: join_request.requestor, account: join_request.requestor.account, season: Season.current.year, From 3042c66e89669c2767056396d285cf1487b14010 Mon Sep 17 00:00:00 2001 From: Vivian Canales Date: Wed, 15 Jan 2025 17:36:26 -0600 Subject: [PATCH 4/6] updated mentor invite/join tests --- .../mentor/mentor_invites_controller_spec.rb | 88 ++++++++--------- .../team_member_invites_controller_spec.rb | 88 ++++++++--------- .../student/join_requests_controller_spec.rb | 96 ++++++++++--------- 3 files changed, 139 insertions(+), 133 deletions(-) diff --git a/spec/controllers/mentor/mentor_invites_controller_spec.rb b/spec/controllers/mentor/mentor_invites_controller_spec.rb index f3f4188d1e..cedfa220e3 100644 --- a/spec/controllers/mentor/mentor_invites_controller_spec.rb +++ b/spec/controllers/mentor/mentor_invites_controller_spec.rb @@ -151,54 +151,56 @@ end end - describe "mentor chapter assignments" do - context "when two students from the same chapter are on a team" do - let(:team) { FactoryBot.create(:team) } - let(:mentor) { FactoryBot.create(:mentor, :onboarded) } - let(:chapter) { FactoryBot.create(:chapter) } - let(:student1) { FactoryBot.create(:student, :not_assigned_to_chapter) } - let(:student2) { FactoryBot.create(:student, :not_assigned_to_chapter) } - let!(:invite) { FactoryBot.create(:team_member_invite, invitee: mentor) } - - before do - student1.chapterable_assignments.create( - chapterable: chapter, - account: student1.account, - season: Season.current.year, - primary: true - ) - - student2.chapterable_assignments.create( - chapterable: chapter, - account: student2.account, - season: Season.current.year, - primary: true - ) - - team.students << student1 - team.students << student2 - team.save - - invite.team = team - invite.save - end + describe "mentor chapterable assignments" do + %w[club chapter].each do |chapterable_type| + context "when two students from the same #{chapterable_type} are on a team" do + let(:team) { FactoryBot.create(:team) } + let(:mentor) { FactoryBot.create(:mentor, :onboarded) } + let(:chapterable) { FactoryBot.create(chapterable_type.to_sym) } + let(:student1) { FactoryBot.create(:student, :not_assigned_to_chapter) } + let(:student2) { FactoryBot.create(:student, :not_assigned_to_chapter) } + let!(:invite) { FactoryBot.create(:team_member_invite, invitee: mentor) } - context "when the mentor invite request for this team is accepted" do before do - sign_in(mentor) - - put :update, params: { - id: invite.invite_token, - team_member_invite: {status: :accepted} - } + student1.chapterable_assignments.create( + chapterable: chapterable, + account: student1.account, + season: Season.current.year, + primary: true + ) + + student2.chapterable_assignments.create( + chapterable: chapterable, + account: student2.account, + season: Season.current.year, + primary: true + ) + + team.students << student1 + team.students << student2 + team.save + + invite.team = team + invite.save end - it "creates one non-primary chapter assignment (since both students belong to the same chapter)" do - expect(mentor.account.chapterable_assignments.where(chapterable: chapter, primary: false).count).to eq(1) - end + context "when the mentor invite request for this team is accepted" do + before do + sign_in(mentor) + + put :update, params: { + id: invite.invite_token, + team_member_invite: {status: :accepted} + } + end + + it "creates one non-primary chapterable assignment (since both students belong to the same #{chapterable_type})" do + expect(mentor.account.chapterable_assignments.where(chapterable: chapterable, primary: false).count).to eq(1) + end - it "assigns the mentor to the student's chapter" do - expect(mentor.account.current_chapters).to include(student1.account.current_chapter) + it "assigns the mentor to the student's #{chapterable_type}" do + expect(mentor.account.chapterable_assignments.map(&:chapterable)).to include(student1.account.current_primary_chapterable_assignment.chapterable) + end end end end diff --git a/spec/controllers/mentor/team_member_invites_controller_spec.rb b/spec/controllers/mentor/team_member_invites_controller_spec.rb index 4cf24a9d0a..a5135f1016 100644 --- a/spec/controllers/mentor/team_member_invites_controller_spec.rb +++ b/spec/controllers/mentor/team_member_invites_controller_spec.rb @@ -75,54 +75,56 @@ end end - describe "mentor chapter assignments" do - context "when two students from the same chapter are on a team" do - let(:team) { FactoryBot.create(:team) } - let(:mentor) { FactoryBot.create(:mentor, :onboarded) } - let(:chapter) { FactoryBot.create(:chapter) } - let(:student1) { FactoryBot.create(:student, :not_assigned_to_chapter) } - let(:student2) { FactoryBot.create(:student, :not_assigned_to_chapter) } - let!(:invite) { FactoryBot.create(:team_member_invite, invitee: mentor) } - - before do - student1.chapterable_assignments.create( - chapterable: chapter, - account: student1.account, - season: Season.current.year, - primary: true - ) - - student2.chapterable_assignments.create( - chapterable: chapter, - account: student2.account, - season: Season.current.year, - primary: true - ) - - team.students << student1 - team.students << student2 - team.save - - invite.team = team - invite.save - end + describe "mentor chapterable assignments" do + %w[club chapter].each do |chapterable_type| + context "when two students from the same #{chapterable_type} are on a team" do + let(:team) { FactoryBot.create(:team) } + let(:mentor) { FactoryBot.create(:mentor, :onboarded) } + let(:chapterable) { FactoryBot.create(chapterable_type.to_sym) } + let(:student1) { FactoryBot.create(:student, :not_assigned_to_chapter) } + let(:student2) { FactoryBot.create(:student, :not_assigned_to_chapter) } + let!(:invite) { FactoryBot.create(:team_member_invite, invitee: mentor) } - context "when the mentor invite request for this team is accepted" do before do - sign_in(mentor) - - put :update, params: { - id: invite.invite_token, - team_member_invite: {status: :accepted} - } + student1.chapterable_assignments.create( + chapterable: chapterable, + account: student1.account, + season: Season.current.year, + primary: true + ) + + student2.chapterable_assignments.create( + chapterable: chapterable, + account: student2.account, + season: Season.current.year, + primary: true + ) + + team.students << student1 + team.students << student2 + team.save + + invite.team = team + invite.save end - it "creates one non-primary chapter assignment (since both students belong to the same chapter)" do - expect(mentor.account.chapterable_assignments.where(chapterable: chapter, primary: false).count).to eq(1) - end + context "when the mentor invite request for this team is accepted" do + before do + sign_in(mentor) + + put :update, params: { + id: invite.invite_token, + team_member_invite: {status: :accepted} + } + end + + it "creates one non-primary chapterable assignment (since both students belong to the same #{chapterable_type})" do + expect(mentor.account.chapterable_assignments.where(chapterable: chapterable, primary: false).count).to eq(1) + end - it "assigns the mentor to the student's chapter" do - expect(mentor.account.current_chapters).to include(student1.account.current_chapter) + it "assigns the mentor to the student's #{chapterable_type}" do + expect(mentor.account.chapterable_assignments.map(&:chapterable)).to include(student1.account.current_primary_chapterable_assignment.chapterable) + end end end end diff --git a/spec/controllers/student/join_requests_controller_spec.rb b/spec/controllers/student/join_requests_controller_spec.rb index d2c95da16d..53ac308be9 100644 --- a/spec/controllers/student/join_requests_controller_spec.rb +++ b/spec/controllers/student/join_requests_controller_spec.rb @@ -248,59 +248,61 @@ end end - describe "mentor chapter assignments" do - context "when two students from the same chapter are on a team" do - let(:team) { FactoryBot.create(:team) } - let(:mentor) { FactoryBot.create(:mentor, :onboarded) } - let(:chapter) { FactoryBot.create(:chapter) } - let(:student1) { FactoryBot.create(:student, :not_assigned_to_chapter) } - let(:student2) { FactoryBot.create(:student, :not_assigned_to_chapter) } - let(:join_request) { - FactoryBot.create( - :join_request, - team: team, - requestor: mentor - ) - } - - before do - student1.chapterable_assignments.create( - chapterable: chapter, - account: student1.account, - season: Season.current.year, - primary: true - ) - - student2.chapterable_assignments.create( - chapterable: chapter, - account: student2.account, - season: Season.current.year, - primary: true - ) - - team.students << student1 - team.students << student2 - team.save - end - - before do - sign_in(student1) - end + describe "mentor chapterable assignments" do + %w[club chapter].each do |chapterable_type| + context "when two students from the same #{chapterable_type} are on a team" do + let(:team) { FactoryBot.create(:team) } + let(:mentor) { FactoryBot.create(:mentor, :onboarded) } + let(:chapterable) { FactoryBot.create(chapterable_type.to_sym) } + let(:student1) { FactoryBot.create(:student, :not_assigned_to_chapter) } + let(:student2) { FactoryBot.create(:student, :not_assigned_to_chapter) } + let(:join_request) { + FactoryBot.create( + :join_request, + team: team, + requestor: mentor + ) + } - context "when the mentor join request for the team is accepted" do before do - put :update, params: { - id: join_request.review_token, - join_request: {status: :approved} - } + student1.chapterable_assignments.create( + chapterable: chapterable, + account: student1.account, + season: Season.current.year, + primary: true + ) + + student2.chapterable_assignments.create( + chapterable: chapterable, + account: student2.account, + season: Season.current.year, + primary: true + ) + + team.students << student1 + team.students << student2 + team.save end - it "creates one non-primary chapter assignment (since both students belong to the same chapter)" do - expect(mentor.account.chapterable_assignments.where(chapterable: chapter, primary: false).count).to eq(1) + before do + sign_in(student1) end - it "assigns the mentor to the student's chapter" do - expect(mentor.account.current_chapters).to include(student1.account.current_chapter) + context "when the mentor join request for the team is accepted" do + before do + put :update, params: { + id: join_request.review_token, + join_request: {status: :approved} + } + end + + it "creates one non-primary chapterable assignment (since both students belong to the same #{chapterable_type})" do + expect(mentor.account.chapterable_assignments.where(chapterable: chapterable, primary: false).count).to eq(1) + end + + it "assigns the mentor to the student's #{chapterable_type}" do + expect(mentor.account.chapterable_assignments.map(&:chapterable)).to include(student1.account.current_primary_chapterable_assignment.chapterable) + end end end end From 7963f5bd48bf868ee132c460b22e26c865607eb3 Mon Sep 17 00:00:00 2001 From: Vivian Canales Date: Thu, 16 Jan 2025 13:49:30 -0600 Subject: [PATCH 5/6] updated chapter and club model --- app/models/chapter.rb | 6 +++--- app/models/club.rb | 3 --- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/app/models/chapter.rb b/app/models/chapter.rb index bd4932573d..14fef78d84 100644 --- a/app/models/chapter.rb +++ b/app/models/chapter.rb @@ -10,10 +10,10 @@ class Chapter < ActiveRecord::Base has_one :legal_contact, dependent: :destroy has_one :chapter_program_information, dependent: :destroy - has_many :chapter_account_assignments, as: :chapterable, class_name: "ChapterableAccountAssignment" - has_many :accounts, through: :chapter_account_assignments + has_many :chapterable_account_assignments, as: :chapterable, class_name: "ChapterableAccountAssignment" + has_many :accounts, through: :chapterable_account_assignments has_many :chapter_ambassadors, -> { where "profile_type = 'ChapterAmbassadorProfile'" }, - through: :chapter_account_assignments, + through: :chapterable_account_assignments, source: :account has_many :chapter_links, dependent: :destroy diff --git a/app/models/club.rb b/app/models/club.rb index 1459bfc9d6..a8630ddeb6 100644 --- a/app/models/club.rb +++ b/app/models/club.rb @@ -16,9 +16,6 @@ class Club < ActiveRecord::Base after_update :update_onboarding_status - has_many :club_account_assignments, as: :chapterable, class_name: "ChapterableAccountAssignment" - has_many :accounts, through: :club_account_assignments - def assign_address_details(geocoded) self.city = geocoded.city self.state_province = geocoded.state_code From b47029e10afca933515efaeab496c11a9fd0fba8 Mon Sep 17 00:00:00 2001 From: Vivian Canales Date: Thu, 16 Jan 2025 13:49:55 -0600 Subject: [PATCH 6/6] updated logic for creating assignments for both clubs and chapters --- app/controllers/mentor/mentor_invites_controller.rb | 3 +-- app/controllers/mentor/team_member_invites_controller.rb | 3 +-- app/technovation/join_request_approved.rb | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/app/controllers/mentor/mentor_invites_controller.rb b/app/controllers/mentor/mentor_invites_controller.rb index 7cddbc270e..31ff504f78 100644 --- a/app/controllers/mentor/mentor_invites_controller.rb +++ b/app/controllers/mentor/mentor_invites_controller.rb @@ -32,8 +32,7 @@ def update student_chapterables.each do |chapterable| if chapterable.present? - chapterable_type = chapterable.is_a?(Club) ? "club" : "chapter" - chapterable.send("#{chapterable_type}_account_assignments").create( + chapterable.chapterable_account_assignments.create( profile: current_mentor, account: current_mentor.account, season: Season.current.year, diff --git a/app/controllers/mentor/team_member_invites_controller.rb b/app/controllers/mentor/team_member_invites_controller.rb index 35f6334583..c8567149c9 100644 --- a/app/controllers/mentor/team_member_invites_controller.rb +++ b/app/controllers/mentor/team_member_invites_controller.rb @@ -15,8 +15,7 @@ def update student_chapterables.each do |chapterable| if chapterable.present? - chapterable_type = chapterable.is_a?(Club) ? "club" : "chapter" - chapterable.send("#{chapterable_type}_account_assignments").create( + chapterable.chapterable_account_assignments.create( profile: current_mentor, account: current_mentor.account, season: Season.current.year, diff --git a/app/technovation/join_request_approved.rb b/app/technovation/join_request_approved.rb index 18e66253d1..99ff525b5b 100644 --- a/app/technovation/join_request_approved.rb +++ b/app/technovation/join_request_approved.rb @@ -14,8 +14,7 @@ def self.call(join_request) student_chapterables.each do |chapterable| if chapterable.present? - chapterable_type = chapterable.is_a?(Club) ? "club" : "chapter" - chapterable.send("#{chapterable_type}_account_assignments").create( + chapterable.chapterable_account_assignments.create( profile: join_request.requestor, account: join_request.requestor.account, season: Season.current.year,