* Change from #after_save to #after_create * Update .babelrc * Update cloud_name for test * Update SlackBot's RssReader channel * Update helpful-hints.md * Create .gitdocs.json * Remove serve-docs script * Update docs/helpful-hints.md * Update approval * Revert "Change from #after_save to #after_create" This reverts commit 548ee0d2c0d56a1aa67316468f4106ac9f437662. * Create delayed_job.rb * Bump ancestry gem to 3.0.3 * Fix broken spec * Remove manual Delayed::Job config in test * Update spec_helper.rb * Fix broken specs * Mute SlackBot in test * Remove weekly-dgiest.yml * Create PodcastEpisodeDecorator
52 lines
1.9 KiB
Ruby
52 lines
1.9 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe MentorRelationship, type: :model do
|
|
let(:mentor) { create(:user) }
|
|
let(:mentee) { create(:user) }
|
|
let(:relationship) { MentorRelationship.new(mentor_id: mentor.id, mentee_id: mentee.id) }
|
|
|
|
describe "validations" do
|
|
subject { MentorRelationship.new(mentor: mentor, mentee: mentee) }
|
|
|
|
it { is_expected.to belong_to(:mentor) }
|
|
it { is_expected.to belong_to(:mentee) }
|
|
it { is_expected.to validate_uniqueness_of(:mentor_id).scoped_to(:mentee_id) }
|
|
end
|
|
|
|
it "is active" do
|
|
expect(relationship.active).to eq(true)
|
|
end
|
|
|
|
it "is not the same user" do
|
|
expect(MentorRelationship.new(mentor_id: mentor.id, mentee_id: mentor.id)).to be_invalid
|
|
end
|
|
|
|
it "makes the users follow one another" do
|
|
relationship.save!
|
|
expect(mentor.reload.following?(mentee)).to eq(true)
|
|
expect(mentee.reload.following?(mentor)).to eq(true)
|
|
end
|
|
|
|
it "sends an email to both users" do
|
|
relationship.save!
|
|
["mentor_email", "mentee_email"].each do |campaign|
|
|
expect(EmailMessage.where(utm_campaign: campaign).count).to eq(1)
|
|
end
|
|
end
|
|
|
|
it "finds unmatched mentors" do
|
|
expect(MentorRelationship.unmatched_mentors.size).to eq(0)
|
|
new_mentor = create(:user, mentor_form_updated_at: Time.current, offering_mentorship: true)
|
|
expect(MentorRelationship.unmatched_mentors.size).to eq(1)
|
|
MentorRelationship.create(mentor_id: new_mentor.id, mentee_id: mentee.id)
|
|
expect(MentorRelationship.unmatched_mentors.size).to eq(0)
|
|
end
|
|
|
|
it "finds unmatched mentees" do
|
|
expect(MentorRelationship.unmatched_mentees.size).to eq(0)
|
|
new_mentee = create(:user, mentee_form_updated_at: Time.current, seeking_mentorship: true)
|
|
expect(MentorRelationship.unmatched_mentees.size).to eq(1)
|
|
MentorRelationship.create(mentor_id: mentor.id, mentee_id: new_mentee.id)
|
|
expect(MentorRelationship.unmatched_mentors.size).to eq(0)
|
|
end
|
|
end
|