Skip to content

Commit

Permalink
adding cleaning of whitespaces around commas in tag list strings
Browse files Browse the repository at this point in the history
  • Loading branch information
gnugeek authored and Daniel Haran committed Feb 9, 2009
1 parent 1cd799b commit 11b1042
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/is_taggable.rb
Expand Up @@ -6,10 +6,10 @@
module IsTaggable
class TagList < Array
cattr_accessor :delimiter
@@delimiter = ', '
@@delimiter = ','

def initialize(list)
list = list.is_a?(Array) ? list : list.split(@@delimiter)
list = list.is_a?(Array) ? list : list.split(@@delimiter).collect(&:strip)
super
end

Expand Down
11 changes: 10 additions & 1 deletion test/is_taggable_test.rb
Expand Up @@ -17,7 +17,7 @@
expect ["one", "two"] do
IsTaggable::TagList.delimiter = " "
n = Comment.new :tag_list => "one two"
IsTaggable::TagList.delimiter = ", " # puts things back to avoid breaking following tests
IsTaggable::TagList.delimiter = "," # puts things back to avoid breaking following tests
n.tag_list
end

Expand Down Expand Up @@ -53,6 +53,15 @@
p = Post.new :language_list => "english, french"
p.language_list.to_s
end

# added - should clean up strings with arbitrary spaces around commas
expect ["spaces","should","not","matter"] do
p = Post.new
p.tag_list = "spaces,should, not,matter"
p.save!
p.tags.reload
p.tag_list
end

expect 2 do
p = Post.new :language_list => "english, french"
Expand Down

0 comments on commit 11b1042

Please sign in to comment.