Created
April 2, 2010 18:13
-
-
Save shuber/353485 to your computer and use it in GitHub Desktop.
Testing attr_encrypted with ActiveRecord 2.1.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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