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