Class: AssociationKeyHolderTest

Inherits:
KeyHolderTest show all
Defined in:
lib/extensions/ezcrypto/ext/test/association_key_holder_test.rb

Direct Known Subclasses

EncryptTest

Instance Attribute Summary

Attributes inherited from KeyHolderTest

#key_holder

Instance Method Summary collapse

Methods inherited from KeyHolderTest

#test_enter_password_should_set_session_key, #test_session_key_should_not_be_set_on_new, #test_set_encoded_key_should_set_session_key, #test_set_session_key_should_set_session_key

Instance Method Details

#setupObject



8
9
10
# File 'lib/extensions/ezcrypto/ext/test/association_key_holder_test.rb', line 8

def setup
  @key_holder=User.create
end

#test_should_retain_session_key_on_reloadObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/extensions/ezcrypto/ext/test/association_key_holder_test.rb', line 12

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

#test_should_retain_session_key_on_reload_for_record_with_key_set_before_createObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/extensions/ezcrypto/ext/test/association_key_holder_test.rb', line 23

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