Skip to content

Commit 6c798a3

Browse files
committed
Tests sessions controller
1 parent 7197048 commit 6c798a3

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

test/fixtures/spina/users.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bram:
2+
name: Bram
3+
email: bram@denkgroot.com
4+
password_digest: <%= BCrypt::Password.create("password", cost: 4) %>
5+
admin: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require 'test_helper'
2+
3+
module Spina
4+
module Admin
5+
class SessionsControllerTest < ActionController::TestCase
6+
setup do
7+
@routes = ::Spina::Engine.routes
8+
end
9+
10+
test "login renders the correct layout" do
11+
get :new
12+
assert_template layout: 'spina/login'
13+
end
14+
15+
test "should be able to login" do
16+
post :create, email: "bram@denkgroot.com", password: "password"
17+
assert_not_nil session[:user_id]
18+
end
19+
20+
test "should be able to logout" do
21+
get :destroy
22+
assert_nil session[:user_id]
23+
end
24+
25+
test "should alert the user when wrong password" do
26+
post :create, email: "bram@denkgroot.com", password: "wrongpassword"
27+
assert_nil session[:user_id]
28+
assert_not_empty flash[:alert]
29+
end
30+
end
31+
end
32+
end

test/functional/spina/pages_controller_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class PagesControllerTest < ActionController::TestCase
66
@routes = Engine.routes
77
end
88

9-
def test_homepage
9+
test "visit homepage" do
1010
get :homepage
1111
assert_response :success
1212
end

test/test_helper.rb

+4
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@
99

1010
# Load fixtures from the engine
1111
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
12+
13+
class ActiveSupport::TestCase
14+
fixtures :all
15+
end

0 commit comments

Comments
 (0)