mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
bug report template for migrations (#26488)
* added bug report template for migrations
This commit is contained in:
parent
1381873fd7
commit
084211a7da
3 changed files with 130 additions and 0 deletions
65
guides/bug_report_templates/active_record_migrations_gem.rb
Normal file
65
guides/bug_report_templates/active_record_migrations_gem.rb
Normal file
|
@ -0,0 +1,65 @@
|
|||
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::Base.logger = Logger.new(STDOUT)
|
||||
|
||||
ActiveRecord::Schema.define do
|
||||
create_table :payments, force: true do |t|
|
||||
t.decimal :amount, precision: 10, scale: 0, default: 0, null: false
|
||||
end
|
||||
end
|
||||
|
||||
class Payment < ActiveRecord::Base
|
||||
end
|
||||
|
||||
class ChangeAmountToAddScale < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
reversible do |dir|
|
||||
dir.up do
|
||||
change_column :payments, :amount, :decimal, precision: 10, scale: 2, default: 0, null: false
|
||||
end
|
||||
|
||||
dir.down do
|
||||
change_column :payments, :amount, :decimal, precision: 10, scale: 0, default: 0, null: false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class BugTest < Minitest::Test
|
||||
def test_migration_up
|
||||
migrator = ActiveRecord::Migrator.new(:up, [ChangeAmountToAddScale])
|
||||
migrator.run
|
||||
Payment.reset_column_information
|
||||
|
||||
assert_equal "decimal(10,2)", Payment.columns.last.sql_type
|
||||
end
|
||||
|
||||
def test_migration_down
|
||||
migrator = ActiveRecord::Migrator.new(:down, [ChangeAmountToAddScale])
|
||||
migrator.run
|
||||
Payment.reset_column_information
|
||||
|
||||
assert_equal "decimal(10,0)", Payment.columns.last.sql_type
|
||||
end
|
||||
end
|
|
@ -0,0 +1,64 @@
|
|||
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 "rails", github: "rails/rails"
|
||||
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::Base.logger = Logger.new(STDOUT)
|
||||
|
||||
ActiveRecord::Schema.define do
|
||||
create_table :payments, force: true do |t|
|
||||
t.decimal :amount, precision: 10, scale: 0, default: 0, null: false
|
||||
end
|
||||
end
|
||||
|
||||
class Payment < ActiveRecord::Base
|
||||
end
|
||||
|
||||
class ChangeAmountToAddScale < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
reversible do |dir|
|
||||
dir.up do
|
||||
change_column :payments, :amount, :decimal, precision: 10, scale: 2, default: 0, null: false
|
||||
end
|
||||
|
||||
dir.down do
|
||||
change_column :payments, :amount, :decimal, precision: 10, scale: 0, default: 0, null: false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class BugTest < Minitest::Test
|
||||
def test_migration_up
|
||||
migrator = ActiveRecord::Migrator.new(:up, [ChangeAmountToAddScale])
|
||||
migrator.run
|
||||
Payment.reset_column_information
|
||||
|
||||
assert_equal "decimal(10,2)", Payment.columns.last.sql_type
|
||||
end
|
||||
|
||||
def test_migration_down
|
||||
migrator = ActiveRecord::Migrator.new(:down, [ChangeAmountToAddScale])
|
||||
migrator.run
|
||||
Payment.reset_column_information
|
||||
|
||||
assert_equal "decimal(10,0)", Payment.columns.last.sql_type
|
||||
end
|
||||
end
|
|
@ -40,6 +40,7 @@ Then, don't get your hopes up! Unless you have a "Code Red, Mission Critical, th
|
|||
Having a way to reproduce your issue will be very helpful for others to help confirm, investigate and ultimately fix your issue. You can do this by providing an executable test case. To make this process easier, we have prepared several bug report templates for you to use as a starting point:
|
||||
|
||||
* Template for Active Record (models, database) issues: [gem](https://github.com/rails/rails/blob/master/guides/bug_report_templates/active_record_gem.rb) / [master](https://github.com/rails/rails/blob/master/guides/bug_report_templates/active_record_master.rb)
|
||||
* Template for testing Active Record (migration) issues: [gem](https://github.com/rails/rails/blob/master/guides/bug_report_templates/active_record_migrations_gem.rb) / [master](https://github.com/rails/rails/blob/master/guides/bug_report_templates/active_record_migrations_master.rb)
|
||||
* Template for Action Pack (controllers, routing) issues: [gem](https://github.com/rails/rails/blob/master/guides/bug_report_templates/action_controller_gem.rb) / [master](https://github.com/rails/rails/blob/master/guides/bug_report_templates/action_controller_master.rb)
|
||||
* Template for Active Job issues: [gem](https://github.com/rails/rails/blob/master/guides/bug_report_templates/active_job_gem.rb) / [master](https://github.com/rails/rails/blob/master/guides/bug_report_templates/active_job_master.rb)
|
||||
* Generic template for other issues: [gem](https://github.com/rails/rails/blob/master/guides/bug_report_templates/generic_gem.rb) / [master](https://github.com/rails/rails/blob/master/guides/bug_report_templates/generic_master.rb)
|
||||
|
|
Loading…
Reference in a new issue