diff --git a/UPGRADING b/UPGRADING index 7436e4f6a..ea282fa64 100644 --- a/UPGRADING +++ b/UPGRADING @@ -2,7 +2,6 @@ When upgrading Re-run the migrations generator - rails generate acts_as_taggable_on:migration - rake db:migrate + rake railties:install:migrations FROM=acts_as_taggable_on_engine db:migrate It will create any new migrations and skip existing ones diff --git a/lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb b/db/migrate/1_acts_as_taggable_on_migration.rb similarity index 100% rename from lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb rename to db/migrate/1_acts_as_taggable_on_migration.rb diff --git a/lib/generators/acts_as_taggable_on/migration/templates/active_record/migration02-add_missing_unique_indices.rb b/db/migrate/2_add_missing_unique_indices.rb similarity index 87% rename from lib/generators/acts_as_taggable_on/migration/templates/active_record/migration02-add_missing_unique_indices.rb rename to db/migrate/2_add_missing_unique_indices.rb index 32a9f125a..d772d1b5f 100644 --- a/lib/generators/acts_as_taggable_on/migration/templates/active_record/migration02-add_missing_unique_indices.rb +++ b/db/migrate/2_add_missing_unique_indices.rb @@ -1,14 +1,16 @@ -class ActsAsTaggableOnAddMissingUniqueIndices < ActiveRecord::Migration +class AddMissingUniqueIndices < ActiveRecord::Migration def self.up + add_index :tags, :name, unique: true + remove_index :taggings, :tag_id remove_index :taggings, [:taggable_id, :taggable_type, :context] - add_index :tags, :name, unique: true add_index :taggings, [:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type], unique: true, name: 'tagging_idx' end def self.down remove_index :tags, :name + remove_index :taggings, name: 'tagging_idx' add_index :taggings, :tag_id add_index :taggings, [:taggable_id, :taggable_type, :context] diff --git a/lib/acts-as-taggable-on.rb b/lib/acts-as-taggable-on.rb index 25eb9dd5b..caf5ac000 100644 --- a/lib/acts-as-taggable-on.rb +++ b/lib/acts-as-taggable-on.rb @@ -48,6 +48,7 @@ def self.setup require "acts_as_taggable_on/tag_list" require "acts_as_taggable_on/tags_helper" require "acts_as_taggable_on/tagging" +require 'acts_as_taggable_on/engine' ActiveSupport.on_load(:active_record) do extend ActsAsTaggableOn::Compatibility @@ -57,4 +58,3 @@ def self.setup ActiveSupport.on_load(:action_view) do include ActsAsTaggableOn::TagsHelper end - diff --git a/lib/acts_as_taggable_on/engine.rb b/lib/acts_as_taggable_on/engine.rb new file mode 100644 index 000000000..79fa8c850 --- /dev/null +++ b/lib/acts_as_taggable_on/engine.rb @@ -0,0 +1,6 @@ +require 'rails/engine' +module ActsAsTaggableOn + class Engine < Rails::Engine + + end +end diff --git a/lib/generators/acts_as_taggable_on/migration/migration_generator.rb b/lib/generators/acts_as_taggable_on/migration/migration_generator.rb deleted file mode 100644 index 2251aa1ae..000000000 --- a/lib/generators/acts_as_taggable_on/migration/migration_generator.rb +++ /dev/null @@ -1,73 +0,0 @@ -require 'rails/generators' -require 'rails/generators/migration' - -module ActsAsTaggableOn - class MigrationGenerator < Rails::Generators::Base - include Rails::Generators::Migration - - desc "Generates migration for Tag and Tagging models" - - # @return [Symbol] The ORM configured by Rails - def self.orm - Rails::Generators.options[:rails][:orm] - end - - # @return [String] The path to the migration templates - def self.source_root - File.join(File.dirname(__FILE__), 'templates', (orm.to_s unless orm.class.eql?(String)) ) - end - - # @return [Boolean] true if the orm is active_record - def self.orm_has_migration? - [:active_record].include? orm - end - - # Generate the next migration number - # @note sleeps to ensure we don't return the same timestamped migration number twice - # @return [String] Unique, sequential migration number based on either the time - # for timestamped migrations, or by incrementing the last migration number - def self.next_migration_number(dirname) - if ActiveRecord::Base.timestamped_migrations - sleep 1 - migration_number = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i - migration_number += 1 - migration_number.to_s - else - "%.3d" % (current_migration_number(dirname) + 1) - end - end - - # @return [Array] An array of migration source files and destination paths - # if the orm supports migrations - # @return [Array] an empty array if the orm does not support migrations - # @example [ ['migration.rb', 'db/migrate/acts_as_taggable_on_migration'] ] - # @note For historical reasons, all migrations are ordered by the format - # migrationsNUMBER-migration_name, where the migration_name is separated - # by a '-', exept for the first migration - def self.available_migrations - if orm_has_migration? - Dir["#{self.source_root}/*.rb"].sort.map do |filepath| - ext = '.rb' - name = File.basename(filepath, ext) - migration_name = name.split('-')[-1] - [ "#{name}#{ext}", "db/migrate/acts_as_taggable_on_#{migration_name}"] - end - else - [] - end - end - - # Setting the class_option :skip to creating a migration that already exists - # @note see https://github.com/rails/rails/blob/3-2-stable/railties/lib/rails/generators/migration.rb#L53 - # see Rails::Generators::Base.class_option # 198 - # see Thor::Base#options - class_option :skip, :type => :boolean, :default => true, :desc => 'Skip copying existing migrations' - - # Creates migrations that do not yet exist - def create_migration_file - self.class.available_migrations.each do |source, destination| - migration_template(source, destination) - end - end - end -end diff --git a/spec/generators/acts_as_taggable_on/migration/migration_generator_spec.rb b/spec/generators/acts_as_taggable_on/migration/migration_generator_spec.rb deleted file mode 100644 index 32f012c3c..000000000 --- a/spec/generators/acts_as_taggable_on/migration/migration_generator_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'spec_helper' - -# Generators are not automatically loaded by Rails -require 'generators/acts_as_taggable_on/migration/migration_generator' - -describe ActsAsTaggableOn::MigrationGenerator do - # Tell the generator where to put its output (what it thinks of as Rails.root) - destination File.expand_path("../../../../../tmp", __FILE__) - - before do - prepare_destination - Rails::Generators.options[:rails][:orm] = :active_record - end - describe 'no arguments' do - before { run_generator } - - describe 'db/migrate/acts_as_taggable_on_migration.rb' do - subject { file('db/migrate/acts_as_taggable_on_migration.rb') } - it { should be_a_migration } - end - end -end