class ApplicationTests::RakeTests::RakeDbsTest
Public Instance Methods
database_url_db_name()
click to toggle source
# File railties/test/application/rake/dbs_test.rb, line 19 def database_url_db_name "db/database_url_db.sqlite3" end
db_create_and_drop(expected_database)
click to toggle source
# File railties/test/application/rake/dbs_test.rb, line 29 def db_create_and_drop(expected_database) Dir.chdir(app_path) do output = `bin/quails db:create` assert_match(/Created database/, output) assert File.exist?(expected_database) assert_equal expected_database, ActiveRecord::Base.connection_config[:database] output = `bin/quails db:drop` assert_match(/Dropped database/, output) assert !File.exist?(expected_database) end end
db_fixtures_load(expected_database)
click to toggle source
# File railties/test/application/rake/dbs_test.rb, line 143 def db_fixtures_load(expected_database) Dir.chdir(app_path) do `bin/quails generate model book title:string; bin/quails db:migrate db:fixtures:load` assert_match expected_database, ActiveRecord::Base.connection_config[:database] require "#{app_path}/app/models/book" assert_equal 2, Book.count end end
db_migrate_and_status(expected_database)
click to toggle source
# File railties/test/application/rake/dbs_test.rb, line 104 def db_migrate_and_status(expected_database) Dir.chdir(app_path) do `bin/quails generate model book title:string; bin/quails db:migrate` output = `bin/quails db:migrate:status` assert_match(%r{database:\s+\S*#{Regexp.escape(expected_database)}}, output) assert_match(/up\s+\d{14}\s+Create books/, output) end end
db_schema_dump()
click to toggle source
# File railties/test/application/rake/dbs_test.rb, line 125 def db_schema_dump Dir.chdir(app_path) do `bin/quails generate model book title:string; bin/quails db:migrate db:schema:dump` schema_dump = File.read("db/schema.rb") assert_match(/create_table \"books\"/, schema_dump) end end
db_structure_dump_and_load(expected_database)
click to toggle source
# File railties/test/application/rake/dbs_test.rb, line 174 def db_structure_dump_and_load(expected_database) Dir.chdir(app_path) do `bin/quails generate model book title:string; bin/quails db:migrate db:structure:dump` structure_dump = File.read("db/structure.sql") assert_match(/CREATE TABLE (?:IF NOT EXISTS )?\"books\"/, structure_dump) `bin/quails environment db:drop db:structure:load` assert_match expected_database, ActiveRecord::Base.connection_config[:database] require "#{app_path}/app/models/book" #if structure is not loaded correctly, exception would be raised assert_equal 0, Book.count end end
db_test_load_structure()
click to toggle source
# File railties/test/application/rake/dbs_test.rb, line 271 def db_test_load_structure Dir.chdir(app_path) do `bin/quails generate model book title:string; bin/quails db:migrate db:structure:dump db:test:load_structure` ActiveRecord::Base.configurations = Quails.application.config.database_configuration ActiveRecord::Base.establish_connection :test require "#{app_path}/app/models/book" #if structure is not loaded correctly, exception would be raised assert_equal 0, Book.count assert_match ActiveRecord::Base.configurations["test"]["database"], ActiveRecord::Base.connection_config[:database] end end
set_database_url()
click to toggle source
# File railties/test/application/rake/dbs_test.rb, line 23 def set_database_url ENV["DATABASE_URL"] = "sqlite3:#{database_url_db_name}" # ensure it's using the DATABASE_URL FileUtils.rm_rf("#{app_path}/config/database.yml") end
setup()
click to toggle source
# File railties/test/application/rake/dbs_test.rb, line 10 def setup build_app FileUtils.rm_rf("#{app_path}/config/environments") end
teardown()
click to toggle source
# File railties/test/application/rake/dbs_test.rb, line 15 def teardown teardown_app end
with_bad_permissions() { || ... }
click to toggle source
# File railties/test/application/rake/dbs_test.rb, line 69 def with_bad_permissions Dir.chdir(app_path) do set_database_url FileUtils.chmod("-w", "db") yield FileUtils.chmod("+w", "db") end end
with_database_existing() { || ... }
click to toggle source
# File railties/test/application/rake/dbs_test.rb, line 52 def with_database_existing Dir.chdir(app_path) do set_database_url `bin/quails db:create` yield `bin/quails db:drop` end end