Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added tests

  • Loading branch information...
commit 7a8f30b51fca4d8b3c2514742be29bece771aa54 1 parent 45c6197
@binarylogic binarylogic authored
View
14 README.mdown
@@ -1,14 +1,12 @@
# Authlogic Example App
-This is an example of how to use Authlogic in a rails app. Authlogic is an object based authentication solution that handles all of the non sense for you. It's as easy as ActiveRecord is with a database.
+This is an example of how to use Authlogic in a rails app. Authlogic is a clean, simple, and unobtrusive ruby authentication solution.
-This application live: [http://authlogicexample.binarylogic.com](http://authlogicexample.binarylogic.com)
-
-Basic setup tutorial: [http://www.binarylogic.com/2008/11/3/tutorial-authlogic-basic-setup](http://www.binarylogic.com/2008/11/3/tutorial-authlogic-basic-setup)
-Reset passwords tutorial: [http://www.binarylogic.com/2008/11/16/tutorial-reset-passwords-with-authlogic](http://www.binarylogic.com/2008/11/16/tutorial-reset-passwords-with-authlogic)
-Open ID tutorial: [http://www.binarylogic.com/2008/11/21/tutorial-using-openid-with-authlogic](http://www.binarylogic.com/2008/11/21/tutorial-using-openid-with-authlogic)
-
-Authlogic: [http://github.com/binarylogic/authlogic](http://github.com/binarylogic/authlogic)
+* This application live: [http://authlogicexample.binarylogic.com](http://authlogicexample.binarylogic.com)
+* Basic setup tutorial: [http://www.binarylogic.com/2008/11/3/tutorial-authlogic-basic-setup](http://www.binarylogic.com/2008/11/3/tutorial-authlogic-basic-setup)
+* Reset passwords tutorial: [http://www.binarylogic.com/2008/11/16/tutorial-reset-passwords-with-authlogic](http://www.binarylogic.com/2008/11/16/tutorial-reset-passwords-with-authlogic)
+* Open ID tutorial: [http://www.binarylogic.com/2008/11/21/tutorial-using-openid-with-authlogic](http://www.binarylogic.com/2008/11/21/tutorial-using-openid-with-authlogic)
+* Authlogic: [http://github.com/binarylogic/authlogic](http://github.com/binarylogic/authlogic)
Copyright (c) 2008 [Ben Johnson](http://github.com/binarylogic) of [Binary Logic](http://www.binarylogic.com), released under the MIT license
View
1  app/models/user.rb
@@ -5,6 +5,7 @@ class User < ActiveRecord::Base
validate :normalize_openid_identifier
validates_uniqueness_of :openid_identifier, :allow_blank => true
+ validates_length_of :email, :minimum => 500, :unless => "true"
# For acts_as_authentic configuration
def openid_identifier_blank?
View
4 db/migrate/20081103171327_create_users.rb
@@ -5,7 +5,7 @@ def self.up
t.string :login, :null => false
t.string :crypted_password, :null => false
t.string :password_salt, :null => false
- t.string :remember_token, :null => false
+ t.string :persistence_token, :null => false
t.integer :login_count, :default => 0, :null => false
t.datetime :last_request_at
t.datetime :last_login_at
@@ -15,7 +15,7 @@ def self.up
end
add_index :users, :login
- add_index :users, :remember_token
+ add_index :users, :persistence_token
add_index :users, :last_request_at
end
View
31 test/fixtures/users.yml
@@ -1,25 +1,6 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-
-one:
- login: MyString
- crypted_password: MyString
- password_salt: MyString
- remember_token: MyString
- login_count: 1
- last_request_at: 2008-11-03 12:13:27
- last_login_at: 2008-11-03 12:13:27
- current_login_at: 2008-11-03 12:13:27
- last_login_ip: MyString
- current_login_ip: MyString
-
-two:
- login: MyString
- crypted_password: MyString
- password_salt: MyString
- remember_token: MyString
- login_count: 1
- last_request_at: 2008-11-03 12:13:27
- last_login_at: 2008-11-03 12:13:27
- current_login_at: 2008-11-03 12:13:27
- last_login_ip: MyString
- current_login_ip: MyString
+ben:
+ login: bjohnson
+ password_salt: <%= salt = User.unique_token %>
+ crypted_password: <%= Authlogic::CryptoProviders::Sha512.encrypt("benrocks" + salt) %>
+ persistence_token: 6cde0674657a8a313ce952df979de2830309aa4c11ca65805dd00bfdc65dbcc2f5e36718660a1d2e68c1a08c276d996763985d2f06fd3d076eb7bc4d97b1e317
+ email: ben@ben.com
View
19 test/functional/user_sessions_controller_test.rb
@@ -1,8 +1,21 @@
require 'test_helper'
class UserSessionsControllerTest < ActionController::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create user session" do
+ post :create, :user_session => { :login => "bjohnson", :password => "benrocks" }
+ assert user_session = UserSession.find
+ assert_equal users(:ben), user_session.user
+ assert_redirected_to account_path
+ end
+
+ test "should destroy user session" do
+ delete :destroy
+ assert_nil UserSession.find
+ assert_redirected_to new_user_session_path
end
end
View
30 test/functional/users_controller_test.rb
@@ -1,42 +1,34 @@
require 'test_helper'
class UsersControllerTest < ActionController::TestCase
-=begin
test "should get new" do
get :new
assert_response :success
end
-
+
test "should create user" do
assert_difference('User.count') do
- post :create, :user => { }
+ post :create, :user => { :login => "ben", :password => "benrocks", :password_confirmation => "benrocks", :email => "myemail@email.com" }
end
-
- assert_redirected_to user_path(assigns(:user))
+
+ assert_redirected_to account_path
end
-=end
+
test "should show user" do
+ set_session_for(users(:ben))
get :show
assert_response :success
end
-=begin
test "should get edit" do
- get :edit, :id => users(:one).id
+ set_session_for(users(:ben))
+ get :edit, :id => users(:ben).id
assert_response :success
end
test "should update user" do
- put :update, :id => users(:one).id, :user => { }
- assert_redirected_to user_path(assigns(:user))
- end
-
- test "should destroy user" do
- assert_difference('User.count', -1) do
- delete :destroy, :id => users(:one).id
- end
-
- assert_redirected_to users_path
+ set_session_for(users(:ben))
+ put :update, :id => users(:ben).id, :user => { }
+ assert_redirected_to account_path
end
-=end
end
View
3  test/test_helper.rb
@@ -1,6 +1,7 @@
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
+require 'authlogic/testing/test_unit_helpers'
class Test::Unit::TestCase
# Transactional fixtures accelerate your tests by wrapping each test method
@@ -33,6 +34,4 @@ class Test::Unit::TestCase
# Note: You'll currently still have to declare fixtures explicitly in integration tests
# -- they do not yet inherit this setting
fixtures :all
-
- # Add more helper methods to be used by all tests here...
end
Please sign in to comment.
Something went wrong with that request. Please try again.