Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
binarylogic committed Dec 1, 2008
1 parent 45c6197 commit 7a8f30b
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 59 deletions.
14 changes: 6 additions & 8 deletions README.mdown
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
4 changes: 2 additions & 2 deletions db/migrate/20081103171327_create_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
31 changes: 6 additions & 25 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 16 additions & 3 deletions test/functional/user_sessions_controller_test.rb
Original file line number Diff line number Diff line change
@@ -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
30 changes: 11 additions & 19 deletions test/functional/users_controller_test.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

0 comments on commit 7a8f30b

Please sign in to comment.