Skip to content

Commit

Permalink
More tests for Omniauth.
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Oct 18, 2010
1 parent 2f360bf commit 611261c
Show file tree
Hide file tree
Showing 22 changed files with 199 additions and 391 deletions.
1 change: 1 addition & 0 deletions app/controllers/devise/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def create
sign_in_and_redirect(resource_name, resource)
else
set_flash_message :notice, :inactive_signed_up, :reason => resource.inactive_message.to_s
expire_session_data_after_sign_in!
redirect_to after_inactive_sign_up_path_for(resource)
end
else
Expand Down
6 changes: 3 additions & 3 deletions app/views/devise/shared/_links.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
<%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
<% end -%>

<%- if devise_mapping.oauthable? %>
<%- resource_class.oauth_providers.each do |provider| %>
<%= link_to "Sign in with #{provider.to_s.titleize}", oauth_authorize_url(resource_name, provider) %><br />
<%- if devise_mapping.omniauthable? %>
<%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %><br />
<% end -%>
<% end -%>
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ en:
unlocks:
send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
unlocked: 'Your account was successfully unlocked. You are now signed in.'
oauth_callbacks:
omniauth_callbacks:
success: 'Successfully authorized from %{kind} account.'
failure: 'Could not authorize you from %{kind} because "%{reason}".'
mailer:
Expand Down
15 changes: 11 additions & 4 deletions lib/devise/controllers/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ def sign_in(resource_or_scope, *args)
scope = Devise::Mapping.find_scope!(resource_or_scope)
resource = args.last || resource_or_scope

expire_session_data_after_sign_in!

if options[:bypass]
warden.session_serializer.store(resource, scope)
else
expire_session_data_after_sign_in!
warden.set_user(resource, options.merge!(:scope => scope))
end
end
Expand Down Expand Up @@ -195,7 +196,13 @@ def sign_in_and_redirect(resource_or_scope, *args)
options = args.extract_options!
scope = Devise::Mapping.find_scope!(resource_or_scope)
resource = args.last || resource_or_scope
sign_in(scope, resource, options) unless warden.user(scope) == resource

if warden.user(scope) == resource
expire_session_data_after_sign_in!
else
sign_in(scope, resource, options)
end

redirect_for_sign_in(scope, resource)
end

Expand All @@ -219,8 +226,8 @@ def redirect_for_sign_out(scope) #:nodoc:
redirect_to after_sign_out_path_for(scope)
end

# A hook called to expire session data after sign up/in. This is used
# by a few extensions, like oauth, to expire tokens stored in session.
# A hook called to expire session data after sign up/in. All keys
# stored under "devise." namespace are removed after sign in.
def expire_session_data_after_sign_in!
session.keys.grep(/^devise\./).each { |k| session.delete(k) }
end
Expand Down
4 changes: 3 additions & 1 deletion lib/devise/omniauth/test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ def self.stub!(provider, stubs=nil, &block)
raise "You either need to pass stubs as a block or as a parameter" unless block_given? || stubs

config = Devise.omniauth_configs[provider]
config.check_if_allow_stubs!
raise "Could not find configuration for #{provider.to_s} omniauth provider" unless config

config.check_if_allow_stubs!
stubs ||= Faraday::Adapter::Test::Stubs.new(&block)

config.build_connection do |b|
b.adapter :test, stubs
end
Expand Down
2 changes: 1 addition & 1 deletion lib/devise/omniauth/url_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def omniauth_authorize_path(resource_or_scope, *args)
send("#{scope}_omniauth_authorize_path", *args)
end

def omniauth_callback_url(resource_or_scope, *args)
def omniauth_callback_path(resource_or_scope, *args)
scope = Devise::Mapping.find_scope!(resource_or_scope)
send("#{scope}_omniauth_callback_path", *args)
end
Expand Down
2 changes: 1 addition & 1 deletion test/integration/authenticatable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ class AuthenticationRequestKeysTest < ActionController::IntegrationTest

class AuthenticationSignOutViaTest < ActionController::IntegrationTest
def sign_in!(scope)
sign_in_as_user(:visit => send("new_#{scope}_session_path"))
sign_in_as_admin(:visit => send("new_#{scope}_session_path"))
assert warden.authenticated?(scope)
end

Expand Down
244 changes: 0 additions & 244 deletions test/integration/oauthable_test.rb

This file was deleted.

Loading

0 comments on commit 611261c

Please sign in to comment.