Commit 1e6dcfa7ca80a1439cb0e8eb01e216040254fa16

Authored by Victor Costa
1 parent c4832b5f

rails3: replace acts_as_taggable_on_steroids by acts-as-taggable-on

Showing 41 changed files with 77 additions and 1318 deletions   Show diff stats
1 source "https://rubygems.org" 1 source "https://rubygems.org"
2 gem 'rails' 2 gem 'rails'
3 gem 'fast_gettext' 3 gem 'fast_gettext'
  4 +gem 'acts-as-taggable-on'
4 5
5 # TODO needs a rebuild diff-lcs wrt wheezy 6 # TODO needs a rebuild diff-lcs wrt wheezy
6 7
@@ -28,6 +28,8 @@ GEM @@ -28,6 +28,8 @@ GEM
28 activesupport (3.2.6) 28 activesupport (3.2.6)
29 i18n (~> 0.6) 29 i18n (~> 0.6)
30 multi_json (~> 1.0) 30 multi_json (~> 1.0)
  31 + acts-as-taggable-on (3.0.1)
  32 + rails (>= 3, < 5)
31 arel (3.0.2) 33 arel (3.0.2)
32 builder (3.0.0) 34 builder (3.0.0)
33 erubis (2.7.0) 35 erubis (2.7.0)
@@ -82,6 +84,7 @@ PLATFORMS @@ -82,6 +84,7 @@ PLATFORMS
82 ruby 84 ruby
83 85
84 DEPENDENCIES 86 DEPENDENCIES
  87 + acts-as-taggable-on
85 fast_gettext 88 fast_gettext
86 rails 89 rails
87 rake 90 rake
app/controllers/public/profile_controller.rb
@@ -32,7 +32,7 @@ class ProfileController &lt; PublicController @@ -32,7 +32,7 @@ class ProfileController &lt; PublicController
32 @tag = params[:id] 32 @tag = params[:id]
33 @tag_cache_key = "tag_#{CGI.escape(@tag.to_s)}_#{profile.id.to_s}_page_#{params[:npage]}" 33 @tag_cache_key = "tag_#{CGI.escape(@tag.to_s)}_#{profile.id.to_s}_page_#{params[:npage]}"
34 if is_cache_expired?(@tag_cache_key) 34 if is_cache_expired?(@tag_cache_key)
35 - @tagged = profile.find_tagged_with(@tag).paginate(:per_page => 20, :page => params[:npage]) 35 + @tagged = profile.tagged_with(@tag).paginate(:per_page => 20, :page => params[:npage])
36 end 36 end
37 end 37 end
38 38
app/controllers/public/search_controller.rb
@@ -133,7 +133,7 @@ class SearchController &lt; PublicController @@ -133,7 +133,7 @@ class SearchController &lt; PublicController
133 @tag = params[:tag] 133 @tag = params[:tag]
134 @tag_cache_key = "tag_#{CGI.escape(@tag.to_s)}_env_#{environment.id.to_s}_page_#{params[:npage]}" 134 @tag_cache_key = "tag_#{CGI.escape(@tag.to_s)}_env_#{environment.id.to_s}_page_#{params[:npage]}"
135 if is_cache_expired?(@tag_cache_key) 135 if is_cache_expired?(@tag_cache_key)
136 - @searches[@asset] = {:results => environment.articles.find_tagged_with(@tag).paginate(paginate_options)} 136 + @searches[@asset] = {:results => environment.articles.tagged_with(@tag).paginate(paginate_options)}
137 end 137 end
138 end 138 end
139 139
app/helpers/tags_helper.rb
@@ -9,7 +9,7 @@ module TagsHelper @@ -9,7 +9,7 @@ module TagsHelper
9 9
10 # <tt>tags</tt> must be a hash where the keys are tag names and the values 10 # <tt>tags</tt> must be a hash where the keys are tag names and the values
11 # the count of elements tagged with the tag, as returned by 11 # the count of elements tagged with the tag, as returned by
12 - # Profile#find_tagged_with. If not tags were returned, just returns 12 + # Profile#tagged_with. If not tags were returned, just returns
13 # _('No tags yet.') 13 # _('No tags yet.')
14 # 14 #
15 # <tagname_option> must be a symbol representing the key to be inserted in 15 # <tagname_option> must be a symbol representing the key to be inserted in
app/models/article.rb
@@ -759,7 +759,7 @@ class Article &lt; ActiveRecord::Base @@ -759,7 +759,7 @@ class Article &lt; ActiveRecord::Base
759 759
760 def sanitize_tag_list 760 def sanitize_tag_list
761 sanitizer = HTML::FullSanitizer.new 761 sanitizer = HTML::FullSanitizer.new
762 - self.tag_list.names.map!{|i| strip_tag_name sanitizer.sanitize(i) } 762 + self.tag_list.map!{|i| strip_tag_name sanitizer.sanitize(i) }
763 end 763 end
764 764
765 def strip_tag_name(tag_name) 765 def strip_tag_name(tag_name)
app/models/profile.rb
@@ -556,8 +556,8 @@ private :generate_url, :url_options @@ -556,8 +556,8 @@ private :generate_url, :url_options
556 end 556 end
557 end 557 end
558 558
559 - def find_tagged_with(tag)  
560 - self.articles.find_tagged_with(tag) 559 + def tagged_with(tag)
  560 + self.articles.tagged_with(tag)
561 end 561 end
562 562
563 # Tells whether a specified profile has members or nor. 563 # Tells whether a specified profile has members or nor.
db/migrate/20140115190131_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb 0 → 100644
@@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
  1 +# This migration comes from acts_as_taggable_on_engine (originally 1)
  2 +class ActsAsTaggableOnMigration < ActiveRecord::Migration
  3 + def self.up
  4 + change_table :taggings do |t|
  5 + t.references :tagger, :polymorphic => true
  6 + t.string :context, :limit => 128
  7 + end
  8 + add_index :taggings, [:taggable_id, :taggable_type, :context]
  9 + end
  10 +
  11 + def self.down
  12 + remove_index :taggings, [:taggable_id, :taggable_type, :context]
  13 + change_table :taggings do |t|
  14 + t.remove_references :tagger, :polymorphic => true
  15 + t.remove :context
  16 + end
  17 + end
  18 +end
db/migrate/20140115190132_add_missing_unique_indices.acts_as_taggable_on_engine.rb 0 → 100644
@@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
  1 +# This migration comes from acts_as_taggable_on_engine (originally 2)
  2 +class AddMissingUniqueIndices < ActiveRecord::Migration
  3 +
  4 + def self.up
  5 + add_index :tags, :name, unique: true
  6 +
  7 + remove_index :taggings, :tag_id
  8 + remove_index :taggings, [:taggable_id, :taggable_type, :context]
  9 + add_index :taggings,
  10 + [:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type],
  11 + unique: true, name: 'taggings_idx'
  12 + end
  13 +
  14 + def self.down
  15 + remove_index :tags, :name
  16 +
  17 + remove_index :taggings, name: 'taggings_idx'
  18 + add_index :taggings, :tag_id
  19 + add_index :taggings, [:taggable_id, :taggable_type, :context]
  20 + end
  21 +
  22 +end
lib/extended_tag.rb
1 -class Tag 1 +class ActsAsTaggableOn::Tag
2 2
3 attr_accessible :name, :parent_id, :pending 3 attr_accessible :name, :parent_id, :pending
4 4
@@ -25,7 +25,7 @@ class Tag @@ -25,7 +25,7 @@ class Tag
25 25
26 # All the tags that can be a new parent for this tag, that is all but itself and its descendents to avoid loops 26 # All the tags that can be a new parent for this tag, that is all but itself and its descendents to avoid loops
27 def parent_candidates 27 def parent_candidates
28 - Tag.find(:all) - descendents - [self] 28 + ActsAsTaggableOn::Tag.find(:all) - descendents - [self]
29 end 29 end
30 30
31 # All tags that have this tag as its one of its ancestors 31 # All tags that have this tag as its one of its ancestors
test/unit/article_test.rb
@@ -67,7 +67,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -67,7 +67,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
67 should 'act as taggable' do 67 should 'act as taggable' do
68 a = create(Article, :name => 'my article', :profile_id => profile.id) 68 a = create(Article, :name => 'my article', :profile_id => profile.id)
69 a.tag_list = ['one', 'two'] 69 a.tag_list = ['one', 'two']
70 - tags = a.tag_list.names 70 + tags = a.tag_list
71 assert tags.include?('one') 71 assert tags.include?('one')
72 assert tags.include?('two') 72 assert tags.include?('two')
73 end 73 end
@@ -746,7 +746,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -746,7 +746,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
746 746
747 should 'get tagged with tag' do 747 should 'get tagged with tag' do
748 a = create(Article, :name => 'Published at', :profile_id => profile.id, :tag_list => 'bli') 748 a = create(Article, :name => 'Published at', :profile_id => profile.id, :tag_list => 'bli')
749 - as = Article.find_tagged_with('bli') 749 + as = Article.tagged_with('bli')
750 750
751 assert_includes as, a 751 assert_includes as, a
752 end 752 end
@@ -758,7 +758,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -758,7 +758,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
758 user_from_other_environment = create_user('other_user', :environment => other_environment).person 758 user_from_other_environment = create_user('other_user', :environment => other_environment).person
759 article_from_other_enviroment = create(Article, :profile => user_from_other_environment, :tag_list => 'bli') 759 article_from_other_enviroment = create(Article, :profile => user_from_other_environment, :tag_list => 'bli')
760 760
761 - tagged_articles_in_other_environment = other_environment.articles.find_tagged_with('bli') 761 + tagged_articles_in_other_environment = other_environment.articles.tagged_with('bli')
762 762
763 assert_includes tagged_articles_in_other_environment, article_from_other_enviroment 763 assert_includes tagged_articles_in_other_environment, article_from_other_enviroment
764 assert_not_includes tagged_articles_in_other_environment, article_from_this_environment 764 assert_not_includes tagged_articles_in_other_environment, article_from_this_environment
@@ -859,16 +859,18 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -859,16 +859,18 @@ class ArticleTest &lt; ActiveSupport::TestCase
859 859
860 should 'sanitize tags after save article' do 860 should 'sanitize tags after save article' do
861 article = fast_create(Article, :slug => 'article-with-tags', :profile_id => profile.id) 861 article = fast_create(Article, :slug => 'article-with-tags', :profile_id => profile.id)
862 - article.tags << build(Tag, :name => "TV Web w<script type='javascript'></script>")  
863 - assert_match /[<>]/, article.tags.last.name 862 + tag = build(ActsAsTaggableOn::Tag, :name => "TV Web w<script type='javascript'></script>")
  863 + assert_match /[<>]/, tag.name
  864 + article.tag_list.add(tag.name)
864 article.save! 865 article.save!
865 assert_no_match /[<>]/, article.tags.last.name 866 assert_no_match /[<>]/, article.tags.last.name
866 end 867 end
867 868
868 should 'strip HTML from tag names after save article' do 869 should 'strip HTML from tag names after save article' do
869 article = fast_create(Article, :slug => 'article-with-tags', :profile_id => profile.id) 870 article = fast_create(Article, :slug => 'article-with-tags', :profile_id => profile.id)
870 - article.tags << build(Tag, :name => "TV Web w<script type=...")  
871 - assert_match /</, article.tags.last.name 871 + tag = build(ActsAsTaggableOn::Tag, :name => "TV Web w<script type=...")
  872 + assert_match /</, tag.name
  873 + article.tag_list.add(tag.name)
872 article.save! 874 article.save!
873 assert_no_match /</, article.tags.last.name 875 assert_no_match /</, article.tags.last.name
874 end 876 end
test/unit/extended_tag_test.rb
@@ -4,30 +4,30 @@ require &#39;extended_tag.rb&#39; @@ -4,30 +4,30 @@ require &#39;extended_tag.rb&#39;
4 class UserTest < ActiveSupport::TestCase 4 class UserTest < ActiveSupport::TestCase
5 5
6 def test_find_without_pendings 6 def test_find_without_pendings
7 - tag1 = Tag.create(:name => 'pending_tag', :pending => true)  
8 - tag2 = Tag.create(:name => 'approved_tag', :pending => false)  
9 - assert_nothing_raised {Tag.find(tag2.id)}  
10 - assert_raise(ActiveRecord::RecordNotFound) {Tag.find(tag1.id)} 7 + tag1 = ActsAsTaggableOn::Tag.create(:name => 'pending_tag', :pending => true)
  8 + tag2 = ActsAsTaggableOn::Tag.create(:name => 'approved_tag', :pending => false)
  9 + assert_nothing_raised {ActsAsTaggableOn::Tag.find(tag2.id)}
  10 + assert_raise(ActiveRecord::RecordNotFound) {ActsAsTaggableOn::Tag.find(tag1.id)}
11 end 11 end
12 12
13 def test_find_pendings 13 def test_find_pendings
14 - tag1 = Tag.create(:name => 'pending_tag', :pending => true)  
15 - tag2 = Tag.create(:name => 'approved_tag', :pending => false)  
16 - assert Tag.find_pendings.include?(tag1)  
17 - assert (not Tag.find_pendings.include?(tag2)) 14 + tag1 = ActsAsTaggableOn::Tag.create(:name => 'pending_tag', :pending => true)
  15 + tag2 = ActsAsTaggableOn::Tag.create(:name => 'approved_tag', :pending => false)
  16 + assert ActsAsTaggableOn::Tag.find_pendings.include?(tag1)
  17 + assert (not ActsAsTaggableOn::Tag.find_pendings.include?(tag2))
18 end 18 end
19 19
20 def test_parent_candidates 20 def test_parent_candidates
21 - tag1 = Tag.create(:name => 'parent_tag')  
22 - tag2 = Tag.create(:name => 'child_tag', :parent_id => tag1.id) 21 + tag1 = ActsAsTaggableOn::Tag.create(:name => 'parent_tag')
  22 + tag2 = ActsAsTaggableOn::Tag.create(:name => 'child_tag', :parent_id => tag1.id)
23 assert ( not tag1.parent_candidates.include?(tag2) ) 23 assert ( not tag1.parent_candidates.include?(tag2) )
24 assert tag2.parent_candidates.include?(tag1) 24 assert tag2.parent_candidates.include?(tag1)
25 end 25 end
26 26
27 def test_descendents 27 def test_descendents
28 - tag1 = Tag.create(:name => 'parent_tag')  
29 - tag2 = Tag.create(:name => 'child_tag', :parent_id => tag1.id)  
30 - tag3 = Tag.create(:name => 'grand_tag', :parent_id => tag2.id) 28 + tag1 = ActsAsTaggableOn::Tag.create(:name => 'parent_tag')
  29 + tag2 = ActsAsTaggableOn::Tag.create(:name => 'child_tag', :parent_id => tag1.id)
  30 + tag3 = ActsAsTaggableOn::Tag.create(:name => 'grand_tag', :parent_id => tag2.id)
31 assert (not tag2.descendents.include?(tag1)) 31 assert (not tag2.descendents.include?(tag1))
32 assert (not tag1.descendents.include?(tag1)) 32 assert (not tag1.descendents.include?(tag1))
33 assert tag1.descendents.include?(tag2) 33 assert tag1.descendents.include?(tag2)
test/unit/profile_test.rb
@@ -285,9 +285,9 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -285,9 +285,9 @@ class ProfileTest &lt; ActiveSupport::TestCase
285 second = create(Article, :profile => profile, :tag_list => 'first-tag, second-tag') 285 second = create(Article, :profile => profile, :tag_list => 'first-tag, second-tag')
286 third = create(Article, :profile => profile, :tag_list => 'first-tag, second-tag, third-tag') 286 third = create(Article, :profile => profile, :tag_list => 'first-tag, second-tag, third-tag')
287 287
288 - assert_equivalent [ first, second, third], profile.find_tagged_with('first-tag')  
289 - assert_equivalent [ second, third ], profile.find_tagged_with('second-tag')  
290 - assert_equivalent [ third], profile.find_tagged_with('third-tag') 288 + assert_equivalent [ first, second, third], profile.tagged_with('first-tag')
  289 + assert_equivalent [ second, third ], profile.tagged_with('second-tag')
  290 + assert_equivalent [ third], profile.tagged_with('third-tag')
291 end 291 end
292 292
293 should 'provide tag count' do 293 should 'provide tag count' do
vendor/plugins/acts_as_taggable_on_steroids/CHANGELOG
@@ -1,58 +0,0 @@ @@ -1,58 +0,0 @@
1 -[1 July 2007]  
2 -  
3 -* Fix incorrect tagging when the case of the tag list is changed.  
4 -  
5 -* Fix deprecated Tag.delimiter accessor.  
6 -  
7 -[23 June 2007]  
8 -  
9 -* Add validation to Tag model.  
10 -  
11 -* find_options_for_tagged_with should always return a hash.  
12 -  
13 -* find_tagged_with passing in no tags should return an empty array.  
14 -  
15 -* Improve compatibility with PostgreSQL.  
16 -  
17 -[21 June 2007]  
18 -  
19 -* Remove extra .rb from generated migration file name.  
20 -  
21 -[15 June 2007]  
22 -  
23 -* Introduce TagList class.  
24 -  
25 -* Various cleanups and improvements.  
26 -  
27 -* Use TagList.delimiter now, not Tag.delimiter. Tag.delimiter will be removed at some stage.  
28 -  
29 -[11 June 2007]  
30 -  
31 -* Restructure the creation of the options for find_tagged_with [Thijs Cadier]  
32 -  
33 -* Add an example migration with a generator.  
34 -  
35 -* Add caching.  
36 -  
37 -* Fix compatibility with Ruby < 1.8.6  
38 -  
39 -[23 April 2007]  
40 -  
41 -* Make tag_list to respect Tag.delimiter  
42 -  
43 -[31 March 2007]  
44 -  
45 -* Add Tag.delimiter accessor to change how tags are parsed.  
46 -* Fix :include => :tags when used with find_tagged_with  
47 -  
48 -[7 March 2007]  
49 -  
50 -* Fix tag_counts for SQLServer [Brad Young]  
51 -  
52 -[21 Feb 2007]  
53 -  
54 -* Use scoping instead of TagCountsExtension [Michael Schuerig]  
55 -  
56 -[7 Jan 2007]  
57 -  
58 -* Add :match_all to find_tagged_with [Michael Sheakoski]  
vendor/plugins/acts_as_taggable_on_steroids/MIT-LICENSE
@@ -1,20 +0,0 @@ @@ -1,20 +0,0 @@
1 -Copyright (c) 2006 Jonathan Viney  
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.  
vendor/plugins/acts_as_taggable_on_steroids/README
@@ -1,116 +0,0 @@ @@ -1,116 +0,0 @@
1 -= acts_as_taggable_on_steroids  
2 -  
3 -If you find this plugin useful, please consider a donation to show your support!  
4 -  
5 - http://www.paypal.com/cgi-bin/webscr?cmd=_send-money  
6 -  
7 - Email address: jonathan.viney@gmail.com  
8 -  
9 -== Instructions  
10 -  
11 -This plugin is based on acts_as_taggable by DHH but includes extras  
12 -such as tests, smarter tag assignment, and tag cloud calculations.  
13 -  
14 -Thanks to www.fanacious.com for allowing this plugin to be released. Please check out  
15 -their site to show your support.  
16 -  
17 -== Resources  
18 -  
19 -Install  
20 - * script/plugin install http://svn.viney.net.nz/things/rails/plugins/acts_as_taggable_on_steroids  
21 -  
22 -== Usage  
23 -  
24 -=== Prepare database  
25 -  
26 -Generate and apply the migration:  
27 -  
28 - ruby script/generate acts_as_taggable_migration  
29 - rake db:migrate  
30 -  
31 -=== Basic tagging  
32 -  
33 -Using the examples from the tests, let's suppose we have users that have many posts and we want those  
34 -posts to be able to be tagged by the user.  
35 -  
36 -As usual, we add +acts_as_taggable+ to the Post class:  
37 -  
38 - class Post < ActiveRecord::Base  
39 - acts_as_taggable  
40 -  
41 - belongs_to :user  
42 - end  
43 -  
44 -We can now use the tagging methods provided by acts_as_taggable, <tt>tag_list</tt> and <tt>tag_list=</tt>. Both these  
45 -methods work like regular attribute accessors.  
46 -  
47 - p = Post.find(:first)  
48 - p.tag_list.to_s # ""  
49 - p.tag_list = "Funny, Silly"  
50 - p.save  
51 - p.reload.tag_list.to_s # "Funny, Silly"  
52 -  
53 -You can also add or remove arrays of tags.  
54 -  
55 - p.tag_list.add("Great", "Awful")  
56 - p.tag_list.remove("Funny")  
57 -  
58 -=== Finding tagged objects  
59 -  
60 -To retrieve objects tagged with a certain tag, use find_tagged_with.  
61 -  
62 - Post.find_tagged_with('Funny, Silly')  
63 -  
64 -By default, find_tagged_with will find objects that have any of the given tags. To  
65 -find only objects that are tagged with all the given tags, use match_all.  
66 -  
67 - Post.find_tagged_with('Funny, Silly', :match_all => true)  
68 -  
69 -=== Tag cloud calculations  
70 -  
71 -To construct tag clouds, the frequency of each tag needs to be calculated.  
72 -Because we specified +acts_as_taggable+ on the <tt>Post</tt> class, we can  
73 -get a calculation of all the tag counts by using <tt>Post.tag_counts</tt>. But what if we wanted a tag count for  
74 -an single user's posts? To achieve this we call tag_counts on the association:  
75 -  
76 - User.find(:first).posts.tag_counts  
77 -  
78 -=== Caching  
79 -  
80 -It is useful to cache the list of tags to reduce the number of queries executed. To do this,  
81 -add a column named <tt>cached_tag_list</tt> to the model which is being tagged.  
82 -  
83 - class CachePostTagList < ActiveRecord::Migration  
84 - def self.up  
85 - # You should make sure that the column is long enough to hold  
86 - # the full tag list. In some situations the :text type may be more appropriate.  
87 - add_column :posts, :cached_tag_list, :string  
88 - end  
89 - end  
90 -  
91 - class Post < ActiveRecord::Base  
92 - acts_as_taggable  
93 -  
94 - # The caching column defaults to cached_tag_list, but can be changed:  
95 - #  
96 - # set_cached_tag_list_column_name "my_caching_column_name"  
97 - end  
98 -  
99 -The details of the caching are handled for you. Just continue to use the tag_list accessor as you normally would.  
100 -Note that the cached tag list will not be updated if you directly create Tagging objects or manually append to the  
101 -<tt>tags</tt> or <tt>taggings</tt> associations. To update the cached tag list you should call <tt>save_cached_tag_list</tt> manually.  
102 -  
103 -=== Delimiter  
104 -  
105 -If you want to change the delimiter used to parse and present tags, set TagList.delimiter.  
106 -For example, to use spaces instead of commas, add the following to config/environment.rb:  
107 -  
108 - TagList.delimiter = " "  
109 -  
110 -=== Other  
111 -  
112 -Problems, comments, and suggestions all welcome. jonathan.viney@gmail.com  
113 -  
114 -== Credits  
115 -  
116 -www.fanacious.com  
vendor/plugins/acts_as_taggable_on_steroids/Rakefile
@@ -1,22 +0,0 @@ @@ -1,22 +0,0 @@
1 -require 'rake'  
2 -require 'rake/testtask'  
3 -require 'rake/rdoctask'  
4 -  
5 -desc 'Default: run unit tests.'  
6 -task :default => :test  
7 -  
8 -desc 'Test the acts_as_taggable_on_steroids plugin.'  
9 -Rake::TestTask.new(:test) do |t|  
10 - t.libs << 'lib'  
11 - t.pattern = 'test/**/*_test.rb'  
12 - t.verbose = true  
13 -end  
14 -  
15 -desc 'Generate documentation for the acts_as_taggable_on_steroids plugin.'  
16 -Rake::RDocTask.new(:rdoc) do |rdoc|  
17 - rdoc.rdoc_dir = 'rdoc'  
18 - rdoc.title = 'Acts As Taggable On Steroids'  
19 - rdoc.options << '--line-numbers' << '--inline-source'  
20 - rdoc.rdoc_files.include('README')  
21 - rdoc.rdoc_files.include('lib/**/*.rb')  
22 -end  
vendor/plugins/acts_as_taggable_on_steroids/generators/acts_as_taggable_migration/acts_as_taggable_migration_generator.rb
@@ -1,11 +0,0 @@ @@ -1,11 +0,0 @@
1 -class ActsAsTaggableMigrationGenerator < Rails::Generator::Base  
2 - def manifest  
3 - record do |m|  
4 - m.migration_template 'migration.rb', 'db/migrate'  
5 - end  
6 - end  
7 -  
8 - def file_name  
9 - "acts_as_taggable_migration"  
10 - end  
11 -end  
vendor/plugins/acts_as_taggable_on_steroids/generators/acts_as_taggable_migration/templates/migration.rb
@@ -1,26 +0,0 @@ @@ -1,26 +0,0 @@
1 -class ActsAsTaggableMigration < ActiveRecord::Migration  
2 - def self.up  
3 - create_table :tags do |t|  
4 - t.column :name, :string  
5 - end  
6 -  
7 - create_table :taggings do |t|  
8 - t.column :tag_id, :integer  
9 - t.column :taggable_id, :integer  
10 -  
11 - # You should make sure that the column created is  
12 - # long enough to store the required class names.  
13 - t.column :taggable_type, :string  
14 -  
15 - t.column :created_at, :datetime  
16 - end  
17 -  
18 - add_index :taggings, :tag_id  
19 - add_index :taggings, [:taggable_id, :taggable_type]  
20 - end  
21 -  
22 - def self.down  
23 - drop_table :taggings  
24 - drop_table :tags  
25 - end  
26 -end  
vendor/plugins/acts_as_taggable_on_steroids/init.rb
@@ -1,4 +0,0 @@ @@ -1,4 +0,0 @@
1 -require File.dirname(__FILE__) + '/lib/acts_as_taggable'  
2 -  
3 -require File.dirname(__FILE__) + '/lib/tagging'  
4 -require File.dirname(__FILE__) + '/lib/tag'  
vendor/plugins/acts_as_taggable_on_steroids/lib/acts_as_taggable.rb
@@ -1,145 +0,0 @@ @@ -1,145 +0,0 @@
1 -module ActiveRecord  
2 - module Acts #:nodoc:  
3 - module Taggable #:nodoc:  
4 - def self.included(base)  
5 - base.extend(ClassMethods)  
6 - end  
7 -  
8 - module ClassMethods  
9 - def acts_as_taggable(options = {})  
10 - has_many :taggings, :as => :taggable, :dependent => :destroy, :include => :tag  
11 - has_many :tags, :through => :taggings  
12 -  
13 - before_save :save_cached_tag_list  
14 - after_save :save_tags  
15 -  
16 - include ActiveRecord::Acts::Taggable::InstanceMethods  
17 - extend ActiveRecord::Acts::Taggable::SingletonMethods  
18 -  
19 - alias_method :reload_without_tag_list, :reload  
20 - alias_method :reload, :reload_with_tag_list  
21 - end  
22 -  
23 - def cached_tag_list_column_name  
24 - "cached_tag_list"  
25 - end  
26 -  
27 - def set_cached_tag_list_column_name(value = nil, &block)  
28 - define_attr_method :cached_tag_list_column_name, value, &block  
29 - end  
30 - end  
31 -  
32 - module SingletonMethods  
33 - # Pass either a tag string, or an array of strings or tags  
34 - #  
35 - # Options:  
36 - # :exclude - Find models that are not tagged with the given tags  
37 - # :match_all - Find models that match all of the given tags, not just one  
38 - # :conditions - A piece of SQL conditions to add to the query  
39 - def find_tagged_with(tags, options = {})  
40 - tags = TagList.from(tags).names  
41 - return [] if tags.empty?  
42 -  
43 - conditions = tags.map {|t| sanitize_sql(["tags.name LIKE ?",t])}.join(' OR ')  
44 - conditions += ' AND ' + sanitize_sql(options.delete(:conditions)) if options[:conditions]  
45 - group = "#{table_name}.id HAVING COUNT(#{table_name}.id) = #{tags.size}" if options.delete(:match_all)  
46 - exclude = options.delete(:exclude)  
47 - taggeds = find(:all, {:conditions => conditions, :include => :tags, :group => group}.update(options))  
48 - exclude ? find(:all) - taggeds : taggeds  
49 - end  
50 -  
51 - # Options:  
52 - # :start_at - Restrict the tags to those created after a certain time  
53 - # :end_at - Restrict the tags to those created before a certain time  
54 - # :conditions - A piece of SQL conditions to add to the query  
55 - # :limit - The maximum number of tags to return  
56 - # :order - A piece of SQL to order by. Eg 'tags.count desc' or 'taggings.created_at desc'  
57 - # :at_least - Exclude tags with a frequency less than the given value  
58 - # :at_most - Exclude tags with a frequency greater then the given value  
59 - def tag_counts(*args)  
60 - Tag.find(:all, find_options_for_tag_counts(*args))  
61 - end  
62 -  
63 - def find_options_for_tag_counts(options = {})  
64 - options.assert_valid_keys :start_at, :end_at, :conditions, :at_least, :at_most, :order, :limit  
65 -  
66 - scope = scope(:find)  
67 - start_at = sanitize_sql(["#{Tagging.table_name}.created_at >= ?", options[:start_at]]) if options[:start_at]  
68 - end_at = sanitize_sql(["#{Tagging.table_name}.created_at <= ?", options[:end_at]]) if options[:end_at]  
69 -  
70 - conditions = [  
71 - "#{Tagging.table_name}.taggable_type = #{quote_value(base_class.name)}",  
72 - options[:conditions],  
73 - scope && scope[:conditions],  
74 - start_at,  
75 - end_at  
76 - ]  
77 - conditions = conditions.compact.join(' and ')  
78 -  
79 - at_least = sanitize_sql(['COUNT(*) >= ?', options[:at_least]]) if options[:at_least]  
80 - at_most = sanitize_sql(['COUNT(*) <= ?', options[:at_most]]) if options[:at_most]  
81 - having = [at_least, at_most].compact.join(' and ')  
82 - group_by = "#{Tag.table_name}.id, #{Tag.table_name}.name HAVING COUNT(*) > 0"  
83 - group_by << " AND #{having}" unless having.blank?  
84 -  
85 - { :select => "#{Tag.table_name}.id, #{Tag.table_name}.name, COUNT(*) AS count",  
86 - :joins => "LEFT OUTER JOIN #{Tagging.table_name} ON #{Tag.table_name}.id = #{Tagging.table_name}.tag_id LEFT OUTER JOIN #{table_name} ON #{table_name}.#{primary_key} = #{Tagging.table_name}.taggable_id",  
87 - :conditions => conditions,  
88 - :group => group_by,  
89 - :order => options[:order],  
90 - :limit => options[:limit]  
91 - }  
92 - end  
93 - end  
94 -  
95 - module InstanceMethods  
96 - def tag_list  
97 - if @tag_list  
98 - @tag_list  
99 - elsif caching_tag_list? and !send(self.class.cached_tag_list_column_name).nil?  
100 - @tag_list = TagList.from(send(self.class.cached_tag_list_column_name))  
101 - else  
102 - @tag_list = TagList.new(tags.map(&:name))  
103 - end  
104 - end  
105 -  
106 - def tag_list=(value)  
107 - @tag_list = TagList.from(value)  
108 - end  
109 -  
110 - def save_cached_tag_list  
111 - if caching_tag_list? and !tag_list.blank?  
112 - self[self.class.cached_tag_list_column_name] = tag_list.to_s  
113 - end  
114 - end  
115 -  
116 - def save_tags  
117 - return unless @tag_list  
118 -  
119 - new_tag_names = @tag_list.names - tags.map(&:name)  
120 - old_tags = tags.reject { |tag| @tag_list.names.include?(tag.name) }  
121 -  
122 - self.class.transaction do  
123 - tags.delete(*old_tags) if old_tags.any?  
124 -  
125 - new_tag_names.each do |new_tag_name|  
126 - tags << (Tag.find(:first, :conditions => ['name like ?',new_tag_name]) || Tag.create(:name => new_tag_name))  
127 - end  
128 - end  
129 - true  
130 - end  
131 -  
132 - def reload_with_tag_list(*args)  
133 - @tag_list = nil  
134 - reload_without_tag_list(*args)  
135 - end  
136 -  
137 - def caching_tag_list?  
138 - self.class.column_names.include?(self.class.cached_tag_list_column_name)  
139 - end  
140 - end  
141 - end  
142 - end  
143 -end  
144 -  
145 -ActiveRecord::Base.send(:include, ActiveRecord::Acts::Taggable)  
vendor/plugins/acts_as_taggable_on_steroids/lib/tag.rb
@@ -1,41 +0,0 @@ @@ -1,41 +0,0 @@
1 -class Tag < ActiveRecord::Base  
2 - has_many :taggings  
3 -  
4 - attr_accessible :name  
5 -  
6 - validates_presence_of :name  
7 - validates_uniqueness_of :name  
8 -  
9 - class << self  
10 - delegate :delimiter, :delimiter=, :to => TagList  
11 - end  
12 -  
13 - def ==(object)  
14 - super || (object.is_a?(Tag) && name == object.name)  
15 - end  
16 -  
17 - def to_s  
18 - name  
19 - end  
20 -  
21 - def count  
22 - read_attribute(:count).to_i  
23 - end  
24 -  
25 - def self.hierarchical=(bool)  
26 - if bool  
27 - acts_as_tree  
28 - end  
29 - end  
30 -  
31 - # All the tags that can be a new parent for this tag, that is all but itself and its descendents to avoid loops  
32 - def parent_candidates  
33 - Tag.find_all_by_pending(false) - descendents - [self]  
34 - end  
35 -  
36 - # All tags that have this tag as its one of its ancestors  
37 - def descendents  
38 - children.to_a.sum([], &:descendents) + children  
39 - end  
40 -  
41 -end  
vendor/plugins/acts_as_taggable_on_steroids/lib/tag_counts_extension.rb
@@ -1,2 +0,0 @@ @@ -1,2 +0,0 @@
1 -module TagCountsExtension  
2 -end  
vendor/plugins/acts_as_taggable_on_steroids/lib/tag_list.rb
@@ -1,66 +0,0 @@ @@ -1,66 +0,0 @@
1 -class TagList  
2 - cattr_accessor :delimiter  
3 - self.delimiter = ','  
4 -  
5 - attr_reader :names  
6 -  
7 - def initialize(*names)  
8 - @names = []  
9 - add(*names)  
10 - end  
11 -  
12 - def add(*names)  
13 - names = names.flatten  
14 -  
15 - # Strip whitespace and remove blank or duplicate tags  
16 - names.map!(&:strip)  
17 - names.reject!(&:blank?)  
18 -  
19 - @names.concat(names)  
20 - @names.uniq!  
21 - end  
22 -  
23 - def remove(*names)  
24 - names = names.flatten  
25 - @names.delete_if { |name| names.include?(name) }  
26 - end  
27 -  
28 - def blank?  
29 - @names.empty?  
30 - end  
31 -  
32 - def to_s  
33 - @names.map do |name|  
34 - name.include?(delimiter) ? "\"#{name}\"" : name  
35 - end.join(delimiter.ends_with?(" ") ? delimiter : "#{delimiter} ")  
36 - end  
37 -  
38 - def ==(other)  
39 - super || (other.is_a?(TagList) && other.names == @names)  
40 - end  
41 -  
42 - class << self  
43 - def from(tags)  
44 - case tags  
45 - when String  
46 - new(parse(tags))  
47 - when Array  
48 - new(tags.map(&:to_s))  
49 - else  
50 - new([])  
51 - end  
52 - end  
53 -  
54 - def parse(string)  
55 - [].tap do |names|  
56 - string = string.to_s.dup  
57 -  
58 - # Parse the quoted tags  
59 - string.gsub!(/"(.*?)"\s*#{delimiter}?\s*/) { names << $1; "" }  
60 - string.gsub!(/'(.*?)'\s*#{delimiter}?\s*/) { names << $1; "" }  
61 -  
62 - names.concat(string.split(delimiter))  
63 - end  
64 - end  
65 - end  
66 -end  
vendor/plugins/acts_as_taggable_on_steroids/lib/tagging.rb
@@ -1,4 +0,0 @@ @@ -1,4 +0,0 @@
1 -class Tagging < ActiveRecord::Base  
2 - belongs_to :tag  
3 - belongs_to :taggable, :polymorphic => true  
4 -end  
vendor/plugins/acts_as_taggable_on_steroids/test/abstract_unit.rb
@@ -1,82 +0,0 @@ @@ -1,82 +0,0 @@
1 -require 'test/unit'  
2 -  
3 -begin  
4 - require File.dirname(__FILE__) + '/../../../../config/environment'  
5 -rescue LoadError  
6 - require 'rubygems'  
7 - require_gem 'activerecord'  
8 - require_gem 'actionpack'  
9 -end  
10 -  
11 -# Search for fixtures first  
12 -fixture_path = File.dirname(__FILE__) + '/fixtures/'  
13 -begin  
14 - Dependencies.load_paths.insert(0, fixture_path)  
15 -rescue  
16 - $LOAD_PATH.unshift(fixture_path)  
17 -end  
18 -  
19 -require 'active_record/fixtures'  
20 -  
21 -require File.dirname(__FILE__) + '/../lib/acts_as_taggable'  
22 -require_dependency File.dirname(__FILE__) + '/../lib/tag_list'  
23 -  
24 -ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + '/debug.log')  
25 -#ActiveRecord::Base.configurations = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))  
26 -#ActiveRecord::Base.establish_connection(ENV['DB'] || 'mysql')  
27 -  
28 -load(File.dirname(__FILE__) + '/schema.rb')  
29 -  
30 -Test::Unit::TestCase.fixture_path = fixture_path  
31 -  
32 -class Test::Unit::TestCase #:nodoc:  
33 - self.use_transactional_fixtures = true  
34 - self.use_instantiated_fixtures = false  
35 -  
36 - def assert_equivalent(expected, actual, message = nil)  
37 - if expected.first.is_a?(ActiveRecord::Base)  
38 - assert_equal expected.sort_by(&:id), actual.sort_by(&:id), message  
39 - else  
40 - assert_equal expected.sort, actual.sort, message  
41 - end  
42 - end  
43 -  
44 - def assert_tag_counts(tags, expected_values)  
45 - # Map the tag fixture names to real tag names  
46 - expected_values = expected_values.inject({}) do |hash, (tag, count)|  
47 - hash[tags(tag).name] = count  
48 - hash  
49 - end  
50 -  
51 - tags.each do |tag|  
52 - value = expected_values.delete(tag.name)  
53 - assert_not_nil value, "Expected count for #{tag.name} was not provided" if value.nil?  
54 - assert_equal value, tag.count, "Expected value of #{value} for #{tag.name}, but was #{tag.count}"  
55 - end  
56 -  
57 - unless expected_values.empty?  
58 - assert false, "The following tag counts were not present: #{expected_values.inspect}"  
59 - end  
60 - end  
61 -  
62 - def assert_queries(num = 1)  
63 - $query_count = 0  
64 - yield  
65 - ensure  
66 - assert_equal num, $query_count, "#{$query_count} instead of #{num} queries were executed."  
67 - end  
68 -  
69 - def assert_no_queries(&block)  
70 - assert_queries(0, &block)  
71 - end  
72 -end  
73 -  
74 -ActiveRecord::Base.connection.class.class_eval do  
75 - def execute_with_counting(sql, name = nil, &block)  
76 - $query_count ||= 0  
77 - $query_count += 1  
78 - execute_without_counting(sql, name, &block)  
79 - end  
80 -  
81 - alias_method_chain :execute, :counting  
82 -end  
vendor/plugins/acts_as_taggable_on_steroids/test/acts_as_taggable_test.rb
@@ -1,272 +0,0 @@ @@ -1,272 +0,0 @@
1 -require File.dirname(__FILE__) + '/abstract_unit'  
2 -  
3 -class ActsAsTaggableOnSteroidsTest < Test::Unit::TestCase  
4 - fixtures :tags, :taggings, :posts, :users, :photos  
5 -  
6 - def test_find_tagged_with  
7 - assert_equivalent [posts(:jonathan_sky), posts(:sam_flowers)], Post.find_tagged_with('"Very good"')  
8 - assert_equal Post.find_tagged_with('"Very good"'), Post.find_tagged_with(['Very good'])  
9 - assert_equal Post.find_tagged_with('"Very good"'), Post.find_tagged_with([tags(:good)])  
10 -  
11 - assert_equivalent [photos(:jonathan_dog), photos(:sam_flower), photos(:sam_sky)], Photo.find_tagged_with('Nature')  
12 - assert_equal Photo.find_tagged_with('Nature'), Photo.find_tagged_with(['Nature'])  
13 - assert_equal Photo.find_tagged_with('Nature'), Photo.find_tagged_with([tags(:nature)])  
14 -  
15 - assert_equivalent [photos(:jonathan_bad_cat), photos(:jonathan_dog), photos(:jonathan_questioning_dog)], Photo.find_tagged_with('"Crazy animal" Bad')  
16 - assert_equal Photo.find_tagged_with('"Crazy animal" Bad'), Photo.find_tagged_with(['Crazy animal', 'Bad'])  
17 - assert_equal Photo.find_tagged_with('"Crazy animal" Bad'), Photo.find_tagged_with([tags(:animal), tags(:bad)])  
18 - end  
19 -  
20 - def test_find_tagged_with_nothing  
21 - assert_equal [], Post.find_tagged_with("")  
22 - assert_equal [], Post.find_tagged_with([])  
23 - end  
24 -  
25 - def test_find_tagged_with_nonexistant_tags  
26 - assert_equal [], Post.find_tagged_with('ABCDEFG')  
27 - assert_equal [], Photo.find_tagged_with(['HIJKLM'])  
28 - assert_equal [], Photo.find_tagged_with([Tag.new(:name => 'unsaved tag')])  
29 - end  
30 -  
31 - def test_find_tagged_with_matching_all_tags  
32 - assert_equivalent [photos(:jonathan_dog)], Photo.find_tagged_with('Crazy animal, "Nature"', :match_all => true)  
33 - assert_equivalent [posts(:jonathan_sky), posts(:sam_flowers)], Post.find_tagged_with(['Very good', 'Nature'], :match_all => true)  
34 - end  
35 -  
36 - def test_find_tagged_with_exclusions  
37 - assert_equivalent [photos(:jonathan_questioning_dog), photos(:jonathan_bad_cat)], Photo.find_tagged_with("Nature", :exclude => true)  
38 - assert_equivalent [posts(:jonathan_grass), posts(:jonathan_rain)], Post.find_tagged_with("'Very good', Bad", :exclude => true)  
39 - end  
40 -  
41 -# def test_find_options_for_tagged_with_no_tags_returns_empty_hash  
42 -# assert_equal Hash.new, Post.find_options_for_tagged_with("")  
43 -# assert_equal Hash.new, Post.find_options_for_tagged_with([nil])  
44 -# end  
45 -  
46 -# def test_find_options_for_tagged_with_leavs_arguments_unchanged  
47 -# original_tags = photos(:jonathan_questioning_dog).tags.dup  
48 -# Photo.find_options_for_tagged_with(photos(:jonathan_questioning_dog).tags)  
49 -# assert_equal original_tags, photos(:jonathan_questioning_dog).tags  
50 -# end  
51 -  
52 -# def test_find_options_for_tagged_with_respects_custom_table_name  
53 -# Tagging.table_name = "categorisations"  
54 -# Tag.table_name = "categories"  
55 -#  
56 -# options = Photo.find_options_for_tagged_with("Hello")  
57 -#  
58 -# assert_no_match Regexp.new(" taggings "), options[:joins]  
59 -# assert_no_match Regexp.new(" tags "), options[:joins]  
60 -#  
61 -# assert_match Regexp.new(" categorisations "), options[:joins]  
62 -# assert_match Regexp.new(" categories "), options[:joins]  
63 -# ensure  
64 -# Tagging.table_name = "taggings"  
65 -# Tag.table_name = "tags"  
66 -# end  
67 -  
68 - def test_include_tags_on_find_tagged_with  
69 - assert_nothing_raised do  
70 - Photo.find_tagged_with('Nature', :include => :tags)  
71 - Photo.find_tagged_with("Nature", :include => { :taggings => :tag })  
72 - end  
73 - end  
74 -  
75 - def test_basic_tag_counts_on_class  
76 - assert_tag_counts Post.tag_counts, :good => 2, :nature => 5, :question => 1, :bad => 1  
77 - assert_tag_counts Photo.tag_counts, :good => 1, :nature => 3, :question => 1, :bad => 1, :animal => 3  
78 - end  
79 -  
80 - def test_tag_counts_on_class_with_date_conditions  
81 - assert_tag_counts Post.tag_counts(:start_at => Date.new(2006, 8, 4)), :good => 1, :nature => 3, :question => 1, :bad => 1  
82 - assert_tag_counts Post.tag_counts(:end_at => Date.new(2006, 8, 6)), :good => 1, :nature => 4, :question => 1  
83 - assert_tag_counts Post.tag_counts(:start_at => Date.new(2006, 8, 5), :end_at => Date.new(2006, 8, 8)), :good => 1, :nature => 2, :bad => 1  
84 -  
85 - assert_tag_counts Photo.tag_counts(:start_at => Date.new(2006, 8, 12), :end_at => Date.new(2006, 8, 17)), :good => 1, :nature => 1, :bad => 1, :question => 1, :animal => 2  
86 - end  
87 -  
88 - def test_tag_counts_on_class_with_frequencies  
89 - assert_tag_counts Photo.tag_counts(:at_least => 2), :nature => 3, :animal => 3  
90 - assert_tag_counts Photo.tag_counts(:at_most => 2), :good => 1, :question => 1, :bad => 1  
91 - end  
92 -  
93 - def test_tag_counts_with_limit  
94 - assert_equal 2, Photo.tag_counts(:limit => 2).size  
95 - assert_equal 1, Post.tag_counts(:at_least => 4, :limit => 2).size  
96 - end  
97 -  
98 - def test_tag_counts_with_limit_and_order  
99 - assert_equal [tags(:nature), tags(:good)], Post.tag_counts(:order => 'count desc', :limit => 2)  
100 - end  
101 -  
102 - def test_tag_counts_on_association  
103 - assert_tag_counts users(:jonathan).posts.tag_counts, :good => 1, :nature => 3, :question => 1  
104 - assert_tag_counts users(:sam).posts.tag_counts, :good => 1, :nature => 2, :bad => 1  
105 -  
106 - assert_tag_counts users(:jonathan).photos.tag_counts, :animal => 3, :nature => 1, :question => 1, :bad => 1  
107 - assert_tag_counts users(:sam).photos.tag_counts, :nature => 2, :good => 1  
108 - end  
109 -  
110 - def test_tag_counts_on_association_with_options  
111 - assert_equal [], users(:jonathan).posts.tag_counts(:conditions => '1=0')  
112 - assert_tag_counts users(:jonathan).posts.tag_counts(:at_most => 2), :good => 1, :question => 1  
113 - end  
114 -  
115 - def test_tag_counts_respects_custom_table_names  
116 - Tagging.table_name = "categorisations"  
117 - Tag.table_name = "categories"  
118 -  
119 - options = Photo.find_options_for_tag_counts(:start_at => 2.weeks.ago, :end_at => Date.today)  
120 - sql = options.values.join(' ')  
121 -  
122 - assert_no_match /taggings/, sql  
123 - assert_no_match /tags/, sql  
124 -  
125 - assert_match /categorisations/, sql  
126 - assert_match /categories/, sql  
127 - ensure  
128 - Tagging.table_name = "taggings"  
129 - Tag.table_name = "tags"  
130 - end  
131 -  
132 - def test_tag_list_reader  
133 - assert_equivalent ["Very good", "Nature"], posts(:jonathan_sky).tag_list.names  
134 - assert_equivalent ["Bad", "Crazy animal"], photos(:jonathan_bad_cat).tag_list.names  
135 - end  
136 -  
137 - def test_reassign_tag_list  
138 - assert_equivalent ["Nature", "Question"], posts(:jonathan_rain).tag_list.names  
139 - posts(:jonathan_rain).taggings.reload  
140 -  
141 - # Only an update of the posts table should be executed  
142 - assert_queries 1 do  
143 - posts(:jonathan_rain).update_attributes!(:tag_list => posts(:jonathan_rain).tag_list.to_s)  
144 - end  
145 -  
146 - assert_equivalent ["Nature", "Question"], posts(:jonathan_rain).tag_list.names  
147 - end  
148 -  
149 - def test_new_tags  
150 - assert_equivalent ["Very good", "Nature"], posts(:jonathan_sky).tag_list.names  
151 - posts(:jonathan_sky).update_attributes!(:tag_list => "#{posts(:jonathan_sky).tag_list}, One, Two")  
152 - assert_equivalent ["Very good", "Nature", "One", "Two"], posts(:jonathan_sky).tag_list.names  
153 - end  
154 -  
155 - def test_remove_tag  
156 - assert_equivalent ["Very good", "Nature"], posts(:jonathan_sky).tag_list.names  
157 - posts(:jonathan_sky).update_attributes!(:tag_list => "Nature")  
158 - assert_equivalent ["Nature"], posts(:jonathan_sky).tag_list.names  
159 - end  
160 -  
161 - def test_change_case_of_tags  
162 - original_tag_names = photos(:jonathan_questioning_dog).tag_list.names  
163 - photos(:jonathan_questioning_dog).update_attributes!(:tag_list => photos(:jonathan_questioning_dog).tag_list.to_s.upcase)  
164 -  
165 - # The new tag list is not uppercase becuase the AR finders are not case-sensitive  
166 - # and find the old tags when re-tagging with the uppercase tags.  
167 - assert_equivalent original_tag_names, photos(:jonathan_questioning_dog).reload.tag_list.names  
168 - end  
169 -  
170 - def test_remove_and_add_tag  
171 - assert_equivalent ["Very good", "Nature"], posts(:jonathan_sky).tag_list.names  
172 - posts(:jonathan_sky).update_attributes!(:tag_list => "Nature, Beautiful")  
173 - assert_equivalent ["Nature", "Beautiful"], posts(:jonathan_sky).tag_list.names  
174 - end  
175 -  
176 - def test_tags_not_saved_if_validation_fails  
177 - assert_equivalent ["Very good", "Nature"], posts(:jonathan_sky).tag_list.names  
178 - assert !posts(:jonathan_sky).update_attributes(:tag_list => "One, Two", :text => "")  
179 - assert_equivalent ["Very good", "Nature"], Post.find(posts(:jonathan_sky).id).tag_list.names  
180 - end  
181 -  
182 - def test_tag_list_accessors_on_new_record  
183 - p = Post.new(:text => 'Test')  
184 -  
185 - assert p.tag_list.blank?  
186 - p.tag_list = "One, Two"  
187 - assert_equal "One, Two", p.tag_list.to_s  
188 - end  
189 -  
190 - def test_clear_tag_list_with_nil  
191 - p = photos(:jonathan_questioning_dog)  
192 -  
193 - assert !p.tag_list.blank?  
194 - assert p.update_attributes(:tag_list => nil)  
195 - assert p.tag_list.blank?  
196 -  
197 - assert p.reload.tag_list.blank?  
198 - end  
199 -  
200 - def test_clear_tag_list_with_string  
201 - p = photos(:jonathan_questioning_dog)  
202 -  
203 - assert !p.tag_list.blank?  
204 - assert p.update_attributes(:tag_list => ' ')  
205 - assert p.tag_list.blank?  
206 -  
207 - assert p.reload.tag_list.blank?  
208 - end  
209 -  
210 - def test_tag_list_reset_on_reload  
211 - p = photos(:jonathan_questioning_dog)  
212 - assert !p.tag_list.blank?  
213 - p.tag_list = nil  
214 - assert p.tag_list.blank?  
215 - assert !p.reload.tag_list.blank?  
216 - end  
217 -  
218 - def test_tag_list_populated_when_cache_nil  
219 - assert_nil posts(:jonathan_sky).cached_tag_list  
220 - posts(:jonathan_sky).save!  
221 - assert_equal posts(:jonathan_sky).tag_list.to_s, posts(:jonathan_sky).cached_tag_list  
222 - end  
223 -  
224 - def test_cached_tag_list_used  
225 - posts(:jonathan_sky).save!  
226 - posts(:jonathan_sky).reload  
227 -  
228 - assert_no_queries do  
229 - assert_equivalent ["Very good", "Nature"], posts(:jonathan_sky).tag_list.names  
230 - end  
231 - end  
232 -  
233 - def test_cached_tag_list_not_used  
234 - # Load fixture and column information  
235 - posts(:jonathan_sky).taggings(:reload)  
236 -  
237 - assert_queries 1 do  
238 - # Tags association will be loaded  
239 - posts(:jonathan_sky).tag_list  
240 - end  
241 - end  
242 -  
243 - def test_cached_tag_list_updated  
244 - assert_nil posts(:jonathan_sky).cached_tag_list  
245 - posts(:jonathan_sky).save!  
246 - assert_equivalent ["Very good", "Nature"], TagList.from(posts(:jonathan_sky).cached_tag_list).names  
247 - posts(:jonathan_sky).update_attributes!(:tag_list => "None")  
248 -  
249 - assert_equal 'None', posts(:jonathan_sky).cached_tag_list  
250 - assert_equal 'None', posts(:jonathan_sky).reload.cached_tag_list  
251 - end  
252 -  
253 - def test_inherited_taggable  
254 - # SpPost inherits acts_as_taggable from its ancestor Post  
255 - p = SpPost.new(:text => 'bla bla bla ...')  
256 - p.tag_list = 'bla'  
257 - p.save  
258 - assert !SpPost.find_tagged_with('bla').blank?  
259 - end  
260 -end  
261 -  
262 -class ActsAsTaggableOnSteroidsFormTest < Test::Unit::TestCase  
263 - fixtures :tags, :taggings, :posts, :users, :photos  
264 -  
265 - include ActionView::Helpers::FormHelper  
266 -  
267 - def test_tag_list_contents  
268 - fields_for :post, posts(:jonathan_sky) do |f|  
269 - assert_match /Very good, Nature/, f.text_field(:tag_list)  
270 - end  
271 - end  
272 -end  
vendor/plugins/acts_as_taggable_on_steroids/test/database.yml
@@ -1,10 +0,0 @@ @@ -1,10 +0,0 @@
1 -mysql:  
2 - adapter: mysql  
3 - host: localhost  
4 - username: rails  
5 - password:  
6 - database: rails_plugin_test  
7 -  
8 -sqlite3:  
9 - adapter: sqlite3  
10 - database: ':memory:'  
vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/photo.rb
@@ -1,8 +0,0 @@ @@ -1,8 +0,0 @@
1 -class Photo < ActiveRecord::Base  
2 - acts_as_taggable  
3 -  
4 - belongs_to :user  
5 -end  
6 -  
7 -class SpecialPhoto < Photo  
8 -end  
vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/photos.yml
@@ -1,24 +0,0 @@ @@ -1,24 +0,0 @@
1 -jonathan_dog:  
2 - id: 1  
3 - user_id: 1  
4 - title: A small dog  
5 -  
6 -jonathan_questioning_dog:  
7 - id: 2  
8 - user_id: 1  
9 - title: What does this dog want?  
10 -  
11 -jonathan_bad_cat:  
12 - id: 3  
13 - user_id: 1  
14 - title: Bad cat  
15 -  
16 -sam_flower:  
17 - id: 4  
18 - user_id: 2  
19 - title: Flower  
20 -  
21 -sam_sky:  
22 - id: 5  
23 - user_id: 2  
24 - title: Sky  
vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/post.rb
@@ -1,7 +0,0 @@ @@ -1,7 +0,0 @@
1 -class Post < ActiveRecord::Base  
2 - acts_as_taggable  
3 -  
4 - belongs_to :user  
5 -  
6 - validates_presence_of :text  
7 -end  
vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/posts.yml
@@ -1,24 +0,0 @@ @@ -1,24 +0,0 @@
1 -jonathan_sky:  
2 - id: 1  
3 - user_id: 1  
4 - text: The sky is particularly blue today  
5 -  
6 -jonathan_grass:  
7 - id: 2  
8 - user_id: 1  
9 - text: The grass seems very green  
10 -  
11 -jonathan_rain:  
12 - id: 3  
13 - user_id: 1  
14 - text: Why does the rain fall?  
15 -  
16 -sam_ground:  
17 - id: 4  
18 - user_id: 2  
19 - text: The ground is looking too brown  
20 -  
21 -sam_flowers:  
22 - id: 5  
23 - user_id: 2  
24 - text: Why are the flowers dead?  
25 \ No newline at end of file 0 \ No newline at end of file
vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/sp_post.rb
@@ -1,5 +0,0 @@ @@ -1,5 +0,0 @@
1 -class SpPost < Post  
2 - def ihnerited  
3 - true  
4 - end  
5 -end  
vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/taggings.yml
@@ -1,126 +0,0 @@ @@ -1,126 +0,0 @@
1 -jonathan_sky_good:  
2 - id: 1  
3 - tag_id: 1  
4 - taggable_id: 1  
5 - taggable_type: Post  
6 - created_at: 2006-08-01  
7 -  
8 -jonathan_sky_nature:  
9 - id: 2  
10 - tag_id: 3  
11 - taggable_id: 1  
12 - taggable_type: Post  
13 - created_at: 2006-08-02  
14 -  
15 -jonathan_grass_nature:  
16 - id: 3  
17 - tag_id: 3  
18 - taggable_id: 2  
19 - taggable_type: Post  
20 - created_at: 2006-08-03  
21 -  
22 -jonathan_rain_question:  
23 - id: 4  
24 - tag_id: 4  
25 - taggable_id: 3  
26 - taggable_type: Post  
27 - created_at: 2006-08-04  
28 -  
29 -jonathan_rain_nature:  
30 - id: 5  
31 - tag_id: 3  
32 - taggable_id: 3  
33 - taggable_type: Post  
34 - created_at: 2006-08-05  
35 -  
36 -sam_ground_nature:  
37 - id: 6  
38 - tag_id: 3  
39 - taggable_id: 4  
40 - taggable_type: Post  
41 - created_at: 2006-08-06  
42 -  
43 -sam_ground_bad:  
44 - id: 7  
45 - tag_id: 2  
46 - taggable_id: 4  
47 - taggable_type: Post  
48 - created_at: 2006-08-07  
49 -  
50 -sam_flowers_good:  
51 - id: 8  
52 - tag_id: 1  
53 - taggable_id: 5  
54 - taggable_type: Post  
55 - created_at: 2006-08-08  
56 -  
57 -sam_flowers_nature:  
58 - id: 9  
59 - tag_id: 3  
60 - taggable_id: 5  
61 - taggable_type: Post  
62 - created_at: 2006-08-09  
63 -  
64 -  
65 -jonathan_dog_animal:  
66 - id: 10  
67 - tag_id: 5  
68 - taggable_id: 1  
69 - taggable_type: Photo  
70 - created_at: 2006-08-10  
71 -  
72 -jonathan_dog_nature:  
73 - id: 11  
74 - tag_id: 3  
75 - taggable_id: 1  
76 - taggable_type: Photo  
77 - created_at: 2006-08-11  
78 -  
79 -jonathan_questioning_dog_animal:  
80 - id: 12  
81 - tag_id: 5  
82 - taggable_id: 2  
83 - taggable_type: Photo  
84 - created_at: 2006-08-12  
85 -  
86 -jonathan_questioning_dog_question:  
87 - id: 13  
88 - tag_id: 4  
89 - taggable_id: 2  
90 - taggable_type: Photo  
91 - created_at: 2006-08-13  
92 -  
93 -jonathan_bad_cat_bad:  
94 - id: 14  
95 - tag_id: 2  
96 - taggable_id: 3  
97 - taggable_type: Photo  
98 - created_at: 2006-08-14  
99 -  
100 -jonathan_bad_cat_animal:  
101 - id: 15  
102 - tag_id: 5  
103 - taggable_id: 3  
104 - taggable_type: Photo  
105 - created_at: 2006-08-15  
106 -  
107 -sam_flower_nature:  
108 - id: 16  
109 - tag_id: 3  
110 - taggable_id: 4  
111 - taggable_type: Photo  
112 - created_at: 2006-08-16  
113 -  
114 -sam_flower_good:  
115 - id: 17  
116 - tag_id: 1  
117 - taggable_id: 4  
118 - taggable_type: Photo  
119 - created_at: 2006-08-17  
120 -  
121 -sam_sky_nature:  
122 - id: 18  
123 - tag_id: 3  
124 - taggable_id: 5  
125 - taggable_type: Photo  
126 - created_at: 2006-08-18  
vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/tags.yml
@@ -1,19 +0,0 @@ @@ -1,19 +0,0 @@
1 -good:  
2 - id: 1  
3 - name: Very good  
4 -  
5 -bad:  
6 - id: 2  
7 - name: Bad  
8 -  
9 -nature:  
10 - id: 3  
11 - name: Nature  
12 -  
13 -question:  
14 - id: 4  
15 - name: Question  
16 -  
17 -animal:  
18 - id: 5  
19 - name: Crazy animal  
20 \ No newline at end of file 0 \ No newline at end of file
vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/user.rb
@@ -1,4 +0,0 @@ @@ -1,4 +0,0 @@
1 -class User < ActiveRecord::Base  
2 - has_many :posts  
3 - has_many :photos  
4 -end  
vendor/plugins/acts_as_taggable_on_steroids/test/fixtures/users.yml
@@ -1,7 +0,0 @@ @@ -1,7 +0,0 @@
1 -jonathan:  
2 - id: 1  
3 - name: Jonathan  
4 -  
5 -sam:  
6 - id: 2  
7 - name: Sam  
vendor/plugins/acts_as_taggable_on_steroids/test/schema.rb
@@ -1,31 +0,0 @@ @@ -1,31 +0,0 @@
1 -ActiveRecord::Schema.define :version => 0 do  
2 - create_table :tags, :force => true do |t|  
3 - t.column :name, :string  
4 - t.column :parent_id, :integer  
5 - t.column :pending, :boolean  
6 - end  
7 -  
8 - create_table :taggings, :force => true do |t|  
9 - t.column :tag_id, :integer  
10 - t.column :taggable_id, :integer  
11 - t.column :taggable_type, :string  
12 - t.column :created_at, :datetime  
13 - end  
14 -  
15 - create_table :users, :force => true do |t|  
16 - t.column :name, :string  
17 - end  
18 -  
19 - create_table :posts, :force => true do |t|  
20 - t.column :text, :text  
21 - t.column :cached_tag_list, :string  
22 - t.column :user_id, :integer  
23 -  
24 - t.column :type, :string  
25 - end  
26 -  
27 - create_table :photos, :force => true do |t|  
28 - t.column :title, :string  
29 - t.column :user_id, :integer  
30 - end  
31 -end  
vendor/plugins/acts_as_taggable_on_steroids/test/tag_list_test.rb
@@ -1,98 +0,0 @@ @@ -1,98 +0,0 @@
1 -require File.dirname(__FILE__) + '/abstract_unit'  
2 -  
3 -class TagListTest < Test::Unit::TestCase  
4 - def test_blank?  
5 - assert TagList.new.blank?  
6 - end  
7 -  
8 - def test_equality  
9 - assert_equal TagList.new, TagList.new  
10 - assert_equal TagList.new("tag"), TagList.new("tag")  
11 -  
12 - assert_not_equal TagList.new, ""  
13 - assert_not_equal TagList.new, TagList.new("tag")  
14 - end  
15 -  
16 - def test_parse_leaves_string_unchanged  
17 - tags = '"one ", two'  
18 - original = tags.dup  
19 - TagList.parse(tags)  
20 - assert_equal tags, original  
21 - end  
22 -  
23 - def test_from_single_name  
24 - assert_equal %w(fun), TagList.from("fun").names  
25 - assert_equal %w(fun), TagList.from('"fun"').names  
26 - end  
27 -  
28 - def test_from_blank  
29 - assert_equal [], TagList.from(nil).names  
30 - assert_equal [], TagList.from("").names  
31 - end  
32 -  
33 - def test_from_single_quoted_tag  
34 - assert_equal ['with, comma'], TagList.from('"with, comma"').names  
35 - end  
36 -  
37 - def test_spaces_do_not_delineate  
38 - assert_equal ['a b', 'c'], TagList.from('a b, c').names  
39 - end  
40 -  
41 - def test_from_multiple_tags  
42 - assert_equivalent %w(alpha beta delta gamma), TagList.from("alpha, beta, delta, gamma").names.sort  
43 - end  
44 -  
45 - def test_from_multiple_tags_with_quotes  
46 - assert_equivalent %w(alpha beta delta gamma), TagList.from('alpha, "beta", gamma , "delta"').names.sort  
47 - end  
48 -  
49 - def test_from_multiple_tags_with_quote_and_commas  
50 - assert_equivalent ['alpha, beta', 'delta', 'gamma, something'], TagList.from('"alpha, beta", delta, "gamma, something"').names  
51 - end  
52 -  
53 - def test_from_removes_white_space  
54 - assert_equivalent %w(alpha beta), TagList.from('" alpha ", "beta "').names  
55 - assert_equivalent %w(alpha beta), TagList.from(' alpha, beta ').names  
56 - end  
57 -  
58 - def test_alternative_delimiter  
59 - TagList.delimiter = " "  
60 -  
61 - assert_equal %w(one two), TagList.from("one two").names  
62 - assert_equal ['one two', 'three', 'four'], TagList.from('"one two" three four').names  
63 - ensure  
64 - TagList.delimiter = ","  
65 - end  
66 -  
67 - def test_duplicate_tags_removed  
68 - assert_equal %w(one), TagList.from("one, one").names  
69 - end  
70 -  
71 - def test_to_s_with_commas  
72 - assert_equal "question, crazy animal", TagList.new(["question", "crazy animal"]).to_s  
73 - end  
74 -  
75 - def test_to_s_with_alternative_delimiter  
76 - TagList.delimiter = " "  
77 -  
78 - assert_equal '"crazy animal" question', TagList.new(["crazy animal", "question"]).to_s  
79 - ensure  
80 - TagList.delimiter = ","  
81 - end  
82 -  
83 - def test_add  
84 - tag_list = TagList.new("one")  
85 - assert_equal %w(one), tag_list.names  
86 -  
87 - tag_list.add("two")  
88 - assert_equal %w(one two), tag_list.names  
89 - end  
90 -  
91 - def test_remove  
92 - tag_list = TagList.new("one", "two")  
93 - assert_equal %w(one two), tag_list.names  
94 -  
95 - tag_list.remove("one")  
96 - assert_equal %w(two), tag_list.names  
97 - end  
98 -end  
vendor/plugins/acts_as_taggable_on_steroids/test/tag_test.rb
@@ -1,42 +0,0 @@ @@ -1,42 +0,0 @@
1 -require File.dirname(__FILE__) + '/abstract_unit'  
2 -  
3 -class TagTest < Test::Unit::TestCase  
4 - fixtures :tags, :taggings, :users, :photos, :posts  
5 -  
6 - def test_name_required  
7 - t = Tag.create  
8 - assert_match /blank/, t.errors[:name].to_s  
9 - end  
10 -  
11 - def test_name_unique  
12 - t = Tag.create!(:name => "My tag")  
13 - duplicate = t.clone  
14 -  
15 - assert !duplicate.save  
16 - assert_match /taken/, duplicate.errors[:name].to_s  
17 - end  
18 -  
19 - def test_taggings  
20 - assert_equivalent [taggings(:jonathan_sky_good), taggings(:sam_flowers_good), taggings(:sam_flower_good)], tags(:good).taggings  
21 - assert_equivalent [taggings(:sam_ground_bad), taggings(:jonathan_bad_cat_bad)], tags(:bad).taggings  
22 - end  
23 -  
24 - def test_to_s  
25 - assert_equal tags(:good).name, tags(:good).to_s  
26 - end  
27 -  
28 - def test_equality  
29 - assert_equal tags(:good), tags(:good)  
30 - assert_equal Tag.find(1), Tag.find(1)  
31 - assert_equal Tag.new(:name => 'A'), Tag.new(:name => 'A')  
32 - assert_not_equal Tag.new(:name => 'A'), Tag.new(:name => 'B')  
33 - end  
34 -  
35 - def test_deprecated_delimiter  
36 - original_delimiter = Tag.delimiter  
37 - Tag.delimiter = ":"  
38 - assert_equal ":", TagList.delimiter  
39 - ensure  
40 - TagList.delimiter = original_delimiter  
41 - end  
42 -end  
vendor/plugins/acts_as_taggable_on_steroids/test/tagging_test.rb
@@ -1,13 +0,0 @@ @@ -1,13 +0,0 @@
1 -require File.dirname(__FILE__) + '/abstract_unit'  
2 -  
3 -class TaggingTest < Test::Unit::TestCase  
4 - fixtures :tags, :taggings, :posts  
5 -  
6 - def test_tag  
7 - assert_equal tags(:good), taggings(:jonathan_sky_good).tag  
8 - end  
9 -  
10 - def test_taggable  
11 - assert_equal posts(:jonathan_sky), taggings(:jonathan_sky_good).taggable  
12 - end  
13 -end