Custom Time Format Breaks In Test

Hello,

I have defined a custom time format which works in development but
causes errors in my functional tests. Is this a Rails bug or
something I am doing wrong?

Here’s my custom time format, as per AWDWRv2, in environment.rb:

ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(
:uk_full => ‘%d %B %Y’
)

In my view template I call it like this:

<%= order.created_at.to_s :uk_full %>

This works perfectly when I look at it in my browser in development.

However, in my functional test where I just try to get the relevant
screen and assert the response is ok, the test breaks with:

ActionView::TemplateError: wrong number of arguments (1 for 0)
#{RAILS_ROOT}/app/views/orders/index.rhtml:4:in `to_s’

I have verified that the :uk_full is the problem by removing it from
the relevant line, at which point the test runs fine.

Any ideas? I would greatly appreciate suggestions.

Thanks and regards,
Andy S.

On 16 Jan 2007, at 13:01, Andrew S. wrote:

#{RAILS_ROOT}/app/views/orders/index.rhtml:4:in `to_s’

I have verified that the :uk_full is the problem by removing it
from the relevant line, at which point the test runs fine.

Well, I’ve solved my own problem. It turned out that
order.created_at was nil in my test. I had set it dynamically in my
fixture but it seems to be overwritten by the time the test method is
run.

So the ‘wrong number of arguments’ was referring to the left hand
side of to_s, not the right hand side.

Regards,
Andy S.

Well, I’ve solved my own problem. It turned out that
order.created_at was nil in my test. I had set it dynamically in
my fixture but it seems to be overwritten by the time the test
method is run.

Further to this point, it turns out one has to call .to_s(:db) on any
times/dates in dynamic fixtures. E.g.:

sample_order:
id: 1
created_at: <%= 10.minutes.ago.to_s :db %>

It was obvious when I thought about it(!).

Regards,
Andy S.