Skip to content

Instantly share code, notes, and snippets.

@staycreativedesign
Last active October 10, 2017 01:30
Show Gist options
  • Save staycreativedesign/8c6493d99a9bc6b149f21dca0265e107 to your computer and use it in GitHub Desktop.
Save staycreativedesign/8c6493d99a9bc6b149f21dca0265e107 to your computer and use it in GitHub Desktop.
Failures:
1) Team test
Failure/Error: expect(@admin.sponsored_teams.count).to eq(4)
expected: 4
got: 6
(compared using ==)
# ./spec/models/user_spec.rb:22:in `block (2 levels) in <top (required)>'
# -e:1:in `<main>'
# == 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
#
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'
def unassigned_business_industries
list = BusinessIndustry.all - business_industries
list.sort_by! { |industry| industry.name.capitalize }
end
def assigned_business_industries
BusinessIndustry.where.not(id: business_industries.pluck(:id))
end
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)
class User < ActiveRecord::Base
has_many :sponsored_teams, class_name: 'Team', foreign_key: "sponsor_id"
validates_length_of :sponsored_teams, maximum: 4
end
require 'rails_helper'
RSpec.describe User, :type => :model do
before(:each) do
@admin = create(:user, role: Role::ADMIN)
coach = create(:user)
coach_1 = create(:user)
coach_2 = create(:user)
coach_3 = create(:user)
@coach_4 = create(:user)
@coach_5 = create(:user)
team_a = create(:team, sponsor: @admin, coach: coach)
team_b = create(:team, sponsor: @admin, coach: coach_1)
team_c = create(:team, sponsor: @admin, coach: coach_2)
team_d = create(:team, sponsor: @admin, coach: coach_3)
end
it "test" do
create(:team, sponsor: @admin, coach: @coach_4)
create(:team, sponsor: @admin, coach: @coach_5)
expect(@admin.sponsored_teams.count).to eq(4)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment