Skip to content

Commit

Permalink
Add Note#to_s for CSV export
Browse files Browse the repository at this point in the history
  • Loading branch information
Malcolm Locke committed Nov 3, 2011
1 parent b601826 commit b88bd62
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/models/note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,11 @@ def create_changeset
def as_json(options = {})
super(:methods => ["errors"])
end

def to_s
note_string = note
user_name = user ? user.name : I18n.t('author unknown')
created_date = I18n.l created_at, :format => :note_date
note_string = note_string + " (" + user_name + " - " + created_date + ")"
end
end
7 changes: 7 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ en:
edit: "Edit"
delete: "Delete"

author unknown: "Author Unknown"

activerecord:
models:
user: 'Member'
Expand All @@ -26,3 +28,8 @@ en:
the iteration starts on x with length of x weeks:
one: "Iterations start on %{day} with a length of 1 week"
other: "Iterations start on %{day} with a length of %{count} weeks"


time:
formats:
note_date: "%b %d, %Y"
8 changes: 8 additions & 0 deletions test/unit/note_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,12 @@ def setup
]
assert_returns_json attrs, @note
end

test "returns a string" do
@note.created_at = "Nov 3, 2011"
assert_equal "Test note (#{@user.name} - Nov 03, 2011)", @note.to_s

@note.user = nil
assert_equal "Test note (Author Unknown - Nov 03, 2011)", @note.to_s
end
end

0 comments on commit b88bd62

Please sign in to comment.