require File.expand_path("#{File.dirname(__FILE__)}/../test_helper") class SchemaStatementsTest < Test::Unit::TestCase def test_plugin_schema_info_table_should_not_exist_by_default assert !PluginSchemaInfo.table_exists? end def test_should_create_plugin_schema_info_table_when_initialized initialize_schema_information assert PluginSchemaInfo.table_exists? end def test_should_not_dump_anything_if_no_main_or_plugin_schema_info assert_equal '', ActiveRecord::Base.connection.dump_schema_information end def test_should_not_dump_anything_if_schema_or_plugin_is_at_version_zero initialize_schema_information PluginSchemaInfo.create(:plugin_name => 'test_plugin', :version => 0) assert_equal '', ActiveRecord::Base.connection.dump_schema_information end def test_should_dump_schema_info_for_one_plugin initialize_schema_information PluginSchemaInfo.create(:plugin_name => 'test_plugin', :version => 1) assert_equal "INSERT INTO plugin_schema_info (plugin_name, version) VALUES ('test_plugin', 1)", ActiveRecord::Base.connection.dump_schema_information end def test_should_dump_schema_info_for_multiple_plugins initialize_schema_information PluginSchemaInfo.create(:plugin_name => 'test_plugin', :version => 1) PluginSchemaInfo.create(:plugin_name => 'another_plugin', :version => 2) expected = [ "INSERT INTO plugin_schema_info (plugin_name, version) VALUES ('test_plugin', 1);", "INSERT INTO plugin_schema_info (plugin_name, version) VALUES ('another_plugin', 2)" ].join("\n") assert_equal expected, ActiveRecord::Base.connection.dump_schema_information end def test_should_dump_both_main_schema_info_and_plugin_schema_info initialize_schema_information ActiveRecord::Base.connection.update("UPDATE #{ActiveRecord::Migrator.schema_info_table_name} SET version = 1") PluginSchemaInfo.create(:plugin_name => 'test_plugin', :version => 1) expected = [ 'INSERT INTO schema_info (version) VALUES (1);', "INSERT INTO plugin_schema_info (plugin_name, version) VALUES ('test_plugin', 1)" ].join("\n") assert_equal expected, ActiveRecord::Base.connection.dump_schema_information end def test_should_dump_only_main_schema_info_if_no_plugins_migrated initialize_schema_information ActiveRecord::Base.connection.update("UPDATE #{ActiveRecord::Migrator.schema_info_table_name} SET version = 1") assert_equal 'INSERT INTO schema_info (version) VALUES (1)', ActiveRecord::Base.connection.dump_schema_information end def teardown ActiveRecord::Base.connection.drop_table(SchemaInfo.table_name) if SchemaInfo.table_exists? ActiveRecord::Base.connection.drop_table(PluginSchemaInfo.table_name) if PluginSchemaInfo.table_exists? end end