Skip to content

Instantly share code, notes, and snippets.

@khustochka
Created May 2, 2020 02:30
Show Gist options
  • Save khustochka/3698dd1af4ba12eeb9e00b2fa3dc66e9 to your computer and use it in GitHub Desktop.
Save khustochka/3698dd1af4ba12eeb9e00b2fa3dc66e9 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails"
gem "pg"
end
require "active_record"
require "minitest/autorun"
require "logger"
ActiveRecord::Base.establish_connection(adapter: "postgresql", database: "postgres")
ActiveRecord::Base.connection.execute("DROP DATABASE IF EXISTS typecast_test")
ActiveRecord::Base.connection.execute("CREATE DATABASE typecast_test")
ActiveRecord::Base.establish_connection(adapter: "postgresql", database: "typecast_test")
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :posts, force: true do |t|
t.date :some_date
end
end
class Post < ActiveRecord::Base
end
class BugTest < Minitest::Test
def test_date_typecasting
Post.create!(some_date: 1.year.ago.to_date)
Post.create!(some_date: 1.month.ago.to_date)
max_date = Post.maximum(:some_date)
assert_equal Date, max_date.class
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment