Skip to content

Instantly share code, notes, and snippets.

@dimerman
Forked from ankane/lockbox_repro.rb
Last active July 22, 2022 18:41
Show Gist options
  • Save dimerman/ce7e1e50b0ef1bf4f248d6de02e0f2bb to your computer and use it in GitHub Desktop.
Save dimerman/ce7e1e50b0ef1bf4f248d6de02e0f2bb to your computer and use it in GitHub Desktop.
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'activerecord', require: 'active_record'
gem 'sqlite3'
gem 'lockbox', git: 'https://github.com/ankane/lockbox.git'
end
puts "Lockbox version: #{Lockbox::VERSION}"
Lockbox.master_key = '0'*64
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
ActiveRecord::Schema.define do
create_table :users do |t|
t.text :email_ciphertext
t.text :words_ciphertext #, null: false - cannot enforce not-null
end
end
class User < ActiveRecord::Base
has_encrypted :email
has_encrypted :words, type: :hash
end
my_hash = { "word": 5 }
user = User.create!(email: '[email protected]', words: nil)
pp user # #<User id: 1, email: [FILTERED], words: nil>
pp user.words # {}
user.update!(words: {})
pp user # #<User id: 1, email: [FILTERED], words: nil>
pp user.words # {}
user.update!(words: {a: 2}) # error: Tried to load unspecified class: Symbol (Psych::DisallowedClass)
pp user
pp user.words
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment