Skip to content
Browse files

Working on test coverage ... still a long way to go

  • Loading branch information...
1 parent 0b8eb58 commit 3bb3fb59c1724de72813acb47382e43c37a376be @jrallison committed
View
2 lib/authlogic_oauth/acts_as_authentic.rb
@@ -79,7 +79,7 @@ def oauth_secret=(value)
private
def authenticating_with_oauth?
- !session_class.controller.params[:register_with_oauth].blank? || oauth_response
+ (session_class.controller.params && !session_class.controller.params[:register_with_oauth].blank?) || oauth_response
end
def authenticate_with_oauth
View
2 lib/authlogic_oauth/oauth_process.rb
@@ -42,7 +42,7 @@ def generate_access_token
end
def oauth_response
- oauth_controller.params[:oauth_token]
+ oauth_controller.params && oauth_controller.params[:oauth_token]
end
def oauth_controller
View
2 lib/authlogic_oauth/session.rb
@@ -49,7 +49,7 @@ def save(&block)
private
def authenticating_with_oauth?
- !controller.params[:login_with_oauth].blank? || oauth_response
+ (controller.params && !controller.params[:login_with_oauth].blank?) || oauth_response
end
def authenticate_with_oauth
View
10 test/session_test.rb
@@ -11,17 +11,13 @@ def test_authenticate_by_record
def test_validate_by_nil_oauth_token
session = UserSession.new
assert !session.save
- #assert !redirecting_to_yahoo?
- end
-
- def test_auth_session
- session = UserSession.new
- #assert session.is_auth_session?
+ assert !redirecting_to_oauth?
end
def test_validate_by_oauth
+ controller.stubs(:params).returns({ :login_with_oauth => true })
session = UserSession.new
assert !session.save
- #assert redirecting_to_yahoo?
+ assert redirecting_to_oauth?
end
end
View
33 test/test_helper.rb
@@ -1,9 +1,7 @@
require "test/unit"
require "rubygems"
-require "oauth"
require "ruby-debug"
require "active_record"
-require "active_record/fixtures"
ActiveRecord::Schema.verbose = false
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
@@ -32,12 +30,26 @@
end
end
-require File.dirname(__FILE__) + '/../../authlogic/lib/authlogic' unless defined?(Authlogic)
-require File.dirname(__FILE__) + '/../../authlogic/lib/authlogic/test_case'
+require "active_record/fixtures"
+require "action_controller"
+require "oauth"
+Rails = true # to trick authlogic into loading the rails adapter
+require File.dirname(__FILE__) + "/../../authlogic/lib/authlogic"
+require File.dirname(__FILE__) + "/../../authlogic/lib/authlogic/test_case"
require File.dirname(__FILE__) + '/../lib/authlogic_oauth' unless defined?(AuthlogicOauth)
require File.dirname(__FILE__) + '/lib/user'
require File.dirname(__FILE__) + '/lib/user_session'
+class ActionController::Base
+ def redirecting_to
+ @redirect_to
+ end
+
+ def redirect_to(*args)
+ @redirect_to = args
+ end
+end
+
class ActiveSupport::TestCase
include ActiveRecord::TestFixtures
self.fixture_path = File.dirname(__FILE__) + "/fixtures"
@@ -46,4 +58,17 @@ class ActiveSupport::TestCase
self.pre_loaded_fixtures = false
fixtures :all
setup :activate_authlogic
+
+
+ def activate_authlogic
+ Authlogic::Session::Base.controller = controller
+ end
+
+ def controller
+ @controller ||= Authlogic::ControllerAdapters::RailsAdapter.new(ActionController::Base.new)
+ end
+
+ def redirecting_to_oauth?
+ controller.redirecting_to.to_s =~ /^http:\/\/example.com/
+ end
end

0 comments on commit 3bb3fb5

Please sign in to comment.
Something went wrong with that request. Please try again.