Hi Nick,
I've located and fixed (a bit dirty though) the issue.
A few notes/details/explanations follows.
tutti_frutti/app/controllers/fruits_controller.rb:18
Saving the new fruit requires that update be called on created fruit.
So, the idea is:
* let repository create a new instance, giving it ID and everything else needed
* consume it from posted data (that's your thingy)
* save changes back to repository
I've updated the code to reflect this.
Why data was not seen in response?
As you probably noticed, when new fruit is added, you get an empty row as a result.
The data is also not saved as can be seen @Â localhost:9292/fruits.json
The reason was that repository updates only if it finds a matching ID.
Now, the data passed in had "id" instead of :id for hash key.
After a bit of debugging, it seems representable has overridden the to_hash and from_hash on Fruit instance being updated.
Hence, the resulting hash passed to repository for saving had no :id key since I didn't expect fruit implementation of those methods to be lost (
http://www.imdb.com/title/tt0335266/).
I fixed those issues in fruit_orchard/lib/fruit_orchard/domain/fruit.rb:14 and fruit_orchard/lib/fruit_orchard/persistence/fruit_repository.rb:30
The whole process
Now the following is taking place:
* tutti_frutti api is calling Fruit.create to get a new instance
* fruit delegates instance data to repositoryÂ
* repository creates and returns the data, creating the ID in the process
* tutti_frutti calls consume on fruit instance it to parse the received data
* tutti_frutti updates fruitÂ
* fruit sends updated data to repository
* repository finds relevant record by ID and updates
A bit of hash conversion in both directions is present but that is the case
How to imporove slightly?
Maybe if in tutti_frutti the call could be:
@fruit = FruitOrcharding::Fruit.create(consume(Fruit))
That way, no updates would be needed, but create flow would get the needed data and return the created record.
How to improve more?
By being good and eating a lot of fruit :-)
OK, my 5 cents for this evening have been spent.
Let me know how you feel about this.
On Wednesday, February 6, 2013 11:13:42 PM UTC+1, Nick Sutterer wrote: