forked from binarylogic/authlogic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Test::Unit helpers and a session generator
- Loading branch information
1 parent
5238a02
commit af9712b
Showing
8 changed files
with
71 additions
and
2 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
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
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class SessionGenerator < Rails::Generator::NamedBase | ||
def manifest | ||
record do |m| | ||
m.class_collisions class_name | ||
m.directory File.join('app/models', class_path) | ||
m.template 'session.rb', File.join('app/models', class_path, "#{file_name}.rb") | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class <%= class_name %> < Authlogic::Session::Base | ||
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Authlogic | ||
module Testing | ||
# = Test Unit Helpers | ||
# | ||
# Provides useful methods for testing in Test::Unit, lets you log records in, etc. | ||
module TestUnitHelpers | ||
private | ||
def session_class(record) # :nodoc: | ||
record.class.acts_as_authentic_config[:session_class].constantize | ||
end | ||
|
||
# Sets the session for a record. This way when you execute a request in your test, session values will be present. | ||
def set_session_for(record) | ||
session_class = session_class(record) | ||
@request.session[session_class.session_key] = record.persistence_token | ||
@request.session["#{session_class.session_key}_id"] = record.id | ||
end | ||
|
||
# Sets the cookie for a record. This way when you execute a request in your test, cookie values will be present. | ||
def set_cookie_for(record) | ||
session_class = session_class(record) | ||
@request.cookies[session_class.cookie_key] = record.persistence_token | ||
end | ||
|
||
# Sets the HTTP_AUTHORIZATION header for basic HTTP auth. This way when you execute a request in your test that is trying to authenticate | ||
# with HTTP basic auth, the neccessary headers will be present. | ||
def set_http_auth_for(username, password) | ||
session_class = session_class(record) | ||
@request.env['HTTP_AUTHORIZATION'] = @controller.encode_credentials(username, password) | ||
end | ||
end | ||
end | ||
end | ||
|
||
Test::Unit::TestCase.send(:include, Authlogic::Testing::TestUnitHelpers) |
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