plugin_migrations 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/CHANGELOG +57 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README +98 -0
  4. data/Rakefile +80 -0
  5. data/init.rb +1 -0
  6. data/lib/plugin_migrations.rb +27 -0
  7. data/lib/plugin_migrations/extensions/plugin.rb +61 -0
  8. data/lib/plugin_migrations/extensions/schema_statements.rb +53 -0
  9. data/lib/plugin_migrations/migrator.rb +38 -0
  10. data/tasks/plugin_migrations_tasks.rake +18 -0
  11. data/test/app_root/app/models/article.rb +4 -0
  12. data/test/app_root/app/models/author.rb +3 -0
  13. data/test/app_root/app/models/comment.rb +3 -0
  14. data/test/app_root/app/models/company.rb +3 -0
  15. data/test/app_root/app/models/employee.rb +3 -0
  16. data/test/app_root/app/models/plugin_schema_info.rb +3 -0
  17. data/test/app_root/app/models/schema_info.rb +3 -0
  18. data/test/app_root/config/environment.rb +25 -0
  19. data/test/app_root/db_bak/migrate/001_migrate_plugin_with_migrations_to_version_2.rb +9 -0
  20. data/test/app_root/db_bak/migrate/002_migrate_second_plugin_with_migrations_to_version_1.rb +9 -0
  21. data/test/app_root/vendor/plugins/plugin_with_migrations/db/migrate/001_create_companies.rb +11 -0
  22. data/test/app_root/vendor/plugins/plugin_with_migrations/db/migrate/002_create_employees.rb +13 -0
  23. data/test/app_root/vendor/plugins/plugin_with_migrations/init.rb +0 -0
  24. data/test/app_root/vendor/plugins/plugin_with_migrations/test/fixtures/companies.yml +3 -0
  25. data/test/app_root/vendor/plugins/plugin_with_migrations/test/fixtures/employees.yml +11 -0
  26. data/test/app_root/vendor/plugins/plugin_with_no_db/init.rb +0 -0
  27. data/test/app_root/vendor/plugins/plugin_with_no_migrations/db/empty +0 -0
  28. data/test/app_root/vendor/plugins/plugin_with_no_migrations/init.rb +0 -0
  29. data/test/app_root/vendor/plugins/second_plugin_with_migrations/db/migrate/001_create_authors.rb +11 -0
  30. data/test/app_root/vendor/plugins/second_plugin_with_migrations/db/migrate/002_create_articles.rb +13 -0
  31. data/test/app_root/vendor/plugins/second_plugin_with_migrations/db/migrate/003_create_comments.rb +12 -0
  32. data/test/app_root/vendor/plugins/second_plugin_with_migrations/init.rb +0 -0
  33. data/test/app_root/vendor/plugins/second_plugin_with_migrations/test/fixtures/articles.yml +5 -0
  34. data/test/app_root/vendor/plugins/second_plugin_with_migrations/test/fixtures/authors.yml +7 -0
  35. data/test/functional/plugin_migration_generator_test.rb +82 -0
  36. data/test/test_helper.rb +10 -0
  37. data/test/unit/migrator_test.rb +59 -0
  38. data/test/unit/plugin_migrations_test.rb +158 -0
  39. data/test/unit/plugin_test.rb +113 -0
  40. data/test/unit/schema_statements_test.rb +63 -0
  41. metadata +84 -0
