Created
October 11, 2017 19:39
-
-
Save staycreativedesign/3c63688a68a846162f9c534dc82661a6 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
class Team < ApplicationRecord | |
has_many :users | |
has_many :business_industries, through: :users | |
belongs_to :coach, class_name: 'User' | |
belongs_to :leader, class_name: 'User', optional: true | |
belongs_to :captain, class_name: 'User', optional: true | |
belongs_to :social_director, class_name: 'User', optional: true | |
belongs_to :trainer, class_name: 'User', optional: true | |
belongs_to :sponsor, class_name: 'User', optional: true | |
validates_associated :sponsor | |
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 | |
binding.pry | |
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 < ApplicationRecord | |
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