Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Test/fixtures files

Status
Not open for further replies.

Kalisto

Programmer
Feb 18, 2003
997
0
0
GB
(Using Eclipse)

I have been chasing an issue round for a few hours now around one of my unit tests.

If within test/fixtures I have a file foos.yml

Code:
shop:
   openingTIme: <%= Time.utc(2009,"Oct",15,09,30,00).to_s(:db) %>

It always creates an item with the correct time, but a date of 01/01/2000 which makes sense as all I want is the time.

In my unit test though, if I write
Code:
openingTime = (2009,"Oct",15,09,29,00)

then openingTime has a value of 15/10/2009 09:29:00

so how do I force my yml file to use todays date, as if I use a > on the 2 dates, it is taking into account the date portion as well.

i.e. although 9.29 is < 9.30, it returns true as 2000 is before 2009
 
Check this out in irb :
Time.utc(2009,"Oct",15,09,30,00)

You'll get an error - invalid octal value.
If you put extra zeros, Ruby thinks you're not using plain decimal.

Try this instead:
Time.utc(2009,"Oct",15,9,30,0).to_s:)db)

Tao Te Ching Discussions : Chapter 9 (includes links to previous chapters)
What is the nature of conflict?
 
Thanks, but that makes no difference to my test fixtures.

I have experimented, and I can dode round it, but that defeats the point of having the fixtures.

Being as the rest of RoR seems to be well thought out, I have to assuem Im doing something wrong. I am assuming that it is because I am using a Time not a DateTime.

In itsself this isnt a major issue, but it does mean I need to do some conversion so that I am comparing just times, and not having date artefacts.
 
Curiously, using :)time) gives me a different anomally again.

Time.utc(2009,"Oct",15,11,30,0).to_s:)time) yields me Jan 01 00:00:00 UTC 2000

Time.utc(2009,"Oct",15,11,30,0).to_s:)time) yields me Jan 01 00:00:00 UTC 2000

Time.utc(2009,"Oct",15,10,30,0).to_s:)time) yields me Jan 01 00:06:30 UTC 2000

There is obviously something fundamental I am not understanding here about the time object, and the way it is stored..
 
Code:
# require 'activesupport', of course
irb(main):019:0> Time.utc(2009,"Oct",15,11,30,0).to_s(:time)
=> "11:30"
irb(main):020:0> Time.utc(2009,"Oct",15,11,30,0).to_s(:time)
=> "11:30"
irb(main):021:0> Time.utc(2009,"Oct",15,10,30,0).to_s(:time)
=> "10:30"

What version of Ruby are you using? I am running 1.8.7 ...

Tao Te Ching Discussions : Chapter 9 (includes links to previous chapters)
What is the nature of conflict?
 
It works in irb, its when I use the foo.yml file in test/fixtures for creating my unit test data it doesnt play nice..

I can get round it by adding extra code into my unit tests, but that defeats the point of unit tests / seed data :)

Ah well, Ive wasted too much time on this, so Im off to find my next problem :)

Thanks for trying to help :)
 
I'm still not sure what I'm trying to solve, to be honest with you ;-)
"so how do I force my yml file to use todays date, as if I use a > on the 2 dates, it is taking into account the date portion as well."

I don't know.. Use Date.today ? Time.now ?

Tao Te Ching Discussions : Chapter 9 (includes links to previous chapters)
What is the nature of conflict?
 
Can you use
Ruby:
Time.now.strftime('%H:%M')
instead?

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top