public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
Fix duplicate tag bug.

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2492 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Wed Nov 22 19:35:11 -0800 2006
commit  39534c95f11f93082e78c34b45b5f59080364f45
tree    ff831ef8adae541dc3bf87d771224758026cb17b
parent  45212feeb2159209190c20c6ff26712607df1992
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 * SVN *
0
 
0
+* Fix duplicate tag bug.
0
+
0
 * add Mephisto.root javascript variable in case a mephisto site sets the relative_url_root
0
 
0
 * Allow Modules to use #include_into to dynamically mixin to loaded classes (plugin stuff)
...
1
 
2
3
4
...
18
19
20
21
22
 
 
23
24
25
...
1
2
3
4
5
...
19
20
21
 
 
22
23
24
25
26
0
@@ -1,4 +1,5 @@
0
 class Tag < ActiveRecord::Base
0
+ @@tag_parse_regex = /((?: |)['"]{0,1})['"]?\s*(.*?)\s*(?:[,'"]|$)(?:\1(?: |$))/
0
   has_many :taggings
0
 
0
   class << self
0
@@ -18,8 +19,8 @@ class Tag < ActiveRecord::Base
0
     # # => ['a', 'b', 'c']
0
     def parse(list)
0
       return list if list.is_a?(Array)
0
- returning list.scan(/((?: |)['"]{0,1})['"]?(.*?)(?:[,'"]|$)(?:\1(?: |$))/) do |tags|
0
- tags.collect! &:last
0
+ returning list.scan(@@tag_parse_regex) do |tags|
0
+ tags.collect! { |t| t.last.strip!; t.last }
0
         tags.uniq!
0
         tags.delete_if &:blank?
0
       end
...
27
28
29
 
 
 
 
 
 
30
31
32
...
27
28
29
30
31
32
33
34
35
36
37
38
0
@@ -27,6 +27,12 @@ class TagTest < Test::Unit::TestCase
0
   def test_should_return_tag_array
0
     assert_equal %w(a b c), Tag.parse(%w(a b c))
0
   end
0
+
0
+ def test_should_return_unique_tags
0
+ ["a, b, b", %('a' 'b' 'b'), %("a" "b" " b ")].each do |input|
0
+ assert_equal %w(a b), Tag.parse(input), "Failed for: #{input.inspect}"
0
+ end
0
+ end
0
 
0
   def test_should_find_or_create_tags
0
     assert_difference Tag, :count do

Comments

    No one has commented yet.