added session controller test
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
<div id="new">
|
<div id="new">
|
||||||
<section>
|
<section>
|
||||||
<h2>Login</h2>
|
<h2>Login</h2>
|
||||||
<% form_tag(session_path) do %>
|
<%= form_tag(session_path) do %>
|
||||||
<table width="100%">
|
<table width="100%">
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -1,8 +1,42 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class SessionsControllerTest < ActionController::TestCase
|
class SessionsControllerTest < ActionController::TestCase
|
||||||
# Replace this with your real tests.
|
context "the sessions controller" do
|
||||||
test "the truth" do
|
setup do
|
||||||
assert true
|
@user = Factory.create(:user)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "new action" do
|
||||||
|
should "render" do
|
||||||
|
get :new
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "create action" do
|
||||||
|
should "create a new session" do
|
||||||
|
post :create, {:name => @user.name, :password => "password"}
|
||||||
|
assert_redirected_to posts_path
|
||||||
|
assert_equal(@user.id, session[:user_id])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "destroy action" do
|
||||||
|
setup do
|
||||||
|
CurrentUser.user = @user
|
||||||
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
|
end
|
||||||
|
|
||||||
|
teardown do
|
||||||
|
CurrentUser.user = nil
|
||||||
|
CurrentUser.ip_addr = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
should "clear the session" do
|
||||||
|
post :destroy, {}, {:user_id => @user.id}
|
||||||
|
assert_redirected_to posts_path
|
||||||
|
assert_nil(session[:user_id])
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user