[Rails] How to DRY with Fixtures (helper or extend Time class, how)?

Henrik henrik at nyh.se
Sat Jan 7 10:21:04 GMT 2006


I have a test/fixtures/users.yml like so:

apa:
  id: 1
  username: apa
  [...]
  created_at: <%=Time.now.strftime("%Y-%m-%d %H:%M:%S")%>
  updated_at: <%=Time.now.strftime("%Y-%m-%d %H:%M:%S")%>

I don't like how I'm repeating myself with the strftime bit.

Is there some shorter Time method to format time for a (MySQL) datetime 
field that I've missed? The magic of created_at/updated_at does not seem 
to work with fixtures.

Assuming I want to avoid repeating myself, in what file would I add a 
helper method for this, or extend the Time class with a method? 
Apparently not test_helper - "undefined local variable or method".

-- 
Posted via http://www.ruby-forum.com/.


More information about the Rails mailing list