forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] Add
active_record_encryption.rb
bug report template
- Loading branch information
1 parent
a4681cd
commit c926d56
Showing
4 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
require "bundler/inline" | ||
|
||
gemfile(true) do | ||
source "https://rubygems.org" | ||
|
||
gem "rails" | ||
# If you want to test against edge Rails replace the previous line with this: | ||
# gem "rails", github: "rails/rails", branch: "main" | ||
|
||
gem "sqlite3" | ||
end | ||
|
||
require "active_record/railtie" | ||
require "minitest/autorun" | ||
|
||
# This connection will do for database-independent bug reports. | ||
ENV["DATABASE_URL"] = "sqlite3::memory:" | ||
|
||
class TestApp < Rails::Application | ||
config.load_defaults Rails::VERSION::STRING.to_f | ||
config.eager_load = false | ||
config.logger = Logger.new($stdout) | ||
|
||
config.active_record.encryption.primary_key = "primary_key" | ||
config.active_record.encryption.deterministic_key = "deterministic_key" | ||
config.active_record.encryption.key_derivation_salt = "key_derivation_salt" | ||
end | ||
Rails.application.initialize! | ||
|
||
ActiveRecord::Schema.define do | ||
create_table :users, force: true do |t| | ||
t.string :email | ||
end | ||
end | ||
|
||
class User < ActiveRecord::Base | ||
encrypts :email | ||
end | ||
|
||
class BugTest < ActiveSupport::TestCase | ||
def test_encryption_stuff | ||
post = User.create!(email: "[email protected]") | ||
|
||
encrypted_email = post.read_attribute_before_type_cast(:email) | ||
|
||
assert_not_equal "[email protected]", encrypted_email | ||
assert_not_equal post.read_attribute(:email), encrypted_email | ||
|
||
assert_equal "[email protected]", post.email | ||
end | ||
end |
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