diff options
author | Wojciech Wnętrzak <w.wnetrzak@gmail.com> | 2014-06-01 17:41:04 +0200 |
---|---|---|
committer | Wojciech Wnętrzak <w.wnetrzak@gmail.com> | 2014-06-12 13:08:56 +0200 |
commit | ad42aaed04a6098732105c12c853bc912ee5cadd (patch) | |
tree | f5c0e595888cb97038ed5b3804f3fca5c1eb64bf /railties/test/application | |
parent | df6dc1b51a95947f26e35edda9005f0b2a2e7df7 (diff) | |
download | rails-ad42aaed04a6098732105c12c853bc912ee5cadd.tar.gz rails-ad42aaed04a6098732105c12c853bc912ee5cadd.tar.bz2 rails-ad42aaed04a6098732105c12c853bc912ee5cadd.zip |
Fixed automatic maintaining test schema to properly handle sql structure schema format.
Additionally:
* It changes `purge` task on `sqlite3` adapter to recreate database file, to
be consistent with other adapters.
* Adds `purge` step when loading from `schema.rb`
Diffstat (limited to 'railties/test/application')
-rw-r--r-- | railties/test/application/test_test.rb | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/railties/test/application/test_test.rb b/railties/test/application/test_test.rb index d3ea8ebc72..c724c867ec 100644 --- a/railties/test/application/test_test.rb +++ b/railties/test/application/test_test.rb @@ -125,12 +125,12 @@ module ApplicationTests assert_unsuccessful_run "models/user_test.rb", "Migrations are pending" - app_file 'db/structure.sql', <<-RUBY + app_file 'db/structure.sql', <<-SQL CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL); CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version"); CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)); INSERT INTO schema_migrations (version) VALUES ('#{version}'); - RUBY + SQL app_file 'config/initializers/disable_maintain_test_schema.rb', <<-RUBY Rails.application.config.active_record.maintain_test_schema = false @@ -143,6 +143,56 @@ module ApplicationTests assert_successful_test_run('models/user_test.rb') end + test "sql structure migrations when adding column to existing table" do + output_1 = script('generate model user name:string') + version_1 = output_1.match(/(\d+)_create_users\.rb/)[1] + + app_file 'test/models/user_test.rb', <<-RUBY + require 'test_helper' + class UserTest < ActiveSupport::TestCase + test "user" do + User.create! name: "Jon" + end + end + RUBY + + app_file 'config/initializers/enable_sql_schema_format.rb', <<-RUBY + Rails.application.config.active_record.schema_format = :sql + RUBY + + app_file 'db/structure.sql', <<-SQL + CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL); + CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version"); + CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)); + INSERT INTO schema_migrations (version) VALUES ('#{version_1}'); + SQL + + assert_successful_test_run('models/user_test.rb') + + output_2 = script('generate migration add_email_to_users') + version_2 = output_2.match(/(\d+)_add_email_to_users\.rb/)[1] + + app_file 'test/models/user_test.rb', <<-RUBY + require 'test_helper' + + class UserTest < ActiveSupport::TestCase + test "user" do + User.create! name: "Jon", email: "jon@doe.com" + end + end + RUBY + + app_file 'db/structure.sql', <<-SQL + CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL); + CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version"); + CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "email" varchar(255)); + INSERT INTO schema_migrations (version) VALUES ('#{version_1}'); + INSERT INTO schema_migrations (version) VALUES ('#{version_2}'); + SQL + + assert_successful_test_run('models/user_test.rb') + end + private def assert_unsuccessful_run(name, message) result = run_test_file(name) |