mirror of
https://github.com/heartcombo/devise.git
synced 2026-04-28 03:00:29 -04:00
This has no actual changes to Devise itself, just fixes the failing tests when running against Mongoid 3 instead of Mongoid 2. Mocha has been locked at 0.10.0 since 0.12.0 raises an error when trying to set an expectation on a frozen object. Tests were updated to work with both AR and Mongoid, some cases the XML serialization was slightly different but both were outputting correct and valid XML, and the id/_id field mismatch is now handled. An active field was missing from the test models for Mongoid, and the invalid :null => true options in field were removed.
50 lines
1.7 KiB
Ruby
50 lines
1.7 KiB
Ruby
require 'test_helper'
|
|
|
|
class SerializableTest < ActiveSupport::TestCase
|
|
setup do
|
|
@user = create_user
|
|
end
|
|
|
|
test 'should not include unsafe keys on XML' do
|
|
assert_match /email/, @user.to_xml
|
|
assert_no_match /confirmation-token/, @user.to_xml
|
|
end
|
|
|
|
test 'should not include unsafe keys on XML even if a new except is provided' do
|
|
assert_no_match /email/, @user.to_xml(:except => :email)
|
|
assert_no_match /confirmation-token/, @user.to_xml(:except => :email)
|
|
end
|
|
|
|
test 'should include unsafe keys on XML if a force_except is provided' do
|
|
assert_no_match /<email/, @user.to_xml(:force_except => :email)
|
|
assert_match /confirmation-token/, @user.to_xml(:force_except => :email)
|
|
end
|
|
|
|
test 'should not include unsafe keys on JSON' do
|
|
keys = from_json().keys.select{ |key| !key.include?("id") }
|
|
assert_equal %w(created_at email facebook_token updated_at username), keys.sort
|
|
end
|
|
|
|
test 'should not include unsafe keys on JSON even if a new except is provided' do
|
|
assert_no_key "email", from_json(:except => :email)
|
|
assert_no_key "confirmation_token", from_json(:except => :email)
|
|
end
|
|
|
|
test 'should include unsafe keys on JSON if a force_except is provided' do
|
|
assert_no_key "email", from_json(:force_except => :email)
|
|
assert_key "confirmation_token", from_json(:force_except => :email)
|
|
end
|
|
|
|
def assert_key(key, subject)
|
|
assert subject.key?(key), "Expected #{subject.inspect} to have key #{key.inspect}"
|
|
end
|
|
|
|
def assert_no_key(key, subject)
|
|
assert !subject.key?(key), "Expected #{subject.inspect} to not have key #{key.inspect}"
|
|
end
|
|
|
|
def from_json(options=nil)
|
|
ActiveSupport::JSON.decode(@user.to_json(options))["user"]
|
|
end
|
|
end
|