|
Danny O Cuiv |
Posts by Danny O Cuiv
|
01 Apr 2011, 16:18
Danny O Cuiv (7 posts) |
Hi, 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: (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:
So that status_date was always a Date. What’s meant by it being “typecast” to a Date? Thanks in advance, Danny. |
|
05 Apr 2011, 13:33
Danny O Cuiv (7 posts) |
I’m going to bump this one, if that’s OK. It’s had a good number of eyeballs at this stage, but nobody’s replied. Which either means that it’s a really basic question or it’s a really badly phrased passage. Let me simplify my question. An object is created with attribute called status_date that is of type Date. It’s saved to the database. After retrieval, you will still get a Date object if you read the attribute. In what sense is there any kind of “typecast” happening here? If anyone has any insights, I’d be very grateful. Danny. |
|
15 May 2011, 12:25
Danny O Cuiv (7 posts) |
Thanks Noel for your answer to my previous question. I’ve got another. On page 77 of the print edition (or page 83 of the PDF), you say:
This implies to me that things like virtual attributes are allowed in a call to create, whereas fixtures are restricted to actual database columns (and associations). I was curious and looked this up in the API. create() just calls new() before saving and in the documentation for the new() method, it states:
This seems to me to be at odds with you wrote above. Can you clarify? Thanks, Danny. |
|
25 May 2011, 08:02
Danny O Cuiv (7 posts) |
(from Rails Test Prescriptions > Framework?)
From page 16 of the print edition:
Danny |
|
27 May 2011, 20:57
Danny O Cuiv (7 posts) |
I’m going to bump this one if that’s OK. (It’s been almost two weeks and 130 views.) Anyone got any idea what was being referred to here? Thanks, Danny. |
|
03 Jun 2011, 21:40
Danny O Cuiv (7 posts) |
Hi James, My guess from the above is that you have downloaded the code from the PragProg site and used that in your work-through. However, this code is for the completed example. What you needed to have done is to get a starting setup as explained in Appendix A: Sample Application Setup. I say this because your first two errors above are undefined method errors for a method called
However, in the version from the code download, there is indeed a call to <% @project.users.each do |user| %>
The Regards, Danny. |
|
18 Jul 2011, 18:52
Danny O Cuiv (7 posts) |
status_date is an ActiveRecord attribute, which means that the accessors are generated, specifically a setter (status_date=) and a setter (status_date). When these are invoked from outside the class, there is no ambiguity object.status_date = Date.today When you want to invoke them inside the class, the getter can be called unqualified, but you need to qualify the setter (with self), because of an ambiguity in the grammar. Specifically status_date = Date.today would look to the interpreter like an assignment to a local variable. Obviously you can qualify the getter too. It’s just that it’s not necessary. Danny. |
7 posts
