From 0150a212c068c6e4a580218913f44f278e086bd3 Mon Sep 17 00:00:00 2001 From: kennyj Date: Thu, 1 Mar 2012 01:01:12 +0900 Subject: Add db:schema:cache:dump and db:schema:cache:clear tasks. --- railties/test/application/rake_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'railties/test/application') diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index ff12b3e9fc..9515e40b6e 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -138,5 +138,24 @@ module ApplicationTests end assert File.exists?(File.join(app_path, 'db', 'my_structure.sql')) end + + def test_rake_dump_schema_cache + Dir.chdir(app_path) do + `rails generate model post title:string` + `rails generate model product name:string` + `bundle exec rake db:migrate` + `bundle exec rake db:schema:cache:dump` + end + assert File.exists?(File.join(app_path, 'db', 'schema_cache.dump')) + end + + def test_rake_clear_schema_cache + Dir.chdir(app_path) do + `bundle exec rake db:schema:cache:dump` + `bundle exec rake db:schema:cache:clear` + end + assert !File.exists?(File.join(app_path, 'db', 'schema_cache.dump')) + end + end end -- cgit v1.2.3 From 0da12df2608969330bd47c543866f79ff8ca9edd Mon Sep 17 00:00:00 2001 From: kennyj Date: Thu, 1 Mar 2012 01:13:14 +0900 Subject: Load db/schema_cache.dump duaring boot time. --- railties/test/application/initializers/frameworks_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'railties/test/application') diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb index 8812685620..d8012eed64 100644 --- a/railties/test/application/initializers/frameworks_test.rb +++ b/railties/test/application/initializers/frameworks_test.rb @@ -193,5 +193,17 @@ module ApplicationTests require "#{app_path}/config/environment" assert_nil defined?(ActiveRecord::Base) end + + test "use schema cache dump" do + Dir.chdir(app_path) do + `rails generate model post title:string` + `bundle exec rake db:migrate` + `bundle exec rake db:schema:cache:dump` + end + require "#{app_path}/config/environment" + ActiveRecord::Base.connection.drop_table("posts") # force drop posts table for test. + assert ActiveRecord::Base.connection.schema_cache.tables["posts"] + end + end end -- cgit v1.2.3 From 5cbba30a1292dde9c83ab42287c2a1f38f3fcc44 Mon Sep 17 00:00:00 2001 From: kennyj Date: Thu, 1 Mar 2012 01:19:27 +0900 Subject: Support judgement expired schema cache dump. --- railties/test/application/initializers/frameworks_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'railties/test/application') diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb index d8012eed64..a0e88cd0f0 100644 --- a/railties/test/application/initializers/frameworks_test.rb +++ b/railties/test/application/initializers/frameworks_test.rb @@ -205,5 +205,19 @@ module ApplicationTests assert ActiveRecord::Base.connection.schema_cache.tables["posts"] end + test "expire schema cache dump" do + Dir.chdir(app_path) do + `rails generate model post title:string` + `bundle exec rake db:migrate` + `bundle exec rake db:schema:cache:dump` + + `bundle exec rake db:rollback` + end + silence_warnings { + require "#{app_path}/config/environment" + assert !ActiveRecord::Base.connection.schema_cache.tables["posts"] + } + end + end end -- cgit v1.2.3