Override #to_s on Tag for simplified joining

This commit is contained in:
Katrina Owen 2013-02-18 18:48:22 -07:00
parent 01b7f78f3c
commit 0b733b6183
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