I’ve been reading the book and enjoying the approach, but am stumped by a passage on page 48. Can anyone who has read the book enlighten me? The passage is:
“In this particular case, the controller creates a new instance from the database and saves that instance, without touching the actual variable created for the test. As a result, the database version has typecast the status_date to a Date when saving, but the live version in memory hasn’t gotten that change.”
So, my difficulties are:
(i) The controller creates a new instance from a hash, not from the database. (I can’t even think what creating a new instance from the database could mean.)
(ii) I’m not sure what is meant by saving the instance without touching the variable. The call is: actual.save Does this constitute not “touching” the variable?
(iii) Most puzzling of all is the bit about the database version having typecast the status_date to a Date when saving. As far as I can see, status_date was a Date right from the time the value appeared in the hash. Playing around on the console gives:
actual = StatusReport.new(:status_date => 10.days.ago.to_date) => #<StatusReport id: nil, project_id: nil, user_id: nil, yesterday: nil, today: nil, status_date: “2011-03-10”, created_at: nil, updated_at: nil> actual.status_date.class => Date
So that status_date was always a Date. What’s meant by it being “typecast” to a Date?
Thanks in advance,