提交 a6d4e5e5 编写于 作者: M Matthew Draper

Internal test migrations use the private 'Current' version

Apart from specific versioning support, our tests should focus on the
behaviour of whatever version they're accompanying, regardless of when
they were written.

Application code should *not* do this.
上级 dc8d40af
......@@ -3,13 +3,13 @@
class PostgresqlExtensionMigrationTest < ActiveRecord::PostgreSQLTestCase
self.use_transactional_tests = false
class EnableHstore < ActiveRecord::Migration
class EnableHstore < ActiveRecord::Migration::Current
def change
enable_extension "hstore"
end
end
class DisableHstore < ActiveRecord::Migration
class DisableHstore < ActiveRecord::Migration::Current
def change
disable_extension "hstore"
end
......
......@@ -86,7 +86,7 @@ def test_change_table_supports_hstore
end
def test_hstore_migration
hstore_migration = Class.new(ActiveRecord::Migration) do
hstore_migration = Class.new(ActiveRecord::Migration::Current) do
def change
change_table("hstores") do |t|
t.hstore :keys
......
......@@ -5,7 +5,7 @@ class Horse < ActiveRecord::Base
module ActiveRecord
class InvertibleMigrationTest < ActiveRecord::TestCase
class SilentMigration < ActiveRecord::Migration
class SilentMigration < ActiveRecord::Migration::Current
def write(text = '')
# sssshhhhh!!
end
......@@ -105,7 +105,7 @@ def change
end
end
class LegacyMigration < ActiveRecord::Migration
class LegacyMigration < ActiveRecord::Migration::Current
def self.up
create_table("horses") do |t|
t.column :content, :text
......
......@@ -339,7 +339,7 @@ def test_keeping_default_and_notnull_constraints_on_change
def test_change_column_null
testing_table_with_only_foo_attribute do
notnull_migration = Class.new(ActiveRecord::Migration) do
notnull_migration = Class.new(ActiveRecord::Migration::Current) do
def change
change_column_null :testings, :foo, false
end
......
......@@ -224,7 +224,7 @@ def test_schema_dumping_on_delete_and_on_update_options
assert_match %r{\s+add_foreign_key "astronauts",.+on_update: :cascade,.+on_delete: :nullify$}, output
end
class CreateCitiesAndHousesMigration < ActiveRecord::Migration
class CreateCitiesAndHousesMigration < ActiveRecord::Migration::Current
def change
create_table("cities") { |t| }
......@@ -243,7 +243,7 @@ def test_add_foreign_key_is_reversible
silence_stream($stdout) { migration.migrate(:down) }
end
class CreateSchoolsAndClassesMigration < ActiveRecord::Migration
class CreateSchoolsAndClassesMigration < ActiveRecord::Migration::Current
def change
create_table(:schools)
......
......@@ -132,12 +132,12 @@ def test_create_table_with_force_true_does_not_drop_nonexisting_table
end
def test_migration_instance_has_connection
migration = Class.new(ActiveRecord::Migration).new
migration = Class.new(ActiveRecord::Migration::Current).new
assert_equal ActiveRecord::Base.connection, migration.connection
end
def test_method_missing_delegates_to_connection
migration = Class.new(ActiveRecord::Migration) {
migration = Class.new(ActiveRecord::Migration::Current) {
def connection
Class.new {
def create_table; "hi mom!"; end
......@@ -226,7 +226,7 @@ def test_filtering_migrations
assert_raise(ActiveRecord::StatementInvalid) { Reminder.first }
end
class MockMigration < ActiveRecord::Migration
class MockMigration < ActiveRecord::Migration::Current
attr_reader :went_up, :went_down
def initialize
@went_up = false
......@@ -268,7 +268,7 @@ def test_instance_based_migration_down
def test_migrator_one_up_with_exception_and_rollback
assert_no_column Person, :last_name
migration = Class.new(ActiveRecord::Migration) {
migration = Class.new(ActiveRecord::Migration::Current) {
def version; 100 end
def migrate(x)
add_column "people", "last_name", :string
......@@ -289,7 +289,7 @@ def migrate(x)
def test_migrator_one_up_with_exception_and_rollback_using_run
assert_no_column Person, :last_name
migration = Class.new(ActiveRecord::Migration) {
migration = Class.new(ActiveRecord::Migration::Current) {
def version; 100 end
def migrate(x)
add_column "people", "last_name", :string
......@@ -310,7 +310,7 @@ def migrate(x)
def test_migration_without_transaction
assert_no_column Person, :last_name
migration = Class.new(ActiveRecord::Migration) {
migration = Class.new(ActiveRecord::Migration::Current) {
self.disable_ddl_transaction!
def version; 101 end
......@@ -525,7 +525,7 @@ def test_out_of_range_limit_should_raise
if ActiveRecord::Base.connection.supports_advisory_locks?
def test_migrator_generates_valid_lock_id
migration = Class.new(ActiveRecord::Migration).new
migration = Class.new(ActiveRecord::Migration::Current).new
migrator = ActiveRecord::Migrator.new(:up, [migration], 100)
lock_id = migrator.send(:generate_migrator_advisory_lock_id)
......@@ -539,7 +539,7 @@ def test_migrator_generates_valid_lock_id
def test_generate_migrator_advisory_lock_id
# It is important we are consistent with how we generate this so that
# exclusive locking works across migrator versions
migration = Class.new(ActiveRecord::Migration).new
migration = Class.new(ActiveRecord::Migration::Current).new
migrator = ActiveRecord::Migrator.new(:up, [migration], 100)
lock_id = migrator.send(:generate_migrator_advisory_lock_id)
......@@ -556,7 +556,7 @@ def test_generate_migrator_advisory_lock_id
def test_migrator_one_up_with_unavailable_lock
assert_no_column Person, :last_name
migration = Class.new(ActiveRecord::Migration) {
migration = Class.new(ActiveRecord::Migration::Current) {
def version; 100 end
def migrate(x)
add_column "people", "last_name", :string
......@@ -577,7 +577,7 @@ def migrate(x)
def test_migrator_one_up_with_unavailable_lock_using_run
assert_no_column Person, :last_name
migration = Class.new(ActiveRecord::Migration) {
migration = Class.new(ActiveRecord::Migration::Current) {
def version; 100 end
def migrate(x)
add_column "people", "last_name", :string
......
......@@ -6,7 +6,7 @@ class MigratorTest < ActiveRecord::TestCase
# Use this class to sense if migrations have gone
# up or down.
class Sensor < ActiveRecord::Migration
class Sensor < ActiveRecord::Migration::Current
attr_reader :went_up, :went_down
def initialize name = self.class.name, version = nil
......
......@@ -312,7 +312,7 @@ def test_do_not_dump_foreign_keys_for_ignored_tables
end
end
class CreateDogMigration < ActiveRecord::Migration
class CreateDogMigration < ActiveRecord::Migration::Current
def up
create_table("dog_owners") do |t|
end
......@@ -357,7 +357,7 @@ def test_schema_dump_with_table_name_prefix_and_suffix
def test_schema_dump_with_table_name_prefix_and_ignoring_tables
original, $stdout = $stdout, StringIO.new
create_cat_migration = Class.new(ActiveRecord::Migration) do
create_cat_migration = Class.new(ActiveRecord::Migration::Current) do
def change
create_table("cats") do |t|
end
......
class AddExpressions < ActiveRecord::Migration
class AddExpressions < ActiveRecord::Migration::Current
def self.up
create_table("expressions") do |t|
t.column :expression, :string
......
class GiveMeBigNumbers < ActiveRecord::Migration
class GiveMeBigNumbers < ActiveRecord::Migration::Current
def self.up
create_table :big_numbers do |table|
table.column :bank_balance, :decimal, :precision => 10, :scale => 2
......
# coding: ISO-8859-15
class CurrenciesHaveSymbols < ActiveRecord::Migration
class CurrenciesHaveSymbols < ActiveRecord::Migration::Current
def self.up
# We use for default currency symbol
add_column "currencies", "symbol", :string, :default => ""
......
class PeopleHaveMiddleNames < ActiveRecord::Migration
class PeopleHaveMiddleNames < ActiveRecord::Migration::Current
def self.up
add_column "people", "middle_name", :string
end
......
class PeopleHaveLastNames < ActiveRecord::Migration
class PeopleHaveLastNames < ActiveRecord::Migration::Current
def self.up
add_column "people", "last_name", :string
end
......
class WeNeedReminders < ActiveRecord::Migration
class WeNeedReminders < ActiveRecord::Migration::Current
def self.up
create_table("reminders") do |t|
t.column :content, :text
......
class InnocentJointable < ActiveRecord::Migration
class InnocentJointable < ActiveRecord::Migration::Current
def self.up
create_table("people_reminders", :id => false) do |t|
t.column :reminder_id, :integer
......
class WeNeedThings < ActiveRecord::Migration
class WeNeedThings < ActiveRecord::Migration::Current
def self.up
create_table("things") do |t|
t.column :content, :text
......
class RenameThings < ActiveRecord::Migration
class RenameThings < ActiveRecord::Migration::Current
def self.up
rename_table "things", "awesome_things"
end
......
class PeopleHaveLastNames < ActiveRecord::Migration
class PeopleHaveLastNames < ActiveRecord::Migration::Current
def self.up
add_column "people", "hobbies", :text
end
......
class PeopleHaveLastNames < ActiveRecord::Migration
class PeopleHaveLastNames < ActiveRecord::Migration::Current
def self.up
add_column "people", "description", :text
end
......
class CreateArticles < ActiveRecord::Migration
class CreateArticles < ActiveRecord::Migration::Current
def self.up
end
......
class CreateArticles < ActiveRecord::Migration
class CreateArticles < ActiveRecord::Migration::Current
def self.up
end
......
class PeopleHaveLastNames < ActiveRecord::Migration
class PeopleHaveLastNames < ActiveRecord::Migration::Current
def self.up
add_column "people", "hobbies", :string
end
......
class PeopleHaveLastNames < ActiveRecord::Migration
class PeopleHaveLastNames < ActiveRecord::Migration::Current
def self.up
add_column "people", "hobbies", :text
end
......
class PeopleHaveLastNames < ActiveRecord::Migration
class PeopleHaveLastNames < ActiveRecord::Migration::Current
def self.up
add_column "people", "description", :text
end
......
class CreateArticles < ActiveRecord::Migration
class CreateArticles < ActiveRecord::Migration::Current
def self.up
end
......
class CreateComments < ActiveRecord::Migration
class CreateComments < ActiveRecord::Migration::Current
def self.up
end
......
class ValidPeopleHaveLastNames < ActiveRecord::Migration
class ValidPeopleHaveLastNames < ActiveRecord::Migration::Current
def self.up
add_column "people", "last_name", :string
end
......
class WeNeedReminders < ActiveRecord::Migration
class WeNeedReminders < ActiveRecord::Migration::Current
def self.up
create_table("reminders") do |t|
t.column :content, :text
......
class InnocentJointable < ActiveRecord::Migration
class InnocentJointable < ActiveRecord::Migration::Current
def self.up
create_table("people_reminders", :id => false) do |t|
t.column :reminder_id, :integer
......
class ValidPeopleHaveLastNames < ActiveRecord::Migration
class ValidPeopleHaveLastNames < ActiveRecord::Migration::Current
def self.up
add_column "people", "last_name", :string
end
......
class WeNeedReminders < ActiveRecord::Migration
class WeNeedReminders < ActiveRecord::Migration::Current
def self.up
create_table("reminders") do |t|
t.column :content, :text
......
class InnocentJointable < ActiveRecord::Migration
class InnocentJointable < ActiveRecord::Migration::Current
def self.up
create_table("people_reminders", :id => false) do |t|
t.column :reminder_id, :integer
......
class ValidWithTimestampsPeopleHaveLastNames < ActiveRecord::Migration
class ValidWithTimestampsPeopleHaveLastNames < ActiveRecord::Migration::Current
def self.up
add_column "people", "last_name", :string
end
......
class ValidWithTimestampsWeNeedReminders < ActiveRecord::Migration
class ValidWithTimestampsWeNeedReminders < ActiveRecord::Migration::Current
def self.up
create_table("reminders") do |t|
t.column :content, :text
......
class ValidWithTimestampsInnocentJointable < ActiveRecord::Migration
class ValidWithTimestampsInnocentJointable < ActiveRecord::Migration::Current
def self.up
create_table("people_reminders", :id => false) do |t|
t.column :reminder_id, :integer
......
class MigrationVersionCheck < ActiveRecord::Migration
class MigrationVersionCheck < ActiveRecord::Migration::Current
def self.up
raise "incorrect migration version" unless version == 20131219224947
end
......
......@@ -103,7 +103,7 @@ class MyLogger < ::Logger
RUBY
app_file 'db/migrate/20140708012246_create_user.rb', <<-RUBY
class CreateUser < ActiveRecord::Migration
class CreateUser < ActiveRecord::Migration::Current
def change
create_table :users
end
......
......@@ -290,7 +290,7 @@ class Post < ActiveRecord::Base
extend Rack::Test::Methods
app_file "db/migrate/1_create_posts.rb", <<-MIGRATION
class CreatePosts < ActiveRecord::Migration
class CreatePosts < ActiveRecord::Migration::Current
def change
create_table :posts do |t|
t.string :title, default: "TITLE"
......@@ -306,7 +306,7 @@ def change
assert_equal "TITLE", last_response.body
app_file "db/migrate/2_add_body_to_posts.rb", <<-MIGRATION
class AddBodyToPosts < ActiveRecord::Migration
class AddBodyToPosts < ActiveRecord::Migration::Current
def change
add_column :posts, :body, :text, default: "BODY"
end
......
......@@ -18,7 +18,7 @@ def teardown
`bin/rails generate model user username:string password:string`
app_file "db/migrate/01_a_migration.bukkits.rb", <<-MIGRATION
class AMigration < ActiveRecord::Migration
class AMigration < ActiveRecord::Migration::Current
end
MIGRATION
......@@ -158,12 +158,12 @@ class AMigration < ActiveRecord::Migration
Dir.chdir(app_path) do
app_file "db/migrate/1_one_migration.rb", <<-MIGRATION
class OneMigration < ActiveRecord::Migration
class OneMigration < ActiveRecord::Migration::Current
end
MIGRATION
app_file "db/migrate/02_two_migration.rb", <<-MIGRATION
class TwoMigration < ActiveRecord::Migration
class TwoMigration < ActiveRecord::Migration::Current
end
MIGRATION
......
......@@ -63,22 +63,22 @@ def boot_rails
test "copying migrations" do
@plugin.write "db/migrate/1_create_users.rb", <<-RUBY
class CreateUsers < ActiveRecord::Migration
class CreateUsers < ActiveRecord::Migration::Current
end
RUBY
@plugin.write "db/migrate/2_add_last_name_to_users.rb", <<-RUBY
class AddLastNameToUsers < ActiveRecord::Migration
class AddLastNameToUsers < ActiveRecord::Migration::Current
end
RUBY
@plugin.write "db/migrate/3_create_sessions.rb", <<-RUBY
class CreateSessions < ActiveRecord::Migration
class CreateSessions < ActiveRecord::Migration::Current
end
RUBY
app_file "db/migrate/1_create_sessions.rb", <<-RUBY
class CreateSessions < ActiveRecord::Migration
class CreateSessions < ActiveRecord::Migration::Current
def up
end
end
......@@ -123,12 +123,12 @@ class Engine < ::Rails::Engine
end
@plugin.write "db/migrate/1_create_users.rb", <<-RUBY
class CreateUsers < ActiveRecord::Migration
class CreateUsers < ActiveRecord::Migration::Current
end
RUBY
@blog.write "db/migrate/2_create_blogs.rb", <<-RUBY
class CreateBlogs < ActiveRecord::Migration
class CreateBlogs < ActiveRecord::Migration::Current
end
RUBY
......@@ -163,11 +163,11 @@ class Engine < ::Rails::Engine; end
end
@core.write "db/migrate/1_create_users.rb", <<-RUBY
class CreateUsers < ActiveRecord::Migration; end
class CreateUsers < ActiveRecord::Migration::Current; end
RUBY
@api.write "db/migrate/2_create_keys.rb", <<-RUBY
class CreateKeys < ActiveRecord::Migration; end
class CreateKeys < ActiveRecord::Migration::Current; end
RUBY
boot_rails
......@@ -190,7 +190,7 @@ class Engine < ::Rails::Engine
RUBY
@plugin.write "db/migrate/0_add_first_name_to_users.rb", <<-RUBY
class AddFirstNameToUsers < ActiveRecord::Migration
class AddFirstNameToUsers < ActiveRecord::Migration::Current
end
RUBY
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册