<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,8 +1,6 @@
 require File.dirname(__FILE__) + '/../spec_helper'
 
-# Be sure to include AuthenticatedTestHelper in spec/spec_helper.rb instead
-# Then, you can remove it from this and the units test.
-include AuthenticatedTestHelper
+include OpenIdAuthentication
 
 describe SessionsController do
   fixtures        :users
@@ -10,7 +8,6 @@ describe SessionsController do
     @user  = mock_user
     @login_params = { :login =&gt; 'quentin', :password =&gt; 'test' }
     User.stub!(:authenticate).with(@login_params[:login], @login_params[:password]).and_return(@user)
-    controller.stub!(:using_open_id?).and_return(false)
   end
   def do_create
     post :create, @login_params
@@ -98,6 +95,39 @@ describe SessionsController do
     it 'redirects me to the home page' do do_destroy; response.should be_redirect     end
   end
   
+  describe &quot;with OpenID&quot; do
+    describe &quot;successful return&quot; do
+      before(:each) do
+        controller.should_receive(:authenticate_with_open_id).
+          and_yield(Result[:successful], 'http://openid.yahoo.com/me/blah')
+      end
+      
+      it &quot;should load the user based on identity url and log in&quot; do
+        User.should_receive(:find_by_identity_url).with('http://openid.yahoo.com/me/blah').and_return(users(:quentin))
+        controller.should_receive(:successful_login)
+        get :create, 'openid.identity' =&gt; 'http://openid.yahoo.com/me/blah', :open_id_complete =&gt; 1
+      end
+      
+      it &quot;should fail the login without a user found&quot; do
+        User.should_receive(:find_by_identity_url).with('http://openid.yahoo.com/me/blah').and_return(nil)
+        controller.should_not_receive(:successful_login)
+        get :create, 'openid.identity' =&gt; 'http://openid.yahoo.com/me/blah', :open_id_complete =&gt; 1
+        flash[:error].should == &quot;Sorry, no user by that identity URL exists (http://openid.yahoo.com/me/blah)&quot;
+        response.should render_template('new')
+      end
+    end
+    
+    describe &quot;failed return&quot; do
+      it &quot;should fail the login&quot; do
+        controller.should_receive(:authenticate_with_open_id).
+          and_yield(Result[:failed], 'http://openid.yahoo.com/me/blah')
+        controller.should_not_receive(:successful_login)
+        get :create, 'openid.identity' =&gt; 'http://openid.yahoo.com/me/blah', :open_id_complete =&gt; 1
+        response.should render_template('new')
+      end
+    end
+  end
+  
 end
 
 describe SessionsController do</diff>
      <filename>spec/controllers/sessions_controller_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,5 @@
 require File.dirname(__FILE__) + '/../spec_helper'
+include OpenIdAuthentication
 
 describe UsersController do
   fixtures :users
@@ -10,9 +11,6 @@ describe UsersController do
     end.should change(User, :count).by(1)
   end
 
-  
-
-
   it 'requires login on signup' do
     lambda do
       create_user(:login =&gt; nil)
@@ -45,11 +43,44 @@ describe UsersController do
     end.should_not change(User, :count)
   end
   
+  describe &quot;with OpenID&quot; do
+    it &quot;should not require login&quot; do
+      controller.should_receive(:authenticate_with_open_id).with('yahoo.com', {:return_to=&gt;&quot;http://test.host/opencreate&quot;})
+      create_user({:login =&gt; nil}, :openid_url =&gt; 'yahoo.com')
+    end
+    
+    it &quot;should put the user info in the session&quot; do
+      controller.should_receive(:authenticate_with_open_id).with('yahoo.com', {:return_to=&gt;&quot;http://test.host/opencreate&quot;})
+      create_user({:login =&gt; nil}, :openid_url =&gt; 'yahoo.com')
+      session[:user_params].should == { 'email' =&gt; 'quire@example.com',
+        'password' =&gt; 'quire69', 'password_confirmation' =&gt; 'quire69', 'login' =&gt; nil }
+    end
+    
+    it &quot;should create the user after returning from the provider&quot; do
+      controller.should_receive(:authenticate_with_open_id).
+        with('http://openid.yahoo.com/me/blah', {:return_to=&gt;&quot;http://test.host/opencreate&quot;}).
+        and_yield(Result[:successful], 'http://openid.yahoo.com/me/blah')
+      controller.should_receive(:create_new_user).
+        with({ 'email' =&gt; 'quire@example.com', :identity_url =&gt; 'http://openid.yahoo.com/me/blah' })
+      request.session[:user_params] = { 'email' =&gt; 'quire@example.com' }
+      get :create, { :openid_url =&gt; 'http://openid.yahoo.com/me/blah', :open_id_complete =&gt; 1 }
+    end
+    
+    it &quot;should warn on failing to create a user after returning from the provider&quot; do
+      controller.should_receive(:authenticate_with_open_id).
+        with('http://openid.yahoo.com/me/blah', {:return_to=&gt;&quot;http://test.host/opencreate&quot;}).
+        and_yield(Result[:failed], 'http://openid.yahoo.com/me/blah')
+      controller.should_not_receive(:create_new_user)
+      controller.should_receive(:failed_creation)
+      request.session[:user_params] = { 'email' =&gt; 'quire@example.com' }
+      get :create, { :openid_url =&gt; 'http://openid.yahoo.com/me/blah', :open_id_complete =&gt; 1 }
+    end
+  end
   
   
-  def create_user(options = {})
-    post :create, :user =&gt; { :login =&gt; 'quire', :email =&gt; 'quire@example.com',
-      :password =&gt; 'quire69', :password_confirmation =&gt; 'quire69' }.merge(options)
+  def create_user(options = {}, extra_params = {})
+    post :create, {:user =&gt; { :login =&gt; 'quire', :email =&gt; 'quire@example.com',
+      :password =&gt; 'quire69', :password_confirmation =&gt; 'quire69' }.merge(options)}.merge(extra_params)
   end
 end
 </diff>
      <filename>spec/controllers/users_controller_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -213,6 +213,27 @@ describe User do
     users(:quentin).remember_token_expires_at.should_not be_nil
     users(:quentin).remember_token_expires_at.between?(before, after).should be_true
   end
+  
+  describe &quot;with OpenID&quot; do
+    before(:each) do
+      @user = User.new(:email =&gt; 'quire@example.com', :identity_url =&gt; 'http://yahoo.com')
+    end
+
+    it &quot;should not require a login or password&quot; do
+      @user.should be_valid
+    end
+    
+    it &quot;should indicate using OpenID&quot; do
+      @user.not_using_openid?.should be_false
+    end
+    
+    it &quot;should require a password if the user attempts to change the password&quot; do
+      @user = users(:quentin)
+      @user.identity_url = 'http://yahoo.com'
+      @user.password = 'foo'
+      @user.password_required?.should be_true
+    end
+  end
 
 protected
   def create_user(options = {})</diff>
      <filename>spec/models/user_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>dc3cf3c0b5b8b21560ad592874c9aa52ee132f39</id>
    </parent>
  </parents>
  <author>
    <name>Benjamin Curtis</name>
    <email>benjamin.curtis@gmail.com</email>
  </author>
  <url>http://github.com/stympy/openid-rails-kit/commit/22a3be9989c1fc1f137283c91c6264f7080520de</url>
  <id>22a3be9989c1fc1f137283c91c6264f7080520de</id>
  <committed-date>2008-05-27T15:29:19-07:00</committed-date>
  <authored-date>2008-05-27T15:29:19-07:00</authored-date>
  <message>Added some tests</message>
  <tree>4190be7187d3c0dc71f75ebddf007440af41e11b</tree>
  <committer>
    <name>Benjamin Curtis</name>
    <email>benjamin.curtis@gmail.com</email>
  </committer>
</commit>
