public
Rubygem
Description: A tagging plugin for Rails applications that allows for custom tagging along dynamic contexts.
Homepage: http://mbleigh.lighthouseapp.com/projects/10116-acts-as-taggable-on
Clone URL: git://github.com/mbleigh/acts-as-taggable-on.git
Click here to lend your support to: acts-as-taggable-on and make a donation at www.pledgie.com !
Applied Sinclair Bain's patch to disallow duplicate contexts. Also cleaned up 
the specs and dealt with some strange failures I've been getting intermittently. 
[#14 status:resolved]
mbleigh (author)
Wed Jun 11 11:41:34 -0700 2008
commit  3723036492fb0f054486c73bbbf2167ee43c2c5c
tree    60758ab0ecdf99c6dccad7542cd106e50ef22b01
parent  8113f9a98747fee8c6d14eb788508ebf6bd1d5ea
...
11
12
13
14
15
16
17
...
53
54
55
56
57
 
58
59
60
 
61
62
63
...
11
12
13
 
14
15
16
...
52
53
54
 
 
55
56
57
 
58
59
60
61
0
@@ -11,7 +11,6 @@ module ActiveRecord
0
         end
0
         
0
         def acts_as_taggable_on(*args)
0
-          puts "Registering #{args.inspect} with #{self.inspect}"
0
           for tag_type in args
0
             tag_type = tag_type.to_s
0
             self.class_eval do
0
@@ -53,11 +52,10 @@ module ActiveRecord
0
           end      
0
           
0
           if respond_to?(:tag_types)
0
-            puts "Appending #{args.inspect} onto #{tag_types.inspect}"
0
-            write_inheritable_attribute(:tag_types, tag_types + args)
0
+            write_inheritable_attribute( :tag_types, (tag_types + args).uniq )
0
           else
0
             self.class_eval do
0
-              write_inheritable_attribute(:tag_types, args)
0
+              write_inheritable_attribute(:tag_types, args.uniq)
0
               class_inheritable_reader :tag_types
0
             
0
               has_many :taggings, :as => :taggable, :dependent => :destroy, :include => :tag
...
1
2
3
 
4
5
 
6
7
8
...
33
34
35
36
 
37
38
39
...
50
51
52
53
 
54
55
56
...
58
59
60
61
 
62
63
64
...
77
78
79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
81
...
1
2
 
3
4
5
6
7
8
9
...
34
35
36
 
37
38
39
40
...
51
52
53
 
54
55
56
57
...
59
60
61
 
62
63
64
65
...
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
0
@@ -1,8 +1,9 @@
0
 require File.dirname(__FILE__) + '/../spec_helper'
0
 
0
-describe "acts_as_taggable_on" do
0
+describe "Acts As Taggable On" do
0
   context "Taggable Method Generation" do
0
     before(:each) do
0
+      [TaggableModel, Tag, Tagging, TaggableUser].each(&:delete_all)
0
       @taggable = TaggableModel.new(:name => "Bob Jones")
0
     end
0
   
0
@@ -33,7 +34,7 @@ describe "acts_as_taggable_on" do
0
     end
0
   end
0
   
0
-  context "inheritance" do
0
+  describe "Single Table Inheritance" do
0
     before do
0
       @taggable = TaggableModel.new(:name => "taggable")
0
       @inherited_same = InheritingTaggableModel.new(:name => "inherited same")
0
@@ -50,7 +51,7 @@ describe "acts_as_taggable_on" do
0
     end
0
   end
0
   
0
-  context "reloading" do
0
+  describe "Reloading" do
0
     it "should save a model instantiated by Model.find" do
0
       taggable = TaggableModel.create!(:name => "Taggable")
0
       found_taggable = TaggableModel.find(taggable.id)
0
@@ -58,7 +59,7 @@ describe "acts_as_taggable_on" do
0
     end
0
   end
0
   
0
-  context "related" do
0
+  describe "Related Objects" do
0
     it "should find related objects based on tag names on context" do
0
       taggable1 = TaggableModel.create!(:name => "Taggable 1")
0
       taggable2 = TaggableModel.create!(:name => "Taggable 2")
0
@@ -77,4 +78,28 @@ describe "acts_as_taggable_on" do
0
       taggable1.find_related_tags.should_not include(taggable2)
0
     end
0
   end
0
+  
0
+  describe 'Tagging Contexts' do
0
+    context '#acts_as_taggable_on' do
0
+      before(:all) do
0
+        class Array
0
+          def freq
0
+            k=Hash.new(0)
0
+            self.each {|e| k[e]+=1}
0
+            k
0
+          end
0
+        end
0
+      end
0
+      
0
+      it 'should eliminate duplicate tagging contexts ' do
0
+        TaggableModel.acts_as_taggable_on(:skills, :skills)
0
+        TaggableModel.tag_types.freq[:skills].should_not == 3
0
+
0
+      end
0
+      after(:all) do
0
+        class Array; remove_method :freq; end
0
+      end
0
+    end
0
+  end
0
+  
0
 end
0
\ No newline at end of file
...
2
3
4
 
5
6
7
...
96
97
98
99
 
100
 
101
102
103
...
2
3
4
5
6
7
8
...
97
98
99
 
100
101
102
103
104
105
0
@@ -2,6 +2,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
0
 
0
 describe "Taggable" do
0
   before(:each) do
0
+    [TaggableModel, Tag, Tagging, TaggableUser].each(&:delete_all)
0
     @taggable = TaggableModel.new(:name => "Bob Jones")
0
   end
0
   
0
@@ -96,8 +97,9 @@ describe "Taggable" do
0
     TaggableModel.find_tagged_with("spinning", :on => :rotors).should_not be_empty
0
   end
0
   
0
-  context "inheritance" do
0
+  describe "Single Table Inheritance" do
0
     before do
0
+      [TaggableModel, Tag, Tagging, TaggableUser].each(&:delete_all)
0
       @taggable = TaggableModel.new(:name => "taggable")
0
       @inherited_same = InheritingTaggableModel.new(:name => "inherited same")
0
       @inherited_different = AlteredInheritingTaggableModel.new(:name => "inherited different")
...
2
3
4
 
5
6
7
...
2
3
4
5
6
7
8
0
@@ -2,6 +2,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
0
 
0
 describe "Tagger" do
0
   before(:each) do
0
+    [TaggableModel, Tag, Tagging, TaggableUser].each(&:delete_all)
0
     @user = TaggableUser.new
0
     @taggable = TaggableModel.new(:name => "Bob Jones")
0
   end
...
1
2
3
 
 
 
 
 
 
 
 
4
5
6
7
8
9
10
11
12
13
 
 
 
 
 
 
14
15
16
...
1
 
 
2
3
4
5
6
7
8
9
10
 
 
 
 
 
 
 
 
 
11
12
13
14
15
16
17
18
19
0
@@ -1,16 +1,19 @@
0
 ActiveRecord::Schema.define :version => 0 do
0
-  create_table :tags, :force => true do |t|
0
-    t.column :name, :string
0
+  create_table "taggings", :force => true do |t|
0
+    t.integer  "tag_id",        :limit => 11
0
+    t.integer  "taggable_id",   :limit => 11
0
+    t.string   "taggable_type"
0
+    t.string   "context"
0
+    t.datetime "created_at"
0
+    t.integer  "tagger_id",     :limit => 11
0
+    t.string   "tagger_type"
0
   end
0
-  
0
-  create_table :taggings, :force => true do |t|
0
-    t.column :tag_id, :integer
0
-    t.column :taggable_id, :integer
0
-    t.column :taggable_type, :string
0
-    t.column :context, :string
0
-    t.column :created_at, :datetime
0
-    t.column :tagger_id, :integer
0
-    t.column :tagger_type, :string
0
+
0
+  add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id"
0
+  add_index "taggings", ["taggable_id", "taggable_type", "context"], :name => "index_taggings_on_taggable_id_and_taggable_type_and_context"
0
+
0
+  create_table "tags", :force => true do |t|
0
+    t.string "name"
0
   end
0
   
0
   create_table :taggable_models, :force => true do |t|

Comments