docbrown/spec/models/mentor_relationship_spec.rb
Keshav Biswa 8d57d45ecc Rubocop Style cops enabled (#2056)
* Rubocop enabled style/alias

* Enabled Style/ArrayJoin Cop

* Enabled Style/Attr

* Enabled Case Equality

* Enabled CharacterLiteral

*  Enabled ColonMethodCall Cop

* Enabled CommentAnnotation cop

* Enabled PreferredHashMethods Cop

*  Enabled DoubleNegation Cop

* Enabled EachWithObject Cop

* Enabled EmptyLiteral Cop

* Enabled EvenOdd Cop

* Enabled IfWithSemicolon Cop

* Enabled Lambda and LambdaCall Cop

* Enabled LineEndConcatenation Cop

* Enabled ModuleFunction Cop;

* Enable NegatedIf and NegatedWhile Cop

* Enabled NilComparison Cop

* Enabled Not Cop

* Enabled NumericLiterals Cop

* Enabled OneLineConditional Cop

* Enabled PercentLiteralDelimiters Cop

* Excluded internal/users_controller from negated_if cop

* Reverted the double negation change from github_issue_tag and github_issue.rb"

* Enabled PerlBackrefs Cop

* Changed Regexp.last_match(1) to Regexp.last_match(0)

* Enabled proc cop

* Enabled RaiseArgs Cop

* Reverted Regexp.last_match(0) to Regexp.last_match(1)

* Enabled SelfAssignment Cop

* Enabled SingleLineMethods Cop

* Enabled SpecialGlobalVars Cop

* Enabled VariableInterpolation Cop

* Enabled WhenThen Cop

* Enabled WhileUntilModifier Cop

* Enabled WordArray Cop

* Enabled IfUnlessModifier Cop

* Enabled GuardClause Cop
2019-03-15 18:33:54 -04:00

54 lines
2 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!
%w[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(0)
new_mentee.update(mentee_description: "MENTEE")
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