Created
April 26, 2018 01:36
-
-
Save abaldwin88/c24db432b7b351fafe56797b97ae6a54 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
# frozen_string_literal: true | |
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" | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
# Activate the gem you are reporting the issue against. | |
gem "activerecord", "5.2.0" | |
gem "pg" | |
end | |
require "active_record" | |
require "minitest/autorun" | |
require "logger" | |
# Ensure backward compatibility with Minitest 4 | |
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test) | |
# This connection will do for database-independent bug reports. | |
ActiveRecord::Base.establish_connection(adapter: "postgresql", database: "issue_reproduction_development", encoding: "utf8", pool: 5, timeout: 5000, host: "localhost") | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
create_table :payments, force: true do |t| | |
t.datetime :created_at | |
end | |
end | |
class Payment < ActiveRecord::Base | |
end | |
class ChangeCastIndex < ActiveRecord::Migration[5.2] | |
def change | |
add_index :payments, 'CAST(created_at AS date)' | |
end | |
end | |
class ChangeCastIndexShorthand < ActiveRecord::Migration[5.2] | |
def change | |
add_index :payments, "((created_at)::date)" | |
end | |
end | |
class BugTest < Minitest::Test | |
def test_cast | |
ChangeCastIndex.migrate(:up) | |
assert_equal ActiveRecord::Base.connection.indexes(:payments).first.name, 'index_payments_on_CAST_created_at_AS_date' | |
ChangeCastIndex.migrate(:down) | |
assert_equal ActiveRecord::Base.connection.indexes(:payments).first, nil | |
end | |
def test_cast_shorthand | |
ChangeCastIndexShorthand.migrate(:up) | |
assert_equal ActiveRecord::Base.connection.indexes(:payments).first.name, 'index_payments_on_created_at_date' | |
ChangeCastIndexShorthand.migrate(:down) | |
assert_equal ActiveRecord::Base.connection.indexes(:payments).first, nil | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment