Skip to content

Commit

Permalink
auto login with tests on setup but still allow logout for testing sec…
Browse files Browse the repository at this point in the history
…urity.
  • Loading branch information
djones committed Feb 26, 2010
1 parent 9a47675 commit 490c0f0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
8 changes: 4 additions & 4 deletions test/functional/dashboard_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ def setup
@controller = Admin::DashboardController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new

login_as(:quentin)
end

def test_should_get_index
login_as(:quentin)

get :index
assert_response :success

Expand All @@ -24,8 +24,6 @@ def test_should_get_index
end

def test_recent_activity_should_report_activity
login_as(:quentin)

sleep 1
pages(:home_page).update_attribute(:updated_at, Time.now)

Expand All @@ -36,6 +34,8 @@ def test_recent_activity_should_report_activity
end

def test_should_require_login_and_redirect
logout

get :index
assert_response :redirect
assert_nil assigns(:recent_activity)
Expand Down
44 changes: 38 additions & 6 deletions test/functional/images_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,58 @@ def setup
@controller = Admin::ImagesController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new

login_as(:quentin)
end

def test_should_get_index
login_as(:quentin)

get :index
assert_response :success
assert_not_nil assigns(:images)
assert assigns(:images).size, Image.count
end

def test_new_image_form
get :new
assert_not_nil assigns(:image)
assert_not_nil assigns(:url_override)
end

def test_search
get :index, :search => "Car"

assert 1, assigns(:images).size
assert images(:the_world), assigns(:images).first
assert_not_nil assigns(:images)
end

def test_should_require_login_and_redirect

logout

get :index
assert_response :redirect
assert_nil assigns(:images)
end

# we need to somehow make it so that recent activity comes
# into tests so we can check the order.
# not sure why the recent activity assign has no activity
def test_edit
get :edit, :id => images(:the_world).id

assert_response :success

assert_not_nil assigns(:image)
assert_equal images(:the_world), assigns(:image)
end

def test_insert

end

def test_create

end

def test_destroy

end

end
4 changes: 4 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,9 @@ class ActiveSupport::TestCase
def login_as(user)
@request.session[:user_id] = user ? users(user).id : nil
end

def logout
@request.session[:user_id] = nil
end

end

0 comments on commit 490c0f0

Please sign in to comment.