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 another patch from Sinclair Bain, better handling of various input to 
acts_as_taggable_on method call. [#18 status:resolved]
mbleigh (author)
Thu Jun 12 11:42:36 -0700 2008
commit  b9b62566de1861dc111cc3ab96d49a39a2d86457
tree    2ea50a61fbef2609071f4aad509091561e667966
parent  3723036492fb0f054486c73bbbf2167ee43c2c5c
...
11
12
13
 
 
14
15
16
...
11
12
13
14
15
16
17
18
0
@@ -11,6 +11,8 @@ module ActiveRecord
0
         end
0
         
0
         def acts_as_taggable_on(*args)
0
+          args.flatten! if args
0
+          args.compact! if args
0
           for tag_type in args
0
             tag_type = tag_type.to_s
0
             self.class_eval do
...
1
2
3
4
 
5
6
7
...
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
...
1
2
3
 
4
5
6
7
...
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
0
@@ -1,7 +1,7 @@
0
 require File.dirname(__FILE__) + '/../spec_helper'
0
 
0
 describe "Acts As Taggable On" do
0
-  context "Taggable Method Generation" do
0
+  describe "Taggable Method Generation" do
0
     before(:each) do
0
       [TaggableModel, Tag, Tagging, TaggableUser].each(&:delete_all)
0
       @taggable = TaggableModel.new(:name => "Bob Jones")
0
@@ -80,25 +80,45 @@ describe "Acts As Taggable On" do
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
+    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
-      
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
+    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
+    end
0
 
0
-      end
0
-      after(:all) do
0
-        class Array; remove_method :freq; end
0
-      end
0
+    it "should not contain embedded/nested arrays" do
0
+      TaggableModel.acts_as_taggable_on([:array], [:array])
0
+      TaggableModel.tag_types.freq[[:array]].should == 0
0
+    end
0
+
0
+    it "should _flatten_ the content of arrays" do
0
+      TaggableModel.acts_as_taggable_on([:array], [:array])
0
+      TaggableModel.tag_types.freq[:array].should == 1
0
+    end
0
+
0
+    it "should not raise an error when passed nil" do
0
+      lambda {
0
+        TaggableModel.acts_as_taggable_on()
0
+      }.should_not raise_error
0
+    end
0
+
0
+    it "should not raise an error when passed [nil]" do
0
+      lambda {
0
+        TaggableModel.acts_as_taggable_on([nil])
0
+      }.should_not raise_error
0
+    end
0
+
0
+    after(:all) do
0
+      class Array; remove_method :freq; end
0
     end
0
   end
0
   

Comments