Skip to content

Commit

Permalink
Merge pull request #49859 from zzak/railties-schema-cache-dump-check-…
Browse files Browse the repository at this point in the history
…errors

Cover railties check_schema_cache_dump_version errors
  • Loading branch information
byroot committed Oct 31, 2023
2 parents cb185fc + 0803589 commit 5a47bb8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
31 changes: 31 additions & 0 deletions railties/test/application/rake/dbs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,37 @@ def db_schema_cache_dump
end
end

test "db:schema:cache:dump ignores expired version" do
Dir.chdir(app_path) do
rails "generate", "model", "book", "title:string"
rails "db:schema:cache:dump"
rails "generate", "model", "cat", "color:string"
rails "db:migrate"

expired_warning = capture(:stderr) do
cache_size = rails("runner", "p ActiveRecord::Base.connection.schema_cache.size", stderr: true).strip
assert_equal "0", cache_size
end
assert_match(/Ignoring .*\.yml because it has expired/, expired_warning)
end
end

test "db:schema:cache:dump ignores validation errors" do
Dir.chdir(app_path) do
rails "generate", "model", "book", "title:string"
rails "db:migrate"
rails "db:schema:cache:dump"

ActiveRecord::Migrator.stub(:current_version, -> { raise ActiveRecord::ActiveRecordError, "stubbed error" }) do
validation_warning = capture(:stderr) do
cache_tables = rails("runner", "p ActiveRecord::Base.connection.schema_cache.columns('books')", stderr: true).strip
assert_includes cache_tables, "title", "expected cache_tables to include a title entry"
end
assert_match(/Failed to validate the schema cache because of ActiveRecord::ActiveRecordError: stubbed error/, validation_warning)
end
end
end

def db_fixtures_load(expected_database)
Dir.chdir(app_path) do
rails "generate", "model", "book", "title:string"
Expand Down
7 changes: 5 additions & 2 deletions railties/test/application/rake/multi_dbs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -822,8 +822,11 @@ class TwoMigration < ActiveRecord::Migration::Current
cache_tables_a = rails("runner", "p ActiveRecord::Base.connection.schema_cache.columns('books')").strip
assert_includes cache_tables_a, "title", "expected cache_tables_a to include a title entry"

cache_size_b = rails("runner", "p AnimalsBase.connection.schema_cache.size", stderr: true).strip
assert_equal "0", cache_size_b
expired_warning = capture(:stderr) do
cache_size_b = rails("runner", "p AnimalsBase.connection.schema_cache.size", stderr: true).strip
assert_equal "0", cache_size_b
end
assert_match(/Ignoring .*\.yml because it has expired/, expired_warning)

cache_tables_b = rails("runner", "p AnimalsBase.connection.schema_cache.columns('dogs')").strip
assert_includes cache_tables_b, "name", "expected cache_tables_b to include a name entry"
Expand Down

0 comments on commit 5a47bb8

Please sign in to comment.