Created
September 11, 2017 21:18
-
-
Save staycreativedesign/860ee3d2ac1fb94bf660eba8bdbaa14c 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
6) UsersController#create sends a notification email to coach of team selected | |
Failure/Error: @team = create(:team, coach: @ref) | |
ActiveModel::MissingAttributeError: | |
can't write unknown attribute `coach_id` | |
# ./spec/controllers/users_controller_spec.rb:6:in `block (2 levels) in <top (required)>' | |
# -e:1:in `<main>' | |
6) UsersController#create sends a notification email to coach of team selected | |
Failure/Error: @team = create(:team, coach_id: @ref) | |
NoMethodError: | |
undefined method `coach_id=' for #<Team:0x007f812c5f4768> | |
Did you mean? coach= | |
6) UsersController#create sends a notification email to coach of team selected | |
Failure/Error: @team = create(:team, coach: @ref.id) | |
ActiveRecord::AssociationTypeMismatch: | |
User(#70096381692760) expected, got Integer(#70096370672360) |
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
# == 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 | |
# team_leader_id :integer | |
# | |
class Team < ActiveRecord::Base | |
has_many :users | |
has_many :business_industries, through: :users | |
belongs_to :coach, class_name: 'User' | |
belongs_to :team_leader, 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: teams | |
# | |
# id :integer not null, primary key | |
# name :string | |
# created_at :datetime not null | |
# updated_at :datetime not null | |
# coach_id :integer | |
# team_leader_id :integer | |
# | |
FactoryGirl.define do | |
factory :team do | |
name { Faker::Address.unique.street_name } | |
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
# == 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 | |
before_create :set_referral_code | |
belongs_to :team | |
belongs_to :business_industry | |
belongs_to :job | |
belongs_to :account | |
belongs_to :subscription | |
has_one :business_category, through: :business_industry | |
accepts_nested_attributes_for :job | |
has_many :member_questionnaires | |
has_many :questionnaires, through: :member_questionnaires | |
validates_presence_of :first_name | |
validates_presence_of :last_name | |
validates_presence_of :email | |
validates_presence_of :role | |
validates_presence_of :referrer | |
has_secure_password |
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
RSpec.describe UsersController do | |
before(:all) do | |
@ref = create(:user, role: 'admin') | |
@team = create(:team, coach: @ref) | |
end | |
describe '#create' do | |
it 'sets a referral code' do | |
post :create, params: new_user_params | |
expect(User.first.referral_code).to be_present | |
end | |
it 'sets referrer code' do | |
post :create, params: new_user_params | |
expect(User.last.referrer).to eq(@ref.referral_code) | |
end | |
it 'adds a point to the referrer' do | |
post :create, params: new_user_params | |
@ref.reload | |
expect(@ref.points).to eq 1 | |
end | |
it 'sends a notification email' do | |
binding.pry | |
expect { post :create, new_user_params }.to change { ActionMailer::Base.deliveries.count }.by(1) | |
end | |
skip 'sends a notification email to admin' do | |
expect { post :create, new_user_params }.to change { ActionMailer::Base.deliveries.count }.by(1) | |
end | |
skip 'sends a notification email to coach of team selected' do | |
expect { post :create, new_user_params }.to change { ActionMailer::Base.deliveries.count }.by(1) | |
end | |
end | |
def new_user_params | |
{ user: FactoryGirl.attributes_for(:user, referrer: @ref.referral_code) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment