2

Say for instance I have a datefield or 3 select fields for day month and yea..

How does the final selection of date get sent to the database? or in what format doesn't it get sent?

20110803 ?

2011-08-03 ?

What I want to do is:

  1. Test for a valid date (a date that has been selected that exists)
  2. Test for an invalid date (invalid would be a date that doesn't exist and also be when nothing has been selected)

I know an idea of how to write these tests but not sure what actually gets sent to the database What actually appears before save and in what format. String? Integer?

Thanks in advance for responses.

1 Answer 1

4

The gets sent to the database as the database expects it. Each database and configuration will yield a different format for a date but this will not make any difference to you as the field is configured to be Date and it will also be a Date on Rails, so you should not care about the format.

While testing, there are many ways you can validate, but you will not be using neither integer or string, you're using Date objects. Here's an example of how you could write the first one:

it 'should find a model today' do 
  @date = Date.today
  @model = Model.create!(:date => @date)
  Model.first( :conditions => {:date => @date}).should == @model 
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.