Sha256: 3cc8cb8cb04f86e7a4dae2f76d5b007e3535e76c58fc7b789a4255f51dc69ef4

Contents?: true

Size: 1.66 KB

Versions: 33

Compression:

Stored size: 1.66 KB

Contents

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

Version data entries

33 entries across 33 versions & 6 rubygems

Version Path
devise-3.5.10 test/models/serializable_test.rb
devise-4.0.3 test/models/serializable_test.rb
devise-4.1.1 test/models/serializable_test.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/devise-4.1.0/test/models/serializable_test.rb
devise-4.1.0 test/models/serializable_test.rb
devise-3.5.9 test/models/serializable_test.rb
devise-4.0.2 test/models/serializable_test.rb
devise-4.0.1 test/models/serializable_test.rb
devise-3.5.8 test/models/serializable_test.rb
devise-3.5.7 test/models/serializable_test.rb
devise-4.0.0 test/models/serializable_test.rb
devise-4.0.0.rc2 test/models/serializable_test.rb
devise-4.0.0.rc1 test/models/serializable_test.rb
devise-3.5.6 test/models/serializable_test.rb
devise-3.5.5 test/models/serializable_test.rb
devise-3.5.4 test/models/serializable_test.rb
devise-3.5.3 test/models/serializable_test.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/devise-3.5.2/test/models/serializable_test.rb
devise-3.5.2 test/models/serializable_test.rb
devise-3.5.1 test/models/serializable_test.rb