Skip to content

Instantly share code, notes, and snippets.

@shuber
Created April 2, 2010 18:13
Show Gist options
  • Save shuber/353485 to your computer and use it in GitHub Desktop.
Save shuber/353485 to your computer and use it in GitHub Desktop.
Testing attr_encrypted with ActiveRecord 2.1.2
require 'rubygems'
require 'test/unit'
gem 'activerecord', '2.1.2'
require 'active_record'
require 'attr_encrypted'
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
silence_stream(STDOUT) do
ActiveRecord::Schema.define(:version => 1) do
create_table :users do |t|
t.string :username
t.string :encrypted_password
end
end
end
class User < ActiveRecord::Base
attr_encrypted :password, :key => 'a secret key'
end
class ActiveRecordTest < Test::Unit::TestCase
def test_should_save_encrypted_values
@user = User.new(:username => 'admin', :password => 'test')
assert @user.save
assert_not_nil @user.encrypted_password
assert_not_nil @user.attributes['encrypted_password']
@user = User.find(@user.id)
assert_not_nil @user.encrypted_password
assert_not_nil @user.attributes['encrypted_password']
assert_not_equal 'test', @user.encrypted_password
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment