Skip to content

Commit adbd86a

Browse files
authored
added a few more tests and removed redundant check in admin and user controllers (#58)
1 parent d8f3415 commit adbd86a

File tree

6 files changed

+35
-24
lines changed

6 files changed

+35
-24
lines changed

app/controllers/admins_controller.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
class AdminsController < ApplicationController
22

33
skip_before_filter :authenticate, :only => ['new', 'create']
4-
before_filter :validate_admin, :except => ['new', 'create']
5-
before_filter :set_admin, :except => ['new', 'create']
6-
4+
before_filter :validate_admin, :set_admin, :except => ['new', 'create']
75

86
def new
97
@admin = Admin.new
@@ -63,12 +61,6 @@ def validate_admin
6361

6462
def set_admin
6563
@admin = Admin.find_by_id session[:user_id]
66-
if @admin.nil?
67-
session[:user_id] = nil
68-
session[:is_admin] = false
69-
return redirect_to '/'
70-
end
71-
7264
end
7365

7466
def admin_params

app/controllers/team_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ def unsubmit
2121
def edit
2222
@user_to_remove = User.find_by_id(params[:unwanted_user])
2323
@user_to_remove.leave_team
24-
@team.withdraw_submission
2524
notice = ""
2625

2726
if @user.is_a? Admin and @team.approved
2827
@team.withdraw_approval
2928
elsif @team.submitted
3029
notice = " Your team's submission has been withdrawn."
3130
end
32-
31+
32+
@team.withdraw_submission
3333
return redirect_to without_team_path if @user_to_remove == @user
3434
return redirect_to team_path(@team.id), notice: "Removed #{@user_to_remove.name} from team." + notice
3535
end

app/controllers/users_controller.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ def update
6565
private
6666
def set_user
6767
@user = User.find_by_id session[:user_id]
68-
if @user.nil?
69-
session[:user_id] = nil
70-
return redirect_to '/'
71-
end
7268
end
7369

7470
def user_params

features/redirect.feature

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ Feature: go to the correct page
88
Given the following users exist
99
| name | email | password | team_passcode | major | sid |
1010
| Jorge | legueoflegends667@hotmail.com | password1 | 0 | Football Player | 999 |
11-
| Sahai | eecs666@hotmail.com | mypassword | penguindrool | EECS | 000 |
12-
| Copy | anotheremail@yahoo.com | anotherpsw | ok | CS | 001 |
11+
| Sahai | eecs666@hotmail.com | mypassword | penguindrool | EECS | 000 |
12+
| Copy | anotheremail@yahoo.com | anotherpsw | ok | CS | 001 |
13+
And the following admins exist
14+
| name | email | password |
15+
| Bob | supreme_ruler@aol.com | ilikcats |
1316

1417
And I am on the login page
1518

@@ -83,4 +86,4 @@ Feature: go to the correct page
8386

8487
Scenario: Only an admin can access that specific admin's page
8588
When I go to the 999_admin page
86-
Then I should be on the login page
89+
Then I should be on the login page

spec/controllers/admins_controller_spec.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,20 @@
99

1010
#admins_controller = class_double("AdminsController")
1111
#admins_controller.team_list_email #BREAKS
12-
13-
12+
end
13+
14+
describe "session has information for an admin that does not exist" do
15+
it "should not show the page for a deleted account" do
16+
Admin.create!({:name => "admin", :email => "[email protected]", :password => "123"})
17+
session[:user_id] = 1
18+
session[:is_admin] = true
19+
get :show, {:id => 1}
20+
response.should render_template(:show)
21+
22+
Admin.find_by_id(1).destroy!
23+
get :show, {:id => 1}
24+
response.should redirect_to(login_path)
25+
end
1426
end
1527

1628

spec/controllers/users_controller_spec.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
require 'spec_helper'
22

33
RSpec.describe UsersController, type: :controller do
4-
5-
describe "a successful new login" do
6-
7-
4+
5+
describe "session has information for a user that does not exist" do
6+
it "should not show the page for a deleted account" do
7+
User.create!({ :name => "John", :major => "English", :sid => "111", :email => "[email protected]", :password => "132619"})
8+
session[:user_id] = 1
9+
post :start_team
10+
response.should redirect_to(team_path(1))
11+
12+
User.find_by_id(1).destroy!
13+
post :start_team
14+
response.should redirect_to(login_path)
15+
end
816
end
917

1018

0 commit comments

Comments
 (0)