Skip to content
This repository has been archived by the owner on Jul 21, 2020. It is now read-only.

Commit

Permalink
Fixed oopsie in stories runner. Now all specs tests and stories run o…
Browse files Browse the repository at this point in the history
…ut of the box for fresh rails install
  • Loading branch information
Philip (flip) Kromer committed May 30, 2008
1 parent a95a742 commit 64372da
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 42 deletions.
10 changes: 1 addition & 9 deletions generators/authenticated/authenticated_generator.rb
@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + "/lib/insert_routes.rb")
require 'digest/sha1'
class AuthenticationGenerator < Rails::Generator::NamedBase
class AuthenticatedGenerator < Rails::Generator::NamedBase
default_options :skip_migration => false,
:skip_routes => false,
:old_passwords => false,
Expand Down Expand Up @@ -259,14 +259,6 @@ def add_options!(opt)
def puts_install_msg
puts "Ready to generate."
puts ("-" * 70)
puts "Once finished, don't forget to:"
puts
puts "- Add routes to these resources. In config/routes.rb, insert routes like:"
puts %( map.signup '/signup', :controller => '#{model_controller_file_name}', :action => 'new')
puts %( map.login '/login', :controller => 'sessions', :action => 'new')
puts %( map.logout '/logout', :controller => 'sessions', :action => 'destroy')
puts
puts ("-" * 70)
puts
if $rest_auth_site_key_from_generator.blank?
puts "You've set a nil site key. This preserves existing users' passwords,"
Expand Down
7 changes: 3 additions & 4 deletions generators/authenticated/templates/rest_auth_stories.rb 100644 → 100755
Expand Up @@ -11,9 +11,8 @@
# module-specific setup
#

# FIXME -- this is crap (will break if user doesn't use that name)
REST_AUTH_STORIES_DIR=File.join(this_dir, '../vendor/plugins/restful_authentication/stories')
require File.join(REST_AUTH_STORIES_DIR, "rest_auth_stories_helper.rb")
# $REST_AUTH_DIR defined in restful-authentication/init.rb
require File.join($REST_AUTH_DIR, 'stories', "rest_auth_stories_helper.rb")

# Decouple users steps from whatever we've named the <%= class_name %> class
def find_user_by_login(login) <%= class_name %>.find_by_login(login) end
Expand All @@ -22,7 +21,7 @@ def find_user_by_login(login) <%= class_name %>.find_by_login(login) end
# do this thing
#
step_components = [:ra_navigation, :ra_response, :ra_resource, :user]
story_files = Dir[File.join(REST_AUTH_STORIES_DIR, "users", '*.story')]
story_files = Dir[File.join($REST_AUTH_DIR, 'stories', "users", '*.story')]
with_steps_for *step_components do
story_files.each do |file|
run file, :type => RailsStory
Expand Down
27 changes: 2 additions & 25 deletions generators/authenticated/templates/spec/lib/access_control_spec.rb
@@ -1,31 +1,8 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe AccessControl do
# before(:each) do
# @user = mock_user
# # set up module rig
# @klass = Class.new do
# stub!(:rescue_from)
# include AccessControl
# end
# @mockcontroller = @klass.new
# # Fake a controller
# # @mockcontroller.stub!(:session).and_return( {} )
# # @mockcontroller.stub!(:cookies).and_return( {} )
# # @mockcontroller.stub!(:reset_session)
# # @mockcontroller.stub!(:authenticate_with_http_basic).and_return nil # FIXME -- session controller not testing xml logins
# end
#
#
# describe "before filters" do
# before(:each) do
# #
# # A test controller with and without access controls
# #
# @klass.class_eval do
#
#

# before(:each) do
# end
# describe 'simple authorization' do
# it "should not authorize logged-out" do
# controller.stub!(:current_user).and_return(false)
Expand Down
8 changes: 6 additions & 2 deletions init.rb
@@ -1,5 +1,3 @@
REST_AUTH_DIR = File.dirname(__FILE__) unless defined? REST_AUTH_DIR

%w[
security_components
authentication
Expand All @@ -8,3 +6,9 @@
].each do |f|
require f
end

# make it so we can find stories dir.
# FIXME -- this is crap
require 'pathname'
$REST_AUTH_DIR = Pathname.new(File.dirname(__FILE__)).realpath
puts $REST_AUTH_DIR
2 changes: 1 addition & 1 deletion lib/authentication.rb
Expand Up @@ -55,7 +55,7 @@ def try_login_chain

# Called from #current_user. First attempt to login by the user id stored in the browser-session.
def try_login_from_session
self.current_user = User.find_by_id(session[:user_id]) if session[:user_id] # FIXME -- depends on User model named User
self.current_user = User.find_by_id(session[:user_id]) if session[:user_id]
end

def handle_signin_error error
Expand Down
2 changes: 1 addition & 1 deletion lib/authentication/by_cookie_token.rb
Expand Up @@ -3,7 +3,7 @@ module Authentication::ByCookieToken
# Called from #current_user. Finaly, attempt to login by an expiring token in the cookie.
# for the paranoid: we _should_ be storing user_token = hash(cookie_token, request IP)
def login_from_cookie
user = cookies[:auth_token] && User.find_by_remember_token(cookies[:auth_token]) # FIXME -- depends on User class being named User
user = cookies[:auth_token] && User.find_by_remember_token(cookies[:auth_token])
if user && user.remember_token? && become_logged_in_as!(user)
handle_remember_cookie! false # freshen cookie token (keeping date)
@current_user
Expand Down

0 comments on commit 64372da

Please sign in to comment.