Skip to content

Bounty #455 - Fix User#on_team? #261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,14 @@ def brief
end
end

def team
if team_id
Team.find(team_id)
else
membership.try(:team)
end
end

def team_ids
[team_id]
end
Expand All @@ -248,7 +256,7 @@ def teams_being_followed
end

def on_team?
not team_document_id.nil?
team_id.present? || membership.present?
end

def team_member_of?(user)
Expand Down
33 changes: 33 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,23 @@ class AlsoNotaBadge < BadgeBase
end
end

describe '#team' do
let(:team) { Fabricate(:team) }
let(:user) { Fabricate(:user) }
it 'returns membership team if user has membership' do
team.add_member(user)
expect(user.team).to eq(team)
end
it 'returns team if team_id is set' do
user.team_id = team.id
user.save
expect(user.team).to eq(team)
end
it 'returns nil if no team_id or membership' do
expect(user.team).to eq(nil)
end
end

it 'should indicate when user is on a premium team' do
team = Fabricate(:team, premium: true)
member = team.add_member(user = Fabricate(:user))
Expand All @@ -234,6 +251,22 @@ class AlsoNotaBadge < BadgeBase
expect(user.team).to be_nil
end

describe '#on_team?' do
let(:team) { Fabricate(:team) }
let(:user) { Fabricate(:user) }
it 'is true if user has a membership' do
expect(user.on_team?).to eq(false)
team.add_member(user)
expect(user.reload.on_team?).to eq(true)
end
it 'is true if user is on a team' do
expect(user.on_team?).to eq(false)
user.team = team
user.save
expect(user.reload.on_team?).to eq(true)
end
end

it 'can follow another user' do
user = Fabricate(:user)
other_user = Fabricate(:user)
Expand Down