aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2012-12-09 15:52:28 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2012-12-09 15:57:34 -0700
commitcff747d304f008c103a7ba92440400a9a0848bee (patch)
tree88e4ac162d9a90db715abecbbfbfe155c7756d6f /activerecord/test
parent3c2c1a46064684a1becc8ae7b6b7fe6eebf9651a (diff)
downloadrails-cff747d304f008c103a7ba92440400a9a0848bee.tar.gz
rails-cff747d304f008c103a7ba92440400a9a0848bee.tar.bz2
rails-cff747d304f008c103a7ba92440400a9a0848bee.zip
Move to the schema-migrations-metadata branch.
Pending work on graceful app upgrades. Revert "Merge pull request #8439 from joshsusser/fixes" This reverts commit ce8ac39338f86388e70356b3a470b3ea443802ae, reversing changes made to b0e7b6f67c984d4b1502e801781ed75fad681633. Revert "Merge pull request #8431 from joshsusser/schemadump" This reverts commit 036d3e1c2b65c4b8cbd23de2e20ad67b9b756182, reversing changes made to 0c692f4d121792117b6a71e5ed590a31c3b9d12e. Revert "Merge branch 'joshsusser-master' into merge" This reverts commit 0c692f4d121792117b6a71e5ed590a31c3b9d12e, reversing changes made to 2e299fca715b083a60222a85e48f9d3b8dd8ce93. Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb activerecord/test/cases/schema_dumper_test.rb
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/ar_schema_test.rb51
-rw-r--r--activerecord/test/cases/migration/logger_test.rb2
-rw-r--r--activerecord/test/cases/migration/table_and_index_test.rb24
-rw-r--r--activerecord/test/cases/migration_test.rb11
-rw-r--r--activerecord/test/cases/migrator_test.rb9
-rw-r--r--activerecord/test/cases/schema_dumper_test.rb17
-rw-r--r--activerecord/test/cases/schema_migration_test.rb54
-rw-r--r--activerecord/test/migrations/always_safe/1001_always_safe.rb5
-rw-r--r--activerecord/test/migrations/always_safe/1002_still_safe.rb5
9 files changed, 30 insertions, 148 deletions
diff --git a/activerecord/test/cases/ar_schema_test.rb b/activerecord/test/cases/ar_schema_test.rb
index bd47ba8741..b2eac0349b 100644
--- a/activerecord/test/cases/ar_schema_test.rb
+++ b/activerecord/test/cases/ar_schema_test.rb
@@ -46,55 +46,4 @@ if ActiveRecord::Base.connection.supports_migrations?
end
end
- class ActiveRecordSchemaMigrationsTest < ActiveRecordSchemaTest
- def setup
- super
- ActiveRecord::SchemaMigration.delete_all
- end
-
- def test_migration_adds_row_to_migrations_table
- schema = ActiveRecord::Schema.new
- schema.migration(1001, "", "")
- schema.migration(1002, "123456789012345678901234567890ab", "add_magic_power_to_unicorns")
-
- migrations = ActiveRecord::SchemaMigration.all.to_a
- assert_equal 2, migrations.length
-
- assert_equal 1001, migrations[0].version
- assert_match %r{^2\d\d\d-}, migrations[0].migrated_at.to_s(:db)
- assert_equal "", migrations[0].fingerprint
- assert_equal "", migrations[0].name
-
- assert_equal 1002, migrations[1].version
- assert_match %r{^2\d\d\d-}, migrations[1].migrated_at.to_s(:db)
- assert_equal "123456789012345678901234567890ab", migrations[1].fingerprint
- assert_equal "add_magic_power_to_unicorns", migrations[1].name
- end
-
- def test_define_clears_schema_migrations
- assert_nothing_raised do
- ActiveRecord::Schema.define do
- migrations do
- migration(123001, "", "")
- end
- end
- ActiveRecord::Schema.define do
- migrations do
- migration(123001, "", "")
- end
- end
- end
- end
-
- def test_define_raises_if_both_version_and_explicit_migrations
- assert_raise(ArgumentError) do
- ActiveRecord::Schema.define(version: 123001) do
- migrations do
- migration(123001, "", "")
- end
- end
- end
- end
- end
-
end
diff --git a/activerecord/test/cases/migration/logger_test.rb b/activerecord/test/cases/migration/logger_test.rb
index c2fdc50e52..ee0c20747e 100644
--- a/activerecord/test/cases/migration/logger_test.rb
+++ b/activerecord/test/cases/migration/logger_test.rb
@@ -10,8 +10,6 @@ module ActiveRecord
def migrate direction
# do nothing
end
- def filename; "anon.rb"; end
- def fingerprint; "123456789012345678901234567890ab"; end
end
def setup
diff --git a/activerecord/test/cases/migration/table_and_index_test.rb b/activerecord/test/cases/migration/table_and_index_test.rb
new file mode 100644
index 0000000000..8fd770abd1
--- /dev/null
+++ b/activerecord/test/cases/migration/table_and_index_test.rb
@@ -0,0 +1,24 @@
+require "cases/helper"
+
+module ActiveRecord
+ class Migration
+ class TableAndIndexTest < ActiveRecord::TestCase
+ def test_add_schema_info_respects_prefix_and_suffix
+ conn = ActiveRecord::Base.connection
+
+ conn.drop_table(ActiveRecord::Migrator.schema_migrations_table_name) if conn.table_exists?(ActiveRecord::Migrator.schema_migrations_table_name)
+ # Use shorter prefix and suffix as in Oracle database identifier cannot be larger than 30 characters
+ ActiveRecord::Base.table_name_prefix = 'p_'
+ ActiveRecord::Base.table_name_suffix = '_s'
+ conn.drop_table(ActiveRecord::Migrator.schema_migrations_table_name) if conn.table_exists?(ActiveRecord::Migrator.schema_migrations_table_name)
+
+ conn.initialize_schema_migrations_table
+
+ assert_equal "p_unique_schema_migrations_s", conn.indexes(ActiveRecord::Migrator.schema_migrations_table_name)[0][:name]
+ ensure
+ ActiveRecord::Base.table_name_prefix = ""
+ ActiveRecord::Base.table_name_suffix = ""
+ end
+ end
+ end
+end
diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb
index 3a861d887f..c155f29973 100644
--- a/activerecord/test/cases/migration_test.rb
+++ b/activerecord/test/cases/migration_test.rb
@@ -59,21 +59,12 @@ class MigrationTest < ActiveRecord::TestCase
def test_migrator_versions
migrations_path = MIGRATIONS_ROOT + "/valid"
ActiveRecord::Migrator.migrations_paths = migrations_path
- m0_path = File.join(migrations_path, "1_valid_people_have_last_names.rb")
- m0_fingerprint = Digest::MD5.hexdigest(File.read(m0_path))
ActiveRecord::Migrator.up(migrations_path)
assert_equal 3, ActiveRecord::Migrator.current_version
assert_equal 3, ActiveRecord::Migrator.last_version
assert_equal false, ActiveRecord::Migrator.needs_migration?
- rows = connection.select_all("SELECT * FROM #{connection.quote_table_name(ActiveRecord::Migrator.schema_migrations_table_name)}")
- assert_equal m0_fingerprint, rows[0]["fingerprint"]
- assert_equal "valid_people_have_last_names", rows[0]["name"]
- rows.each do |row|
- assert_match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/, row["migrated_at"].to_s, "missing migrated_at") # sometimes a String, sometimes a Time
- end
-
ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid")
assert_equal 0, ActiveRecord::Migrator.current_version
assert_equal 3, ActiveRecord::Migrator.last_version
@@ -346,7 +337,7 @@ class MigrationTest < ActiveRecord::TestCase
assert_nothing_raised {
Person.connection.create_table :binary_testings do |t|
- t.column :data, :binary, :null => false
+ t.column "data", :binary, :null => false
end
}
diff --git a/activerecord/test/cases/migrator_test.rb b/activerecord/test/cases/migrator_test.rb
index 0f0384382f..1e16addcf3 100644
--- a/activerecord/test/cases/migrator_test.rb
+++ b/activerecord/test/cases/migrator_test.rb
@@ -18,9 +18,6 @@ module ActiveRecord
def up; @went_up = true; end
def down; @went_down = true; end
- # also used in place of a MigrationProxy
- def filename; "anon.rb"; end
- def fingerprint; "123456789012345678901234567890ab"; end
end
def setup
@@ -105,7 +102,7 @@ module ActiveRecord
end
def test_finds_pending_migrations
- ActiveRecord::SchemaMigration.create!(:version => '1', :name => "anon", :migrated_at => Time.now)
+ ActiveRecord::SchemaMigration.create!(:version => '1')
migration_list = [ Migration.new('foo', 1), Migration.new('bar', 3) ]
migrations = ActiveRecord::Migrator.new(:up, migration_list).pending_migrations
@@ -155,7 +152,7 @@ module ActiveRecord
end
def test_current_version
- ActiveRecord::SchemaMigration.create!(:version => '1000', :name => "anon", :migrated_at => Time.now)
+ ActiveRecord::SchemaMigration.create!(:version => '1000')
assert_equal 1000, ActiveRecord::Migrator.current_version
end
@@ -323,7 +320,7 @@ module ActiveRecord
def test_only_loads_pending_migrations
# migrate up to 1
- ActiveRecord::SchemaMigration.create!(:version => '1', :name => "anon", :migrated_at => Time.now)
+ ActiveRecord::SchemaMigration.create!(:version => '1')
calls, migrator = migrator_class(3)
migrator.migrate("valid", nil)
diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb
index 264846eedb..7ff0044bd4 100644
--- a/activerecord/test/cases/schema_dumper_test.rb
+++ b/activerecord/test/cases/schema_dumper_test.rb
@@ -1,5 +1,6 @@
require "cases/helper"
+
class SchemaDumperTest < ActiveRecord::TestCase
def setup
super
@@ -17,15 +18,11 @@ class SchemaDumperTest < ActiveRecord::TestCase
def test_dump_schema_information_outputs_lexically_ordered_versions
versions = %w{ 20100101010101 20100201010101 20100301010101 }
versions.reverse.each do |v|
- ActiveRecord::SchemaMigration.create!(
- :version => v, :migrated_at => Time.now,
- :fingerprint => "123456789012345678901234567890ab", :name => "anon")
+ ActiveRecord::SchemaMigration.create!(:version => v)
end
schema_info = ActiveRecord::Base.connection.dump_schema_information
assert_match(/20100201010101.*20100301010101/m, schema_info)
- target_line = %q{INSERT INTO schema_migrations (version, migrated_at, fingerprint, name) VALUES ('20100101010101',CURRENT_TIMESTAMP,'123456789012345678901234567890ab','anon');}
- assert_match target_line, schema_info
end
def test_magic_comment
@@ -39,16 +36,6 @@ class SchemaDumperTest < ActiveRecord::TestCase
assert_no_match %r{create_table "schema_migrations"}, output
end
- def test_schema_dump_includes_migrations
- ActiveRecord::SchemaMigration.delete_all
- ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/always_safe")
-
- output = standard_dump
- assert_match %r{migrations do}, output, "Missing migrations block"
- assert_match %r{migration 1001, "[0-9a-f]{32}", "always_safe"}, output, "Missing migration line"
- assert_match %r{migration 1002, "[0-9a-f]{32}", "still_safe"}, output, "Missing migration line"
- end
-
def test_schema_dump_excludes_sqlite_sequence
output = standard_dump
assert_no_match %r{create_table "sqlite_sequence"}, output
diff --git a/activerecord/test/cases/schema_migration_test.rb b/activerecord/test/cases/schema_migration_test.rb
deleted file mode 100644
index 882067a7d4..0000000000
--- a/activerecord/test/cases/schema_migration_test.rb
+++ /dev/null
@@ -1,54 +0,0 @@
-require "cases/helper"
-
-class SchemaMigrationTest < ActiveRecord::TestCase
- def sm_table_name
- ActiveRecord::SchemaMigration.table_name
- end
-
- def connection
- ActiveRecord::Base.connection
- end
-
- def test_add_schema_info_respects_prefix_and_suffix
- connection.drop_table(sm_table_name) if connection.table_exists?(sm_table_name)
- # Use shorter prefix and suffix as in Oracle database identifier cannot be larger than 30 characters
- ActiveRecord::Base.table_name_prefix = 'p_'
- ActiveRecord::Base.table_name_suffix = '_s'
- connection.drop_table(sm_table_name) if connection.table_exists?(sm_table_name)
-
- ActiveRecord::SchemaMigration.create_table
-
- assert_equal "p_unique_schema_migrations_s", connection.indexes(sm_table_name)[0][:name]
- ensure
- ActiveRecord::Base.table_name_prefix = ""
- ActiveRecord::Base.table_name_suffix = ""
- end
-
- def test_add_metadata_columns_to_exisiting_schema_migrations
- # creates the old table schema from pre-Rails4.0, so we can test adding to it below
- if connection.table_exists?(sm_table_name)
- connection.drop_table(sm_table_name)
- end
- connection.create_table(sm_table_name, :id => false) do |schema_migrations_table|
- schema_migrations_table.column("version", :string, :null => false)
- end
-
- connection.insert "INSERT INTO #{connection.quote_table_name(sm_table_name)} (version) VALUES (100)"
- connection.insert "INSERT INTO #{connection.quote_table_name(sm_table_name)} (version) VALUES (200)"
-
- ActiveRecord::SchemaMigration.create_table
-
- rows = connection.select_all("SELECT * FROM #{connection.quote_table_name(sm_table_name)}")
- assert rows[0].has_key?("migrated_at"), "missing column `migrated_at`"
- assert_match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/, rows[0]["migrated_at"].to_s) # sometimes a String, sometimes a Time
- assert rows[0].has_key?("fingerprint"), "missing column `fingerprint`"
- assert rows[0].has_key?("name"), "missing column `name`"
- end
-
- def test_schema_migrations_columns
- ActiveRecord::SchemaMigration.create_table
-
- columns = connection.columns(sm_table_name).collect(&:name)
- %w[version migrated_at fingerprint name].each { |col| assert columns.include?(col), "missing column `#{col}`" }
- end
-end
diff --git a/activerecord/test/migrations/always_safe/1001_always_safe.rb b/activerecord/test/migrations/always_safe/1001_always_safe.rb
deleted file mode 100644
index 454b972507..0000000000
--- a/activerecord/test/migrations/always_safe/1001_always_safe.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-class AlwaysSafe < ActiveRecord::Migration
- def change
- # do nothing to avoid side-effect conflicts from running multiple times
- end
-end
diff --git a/activerecord/test/migrations/always_safe/1002_still_safe.rb b/activerecord/test/migrations/always_safe/1002_still_safe.rb
deleted file mode 100644
index 7398ae27a2..0000000000
--- a/activerecord/test/migrations/always_safe/1002_still_safe.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-class StillSafe < ActiveRecord::Migration
- def change
- # do nothing to avoid side-effect conflicts from running multiple times
- end
-end