Last active
October 10, 2017 20:48
-
-
Save staycreativedesign/0e2fad6e4f0413be517423f20d8f809b 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
with @admin.save | |
Team | |
doesn't allow for more than 4 teams for a sponsor (FAILED - 1) | |
Failures: | |
1) Team doesn't allow for more than 4 teams for a sponsor | |
Failure/Error: expect(@admin.sponsored_teams.count).to eq(4) | |
expected: 4 | |
got: 5 | |
(compared using ==) | |
# ./spec/models/team_spec.rb:13:in `block (2 levels) in <top (required)>' | |
# -e:1:in `<main>' | |
with @admin.save! | |
Failures: | |
1) Team doesn't allow for more than 4 teams for a sponsor | |
Failure/Error: @admin.save! | |
ActiveRecord::RecordInvalid: | |
Validation failed: Sponsored teams is too long (maximum is 4 characters) | |
# ./spec/models/team_spec.rb:12:in `block (2 levels) in <top (required)>' | |
# -e:1:in `<main>' | |
Finished in 0.23367 seconds (files took 142 minutes 25 seconds to load) | |
1 example, 1 failure |
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] pry(#<RSpec::ExampleGroups::Team>)> Team.all | |
=> [#<Team:0x007f8a150ec760 | |
id: 1, | |
updated_at: Tue, 10 Oct 2017 20:30:06 UTC +00:00, | |
coach_id: 2, | |
leader_id: nil, | |
captain_id: nil, | |
social_director_id: nil, | |
trainer_id: nil, | |
sponsor_id: 1>, | |
#<Team:0x007f8a150ec5f8 | |
id: 2, | |
name: "Rice Fords", | |
created_at: Tue, 10 Oct 2017 20:30:06 UTC +00:00, | |
updated_at: Tue, 10 Oct 2017 20:30:06 UTC +00:00, | |
coach_id: 3, | |
leader_id: nil, | |
captain_id: nil, | |
social_director_id: nil, | |
trainer_id: nil, | |
sponsor_id: 1>, | |
#<Team:0x007f8a150ec3c8 | |
id: 3, | |
name: "Reynold Parkway", | |
created_at: Tue, 10 Oct 2017 20:30:06 UTC +00:00, | |
updated_at: Tue, 10 Oct 2017 20:30:06 UTC +00:00, | |
coach_id: 4, | |
leader_id: nil, | |
captain_id: nil, | |
social_director_id: nil, | |
trainer_id: nil, | |
sponsor_id: 1>, | |
#<Team:0x007f8a150ec260 | |
id: 4, | |
name: "Mortimer Brook", | |
created_at: Tue, 10 Oct 2017 20:30:06 UTC +00:00, | |
updated_at: Tue, 10 Oct 2017 20:30:06 UTC +00:00, | |
coach_id: 5, | |
leader_id: nil, | |
captain_id: nil, | |
social_director_id: nil, | |
trainer_id: nil, | |
sponsor_id: 1>, | |
#<Team:0x007f8a150ec120 | |
id: 5, | |
name: "Murphy Manor", | |
created_at: Tue, 10 Oct 2017 20:30:06 UTC +00:00, | |
updated_at: Tue, 10 Oct 2017 20:30:06 UTC +00:00, | |
coach_id: 6, | |
leader_id: nil, | |
captain_id: nil, | |
social_director_id: nil, | |
trainer_id: nil, | |
sponsor_id: 1>] |
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
class Team < ActiveRecord::Base | |
has_many :users | |
belongs_to :coach, class_name: 'User' | |
belongs_to :leader, class_name: 'User' | |
belongs_to :captain, class_name: 'User' | |
belongs_to :social_director, class_name: 'User' | |
belongs_to :trainer, class_name: 'User' | |
belongs_to :sponsor, class_name: 'User' | |
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
require 'rails_helper' | |
RSpec.describe Team, :type => :model do | |
let(:admin) { create(:user, role: Role::ADMIN) } | |
before(:each) do | |
create_list(:team, 4, sponsor: admin) | |
end | |
it "doesn't allow for more than 4 teams for a sponsor" do | |
admin.reload | |
admin.sponsored_teams << build(:team) | |
admin.save | |
expect(admin.save).to be(false) | |
expect(admin.valid?).to be(false) | |
expect(admin.sponsored_teams.count).to eq(4) | |
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
class User < ActiveRecord::Base | |
has_many :sponsored_teams, class_name: 'Team', foreign_key: "sponsor_id" | |
validates_length_of :sponsored_teams, maximum: 4 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment