Skip to content

Commit

Permalink
Fix all tests.
Browse files Browse the repository at this point in the history
All test passing on version 2.0.0. Releasing a new version.
  • Loading branch information
Daniel Palacio committed Jul 17, 2013
1 parent a6b8f5d commit 457b098
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -5,9 +5,9 @@ source 'https://rubygems.org'
gem 'encryptor2'

group :development do
gem 'pry'
gem 'activerecord'
gem 'datamapper'

gem 'mocha'
gem 'sequel'
gem 'dm-sqlite-adapter'
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Expand Up @@ -21,6 +21,7 @@ GEM
atomic (1.1.10)
bcrypt-ruby (3.1.1)
builder (3.1.4)
coderay (1.0.9)
data_objects (0.10.13)
addressable (~> 2.1)
datamapper (1.2.0)
Expand Down Expand Up @@ -75,11 +76,17 @@ GEM
json (1.8.0)
json_pure (1.8.0)
metaclass (0.0.1)
method_source (0.8.1)
minitest (4.7.5)
mocha (0.14.0)
metaclass (~> 0.0.1)
multi_json (1.7.7)
pry (0.9.12.2)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.4)
sequel (4.0.0)
slop (3.4.5)
sqlite3 (1.3.7)
stringex (1.5.1)
thread_safe (0.1.0)
Expand All @@ -96,5 +103,6 @@ DEPENDENCIES
dm-sqlite-adapter
encryptor2
mocha
pry
sequel
sqlite3
15 changes: 10 additions & 5 deletions test/attr_encrypted_test.rb
Expand Up @@ -167,23 +167,26 @@ def test_should_evaluate_a_key_passed_as_a_symbol
assert_nil @user.ssn_encrypted
@user.ssn = 'testing'
assert_not_nil @user.ssn_encrypted
assert_equal Encryptor.encrypt(:value => 'testing', :key => SECRET_KEY, :iv => @user.ssn_encrypted_iv.unpack("m").first, :salt => Time.now.to_i.to_s), @user.ssn_encrypted
encrypted = Encryptor.encrypt(:value => 'testing', :key => SECRET_KEY, :iv => @user.ssn_encrypted_iv.unpack("m").first, :salt => @user.ssn_encrypted_salt )
assert_equal encrypted, @user.ssn_encrypted
end

def test_should_evaluate_a_key_passed_as_a_proc
@user = User.new
assert_nil @user.crypted_password_test
@user.password = 'testing'
assert_not_nil @user.crypted_password_test
assert_equal Encryptor.encrypt(:value => 'testing', :key => SECRET_KEY, :iv => @user.crypted_password_test_iv.unpack("m").first, :salt => Time.now.to_i.to_s), @user.crypted_password_test
encrypted = Encryptor.encrypt(:value => 'testing', :key => SECRET_KEY, :iv => @user.crypted_password_test_iv.unpack("m").first, :salt => @user.crypted_password_test_salt)
assert_equal encrypted, @user.crypted_password_test
end

def test_should_use_options_found_in_the_attr_encrypted_options_attribute
@user = User.new
assert_nil @user.crypted_password_test
@user.password = 'testing'
assert_not_nil @user.crypted_password_test
assert_equal Encryptor.encrypt(:value => 'testing', :key => SECRET_KEY, :iv => @user.crypted_password_test_iv.unpack("m").first, :salt => Time.now.to_i.to_s), @user.crypted_password_test
encrypted = Encryptor.encrypt(:value => 'testing', :key => SECRET_KEY, :iv => @user.crypted_password_test_iv.unpack("m").first, :salt => @user.crypted_password_test_salt)
assert_equal encrypted, @user.crypted_password_test
end

def test_should_inherit_encrypted_attributes
Expand Down Expand Up @@ -225,7 +228,8 @@ def test_should_encrypt_with_true_if
assert_nil @user.encrypted_with_true_if
@user.with_true_if = 'testing'
assert_not_nil @user.encrypted_with_true_if
assert_equal Encryptor.encrypt(:value => 'testing', :key => SECRET_KEY, :iv => @user.encrypted_with_true_if_iv.unpack("m").first, :salt => Time.now.to_i.to_s), @user.encrypted_with_true_if
encrypted = Encryptor.encrypt(:value => 'testing', :key => SECRET_KEY, :iv => @user.encrypted_with_true_if_iv.unpack("m").first, :salt => @user.encrypted_with_true_if_salt)
assert_equal encrypted, @user.encrypted_with_true_if
end

def test_should_not_encrypt_with_false_if
Expand All @@ -241,7 +245,8 @@ def test_should_encrypt_with_false_unless
assert_nil @user.encrypted_with_false_unless
@user.with_false_unless = 'testing'
assert_not_nil @user.encrypted_with_false_unless
assert_equal Encryptor.encrypt(:value => 'testing', :key => SECRET_KEY, :iv => @user.encrypted_with_false_unless_iv.unpack("m").first, :salt => Time.now.to_i.to_s,), @user.encrypted_with_false_unless
encrypted = Encryptor.encrypt(:value => 'testing', :key => SECRET_KEY, :iv => @user.encrypted_with_false_unless_iv.unpack("m").first, :salt => @user.encrypted_with_false_unless_salt)
assert_equal encrypted, @user.encrypted_with_false_unless
end

def test_should_not_encrypt_with_true_unless
Expand Down
3 changes: 1 addition & 2 deletions test/sequel_test.rb
Expand Up @@ -29,7 +29,6 @@ def setup
end

def test_should_encrypt_email
require 'ruby-debug'
@human = Human.new :email => 'test@example.com'
assert @human.save
assert_not_nil @human.encrypted_email
Expand All @@ -39,7 +38,7 @@ def test_should_encrypt_email

def test_should_marshal_and_encrypt_credentials

@human = Human.new
@human = Human.new :credentials => { :username => 'example', :password => 'test' }
assert @human.save
assert_not_nil @human.encrypted_credentials
assert_not_equal @human.credentials, @human.encrypted_credentials
Expand Down
4 changes: 2 additions & 2 deletions test/test_helper.rb
Expand Up @@ -5,12 +5,12 @@
require 'active_record'
require 'data_mapper'
require 'sequel'
require 'mocha'
require 'mocha/setup'

$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$:.unshift(File.dirname(__FILE__))
require 'attr_encryptor'

puts "\nTesting with ActiveRecord #{ActiveRecord::VERSION::STRING rescue ENV['ACTIVE_RECORD_VERSION']}"

SECRET_KEY = 4.times.map { Digest::SHA256.hexdigest((Time.now.to_i * rand(5)).to_s) }.join
SECRET_KEY = 4.times.map { Digest::SHA256.hexdigest((Time.now.to_i * rand(5)).to_s) }.join

0 comments on commit 457b098

Please sign in to comment.