Last active
February 17, 2025 12:20
-
-
Save Vagab/088bdd5d36e873dd8a13aaab19c9b75c to your computer and use it in GitHub Desktop.
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
| # frozen_string_literal: true | |
| require "bundler/inline" | |
| gemfile(true) do | |
| source "https://rubygems.org" | |
| gem "rails" | |
| gem "sqlite3" | |
| end | |
| require "active_record/railtie" | |
| require "minitest/autorun" | |
| 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.secret_key_base = "secret_key_base" | |
| 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 :posts, force: true do |t| | |
| t.integer :field, default: 0 | |
| end | |
| end | |
| class FieldType < ActiveModel::Type::Value | |
| VALUES = { 0 => "zero" } | |
| def type | |
| :field_type | |
| end | |
| def deserialize(value) | |
| VALUES.fetch(value) unless value.nil? | |
| end | |
| def serialize(value) | |
| VALUES.key(value) | |
| end | |
| end | |
| class Post < ActiveRecord::Base | |
| attribute :field, FieldType.new | |
| end | |
| class BugTest < ActiveSupport::TestCase | |
| def test_association_stuff | |
| post = Post.create! | |
| assert post.field == "zero" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment