22 Sep 2012, 23:01
Generic-user-small

Albert Yu (2 posts)

In the first test code, there is a line:

@assert_equal Date.today.to_s(:db), actual.status_date.to_s(:db)@

I’m confusing about the symbol @:db@, what’s the meaning at here?

I try to remove it or rename it, the test still pass, it seems like useless at all, isn’t it?

There’s no related description about this symbol, can anyone enlighten me about this?

Thanks.

25 Apr 2013, 11:57
Generic-user-small

Dawid Stępień (3 posts)

The book describes this symbol as format of date. @to_s@ method is overide by rails core ( https://github.com/rails/rails/blob/master/activesupport/lib/active_support/time_with_zone.rb ) and therefore it can take an argument. @:db@ symbol is one of the format type. Look here http://apidock.com/rails/v3.2.13/ActiveSupport/TimeWithZone/to_s for others.

Another thing is why author used @to_s@ method with format type. The answer is simple: if test fails, it is much clearer to read a human-readable format of date.

  You must be logged in to comment