开发者

How to get TimeWithZone within rails3 unit/test

开发者 https://www.devze.com 2023-01-20 15:08 出处:网络
I\'m trying to test a rails, application, and in one particular case, I need to create a TimeWithZone object inside my testcase. So I write sth like this:

I'm trying to test a rails, application, and in one particular case, I need to create a TimeWithZone object inside my testcase. So I write sth like this:

started_at = ActiveSupport::TimeWithZone(started_at, Time.zone)

only to get an error:

NoMethodError: undefined method `TimeWithZone' for ActiveSupport:Module

I tried requiring 'active_support', 'active_support/time', ''active_support/time_with_zone'. each of those statements evaluates to false when I run tests (it works fine in irb)

An开发者_运维问答y idea on what I'm doing wrong?


Try creating a new object:

started_at = ActiveSupport::TimeWithZone.new(started_at, Time.zone)

However, you should never need to create instances of this class directly.

If you have Time.zone set up correctly already, you can simply use the at method on it:

started_at_with_zone = Time.zone.at(started_at)

Take a look at the Rails API documentation for details.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号