Skip to content

Commit 2ae3e6f

Browse files
committed
Merge pull request #261 from jakegavin/welcome-email-bug
Bounty #455 - Fix User#on_team?
2 parents 894861d + 7f3f2a9 commit 2ae3e6f

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

app/models/user.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,14 @@ def brief
225225
end
226226
end
227227

228+
def team
229+
if team_id
230+
Team.find(team_id)
231+
else
232+
membership.try(:team)
233+
end
234+
end
235+
228236
def team_ids
229237
[team_id]
230238
end
@@ -248,7 +256,7 @@ def teams_being_followed
248256
end
249257

250258
def on_team?
251-
not team_document_id.nil?
259+
team_id.present? || membership.present?
252260
end
253261

254262
def team_member_of?(user)

spec/models/user_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,23 @@ class AlsoNotaBadge < BadgeBase
214214
end
215215
end
216216

217+
describe '#team' do
218+
let(:team) { Fabricate(:team) }
219+
let(:user) { Fabricate(:user) }
220+
it 'returns membership team if user has membership' do
221+
team.add_member(user)
222+
expect(user.team).to eq(team)
223+
end
224+
it 'returns team if team_id is set' do
225+
user.team_id = team.id
226+
user.save
227+
expect(user.team).to eq(team)
228+
end
229+
it 'returns nil if no team_id or membership' do
230+
expect(user.team).to eq(nil)
231+
end
232+
end
233+
217234
it 'should indicate when user is on a premium team' do
218235
team = Fabricate(:team, premium: true)
219236
member = team.add_member(user = Fabricate(:user))
@@ -234,6 +251,22 @@ class AlsoNotaBadge < BadgeBase
234251
expect(user.team).to be_nil
235252
end
236253

254+
describe '#on_team?' do
255+
let(:team) { Fabricate(:team) }
256+
let(:user) { Fabricate(:user) }
257+
it 'is true if user has a membership' do
258+
expect(user.on_team?).to eq(false)
259+
team.add_member(user)
260+
expect(user.reload.on_team?).to eq(true)
261+
end
262+
it 'is true if user is on a team' do
263+
expect(user.on_team?).to eq(false)
264+
user.team = team
265+
user.save
266+
expect(user.reload.on_team?).to eq(true)
267+
end
268+
end
269+
237270
it 'can follow another user' do
238271
user = Fabricate(:user)
239272
other_user = Fabricate(:user)

0 commit comments

Comments
 (0)