Created
May 26, 2025 13:53
-
-
Save mtsmfm/ed5d62e5e5fab4b3b814fb2c673b476c to your computer and use it in GitHub Desktop.
virtual column for PG
This file contains hidden or 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(true) do | |
source "https://rubygems.org" | |
gem "rails" | |
gem "pg" | |
end | |
require "active_record/railtie" | |
require "minitest/autorun" | |
ENV["DATABASE_URL"] = "postgres://postgres:mysecretpassword@localhost:5432/postgres" | |
class TestApp < Rails::Application | |
config.load_defaults Rails::VERSION::STRING.to_f | |
config.eager_load = false | |
config.logger = Logger.new($stdout) | |
config.secret_key_base = "secret_key_base" | |
end | |
Rails.application.initialize! | |
ActiveRecord::Schema.define do | |
create_table :users, force: true do |t| | |
t.string :name, null: false | |
t.virtual :upcase_name, type: :string, as: "UPPER(name)" | |
end | |
end | |
class User < ActiveRecord::Base | |
end | |
class BugTest < ActiveSupport::TestCase | |
def test_migration_up | |
User.reset_column_information | |
User.create!(name: "John Doe") | |
user = User.first | |
assert_equal "JOHN DOE", user.upcase_name | |
end | |
end |
Author
mtsmfm
commented
May 26, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment