Skip to content

Commit edfddb2

Browse files
committed
WIP: Fixing tests and code for the Team functionality
1 parent eec4976 commit edfddb2

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

app/models/team.rb

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ def self.completed_at_least(section_count = 6, page=1, per_page=Team.count, sear
125125
end
126126

127127
def self.with_similar_names(name)
128-
Team.where('name ilike ?', "#{name.gsub!(/ \-\./, '.*')}%").limit(3).to_a
128+
pattern = "%#{name}%"
129+
Team.where('name ilike ?', pattern).limit(3).to_a
129130
end
130131

131132
def self.with_completed_section(section)
@@ -430,15 +431,6 @@ def sorted_members
430431
@sorted_members = members.order('score_cache DESC')
431432
end
432433

433-
def add_user(user)
434-
touch!
435-
436-
user.tap do |u|
437-
u.update_attribute(:team_document_id, id.to_s)
438-
u.save!
439-
end
440-
end
441-
442434
def add_member(user)
443435
Rails.logger.warn("Called #{self.class.name}#add_member(#{user.inspect}")
444436

@@ -449,6 +441,7 @@ def add_member(user)
449441
save!
450442
member
451443
end
444+
alias_method :add_user, :add_member
452445

453446
def remove_member(user)
454447
return nil unless member = members.select { |m| m.user_id == user.id }

app/models/teams/member.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def display_name
3333
speciality_tags
3434
state_name
3535
country
36+
referral_token
3637
).each do |user_method|
3738
delegate user_method, to: :user
3839
end

spec/models/team_spec.rb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
require 'rails_helper'
22

3-
RSpec.describe Team, type: :model, skip: true do
3+
RSpec.describe Team, type: :model do
4+
let(:team) { Fabricate(:team) }
5+
let(:invitee) { Fabricate(:user) }
6+
47
it { is_expected.to have_one :account }
58

69
it { is_expected.to have_many :locations }
@@ -20,14 +23,14 @@
2023
end
2124

2225
it 'returns teams using wildcards' do
23-
result = Team.with_similar_names('dr -.')
26+
result = Team.with_similar_names('dr%')
2427
expect(result).to include(team_1, team_2)
2528
end
2629
end
2730

2831
it 'adds the team id to the user when they are added to a team' do
2932
team.add_user(invitee)
30-
expect(invitee.reload.team).to eq(team)
33+
expect(invitee.reload.membership.team).to eq(team)
3134
end
3235

3336
it 'should indicate if team member has referral' do
@@ -55,7 +58,7 @@
5558
expect(team.slug).to eq('tilde-inc')
5659
end
5760

58-
it 'should clear the cache when a premium team is updated' do
61+
skip 'should clear the cache when a premium team is updated' do
5962
# TODO: Refactor api calls to Sidekiq job
6063
VCR.use_cassette('Opportunity') do
6164
seed_plans!
@@ -76,11 +79,7 @@
7679
end
7780

7881
it 'should be able to add team link' do
79-
team.update_attributes(
80-
featured_links: [{
81-
name: 'Google',
82-
url: 'http://www.google.com'
83-
}])
82+
team.links.create(name: 'Google', url: 'http://www.google.com')
8483
expect(team.featured_links.size).to eq(1)
8584
end
8685

0 commit comments

Comments
 (0)