Skip to content

Commit

Permalink
Work around AR that does not call serializable_hash on to_xml.
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jun 29, 2011
1 parent 6a8ee47 commit 07db04e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rdoc
Expand Up @@ -6,6 +6,7 @@
* Better localization for devise_error_messages! (by github.com/zedtux)

* bug fix
* Ensure to_xml is properly white listened
* Ensure handle_unverified_request clean up any cached signed-in user

== 1.4.0
Expand Down
19 changes: 12 additions & 7 deletions lib/devise/models/authenticatable.rb
Expand Up @@ -76,13 +76,18 @@ def inactive_message
def authenticatable_salt
end

def serializable_hash(options={})
if self.class.respond_to?(:accessible_attributes)
options = { :only => self.class.accessible_attributes.to_a }.merge(options || {})
super(options)
else
super
end
# TODO: to_xml does not call serializable_hash. Hopefully someone will fix this in AR.
%w(to_xml serializable_hash).each do |method|
class_eval <<-RUBY, __FILE__, __LINE__
def #{method}(options={})
if self.class.respond_to?(:accessible_attributes)
options = { :only => self.class.accessible_attributes.to_a }.merge(options || {})
super(options)
else
super
end
end
RUBY
end

module ClassMethods
Expand Down
2 changes: 1 addition & 1 deletion test/integration/registerable_test.rb
Expand Up @@ -211,7 +211,7 @@ class RegistrationTest < ActionController::IntegrationTest
get new_user_registration_path(:format => 'xml')
assert_response :success
assert_match %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>), response.body
assert_no_match(/<confirmation_token>/, response.body) if DEVISE_ORM == :active_record
assert_no_match(/<confirmation-token/, response.body) if DEVISE_ORM == :active_record
end

test 'a user with JSON sign up stub' do
Expand Down

0 comments on commit 07db04e

Please sign in to comment.