Skip to content

Instantly share code, notes, and snippets.

@girishso
Last active September 14, 2016 05:40
Show Gist options
  • Save girishso/93bb3ec2243723acf52a019aa931ab9d to your computer and use it in GitHub Desktop.
Save girishso/93bb3ec2243723acf52a019aa931ab9d to your computer and use it in GitHub Desktop.
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"
# Activate the gem you are reporting the issue against.
gem "activerecord", "5.0.0.1"
gem "sqlite3"
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: "sqlite3", database: ":memory:")
ActiveRecord::Schema.define do
create_table :payment_logs, force: true do |t|
t.decimal :amount, precision: 10, scale: 0, default: 0, null: false
end
end
class PaymentLog < ActiveRecord::Base
end
class ChangeAmountToAddScale < ActiveRecord::Migration[5.0]
def change
reversible do |dir|
dir.up do
change_column :payment_logs, :amount, :decimal, precision: 10, scale: 2, default: 0, null: false
end
dir.down do
change_column :payment_logs, :amount, :decimal, precision: 10, scale: 0, default: 0, null: false
end
end
end
end
class BugTest < Minitest::Test
def test_migrations
migrator = ActiveRecord::Migrator.new(:up, [ChangeAmountToAddScale])
migrator.run
PaymentLog.reset_column_information
assert_equal "decimal(10,2)", PaymentLog.columns.last.sql_type
migrator = ActiveRecord::Migrator.new(:down, [ChangeAmountToAddScale])
migrator.run
PaymentLog.reset_column_information
assert_equal "decimal(10,0)", PaymentLog.columns.last.sql_type
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment