Skip to content

Commit 9827ae4

Browse files
committed
Fix team invitation 500, team members partial, controller + request specs.
1 parent 8da856e commit 9827ae4

File tree

4 files changed

+122
-28
lines changed

4 files changed

+122
-28
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
- # Local params
2+
- # @param [ Team ] - team
3+
4+
%ul#teams
5+
%li.team{id: dom_id(team)}
6+
.team-inside.cf
7+
%h3= team.name
8+
.members
9+
- team.top_three_team_members.each do |member|
10+
=link_to(image_tag(member.avatar.url, class: 'avatar', alt: member.username), profile_path(member.username))
11+
-if team.size > 3
12+
.size
13+
="+ #{team.size - 3}"
14+
-if current_user.belongs_to_team?(team)
15+
=link_to('Stay with this team', team_path(current_user.team, flash: "Great, you're still on team #{current_user.team.name}"), class: 'button stay')
16+
-else
17+
=link_to('Join this team', accept_team_path(team, r: params[:r]), class: 'join')

app/views/invitations/show.html.haml

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,10 @@
1212
%li=link_to('Sign Up', root_path, :class => 'join')
1313
%li=link_to('Sign In', signin_path, :id => 'signin', :class => 'join')
1414
-else
15-
-if current_user.team
15+
-if users_team = current_user.team
1616
#currentteam
17-
%h2==You are currently on team #{current_user.team.name}
18-
%ul#teams
19-
%li.team{:id => dom_id(current_user.team)}
20-
.team-inside.cf
21-
%h3=current_user.team.name
22-
.members
23-
-current_user.team.top_three_team_members.each do |member|
24-
=link_to(image_tag(member.avatar.url, :class => 'avatar', :alt => member.username), profile_path(member.username))
25-
-if current_user.team.size > 3
26-
.size="+ #{current_user.team.size - 3}"
27-
=link_to('Stay with this team', team_path(current_user.team, :flash => "Great, you're still on team #{current_user.team.name}"), :class => 'button stay')
28-
17+
%h2==You are currently on team #{users_team.name}
18+
= render partial: "invitations/team_members", locals: {team: users_team }
2919
.clear
3020
%h2 Team invitations
31-
%ul#teams
32-
%li.team{:id => dom_id(@team)}
33-
.team-inside.cf
34-
%h3=@team.name
35-
.members
36-
-@team.top_three_team_members.each do |member|
37-
=link_to(image_tag(member.thumbnail_url, :class => 'avatar', :alt => member.username), profile_path(member.username))
38-
-if @team.size > 3
39-
.size
40-
="+ #{@team.size - 3}"
41-
-if current_user.belongs_to_team?(@team)
42-
=link_to('Stay with this team', accept_team_path(@team, :r => params[:r]), :class => 'button stay')
43-
-else
44-
=link_to('Join this team', accept_team_path(@team, :r => params[:r]), :class => 'join')
21+
= render partial: "invitations/team_members", locals: {team: @team }

spec/controllers/invitations_controller_spec.rb

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,55 @@
99
expect(session[:referred_by]).to eq('asdfasdf')
1010
end
1111

12-
end
12+
describe "GET invitations#show" do
13+
14+
let(:current_user) { Fabricate(:user) }
15+
let(:team) { Fabricate(:team) }
16+
17+
describe "logged in" do
18+
before { controller.send :sign_in, current_user }
19+
20+
it "should render invitation page successfully with valid referral" do
21+
allow(Team).to receive(:find).with(team.id).and_return(team)
22+
allow(team).to receive(:has_user_with_referral_token?).and_return(true)
23+
24+
get :show, id: team.id
25+
expect(assigns(:team)).to eq(team)
26+
expect(response).to render_template("invitations/show")
27+
end
28+
29+
it "should redirect to root_url with invalid referral" do
30+
allow(Team).to receive(:find).with(team.id).and_return(team)
31+
allow(team).to receive(:has_user_with_referral_token?).and_return(false)
32+
33+
get :show, id: team.id
34+
expect(response).to redirect_to(root_url)
35+
end
36+
37+
38+
end
39+
40+
describe "logged out" do
41+
it "should render invitation page successfully with valid referral" do
42+
allow(Team).to receive(:find).with(team.id).and_return(team)
43+
allow(team).to receive(:has_user_with_referral_token?).and_return(true)
44+
45+
get :show, id: team.id
46+
expect(assigns(:team)).to eq(team)
47+
expect(response).to render_template("invitations/show")
48+
end
49+
50+
it "should redirect to root_url with invalid referral" do
51+
allow(Team).to receive(:find).with(team.id).and_return(team)
52+
allow(team).to receive(:has_user_with_referral_token?).and_return(false)
53+
54+
get :show, id: team.id
55+
expect(response).to redirect_to(root_url)
56+
end
57+
end
58+
59+
end
60+
61+
62+
63+
end

spec/requests/invitations_spec.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
require 'spec_helper'
2+
3+
RSpec.describe "Viewing an invitation", :type => :request do
4+
5+
before :each do
6+
@user = Fabricate(:user)
7+
@team = Fabricate(:team)
8+
end
9+
10+
describe 'when logged in' do
11+
12+
def sign_in
13+
allow(User).to receive(:find_with_oauth).and_return(@user)
14+
post "/sessions"
15+
end
16+
17+
it "should render invitation page for logged in user" do
18+
sign_in
19+
20+
# Stub out what we need from our controller
21+
allow(Team).to receive(:find).with(@team.id).and_return(@team)
22+
allow(@team).to receive(:has_user_with_referral_token?).and_return(true)
23+
allow(@team).to receive(:top_three_team_members).and_return([@user])
24+
25+
get invitation_url(id: @team.id,r: @user.referral_token)
26+
27+
expect(response.body).to include("Join this team")
28+
expect(response).to render_template("invitations/show")
29+
expect(response.code).to eq("200")
30+
end
31+
32+
end
33+
34+
describe "when logged out" do
35+
it "should show invitation page asking user to sign in" do
36+
# Stub out what we need from our controller
37+
allow(Team).to receive(:find).with(@team.id).and_return(@team)
38+
allow(@team).to receive(:has_user_with_referral_token?).and_return(true)
39+
40+
get invitation_url(id: @team.id,r: @user.referral_token)
41+
42+
expect(response.body).to include("you need to create a coderwall account")
43+
expect(response).to render_template("invitations/show")
44+
expect(response.code).to eq("200")
45+
end
46+
47+
end
48+
49+
end

0 commit comments

Comments
 (0)