Merge pull request #153 from kytrinyx/tag-to-s

Override #to_s on Tag for simplified joining
This commit is contained in:
Matt Rogers 2013-02-19 08:30:26 -08:00
commit a94ea6b0f2
3 changed files with 11 additions and 2 deletions

View file

@ -127,7 +127,7 @@ module TodosHelper
end
def tag_list_text(todo=@todo)
todo.tags.collect{|t| t.name}.join(', ')
todo.tags.join(', ')
end
def tag_span (tag, mobile=false)

View file

@ -30,4 +30,8 @@ class Tag < ActiveRecord::Base
@label ||= name.gsub(' ', '-')
end
def to_s
name
end
end

View file

@ -45,5 +45,10 @@ class TagTest < ActiveSupport::TestCase
def test_tag_label
assert_equal 'one-two-three', Tag.new(:name => 'one two three').label
end
def test_tag_as_string
tags = [Tag.new(:name => 'tag1'), Tag.new(:name => 'tag2')]
assert_equal 'tag1, tag2', tags.join(', ')
end
end