Permalink
Browse files

trying to get tests to run on rails 2.3.5

  • Loading branch information...
1 parent 4d1fed2 commit 55e37fe506db909e9ff99a7caf29dc58a4325096 @mreinsch mreinsch committed Mar 18, 2010
Showing with 41 additions and 4 deletions.
  1. +41 −4 test/test_helper.rb
View
@@ -2,6 +2,8 @@
require "rubygems"
require "ruby-debug"
require "active_record"
+require "action_controller"
+require "action_controller/test_process"
ActiveRecord::Schema.verbose = false
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
@@ -45,14 +47,34 @@
require "active_record/fixtures"
require "openid"
-Rails = true # to trick authlogic into loading the rails adapter
+
+module Rails
+ module VERSION
+ STRING = "2.3.5"
+ end
+end
+
require File.dirname(__FILE__) + "/../../authlogic/lib/authlogic"
require File.dirname(__FILE__) + "/../../authlogic/lib/authlogic/test_case"
-require File.dirname(__FILE__) + '/../../open_id_authentication/lib/open_id_authentication.rb'
+require File.dirname(__FILE__) + '/../../open_id_authentication/lib/open_id_authentication'
+
+# this is partly from open_id_authentication/init.rb
+ActionController::Base.send :include, OpenIdAuthentication
+
require File.dirname(__FILE__) + '/../lib/authlogic_openid' unless defined?(AuthlogicOpenid)
require File.dirname(__FILE__) + '/libs/user'
require File.dirname(__FILE__) + '/libs/user_session'
+ActionController::Routing::Routes.draw do |map|
+ map.connect ':controller/:action/:id', :controller => 'session'
+end
+
+class SessionController < ActionController::Base
+ def default_template(action_name = self.action_name)
+ nil
+ end
+end
+
class ActiveSupport::TestCase
include ActiveRecord::TestFixtures
self.fixture_path = File.dirname(__FILE__) + "/fixtures"
@@ -68,10 +90,25 @@ def activate_authlogic
end
def controller
- @controller ||= Authlogic::ControllerAdapters::RailsAdapter.new(ActionController.new)
+ @controller ||= create_controller
+ end
+
+ def create_controller
+ @request = ActionController::TestRequest.new
+ @request.path_parameters = {:action => "index", :controller => "session"}
+ @response = ActionController::TestResponse.new
+
+ c = SessionController.new
+ c.params = {}
+ c.request = @request
+ c.response = @response
+ c.send(:reset_session)
+ c.send(:initialize_current_url)
+
+ Authlogic::ControllerAdapters::RailsAdapter.new(c)
end
def redirecting_to_yahoo?
- controller.redirecting_to.to_s =~ /^https:\/\/open.login.yahooapis.com\/openid\/op\/auth/
+ @response.redirected_to.to_s =~ /^https:\/\/open.login.yahooapis.com\/openid\/op\/auth/
end
end

0 comments on commit 55e37fe

Please sign in to comment.