Sha256: 292611bcfe9c57a8bb24354d0aaf947166426da530291cb4edb6b961b020bad4

Contents?: true

Size: 1.81 KB

Versions: 2

Compression:

Stored size: 1.81 KB

Contents

require "pod4"
require "pod4/sequel_interface"
require "pod4/encrypting"
require "sequel"
require "jdbc/postgres"


describe "(writing encrypted data via sequel_interface)" do

  def db_setup(connection)
    connection.run(%Q| drop table if exists medical;
                       create table medical ( 
                         id      serial primary key,
                         nonce   text,
                         name    text,
                         ailment text );| )

  end

  def db_truncate(connection)
    connection.run(%Q| truncate table medical restart identity; |)
  end


  before(:all) do
    @connection = Sequel.connect('jdbc:postgresql://centos7andy/pod4_test?user=pod4test&password=pod4test')
    db_setup(@connection)
  end

  before(:each) do
    db_truncate(@connection)
    medical_model_class.set_interface medical_interface_class.new(@connection)
  end


  let(:medical_interface_class) do 
    Class.new Pod4::SequelInterface do
      set_table  :medical
      set_id_fld :id
    end
  end

  let(:medical_model_class) do 
    Class.new Pod4::Model do
      include Pod4::Encrypting

      encrypted_columns :name, :ailment
      set_key           "dflkasdgklajndgnalkghlgasdgasdghaalsdg"
      set_iv_column     :nonce
    end
  end

  #####


  it "writes encrypted data to the database" do
    m = medical_model_class.new
    m.name    = "frank"
    m.ailment = "sore toe"

    expect{ m.create }.not_to raise_exception

    record = m.class.interface.list.first
    expect( record ).not_to be_nil
  end

  it "reads encrypted data back from the database" do
    m1 = medical_model_class.new
    m1.name    = "roger"
    m1.ailment = "hiccups"
    m1.create

    m2 = medical_model_class.list.first
    expect( m2 ).not_to be_nil
    expect( m2.name    ).to eq "roger"
    expect( m2.ailment ).to eq "hiccups"
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pod4-0.10.6 spec/jruby/sequel_encrypting_jdbc_pg_spec.rb
pod4-0.10.5 spec/jruby/sequel_encrypting_jdbc_pg_spec.rb