data/CHANGELOG ADDED
@@ -0,0 +1,57 @@
1
+ *SVN*
2
+
3
+ *0.1.2* (September 28th, 2007)
4
+
5
+ * Fix Plugin#current_version failing if the plugin_schema_info table doesn't exist
6
+
7
+ * Add functional tests for plugin_migration generator
8
+
9
+ * Don't loop over plugins for self.down in generated plugin_migration
10
+
11
+ *0.1.1* (September 26th, 2007)
12
+
13
+ * Fix copyright to include proper credits
14
+
15
+ * Add plugin_migration generator
16
+
17
+ * Move SchemaStatements/Plugin extensions into separate modules rather than modifying the modules/classes directly
18
+
19
+ * Adopt Engines-style plugin migrations
20
+
21
+ * Use plugin_test_helper for testing
22
+
23
+ * Remove gem dependency on activerecord
24
+
25
+ * Convert dos newlines to unix newlines
26
+
27
+ * Fix README typo: db/migrations -> db/migrate
28
+
29
+ * Add proper terminator character at the end of statements produced when dumping schema information. Fixes #16
30
+
31
+ *0.1.0* (March 31st, 2007)
32
+
33
+ * Refactor plugin_migrations.rb into files specific to each class being extended
34
+
35
+ * Support running tests with plugins loaded via edge pluginaweek. Fixes #10 [Brian Takita]
36
+
37
+ * Updated to use the new Plugin interface
38
+
39
+ * Added empty files so that test directories get added to the gem
40
+
41
+ *0.0.2* (February 3rd, 2007)
42
+
43
+ * Released as a gem
44
+
45
+ * Added tests
46
+
47
+ * Refactored tasks so that they could be tested
48
+
49
+ * You can now specify PLUGINS and VERSION at the same time in the migration task
50
+
51
+ * You can now specify PLUGINS and FIXTURES at the same time in the fixtures task
52
+
53
+ * The plugin_migrations plugin doesn't access the LOADED_PLUGINS variable correctly (Peter Marklund).
54
+
55
+ *0.0.1* (November 5th, 2006)
56
+
57
+ * Initial release
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2006 James Adam, 2006-2007 Aaron Pfeifer & Neil Abraham
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,98 @@
1
+ = plugin_migrations
2
+
3
+ +plugin_migrations+ adds support for plugin-based migrations.
4
+
5
+ == Resources
6
+
7
+ Announcement
8
+
9
+ * http://www.pluginaweek.org/2006/11/05/3-plugin_migrations-where-have-all-the-migrations-gone
10
+
11
+ Wiki
12
+
13
+ * http://wiki.pluginaweek.org/Plugin_migrations
14
+
15
+ API
16
+
17
+ * http://api.pluginaweek.org/plugin_migrations
18
+
19
+ Development
20
+
21
+ * http://dev.pluginaweek.org/browser/trunk/plugins/active_record/migrations/plugin_migrations
22
+
23
+ Source
24
+
25
+ * http://svn.pluginaweek.org/trunk/plugins/active_record/migrations/plugin_migrations
26
+
27
+ == Description
28
+
29
+ In addition to the normal schema_info table that Rails created in your database
30
+ to keep track of the current migration version, this plugin adds a new table
31
+ called plugin_schema_info:
32
+
33
+ plugin_schema_info
34
+ ------------------
35
+ plugin_name (string)
36
+ version (integer)
37
+
38
+ Plugin migrations expects the migrations to be located in a similar directory
39
+ structure as that of your Rails application. That is, it would look in
40
+ /db/migrate in your plugin's folder.
41
+
42
+ == Usage
43
+
44
+ The plugin can be used via the new rake tasks that have been added. The plugins
45
+ which are migrated are based on what is stored in +Rails.plugins+. For more
46
+ information on this attributes, see the loaded_plugins[http://wiki.pluginaweek.org/Loaded_plugins] plugin.
47
+
48
+ === db:migrate:plugins
49
+
50
+ Running <tt>db:migrate:plugins</tt> will run the migrations for every plugin that is
51
+ loaded. You can also specify exactly which plugin you want to migrate.
52
+
53
+ Examples:
54
+
55
+ Assuming the following directory structure:
56
+
57
+ vendor/
58
+ vendor/plugins/
59
+ vendor/plugins/acts_as_bunny/
60
+ vendor/plugins/acts_as_as_chicken/
61
+
62
+ rake db:migrate:plugins # Migrates both acts_as_bunny and acts_as_chicken
63
+ rake db:migrate:plugins PLUGIN=acts_as_bunny
64
+ rake db:migrate:plugins PLUGIN=acts_as_bunny VERSION=2
65
+
66
+ === db:fixtures:load:plugins
67
+
68
+ Running <tt>db:fixtures:load:plugins</tt> will load the fixtures for every plugin that is
69
+ loaded. You can also specify exactly which plugin you want to load fixtures for.
70
+
71
+ Examples:
72
+
73
+ Assuming the following directory structure:
74
+
75
+ vendor/
76
+ vendor/plugins/
77
+ vendor/plugins/acts_as_bunny/
78
+ vendor/plugins/acts_as_as_chicken/
79
+
80
+ rake db:fixtures:load:plugins # Loads fixtures for both acts_as_bunny and acts_as_chicken
81
+ rake db:fixtures:load:plugins PLUGIN=acts_as_bunny
82
+ rake db:fixtures:load:plugins PLUGIN=acts_as_bunny FIXTURES=bunnies
83
+ rake db:fixtures:load:plugins PLUGIN=acts_as_bunny FIXTURES=bunnies,rabbits
84
+
85
+ == Testing
86
+
87
+ Before you can run any tests, the following gems must be installed:
88
+ * plugin_test_helper[http://wiki.pluginaweek.org/Plugin_test_helper]
89
+
90
+ == Dependencies
91
+
92
+ This plugin dependencies on the presence of the following plugins:
93
+ * loaded_plugins[http://wiki.pluginaweek.org/Loaded_plugins]
94
+ * plugin_dependencies[http://wiki.pluginaweek.org/Plugin_dependencies]
95
+
96
+ == References
97
+
98
+ * James Adam - Engines[http://www.rails-engines.org]
data/Rakefile ADDED
@@ -0,0 +1,80 @@
1
+ require 'rake/testtask'
2
+ require 'rake/rdoctask'
3
+ require 'rake/gempackagetask'
4
+ require 'rake/contrib/sshpublisher'
5
+
6
+ PKG_NAME = 'plugin_migrations'
7
+ PKG_VERSION = '0.1.2'
8
+ PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
9
+ RUBY_FORGE_PROJECT = 'pluginaweek'
10
+
11
+ desc 'Default: run unit tests.'
12
+ task :default => :test
13
+
14
+ desc 'Test the plugin_migrations plugin.'
15
+ Rake::TestTask.new(:test) do |t|
16
+ t.libs << 'lib'
17
+ t.pattern = 'test/**/*_test.rb'
18
+ t.verbose = true
19
+ end
20
+
21
+ desc 'Generate documentation for the plugin_migrations plugin.'
22
+ Rake::RDocTask.new(:rdoc) do |rdoc|
23
+ rdoc.rdoc_dir = 'rdoc'
24
+ rdoc.title = 'PluginMigrations'
25
+ rdoc.options << '--line-numbers' << '--inline-source'
26
+ rdoc.rdoc_files.include('README')
27
+ rdoc.rdoc_files.include('lib/**/*.rb')
28
+ end
29
+
30
+ spec = Gem::Specification.new do |s|
31
+ s.name = PKG_NAME
32
+ s.version = PKG_VERSION
33
+ s.platform = Gem::Platform::RUBY
34
+ s.summary = 'Adds support for plugin-based migrations'
35
+
36
+ s.files = FileList['{lib,tasks,test}/**/*'].to_a + %w(CHANGELOG init.rb MIT-LICENSE Rakefile README)
37
+ s.require_path = 'lib'
38
+ s.autorequire = 'plugin_migrations'
39
+ s.has_rdoc = true
40
+ s.test_files = Dir['test/**/*_test.rb']
41
+ s.add_dependency 'loaded_plugins', '>= 0.1.0'
42
+
43
+ s.author = 'Aaron Pfeifer, Neil Abraham'
44
+ s.email = 'info@pluginaweek.org'
45
+ s.homepage = 'http://www.pluginaweek.org'
46
+ end
47
+
48
+ Rake::GemPackageTask.new(spec) do |p|
49
+ p.gem_spec = spec
50
+ p.need_tar = true
51
+ p.need_zip = true
52
+ end
53
+
54
+ desc 'Publish the beta gem'
55
+ task :pgem => [:package] do
56
+ Rake::SshFilePublisher.new('pluginaweek@pluginaweek.org', '/home/pluginaweek/gems.pluginaweek.org/gems', 'pkg', "#{PKG_FILE_NAME}.gem").upload
57
+ end
58
+
59
+ desc 'Publish the API documentation'
60
+ task :pdoc => [:rdoc] do
61
+ Rake::SshDirPublisher.new('pluginaweek@pluginaweek.org', "/home/pluginaweek/api.pluginaweek.org/#{PKG_NAME}", 'rdoc').upload
62
+ end
63
+
64
+ desc 'Publish the API docs and gem'
65
+ task :publish => [:pdoc, :release]
66
+
67
+ desc 'Publish the release files to RubyForge.'
68
+ task :release => [:gem, :package] do
69
+ require 'rubyforge'
70
+
71
+ ruby_forge = RubyForge.new
72
+ ruby_forge.login
73
+
74
+ %w( gem tgz zip ).each do |ext|
75
+ file = "pkg/#{PKG_FILE_NAME}.#{ext}"
76
+ puts "Releasing #{File.basename(file)}..."
77
+
78
+ ruby_forge.add_release(RUBY_FORGE_PROJECT, PKG_NAME, PKG_VERSION, file)
79
+ end
80
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'plugin_migrations'
@@ -0,0 +1,27 @@
1
+ require 'loaded_plugins'
2
+ require 'plugin_migrations/extensions/plugin'
3
+ require 'plugin_migrations/extensions/schema_statements'
4
+ require 'plugin_migrations/migrator'
5
+
6
+ module PluginAWeek #:nodoc:
7
+ # Adds support for running migrations and loading fixtures from plugins
8
+ module PluginMigrations
9
+ class << self
10
+ # Migrate the database through scripts in plugin_xyz/db/migrate. Specify
11
+ # target plugins through plugin_names. The version can only be used when
12
+ # targeting specific plugins.
13
+ def migrate(plugin_names = nil, version = nil)
14
+ version = version.to_i if version
15
+ Rails.plugins.find_by_names(plugin_names).each {|plugin| plugin.migrate(version)}
16
+ end
17
+
18
+ # Load plugin fixtures into the current environment's database. Load
19
+ # fixtures for a specific plugin using +plugin_names+, specific fixtures
20
+ # using +fixtures+
21
+ def load_fixtures(plugin_names = nil, fixtures = nil)
22
+ require 'active_record/fixtures'
23
+ Rails.plugins.find_by_names(plugin_names).each {|plugin| plugin.load_fixtures(fixtures)}
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,61 @@
1
+ module PluginAWeek #:nodoc:
2
+ module PluginMigrations
3
+ module Extensions #:nodoc:
4
+ # Adds migration/fixture support
5
+ module Plugin
6
+ # The location of the plugin's migrations
7
+ def migration_path
8
+ "#{root}/db/migrate"
9
+ end
10
+
11
+ # The current version of the plugin migrated in the database
12
+ def current_version
13
+ begin
14
+ if result = ActiveRecord::Base.connection.select_one("SELECT version FROM #{PluginAWeek::PluginMigrations::Migrator.schema_info_table_name} WHERE plugin_name = '#{name}'")
15
+ result['version'].to_i
16
+ else
17
+ # There probably isn't an entry for this plugin in the migration info table.
18
+ 0
19
+ end
20
+ rescue ActiveRecord::StatementInvalid
21
+ # No migraiton info table, so never migrated
22
+ 0
23
+ end
24
+ end
25
+
26
+ # The latest version of the plugin according to the current migrations
27
+ def latest_version
28
+ migrations = Dir["#{migration_path}/[0-9]*_[_a-z0-9]*.rb"]
29
+ migrations.map {|migration| File.basename(migration).match(/^([0-9]+)/)[1].to_i}.max || 0
30
+ end
31
+
32
+ # Migrate this plugin to the given version
33
+ def migrate(version = nil)
34
+ PluginAWeek::PluginMigrations::Migrator.migrate_plugin(self, version)
35
+ end
36
+
37
+ # The location of the plugin's fixtures
38
+ def fixtures_path
39
+ "#{root}/test/fixtures"
40
+ end
41
+
42
+ # The paths of all of the plugin's fixtures
43
+ def fixtures(names = nil)
44
+ names ||= '*'
45
+ Dir["#{fixtures_path}/{#{names}}.{yml,csv}"].sort
46
+ end
47
+
48
+ # Loads the fixtures for the plugin
49
+ def load_fixtures(*args)
50
+ fixtures(*args).each do |fixture|
51
+ Fixtures.create_fixtures(File.dirname(fixture), File.basename(fixture, '.*'))
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ Plugin.class_eval do
60
+ include PluginAWeek::PluginMigrations::Extensions::Plugin
61
+ end
@@ -0,0 +1,53 @@
1
+ module PluginAWeek #:nodoc:
2
+ module PluginMigrations
3
+ module Extensions #:nodoc:
4
+ # Adds support for the plugin schema info table
5
+ module SchemaStatements
6
+ def self.included(base) #:nodoc:
7
+ base.class_eval do
8
+ alias_method_chain :initialize_schema_information, :plugins
9
+ alias_method_chain :dump_schema_information, :plugins
10
+ end
11
+ end
12
+
13
+ # Creates the plugin schema info table
14
+ def initialize_schema_information_with_plugins
15
+ initialize_schema_information_without_plugins
16
+
17
+ begin
18
+ execute "CREATE TABLE #{PluginAWeek::PluginMigrations::Migrator.schema_info_table_name} (plugin_name #{type_to_sql(:string)}, version #{type_to_sql(:integer)})"
19
+ rescue ActiveRecord::StatementInvalid
20
+ # Schema has been initialized
21
+ end
22
+ end
23
+
24
+ # Dumps the plugin schema info table as well as information about the
25
+ # current plugin migrations
26
+ def dump_schema_information_with_plugins
27
+ schema_information = []
28
+
29
+ dump = dump_schema_information_without_plugins
30
+ schema_information << dump if dump
31
+
32
+ begin
33
+ plugins = ActiveRecord::Base.connection.select_all("SELECT * FROM #{PluginAWeek::PluginMigrations::Migrator.schema_info_table_name}")
34
+ plugins.each do |plugin|
35
+ if (version = plugin['version'].to_i) > 0
36
+ plugin_name = ActiveRecord::Base.quote_value(plugin['plugin_name'])
37
+ schema_information << "INSERT INTO #{PluginAWeek::PluginMigrations::Migrator.schema_info_table_name} (plugin_name, version) VALUES (#{plugin_name}, #{version})"
38
+ end
39
+ end
40
+ rescue ActiveRecord::StatementInvalid
41
+ # No Schema Info
42
+ end
43
+
44
+ schema_information.join(";\n")
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ ActiveRecord::ConnectionAdapters::SchemaStatements.class_eval do
52
+ include PluginAWeek::PluginMigrations::Extensions::SchemaStatements
53
+ end
@@ -0,0 +1,38 @@
1
+ module PluginAWeek #:nodoc:
2
+ module PluginMigrations
3
+ # Responsible for migrating plugins. +current_plugin+ indicates which plugin
4
+ # is currently being migrated.
5
+ class Migrator < ActiveRecord::Migrator
6
+ # We need to be able to set the current plugin being migrated
7
+ cattr_accessor :current_plugin
8
+
9
+ class << self
10
+ # Runs the migrations from a plugin, up (or down) to the version given
11
+ def migrate_plugin(plugin, version = nil)
12
+ self.current_plugin = plugin
13
+ migrate(plugin.migration_path, version)
14
+ end
15
+
16
+ def schema_info_table_name #:nodoc:
17
+ ActiveRecord::Base.table_name_prefix + 'plugin_schema_info' + ActiveRecord::Base.table_name_suffix
18
+ end
19
+
20
+ def current_version #:nodoc:
21
+ current_plugin.current_version
22
+ end
23
+ end
24
+
25
+ # Sets the version of the current plugin
26
+ def set_schema_version(version)
27
+ version = down? ? version.to_i - 1 : version.to_i
28
+
29
+ if ActiveRecord::Base.connection.select_one("SELECT version FROM #{self.class.schema_info_table_name} WHERE plugin_name = '#{current_plugin.name}'")
30
+ ActiveRecord::Base.connection.update("UPDATE #{self.class.schema_info_table_name} SET version = #{version} WHERE plugin_name = '#{current_plugin.name}'")
31
+ else
32
+ # We need to create the entry since it doesn't exist
33
+ ActiveRecord::Base.connection.execute("INSERT INTO #{self.class.schema_info_table_name} (version, plugin_name) VALUES (#{version},'#{current_plugin.name}')")
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,18 @@
1
+ namespace :db do
2
+ namespace :migrate do
3
+ desc 'Migrate the database through scripts in plugin_xyz/db/migrate. Target specific plugin with PLUGIN=x, specific version with VERSION=y'
4
+ task :plugins => :environment do
5
+ PluginAWeek::PluginMigrations.migrate(ENV['PLUGIN'], ENV['VERSION'])
6
+ Rake::Task['db:schema:dump'].invoke if ActiveRecord::Base.schema_format == :ruby
7
+ end
8
+ end
9
+
10
+ namespace :fixtures do
11
+ namespace :load do
12
+ desc "Load plugin fixtures into the current environment's database. Load fixtures for a specific plugin using PLUGIN=x, specific fixtures using FIXTURES=y,z"
13
+ task :plugins => :environment do
14
+ PluginAWeek::PluginMigrations.load_fixtures(ENV['PLUGIN'], ENV['FIXTURES'])
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ class Article < ActiveRecord::Base
2
+ belongs_to :author
3
+ has_many :comments
4
+ end
@@ -0,0 +1,3 @@
1
+ class Author < ActiveRecord::Base
2
+ has_many :articles
3
+ end
@@ -0,0 +1,3 @@
1
+ class Comment < ActiveRecord::Base
2
+ belongs_to :article
3
+ end
@@ -0,0 +1,3 @@
1
+ class Company < ActiveRecord::Base
2
+ has_many :employees
3
+ end
@@ -0,0 +1,3 @@
1
+ class Employee < ActiveRecord::Base
2
+ belongs_to :company
3
+ end
@@ -0,0 +1,3 @@
1
+ class PluginSchemaInfo < ActiveRecord::Base
2
+ set_table_name 'plugin_schema_info'
3
+ end
@@ -0,0 +1,3 @@
1
+ class SchemaInfo < ActiveRecord::Base
2
+ set_table_name ActiveRecord::Migrator.schema_info_table_name
3
+ end
@@ -0,0 +1,25 @@
1
+ require 'config/boot'
2
+
3
+ $:.unshift("#{RAILS_ROOT}/../../../../../rails/plugin_dependencies/lib")
4
+ begin
5
+ require 'plugin_dependencies'
6
+ rescue Exception => e
7
+ end
8
+
9
+ Rails::Initializer.run do |config|
10
+ config.plugin_paths.concat([
11
+ "#{RAILS_ROOT}/../../..",
12
+ "#{RAILS_ROOT}/../../../../../rails"
13
+ ])
14
+ config.plugins = [
15
+ 'loaded_plugins',
16
+ File.basename(File.expand_path("#{RAILS_ROOT}/../..")),
17
+ 'plugin_with_migrations',
18
+ 'plugin_with_no_db',
19
+ 'plugin_with_no_migrations',
20
+ 'second_plugin_with_migrations'
21
+ ]
22
+ config.cache_classes = false
23
+ config.frameworks -= [:action_web_service]
24
+ config.whiny_nils = true
25
+ end
@@ -0,0 +1,9 @@
1
+ class MigratePluginWithMigrationsToVersion2 < ActiveRecord::Migration
2
+ def self.up
3
+ Rails.plugins[:plugin_with_migrations].migrate(2)
4
+ end
5
+
6
+ def self.down
7
+ Rails.plugins[:plugin_with_migrations].migrate(0)
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class MigrateSecondPluginWithMigrationsToVersion1 < ActiveRecord::Migration
2
+ def self.up
3
+ Rails.plugins[:second_plugin_with_migrations].migrate(1)
4
+ end
5
+
6
+ def self.down
7
+ Rails.plugins[:second_plugin_with_migrations].migrate(0)
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ class CreateCompanies < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :companies do |t|
4
+ t.column :name, :string, :null => false
5
+ end
6
+ end
7
+
8
+ def self.down
9
+ drop_table :companies
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ class CreateEmployees < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :employees do |t|
4
+ t.column :company_id, :integer, :null => false
5
+ t.column :first_name, :string, :null => false
6
+ t.column :last_name, :string, :null => false
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :employees
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ pluginaweek:
2
+ id: 1
3
+ name: PluginAWeek
@@ -0,0 +1,11 @@
1
+ aaron:
2
+ id: 1
3
+ first_name: Aaron
4
+ last_name: Pfeifer
5
+ company_id: 1
6
+
7
+ neil:
8
+ id: 2
9
+ first_name: Neil
10
+ last_name: Abraham
11
+ company_id: 2
@@ -0,0 +1,11 @@
1
+ class CreateAuthors < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :authors do |t|
4
+ t.column :name, :string, :null => false
5
+ end
6
+ end
7
+
8
+ def self.down
9
+ drop_table :authors
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ class CreateArticles < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :articles do |t|
4
+ t.column :title, :string, :null => false
5
+ t.column :content, :text, :null => false
6
+ t.column :author_id, :integer, :null => false
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :articles
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ class CreateComments < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :comments do |t|
4
+ t.column :content, :string, :null => false
5
+ t.column :article_id, :integer, :null => false
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table :comments
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ aaron_welcome:
2
+ id: 1
3
+ title: Welcome to PluginAWeek!
4
+ content: Hey, thanks for dropping by!
5
+ author_id: 1
@@ -0,0 +1,7 @@
1
+ aaron:
2
+ id: 1
3
+ name: Aaron Pfeifer
4
+
5
+ neil:
6
+ id: 2
7
+ name: Neil Abraham
@@ -0,0 +1,82 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
2
+
3
+ require 'rails_generator'
4
+ require 'rails_generator/scripts/generate'
5
+
6
+ # Add the plugin_migrations generators since it's not in the normal vendor/plugins path
7
+ Rails::Generator::Base.sources << Rails::Generator::PathSource.new(:plugin_migrations, "#{::RAILS_ROOT}/../../generators")
8
+
9
+ Rails::Generator::Commands::Base.class_eval do
10
+ def migration_directory(relative_path)
11
+ directory(relative_path)
12
+ @migration_directory = "#{RAILS_ROOT}/#{relative_path}"
13
+ end
14
+ end
15
+
16
+ class PluginMigrationGeneratorTest < Test::Unit::TestCase
17
+ def setup
18
+ @db_root = "#{RAILS_ROOT}/db"
19
+ FileUtils.cp_r("#{RAILS_ROOT}/db_bak", @db_root)
20
+ end
21
+
22
+ def test_should_throw_exception_if_plugin_doesnt_exist
23
+ assert_raise(SystemExit) {generate('invalid')}
24
+ end
25
+
26
+ def test_should_throw_exception_if_plugin_migration_already_created_for_latest_version
27
+ assert_raise(SystemExit) {generate('plugin_with_migrations')}
28
+ end
29
+
30
+ def test_should_create_migration_for_plugin_never_migrated_before
31
+ FileUtils.rm("#{@db_root}/migrate/002_migrate_second_plugin_with_migrations_to_version_1.rb")
32
+
33
+ generate('second_plugin_with_migrations')
34
+ migration_path = "#{@db_root}/migrate/002_migrate_second_plugin_with_migrations_to_version_3.rb"
35
+ assert File.exists?(migration_path)
36
+
37
+ expected = <<-EOS
38
+ class MigrateSecondPluginWithMigrationsToVersion3 < ActiveRecord::Migration
39
+ def self.up
40
+ Rails.plugins[:second_plugin_with_migrations].migrate(3)
41
+ end
42
+
43
+ def self.down
44
+ Rails.plugins[:second_plugin_with_migrations].migrate(0)
45
+ end
46
+ end
47
+
48
+ EOS
49
+ assert_equal expected, File.open(migration_path).readlines.join
50
+ end
51
+
52
+ def test_should_create_migration_for_plugin_previously_migrated
53
+ PluginAWeek::PluginMigrations.migrate('second_plugin_with_migrations', 1)
54
+
55
+ generate('second_plugin_with_migrations')
56
+ migration_path = "#{@db_root}/migrate/003_migrate_second_plugin_with_migrations_to_version_3.rb"
57
+ assert File.exists?(migration_path)
58
+
59
+ expected = <<-EOS
60
+ class MigrateSecondPluginWithMigrationsToVersion3 < ActiveRecord::Migration
61
+ def self.up
62
+ Rails.plugins[:second_plugin_with_migrations].migrate(3)
63
+ end
64
+
65
+ def self.down
66
+ Rails.plugins[:second_plugin_with_migrations].migrate(1)
67
+ end
68
+ end
69
+
70
+ EOS
71
+ assert_equal expected, File.open(migration_path).readlines.join
72
+ end
73
+
74
+ def teardown
75
+ FileUtils.rmtree(@db_root)
76
+ end
77
+
78
+ private
79
+ def generate(plugin)
80
+ Rails::Generator::Scripts::Generate.new.run(['plugin_migration', plugin])
81
+ end
82
+ end
@@ -0,0 +1,10 @@
1
+ # Load the plugin testing framework
2
+ $:.unshift("#{File.dirname(__FILE__)}/../../../../test/plugin_test_helper/lib")
3
+ require 'rubygems'
4
+ require 'plugin_test_helper'
5
+
6
+ class Test::Unit::TestCase
7
+ def initialize_schema_information
8
+ ActiveRecord::Base.connection.initialize_schema_information
9
+ end
10
+ end
@@ -0,0 +1,59 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
2
+
3
+ class MigratorTest < Test::Unit::TestCase
4
+ def setup
5
+ ActiveRecord::Migration.verbose = true
6
+ initialize_schema_information
7
+ end
8
+
9
+ def test_schema_info_table_name_should_not_have_prefix_or_suffix
10
+ assert_equal 'plugin_schema_info', PluginAWeek::PluginMigrations::Migrator.schema_info_table_name
11
+ end
12
+
13
+ def test_schema_info_table_name_should_have_prefix_if_prefix_exists
14
+ ActiveRecord::Base.table_name_prefix = 'prefix_'
15
+ assert_equal 'prefix_plugin_schema_info', PluginAWeek::PluginMigrations::Migrator.schema_info_table_name
16
+ end
17
+
18
+ def test_schema_info_table_name_should_have_suffix_if_suffix_exists
19
+ ActiveRecord::Base.table_name_suffix = '_suffix'
20
+ assert_equal 'plugin_schema_info_suffix', PluginAWeek::PluginMigrations::Migrator.schema_info_table_name
21
+ end
22
+
23
+ def test_schema_info_table_name_should_have_prefix_and_suffix_if_both_exist
24
+ ActiveRecord::Base.table_name_prefix = 'prefix_'
25
+ ActiveRecord::Base.table_name_suffix = '_suffix'
26
+ assert_equal 'prefix_plugin_schema_info_suffix', PluginAWeek::PluginMigrations::Migrator.schema_info_table_name
27
+ end
28
+
29
+ def test_current_plugin_version_should_be_zero_if_never_migrated
30
+ PluginAWeek::PluginMigrations::Migrator.current_plugin = Plugin.new('/path/to/test_plugin')
31
+ assert_equal 0, PluginAWeek::PluginMigrations::Migrator.current_version
32
+ assert_equal 0, PluginSchemaInfo.count
33
+ end
34
+
35
+ def test_should_add_plugin_schema_info_after_setting_schema_version
36
+ PluginAWeek::PluginMigrations::Migrator.allocate.set_schema_version(0)
37
+ assert_equal 0, PluginAWeek::PluginMigrations::Migrator.current_version
38
+ assert_equal 1, PluginSchemaInfo.count
39
+ end
40
+
41
+ def test_should_update_plugin_schema_info_if_plugin_version_previously_set
42
+ PluginAWeek::PluginMigrations::Migrator.allocate.set_schema_version(0)
43
+ assert_equal 0, PluginAWeek::PluginMigrations::Migrator.current_version
44
+ assert_equal 1, PluginSchemaInfo.count
45
+
46
+ PluginAWeek::PluginMigrations::Migrator.allocate.set_schema_version(1)
47
+ assert_equal 1, PluginAWeek::PluginMigrations::Migrator.current_version
48
+ assert_equal 1, PluginSchemaInfo.count
49
+ end
50
+
51
+ def teardown
52
+ ActiveRecord::Base.table_name_prefix = ''
53
+ ActiveRecord::Base.table_name_suffix = ''
54
+ ActiveRecord::Base.connection.drop_table(ActiveRecord::Migrator.schema_info_table_name)
55
+ [PluginSchemaInfo].each do |model|
56
+ ActiveRecord::Base.connection.drop_table(model.table_name) if model.table_exists?
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,158 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
2
+
3
+ class PluginMigrationsTest < Test::Unit::TestCase
4
+ def setup
5
+ ActiveRecord::Migration.verbose = true
6
+ initialize_schema_information
7
+ end
8
+
9
+ def test_should_migrate_all_plugins_up_to_latest_version_by_default
10
+ PluginAWeek::PluginMigrations.migrate
11
+
12
+ assert Company.table_exists?
13
+ assert Employee.table_exists?
14
+ assert Author.table_exists?
15
+ assert Article.table_exists?
16
+ assert Comment.table_exists?
17
+
18
+ assert_equal 2, PluginSchemaInfo.count
19
+ expected = [
20
+ PluginSchemaInfo.new(:plugin_name => 'plugin_with_migrations', :version => 2),
21
+ PluginSchemaInfo.new(:plugin_name => 'second_plugin_with_migrations', :version => 3)
22
+ ]
23
+ assert_equal expected, PluginSchemaInfo.find(:all)
24
+ end
25
+
26
+ def test_should_migrate_all_plugins_up_to_specific_version_if_specified
27
+ PluginAWeek::PluginMigrations.migrate(nil, 3)
28
+
29
+ assert Company.table_exists?
30
+ assert Employee.table_exists?
31
+ assert Author.table_exists?
32
+ assert Article.table_exists?
33
+ assert Comment.table_exists?
34
+
35
+ assert_equal 2, PluginSchemaInfo.count
36
+ expected = [
37
+ PluginSchemaInfo.new(:plugin_name => 'plugin_with_migrations', :version => 2),
38
+ PluginSchemaInfo.new(:plugin_name => 'second_plugin_with_migrations', :version => 3)
39
+ ]
40
+ assert_equal expected, PluginSchemaInfo.find(:all)
41
+ end
42
+
43
+ def test_should_migrate_all_plugins_down_to_specific_version_if_specified
44
+ PluginAWeek::PluginMigrations.migrate(nil, 3)
45
+ PluginAWeek::PluginMigrations.migrate(nil, 1)
46
+
47
+ assert Company.table_exists?
48
+ assert !Employee.table_exists?
49
+ assert Author.table_exists?
50
+ assert !Article.table_exists?
51
+ assert !Comment.table_exists?
52
+
53
+ assert_equal 2, PluginSchemaInfo.count
54
+ expected = [
55
+ PluginSchemaInfo.new(:plugin_name => 'plugin_with_migrations', :version => 1),
56
+ PluginSchemaInfo.new(:plugin_name => 'second_plugin_with_migrations', :version => 1)
57
+ ]
58
+ assert_equal expected, PluginSchemaInfo.find(:all)
59
+ end
60
+
61
+ def test_should_migrate_specific_plugins_to_latest_version_if_specified
62
+ PluginAWeek::PluginMigrations.migrate('plugin_with_migrations')
63
+
64
+ assert Company.table_exists?
65
+ assert Employee.table_exists?
66
+ assert !Author.table_exists?
67
+ assert !Article.table_exists?
68
+ assert !Comment.table_exists?
69
+
70
+ assert_equal 1, PluginSchemaInfo.count
71
+ expected = [
72
+ PluginSchemaInfo.new(:plugin_name => 'plugin_with_migrations', :version => 2)
73
+ ]
74
+ assert_equal expected, PluginSchemaInfo.find(:all)
75
+ end
76
+
77
+ def test_should_migrate_specific_plugins_up_to_specific_version_if_both_specified
78
+ PluginAWeek::PluginMigrations.migrate('plugin_with_migrations', 1)
79
+
80
+ assert Company.table_exists?
81
+ assert !Employee.table_exists?
82
+ assert !Author.table_exists?
83
+ assert !Article.table_exists?
84
+ assert !Comment.table_exists?
85
+
86
+ assert_equal 1, PluginSchemaInfo.count
87
+ expected = [
88
+ PluginSchemaInfo.new(:plugin_name => 'plugin_with_migrations', :version => 2)
89
+ ]
90
+ assert_equal expected, PluginSchemaInfo.find(:all)
91
+ end
92
+
93
+ def test_should_migrate_specific_plugins_down_to_specific_version_if_both_specified
94
+ PluginAWeek::PluginMigrations.migrate('plugin_with_migrations', 1)
95
+ PluginAWeek::PluginMigrations.migrate('plugin_with_migrations', 0)
96
+
97
+ assert !Company.table_exists?
98
+ assert !Employee.table_exists?
99
+ assert !Author.table_exists?
100
+ assert !Article.table_exists?
101
+ assert !Comment.table_exists?
102
+
103
+ assert_equal 1, PluginSchemaInfo.count
104
+ expected = [
105
+ PluginSchemaInfo.new(:plugin_name => 'plugin_with_migrations', :version => 0)
106
+ ]
107
+ assert_equal expected, PluginSchemaInfo.find(:all)
108
+ end
109
+
110
+ def test_should_load_fixtures_for_all_plugins_by_default
111
+ PluginAWeek::PluginMigrations.migrate
112
+ PluginAWeek::PluginMigrations.load_fixtures
113
+
114
+ assert_equal 1, Company.count
115
+ assert_equal 2, Employee.count
116
+ assert_equal 2, Author.count
117
+ assert_equal 1, Article.count
118
+ end
119
+
120
+ def test_should_load_specific_fixtures_for_all_plugins_if_specified
121
+ PluginAWeek::PluginMigrations.migrate
122
+ PluginAWeek::PluginMigrations.load_fixtures(nil, 'companies,authors')
123
+
124
+ assert_equal 1, Company.count
125
+ assert_equal 0, Employee.count
126
+ assert_equal 2, Author.count
127
+ assert_equal 0, Article.count
128
+ end
129
+
130
+ def test_should_load_all_fixtures_for_specific_plugins_if_specified
131
+ PluginAWeek::PluginMigrations.migrate
132
+ PluginAWeek::PluginMigrations.load_fixtures('plugin_with_migrations')
133
+
134
+ assert_equal 1, Company.count
135
+ assert_equal 2, Employee.count
136
+ assert_equal 0, Author.count
137
+ assert_equal 0, Article.count
138
+ end
139
+
140
+ def test_should_load_specific_fixtures_specific_plugins_if_both_specified
141
+ PluginAWeek::PluginMigrations.migrate
142
+ PluginAWeek::PluginMigrations.load_fixtures('plugin_with_migrations', 'companies')
143
+
144
+ assert_equal 1, Company.count
145
+ assert_equal 0, Employee.count
146
+ assert_equal 0, Author.count
147
+ assert_equal 0, Article.count
148
+ end
149
+
150
+ def teardown
151
+ ActiveRecord::Base.table_name_prefix = ''
152
+ ActiveRecord::Base.table_name_suffix = ''
153
+ ActiveRecord::Base.connection.drop_table(ActiveRecord::Migrator.schema_info_table_name)
154
+ [Article, Author, Comment, Company, Employee, PluginSchemaInfo].each do |model|
155
+ ActiveRecord::Base.connection.drop_table(model.table_name) if model.table_exists?
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,113 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
2
+
3
+ class PluginTest < Test::Unit::TestCase
4
+ def setup
5
+ @plugin = Plugin.new("#{RAILS_ROOT}/vendor/plugins/plugin_with_migrations")
6
+ ActiveRecord::Migration.verbose = true
7
+ initialize_schema_information
8
+ end
9
+
10
+ def test_should_have_migration_path
11
+ assert_equal "#{RAILS_ROOT}/vendor/plugins/plugin_with_migrations/db/migrate", @plugin.migration_path
12
+ end
13
+
14
+ def test_current_version_should_be_zero_if_no_version_found
15
+ assert_equal 0, @plugin.current_version
16
+ end
17
+
18
+ def test_current_version_should_be_latest_migrated_in_the_database
19
+ PluginSchemaInfo.create(:plugin_name => 'plugin_with_migrations', :version => 2)
20
+ assert_equal 2, @plugin.current_version
21
+ end
22
+
23
+ def test_latest_version_should_be_zero_if_no_migrations_found
24
+ plugin = Plugin.new("#{RAILS_ROOT}/vendor/plugins/plugin_with_no_migrations")
25
+ assert_equal 0, plugin.latest_version
26
+ end
27
+
28
+ def test_latest_version_should_be_latest_migration_available_if_migrations_exist
29
+ assert_equal 2, @plugin.latest_version
30
+ end
31
+
32
+ def test_should_migrate_to_latest_version_by_default
33
+ @plugin.migrate
34
+
35
+ assert Company.table_exists?
36
+ assert Employee.table_exists?
37
+
38
+ assert_equal 1, PluginSchemaInfo.count
39
+ expected = [
40
+ PluginSchemaInfo.new(:plugin_name => 'plugin_with_migrations', :version => 2)
41
+ ]
42
+ assert_equal expected, PluginSchemaInfo.find(:all)
43
+ end
44
+
45
+ def test_should_migrate_to_specific_version_if_version_specified
46
+ @plugin.migrate(1)
47
+
48
+ assert Company.table_exists?
49
+ assert !Employee.table_exists?
50
+
51
+ assert_equal 1, PluginSchemaInfo.count
52
+ expected = [
53
+ PluginSchemaInfo.new(:plugin_name => 'plugin_with_migrations', :version => 1)
54
+ ]
55
+ assert_equal expected, PluginSchemaInfo.find(:all)
56
+
57
+ @plugin.migrate(0)
58
+
59
+ assert !Company.table_exists?
60
+ assert !Employee.table_exists?
61
+
62
+ assert_equal 1, PluginSchemaInfo.count
63
+ expected = [
64
+ PluginSchemaInfo.new(:plugin_name => 'plugin_with_migrations', :version => 0)
65
+ ]
66
+ assert_equal expected, PluginSchemaInfo.find(:all)
67
+ end
68
+
69
+ def test_should_have_fixtures_path
70
+ assert_equal "#{RAILS_ROOT}/vendor/plugins/plugin_with_migrations/test/fixtures", @plugin.fixtures_path
71
+ end
72
+
73
+ def test_fixtures_should_include_all_by_default
74
+ expected = [
75
+ "#{@plugin.fixtures_path}/companies.yml",
76
+ "#{@plugin.fixtures_path}/employees.yml"
77
+ ]
78
+ assert_equal expected, @plugin.fixtures
79
+ end
80
+
81
+ def test_fixtures_should_only_include_specific_fixtures_if_specified
82
+ assert_equal ["#{@plugin.fixtures_path}/companies.yml"], @plugin.fixtures('companies')
83
+
84
+ expected = [
85
+ "#{@plugin.fixtures_path}/companies.yml",
86
+ "#{@plugin.fixtures_path}/employees.yml"
87
+ ]
88
+ assert_equal expected, @plugin.fixtures('companies,employees')
89
+ end
90
+
91
+ def test_load_should_create_all_fixtures_by_default
92
+ @plugin.migrate
93
+ @plugin.load_fixtures
94
+
95
+ assert_equal 1, Company.count
96
+ assert_equal 2, Employee.count
97
+ end
98
+
99
+ def test_load_should_only_create_specific_fixtures_if_specified
100
+ @plugin.migrate
101
+ @plugin.load_fixtures('companies')
102
+
103
+ assert_equal 1, Company.count
104
+ assert_equal 0, Employee.count
105
+ end
106
+
107
+ def teardown
108
+ ActiveRecord::Base.connection.drop_table(ActiveRecord::Migrator.schema_info_table_name)
109
+ [Company, Employee, PluginSchemaInfo].each do |model|
110
+ ActiveRecord::Base.connection.drop_table(model.table_name) if model.table_exists?
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,63 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../test_helper")
2
+
3
+ class SchemaStatementsTest < Test::Unit::TestCase
4
+ def test_plugin_schema_info_table_should_not_exist_by_default
5
+ assert !PluginSchemaInfo.table_exists?
6
+ end
7
+
8
+ def test_should_create_plugin_schema_info_table_when_initialized
9
+ initialize_schema_information
10
+ assert PluginSchemaInfo.table_exists?
11
+ end
12
+
13
+ def test_should_not_dump_anything_if_no_main_or_plugin_schema_info
14
+ assert_equal '', ActiveRecord::Base.connection.dump_schema_information
15
+ end
16
+
17
+ def test_should_not_dump_anything_if_schema_or_plugin_is_at_version_zero
18
+ initialize_schema_information
19
+ PluginSchemaInfo.create(:plugin_name => 'test_plugin', :version => 0)
20
+ assert_equal '', ActiveRecord::Base.connection.dump_schema_information
21
+ end
22
+
23
+ def test_should_dump_schema_info_for_one_plugin
24
+ initialize_schema_information
25
+ PluginSchemaInfo.create(:plugin_name => 'test_plugin', :version => 1)
26
+ assert_equal "INSERT INTO plugin_schema_info (plugin_name, version) VALUES ('test_plugin', 1)", ActiveRecord::Base.connection.dump_schema_information
27
+ end
28
+
29
+ def test_should_dump_schema_info_for_multiple_plugins
30
+ initialize_schema_information
31
+ PluginSchemaInfo.create(:plugin_name => 'test_plugin', :version => 1)
32
+ PluginSchemaInfo.create(:plugin_name => 'another_plugin', :version => 2)
33
+
34
+ expected = [
35
+ "INSERT INTO plugin_schema_info (plugin_name, version) VALUES ('test_plugin', 1);",
36
+ "INSERT INTO plugin_schema_info (plugin_name, version) VALUES ('another_plugin', 2)"
37
+ ].join("\n")
38
+ assert_equal expected, ActiveRecord::Base.connection.dump_schema_information
39
+ end
40
+
41
+ def test_should_dump_both_main_schema_info_and_plugin_schema_info
42
+ initialize_schema_information
43
+ ActiveRecord::Base.connection.update("UPDATE #{ActiveRecord::Migrator.schema_info_table_name} SET version = 1")
44
+ PluginSchemaInfo.create(:plugin_name => 'test_plugin', :version => 1)
45
+
46
+ expected = [
47
+ 'INSERT INTO schema_info (version) VALUES (1);',
48
+ "INSERT INTO plugin_schema_info (plugin_name, version) VALUES ('test_plugin', 1)"
49
+ ].join("\n")
50
+ assert_equal expected, ActiveRecord::Base.connection.dump_schema_information
51
+ end
52
+
53
+ def test_should_dump_only_main_schema_info_if_no_plugins_migrated
54
+ initialize_schema_information
55
+ ActiveRecord::Base.connection.update("UPDATE #{ActiveRecord::Migrator.schema_info_table_name} SET version = 1")
56
+ assert_equal 'INSERT INTO schema_info (version) VALUES (1)', ActiveRecord::Base.connection.dump_schema_information
57
+ end
58
+
59
+ def teardown
60
+ ActiveRecord::Base.connection.drop_table(SchemaInfo.table_name) if SchemaInfo.table_exists?
61
+ ActiveRecord::Base.connection.drop_table(PluginSchemaInfo.table_name) if PluginSchemaInfo.table_exists?
62
+ end
63
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: plugin_migrations
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Aaron Pfeifer, Neil Abraham
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-09 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email: info@pluginaweek.org
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/plugin_migrations.rb
21
+ - lib/plugin_migrations/migrator.rb
22
+ - lib/plugin_migrations/extensions/plugin.rb
23
+ - lib/plugin_migrations/extensions/schema_statements.rb
24
+ - tasks/plugin_migrations_tasks.rake
25
+ - test/test_helper.rb
26
+ - test/app_root/vendor/plugins/plugin_with_no_migrations/init.rb
27
+ - test/app_root/vendor/plugins/plugin_with_no_migrations/db/empty
28
+ - test/app_root/vendor/plugins/plugin_with_migrations/init.rb
29
+ - test/app_root/vendor/plugins/plugin_with_migrations/test/fixtures/employees.yml
30
+ - test/app_root/vendor/plugins/plugin_with_migrations/test/fixtures/companies.yml
31
+ - test/app_root/vendor/plugins/plugin_with_migrations/db/migrate/002_create_employees.rb
32
+ - test/app_root/vendor/plugins/plugin_with_migrations/db/migrate/001_create_companies.rb
33
+ - test/app_root/vendor/plugins/plugin_with_no_db/init.rb
34
+ - test/app_root/vendor/plugins/second_plugin_with_migrations/init.rb
35
+ - test/app_root/vendor/plugins/second_plugin_with_migrations/test/fixtures/authors.yml
36
+ - test/app_root/vendor/plugins/second_plugin_with_migrations/test/fixtures/articles.yml
37
+ - test/app_root/vendor/plugins/second_plugin_with_migrations/db/migrate/002_create_articles.rb
38
+ - test/app_root/vendor/plugins/second_plugin_with_migrations/db/migrate/001_create_authors.rb
39
+ - test/app_root/vendor/plugins/second_plugin_with_migrations/db/migrate/003_create_comments.rb
40
+ - test/app_root/config/environment.rb
41
+ - test/app_root/app/models/employee.rb
42
+ - test/app_root/app/models/plugin_schema_info.rb
43
+ - test/app_root/app/models/author.rb
44
+ - test/app_root/app/models/company.rb
45
+ - test/app_root/app/models/article.rb
46
+ - test/app_root/app/models/comment.rb
47
+ - test/app_root/app/models/schema_info.rb
48
+ - test/app_root/db_bak/migrate/001_migrate_plugin_with_migrations_to_version_2.rb
49
+ - test/app_root/db_bak/migrate/002_migrate_second_plugin_with_migrations_to_version_1.rb
50
+ - test/unit/plugin_test.rb
51
+ - test/unit/migrator_test.rb
52
+ - test/unit/plugin_migrations_test.rb
53
+ - test/unit/schema_statements_test.rb
54
+ - test/functional/plugin_migration_generator_test.rb
55
+ - CHANGELOG
56
+ - init.rb
57
+ - MIT-LICENSE
58
+ - Rakefile
59
+ - README
60
+ homepage:
61
+ licenses: []
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 1.7.2
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Adds support for plugin-based migrations
84
+ test_files: []