Created
October 10, 2017 18:14
-
-
Save staycreativedesign/f33e6e28d7336ddb8b5f8eba70aeb94e 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
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:12:in `block (2 levels) in <top (required)>' | |
# -e:1:in `<main>' | |
Finished in 0.23526 seconds (files took 4 minutes 5.4 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
class Team < ActiveRecord::Base | |
has_many :users | |
has_many :business_industries, through: :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', inverse_of: :sponsored_teams | |
validates_associated :sponsor | |
end | |
# == Schema Information | |
# | |
# Table name: teams | |
# | |
# id :integer not null, primary key | |
# name :string | |
# created_at :datetime not null | |
# updated_at :datetime not null | |
# coach_id :integer | |
# leader_id :integer | |
# captain_id :integer | |
# social_director_id :integer | |
# trainer_id :integer | |
# sponsor_id :integer | |
# |
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 | |
before(:each) do | |
@admin = create(:user, role: Role::ADMIN) | |
create_list(:team, 4, sponsor: @admin) | |
end | |
it "doesn't allow for more than 4 teams for a sponsor" do | |
@admin.sponsored_teams << build(:team) | |
@admin.save! | |
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", inverse_of: :sponsor | |
validates_length_of :sponsored_teams, maximum: 4 | |
end | |
# == Schema Information | |
# | |
# Table name: users | |
# | |
# id :integer not null, primary key | |
# email :string | |
# password_digest :string | |
# role :string default("visitor") | |
# team_id :integer | |
# business_industry_id :integer | |
# job_id :integer | |
# first_name :string | |
# last_name :string | |
# phone_number :string | |
# birthday :date | |
# account_id :integer | |
# subscription_id :integer | |
# referral_code :string | |
# referrer :string default("none") | |
# points :integer default(0) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment