Last active
October 25, 2017 19:12
-
-
Save staycreativedesign/beed5082be972756c9e7f50fc57ce555 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
1) Team adds team to downline coach which doesnt have 4 sponsord teams | |
Failure/Error: expect(@coach.sponsored_teams.count).to eq(1) | |
expected: 1 | |
got: 0 | |
(compared using ==) | |
# ./spec/models/team_spec.rb:40:in `block (2 levels) in <top (required)>' | |
# -e:1:in `<main>' | |
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
PASSING | |
it "if more than 4 team sponsored new team goes to first downline coach" do | |
create(:team, sponsor: @admin, coach: @man) | |
create_list(:team, 3, sponsor: @admin) | |
@admin.reload | |
@admin.sponsored_teams.build(sponsor: @admin, coach: @coach) | |
expect(@man.sponsored_teams.count).to eq(1) | |
end | |
FAILING | |
it "adds team to downline coach which doesnt have 4 sponsord teams" do | |
create(:team, sponsor: @admin, coach: @man) | |
create(:team, sponsor: @man, coach: @coach) | |
create_list(:team, 4, sponsor: @admin) | |
create_list(:team, 4, sponsor: @man) | |
@admin.reload | |
@man.reload | |
@coach.reload | |
@admin.sponsored_teams.build(sponsor: @admin, coach: @foo) | |
expect(@coach.sponsored_teams.count).to eq(1) | |
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 check_to_if_sponsor_count(new_team) | |
if new_team.sponsor.sponsored_teams.count >= 4 | |
add_team_to_new_sponsor(new_team) | |
end | |
end | |
def add_team_to_new_sponsor(new_team) | |
u = new_team.sponsor | |
new_sponsor = u.sponsored_teams.first.coach | |
new_team.sponsor = new_sponsor | |
new_team.save | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment