-
-
Save dimerman/ce7e1e50b0ef1bf4f248d6de02e0f2bb to your computer and use it in GitHub Desktop.
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 '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