Last active
October 24, 2017 20:16
-
-
Save staycreativedesign/9c9a13eda6b08c9b3a09dd80f21d11c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.describe Team, :type => :model do | |
let(:admin) { create(:user, role: Role::ADMIN, first_name: 'Administrator') } | |
let(:man) { create(:user, role: Role::COACH, first_name: 'Coach') } | |
it "doesn't allow for more than 4 teams for a sponsor" do | |
create_list(:team, 4, sponsor: admin) | |
admin.reload | |
admin.sponsored_teams.build(sponsor: admin) | |
admin.save | |
expect(admin.sponsored_teams.count).to eq(4) | |
end | |
it "if more than 4 team sponsored new team goes to first downline" do | |
create(:team, sponsor: admin, coach: man) | |
3.times do | |
create(:team, sponsor: admin) | |
end | |
admin.sponsored_teams.build(sponsor: admin) | |
admin.save | |
expect(man.sponsored_teams.count).to eq(1) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def foo(team) | |
# check current sponsor sponsored teams | |
# if equal or greather than 4 | |
# find the first coach of a sponsored team by current sponsor and add the | |
# team as a sponsored team of coach | |
# else | |
# : | |
if team.sponsor.sponsored_teams.count >= 4 | |
u = User.find(team.sponsor.id) | |
foo = User.find(u.sponsored_teams.first.coach.id) | |
team = foo.sponsored_teams << team | |
return team | |
else | |
end | |
end |
nilbus
commented
Oct 24, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment