Created
May 8, 2020 10:00
-
-
Save casperisfine/bc4804c42b788f8e42a23672cfcd36cd 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
begin | |
require "bundler/inline" | |
rescue LoadError => e | |
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler" | |
raise e | |
end | |
gemfile(true) do | |
source "https://rubygems.org" | |
gem "activerecord" | |
gem "sqlite3" | |
end | |
require "active_record" | |
require "minitest/autorun" | |
require "logger" | |
# This connection will do for database-independent bug reports. | |
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
create_table :users do |t| | |
t.integer :user_type | |
end | |
end | |
class User < ActiveRecord::Base | |
enum user_type: [:normal, :invited] | |
end | |
user = User.new(user_type: :invited) | |
p user.user_type | |
p user.user_type == :invited | |
user.save! | |
p user.reload.user_type | |
p User.first.user_type | |
p User.first.user_type == :invited |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment