Sha256: 621cffc2fc6389a53e4ca9b0d0d7cb12b246c2032a0a67c221dc182aea5389ed

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

require 'test_helper'

describe Enkrip do
  def test_version
    assert Enkrip::VERSION
  end

  def test_encryption_decryption
    model = ExampleModel.new my_string: '', my_numeric: 0
    assert_equal model.valid?, false

    model.my_string = 'my example string'
    model.my_numeric = 1
    model.save!
    model.reload

    raw = ActiveRecord::Base.connection.exec_query 'SELECT my_string, my_numeric FROM example_models limit 1'
    encrypted_my_string = raw.rows.first.first
    encrypted_my_numeric = raw.rows.first.last

    assert_equal encrypted_my_string.nil?, false
    assert_equal encrypted_my_string.empty?, false
    refute_equal encrypted_my_string, model.my_string
    assert_equal model.my_string, 'my example string'
    assert_equal Enkrip::Engine.decrypt(encrypted_my_string, purpose: :example), 'my example string'

    assert_equal encrypted_my_numeric.nil?, false
    assert_equal encrypted_my_numeric.empty?, false
    refute_equal encrypted_my_numeric, model.my_numeric
    assert_equal model.my_numeric, 1
    assert_equal Enkrip::Engine.decrypt(encrypted_my_numeric, purpose: :example).to_i, 1
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
enkrip-0.1.0 test/test_enkrip.rb