1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Revert "Merge pull request #15394 from morgoth/fix-automatic-maintaining-test-schema-for-sql-format"

This reverts commit 46139d33c0, reversing
changes made to 8f247871bb.

Conflicts:
	activerecord/CHANGELOG.md
This commit is contained in:
Rafael Mendonça França 2014-07-02 09:41:52 -03:00
parent 4cb4e87b93
commit 5c87b5c524
4 changed files with 3 additions and 105 deletions

View file

@ -128,14 +128,7 @@
Serialized attributes on ActiveRecord models will no longer save when Serialized attributes on ActiveRecord models will no longer save when
unchanged. Fixes #8328. unchanged. Fixes #8328.
Sean Griffin *Sean Griffin*
* Fixed automatic maintaining test schema to properly handle sql structure
schema format.
Fixes #15394.
*Wojciech Wnętrzak*
* Pluck now works when selecting columns from different tables with the same * Pluck now works when selecting columns from different tables with the same
name. name.

View file

@ -176,12 +176,10 @@ module ActiveRecord
when :ruby when :ruby
file ||= File.join(db_dir, "schema.rb") file ||= File.join(db_dir, "schema.rb")
check_schema_file(file) check_schema_file(file)
purge(current_config)
load(file) load(file)
when :sql when :sql
file ||= File.join(db_dir, "structure.sql") file ||= File.join(db_dir, "structure.sql")
check_schema_file(file) check_schema_file(file)
purge(current_config)
structure_load(current_config, file) structure_load(current_config, file)
else else
raise ArgumentError, "unknown format #{format.inspect}" raise ArgumentError, "unknown format #{format.inspect}"

View file

@ -21,11 +21,7 @@ module ActiveRecord
FileUtils.rm(file) if File.exist?(file) FileUtils.rm(file) if File.exist?(file)
end end
alias :purge :drop
def purge
drop
create
end
def charset def charset
connection.encoding connection.encoding

View file

@ -67,7 +67,7 @@ module ApplicationTests
assert_match %r{/app/test/unit/failing_test\.rb}, output assert_match %r{/app/test/unit/failing_test\.rb}, output
end end
test "ruby schema migrations" do test "migrations" do
output = script('generate model user name:string') output = script('generate model user name:string')
version = output.match(/(\d+)_create_users\.rb/)[1] version = output.match(/(\d+)_create_users\.rb/)[1]
@ -104,95 +104,6 @@ module ApplicationTests
assert !result.include?("create_table(:users)") assert !result.include?("create_table(:users)")
end end
test "sql structure migrations" do
output = script('generate model user name:string')
version = output.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 'db/structure.sql', ''
app_file 'config/initializers/enable_sql_schema_format.rb', <<-RUBY
Rails.application.config.active_record.schema_format = :sql
RUBY
assert_unsuccessful_run "models/user_test.rb", "Migrations are pending"
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}');
SQL
app_file 'config/initializers/disable_maintain_test_schema.rb', <<-RUBY
Rails.application.config.active_record.maintain_test_schema = false
RUBY
assert_unsuccessful_run "models/user_test.rb", "Could not find table 'users'"
File.delete "#{app_path}/config/initializers/disable_maintain_test_schema.rb"
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 private
def assert_unsuccessful_run(name, message) def assert_unsuccessful_run(name, message)
result = run_test_file(name) result = run_test_file(name)