Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
48 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html | ||
|
||
one: | ||
name: MyString | ||
name: Tester One | ||
description: MyText | ||
|
||
two: | ||
name: MyString | ||
name: Tester Two | ||
description: MyText |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,27 @@ | ||
require 'test_helper' | ||
|
||
class SessionsControllerTest < ActionController::TestCase | ||
setup do | ||
@user = User.create(:name => "Super Tester", :password => "12345", :password_confirmation => "12345") | ||
end | ||
|
||
test "should get new" do | ||
get :new | ||
assert_response :success | ||
end | ||
|
||
test "should log in a user" do | ||
post :create, :name => "Super Tester", :password => "12345" | ||
assert_equal(session[:user_id], @user.id) | ||
assert_equal(flash[:notice], "Logged in!") | ||
assert_redirected_to root_url | ||
end | ||
|
||
test "should log out a user" do | ||
post :create, :name => "Super Tester", :password => "12345" | ||
delete :destroy | ||
assert_nil(session[:user_id]) | ||
assert_equal(flash[:notice], "Logged out!") | ||
assert_redirected_to root_url | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,32 @@ | ||
require 'test_helper' | ||
require 'bcrypt' | ||
|
||
class UserTest < ActiveSupport::TestCase | ||
# Replace this with your real tests. | ||
test "the truth" do | ||
assert true | ||
test "a password is encrypted" do | ||
user = User.new(:password => "12345") | ||
|
||
user.encrypt_password | ||
|
||
assert_not_nil(user.password_salt) | ||
assert_not_nil(user.password_hash) | ||
assert_equal(user.password_hash, BCrypt::Engine.hash_secret(user.password, user.password_salt)) | ||
end | ||
|
||
test "a user can authenticate" do | ||
user = User.create(:name => "Test guy", :password => "54321", :password_confirmation => "54321") | ||
|
||
assert_not_nil(user) | ||
assert_equal(User.authenticate("Test guy", "54321"), user) | ||
end | ||
|
||
test "a non-existance user cannot authenticate" do | ||
assert_nil(User.authenticate("Bobo deosn't exist", "12345")) | ||
end | ||
|
||
test "a user cannot authenticate with a bad password" do | ||
user = User.create(:name => "Test guy 2", :password => "54321", :password_confirmation => "54321") | ||
|
||
assert_not_nil(user) | ||
assert_nil(User.authenticate("Test guy 2", "bad password")) | ||
end | ||
end |