cirandas.net

ref: master

vendor/ezcrypto/test/association_key_holder_test.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require 'key_holder_test'

class User < ActiveRecord::Base
  keyholder
end

class AssociationKeyHolderTest < KeyHolderTest
  def setup
    @key_holder=User.create
  end
  
  def test_should_retain_session_key_on_reload
    key=EzCrypto::Key.generate
    key_holder.set_session_key key
    assert_not_nil key_holder.session_key
    assert_equal key.raw,key_holder.session_key.raw
    
    reloaded=User.find key_holder.id
    assert_not_nil reloaded.session_key
    assert_equal key.raw,reloaded.session_key.raw    
  end
  
  def test_should_retain_session_key_on_reload_for_record_with_key_set_before_create
    key=EzCrypto::Key.generate
    key_holder=User.new
    assert_nil key_holder.session_key
    
    key_holder.set_session_key key
    assert_not_nil key_holder.session_key
    
    assert_equal key.raw,key_holder.session_key.raw
    key_holder.save
    
    reloaded=User.find key_holder.id
    assert_not_nil reloaded.session_key
    assert_equal key.raw,reloaded.session_key.raw    
  end
end