1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

sessions/new also responds to xml and json now

This commit is contained in:
José Valim 2011-04-18 09:56:24 +02:00
parent 2cfa58b433
commit 4a4dcb30ef
3 changed files with 21 additions and 8 deletions

View file

@ -4,8 +4,9 @@ class Devise::SessionsController < ApplicationController
# GET /resource/sign_in
def new
clean_up_passwords(build_resource)
render_with_scope :new
resource = build_resource
clean_up_passwords(resource)
respond_with_navigational(resource, stub_options(resource)){ render_with_scope :new }
end
# POST /resource/sign_in
@ -33,4 +34,12 @@ class Devise::SessionsController < ApplicationController
end
end
end
end
protected
def stub_options(resource)
hash = { :only => resource_class.authentication_keys }
hash[:methods] = [:password] if resource.respond_to?(:password)
hash
end
end

View file

@ -41,7 +41,7 @@ module Devise
# Set password and password confirmation to nil
def clean_up_passwords
self.password = self.password_confirmation = nil
self.password = self.password_confirmation = ""
end
# Update record attributes when :current_password matches, otherwise returns

View file

@ -336,10 +336,14 @@ class AuthenticationOthersTest < ActionController::IntegrationTest
end
end
test 'registration in xml format works when recognizing path' do
assert_nothing_raised do
post user_registration_path(:format => 'xml', :user => {:email => "test@example.com", :password => "invalid"} )
end
test 'sign in stub in xml format' do
get new_user_session_path(:format => 'xml')
assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>\n <email></email>\n <password></password>\n</user>\n", response.body
end
test 'sign in stub in json format' do
get new_user_session_path(:format => 'json')
assert_equal "{\"user\":{\"password\":\"\",\"email\":\"\"}}", response.body
end
test 'uses the mapping from router' do