From 1e6dcfa7ca80a1439cb0e8eb01e216040254fa16 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Wed, 15 Jan 2014 17:43:08 -0300 Subject: [PATCH] rails3: replace acts_as_taggable_on_steroids by acts-as-taggable-on --- Gemfile | 1 + Gemfile.lock | 3 +++ app/controllers/public/profile_controller.rb | 2 +- app/controllers/public/search_controller.rb | 2 +- app/helpers/tags_helper.rb | 2 +- app/models/article.rb | 2 +- app/models/profile.rb | 4 ++-- db/migrate/20140115190131_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb | 18 ++++++++++++++++++ db/migrate/20140115190132_add_missing_unique_indices.acts_as_taggable_on_engine.rb | 22 ++++++++++++++++++++++ lib/extended_tag.rb | 4 ++-- test/unit/article_test.rb | 16 +++++++++------- test/unit/extended_tag_test.rb | 26 +++++++++++++------------- test/unit/profile_test.rb | 6 +++--- vendor/plugins/acts_as_taggable_on_steroids/CHANGELOG | 58 ---------------------------------------------------------- vendor/plugins/acts_as_taggable_on_steroids/MIT-LICENSE | 20 -------------------- vendor/plugins/acts_as_taggable_on_steroids/README | 116 -------------------------------------------------------------------------------------------------------------------- vendor/plugins/acts_as_taggable_on_steroids/Rakefile | 22 ---------------------- vendor/plugins/acts_as_taggable_on_steroids/generators/acts_as_taggable_migration/acts_as_taggable_migration_generator.rb | 11 ----------- vendor/plugins/acts_as_taggable_on_steroids/generators/acts_as_taggable_migration/templates/migration.rb | 26 -------------------------- vendor/plugins/acts_as_taggable_on_steroids/init.rb | 4 ---- vendor/plugins/acts_as_taggable_on_steroids/lib/acts_as_taggable.rb | 145 ------------------------------------------------------------------------------------------------------------------------------------------------- vendor/plugins/acts_as_taggable_on_steroids/lib/tag.rb | 41 ----------------------------------------- vendor/plugins/acts_as_taggable_on_steroids/lib/tag_counts_extension.rb | 2 -- vendor/plugins/acts_as_taggable_on_steroids/lib/tag_list.rb | 66 ------------------------------------------------------------------ vendor/plugins/acts_as_taggable_on_steroids/lib/tagging.rb | 4 ---- vendor/plugins/acts_as_taggable_on_steroids/test/abstract_unit.rb | 82 ---------------------------------------------------------------------------------- vendor/plugins/acts_as_taggable_on_steroids/test/acts_as_taggable_test.rb | 272 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- vendor/plugins/acts_as_taggable_on_steroids/test/database.yml | 10 ---------- vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/photo.rb | 8 -------- vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/photos.yml | 24 ------------------------ vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/post.rb | 7 ------- vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/posts.yml | 24 ------------------------ vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/sp_post.rb | 5 ----- vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/taggings.yml | 126 ------------------------------------------------------------------------------------------------------------------------------ vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/tags.yml | 19 ------------------- vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/user.rb | 4 ---- vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/users.yml | 7 ------- vendor/plugins/acts_as_taggable_on_steroids/test/schema.rb | 31 ------------------------------- vendor/plugins/acts_as_taggable_on_steroids/test/tag_list_test.rb | 98 -------------------------------------------------------------------------------------------------- vendor/plugins/acts_as_taggable_on_steroids/test/tag_test.rb | 42 ------------------------------------------ vendor/plugins/acts_as_taggable_on_steroids/test/tagging_test.rb | 13 ------------- 41 files changed, 77 insertions(+), 1318 deletions(-) create mode 100644 db/migrate/20140115190131_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb create mode 100644 db/migrate/20140115190132_add_missing_unique_indices.acts_as_taggable_on_engine.rb delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/CHANGELOG delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/MIT-LICENSE delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/README delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/Rakefile delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/generators/acts_as_taggable_migration/acts_as_taggable_migration_generator.rb delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/generators/acts_as_taggable_migration/templates/migration.rb delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/init.rb delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/lib/acts_as_taggable.rb delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/lib/tag.rb delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/lib/tag_counts_extension.rb delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/lib/tag_list.rb delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/lib/tagging.rb delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/test/abstract_unit.rb delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/test/acts_as_taggable_test.rb delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/test/database.yml delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/photo.rb delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/photos.yml delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/post.rb delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/posts.yml delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/sp_post.rb delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/taggings.yml delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/tags.yml delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/user.rb delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/users.yml delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/test/schema.rb delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/test/tag_list_test.rb delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/test/tag_test.rb delete mode 100644 vendor/plugins/acts_as_taggable_on_steroids/test/tagging_test.rb diff --git a/Gemfile b/Gemfile index e6b62b3..7f5fae8 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,7 @@ source "https://rubygems.org" gem 'rails' gem 'fast_gettext' +gem 'acts-as-taggable-on' # TODO needs a rebuild diff-lcs wrt wheezy diff --git a/Gemfile.lock b/Gemfile.lock index db7de1a..28fa821 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -28,6 +28,8 @@ GEM activesupport (3.2.6) i18n (~> 0.6) multi_json (~> 1.0) + acts-as-taggable-on (3.0.1) + rails (>= 3, < 5) arel (3.0.2) builder (3.0.0) erubis (2.7.0) @@ -82,6 +84,7 @@ PLATFORMS ruby DEPENDENCIES + acts-as-taggable-on fast_gettext rails rake diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index f1d0f66..2313a0c 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -32,7 +32,7 @@ class ProfileController < PublicController @tag = params[:id] @tag_cache_key = "tag_#{CGI.escape(@tag.to_s)}_#{profile.id.to_s}_page_#{params[:npage]}" if is_cache_expired?(@tag_cache_key) - @tagged = profile.find_tagged_with(@tag).paginate(:per_page => 20, :page => params[:npage]) + @tagged = profile.tagged_with(@tag).paginate(:per_page => 20, :page => params[:npage]) end end diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index 7cf89c1..ba7ab4f 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -133,7 +133,7 @@ class SearchController < PublicController @tag = params[:tag] @tag_cache_key = "tag_#{CGI.escape(@tag.to_s)}_env_#{environment.id.to_s}_page_#{params[:npage]}" if is_cache_expired?(@tag_cache_key) - @searches[@asset] = {:results => environment.articles.find_tagged_with(@tag).paginate(paginate_options)} + @searches[@asset] = {:results => environment.articles.tagged_with(@tag).paginate(paginate_options)} end end diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index 44325ef..da2412a 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -9,7 +9,7 @@ module TagsHelper # tags must be a hash where the keys are tag names and the values # the count of elements tagged with the tag, as returned by - # Profile#find_tagged_with. If not tags were returned, just returns + # Profile#tagged_with. If not tags were returned, just returns # _('No tags yet.') # # must be a symbol representing the key to be inserted in diff --git a/app/models/article.rb b/app/models/article.rb index 12b8276..f7dbf41 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -759,7 +759,7 @@ class Article < ActiveRecord::Base def sanitize_tag_list sanitizer = HTML::FullSanitizer.new - self.tag_list.names.map!{|i| strip_tag_name sanitizer.sanitize(i) } + self.tag_list.map!{|i| strip_tag_name sanitizer.sanitize(i) } end def strip_tag_name(tag_name) diff --git a/app/models/profile.rb b/app/models/profile.rb index 772008f..cfd6650 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -556,8 +556,8 @@ private :generate_url, :url_options end end - def find_tagged_with(tag) - self.articles.find_tagged_with(tag) + def tagged_with(tag) + self.articles.tagged_with(tag) end # Tells whether a specified profile has members or nor. diff --git a/db/migrate/20140115190131_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb b/db/migrate/20140115190131_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..fd81a6d --- /dev/null +++ b/db/migrate/20140115190131_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb @@ -0,0 +1,18 @@ +# This migration comes from acts_as_taggable_on_engine (originally 1) +class ActsAsTaggableOnMigration < ActiveRecord::Migration + def self.up + change_table :taggings do |t| + t.references :tagger, :polymorphic => true + t.string :context, :limit => 128 + end + add_index :taggings, [:taggable_id, :taggable_type, :context] + end + + def self.down + remove_index :taggings, [:taggable_id, :taggable_type, :context] + change_table :taggings do |t| + t.remove_references :tagger, :polymorphic => true + t.remove :context + end + end +end diff --git a/db/migrate/20140115190132_add_missing_unique_indices.acts_as_taggable_on_engine.rb b/db/migrate/20140115190132_add_missing_unique_indices.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..35eee17 --- /dev/null +++ b/db/migrate/20140115190132_add_missing_unique_indices.acts_as_taggable_on_engine.rb @@ -0,0 +1,22 @@ +# This migration comes from acts_as_taggable_on_engine (originally 2) +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 :taggings, + [:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type], + unique: true, name: 'taggings_idx' + end + + def self.down + remove_index :tags, :name + + remove_index :taggings, name: 'taggings_idx' + add_index :taggings, :tag_id + add_index :taggings, [:taggable_id, :taggable_type, :context] + end + +end diff --git a/lib/extended_tag.rb b/lib/extended_tag.rb index ed49637..eafe8ab 100644 --- a/lib/extended_tag.rb +++ b/lib/extended_tag.rb @@ -1,4 +1,4 @@ -class Tag +class ActsAsTaggableOn::Tag attr_accessible :name, :parent_id, :pending @@ -25,7 +25,7 @@ class Tag # All the tags that can be a new parent for this tag, that is all but itself and its descendents to avoid loops def parent_candidates - Tag.find(:all) - descendents - [self] + ActsAsTaggableOn::Tag.find(:all) - descendents - [self] end # All tags that have this tag as its one of its ancestors diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 3e372d6..ae93ef7 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -67,7 +67,7 @@ class ArticleTest < ActiveSupport::TestCase should 'act as taggable' do a = create(Article, :name => 'my article', :profile_id => profile.id) a.tag_list = ['one', 'two'] - tags = a.tag_list.names + tags = a.tag_list assert tags.include?('one') assert tags.include?('two') end @@ -746,7 +746,7 @@ class ArticleTest < ActiveSupport::TestCase should 'get tagged with tag' do a = create(Article, :name => 'Published at', :profile_id => profile.id, :tag_list => 'bli') - as = Article.find_tagged_with('bli') + as = Article.tagged_with('bli') assert_includes as, a end @@ -758,7 +758,7 @@ class ArticleTest < ActiveSupport::TestCase user_from_other_environment = create_user('other_user', :environment => other_environment).person article_from_other_enviroment = create(Article, :profile => user_from_other_environment, :tag_list => 'bli') - tagged_articles_in_other_environment = other_environment.articles.find_tagged_with('bli') + tagged_articles_in_other_environment = other_environment.articles.tagged_with('bli') assert_includes tagged_articles_in_other_environment, article_from_other_enviroment assert_not_includes tagged_articles_in_other_environment, article_from_this_environment @@ -859,16 +859,18 @@ class ArticleTest < ActiveSupport::TestCase should 'sanitize tags after save article' do article = fast_create(Article, :slug => 'article-with-tags', :profile_id => profile.id) - article.tags << build(Tag, :name => "TV Web w") - assert_match /[<>]/, article.tags.last.name + tag = build(ActsAsTaggableOn::Tag, :name => "TV Web w") + assert_match /[<>]/, tag.name + article.tag_list.add(tag.name) article.save! assert_no_match /[<>]/, article.tags.last.name end should 'strip HTML from tag names after save article' do article = fast_create(Article, :slug => 'article-with-tags', :profile_id => profile.id) - article.tags << build(Tag, :name => "TV Web w