EvdB has asked for the wisdom of the Perl Monks concerning the following question:
I've been using Class::DBI to create a web site and it is going nicely. I now want to create a comprehensive test suite that tests the site via the web using Test::WWW::Mechanize. The problem is getting CDBI to grab new data from the database after a change has been made on the site.
The problem rests with CDBI's cache of objects in memory. This code demonstrates the problem:
# In test suite. # Check CDBI object is as expected. is $cdbi_object->name, 'Foo', "name is correct (Foo)" # Change the name through web site. $mech->get_ok('http://localhost:3000/object/change?name=Bar'); # Check that the name has changed. is $cdbi_object->name, 'Bar', "name has changed to 'Bar'"; # Test fails.
Arguably the tests should fail as there is no way for one instance of perl (test) to know that the object has changed in another (webserver). The tests can be made to work as they should by inserting something like this before the test that checks for changed values:
# Reload the object from the database. $cdbi_object->remove_from_object_index; $cdbi_object = My::Object->retrieve( $cdbi_object->id );
To get to the point is there a simpler and better way to do this. Can the cache be turned off completely? Is there a way to get a method like $cdbi_object->freshen that will do the above? Am I missing the point
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reloading CDBI objects from database elegantly
by perrin (Chancellor) on May 19, 2005 at 20:05 UTC | |
by EvdB (Deacon) on May 19, 2005 at 20:29 UTC | |
by exussum0 (Vicar) on May 19, 2005 at 21:56 UTC | |
by perrin (Chancellor) on May 20, 2005 at 04:00 UTC | |
by exussum0 (Vicar) on May 20, 2005 at 14:27 UTC | |
by perrin (Chancellor) on May 20, 2005 at 17:14 UTC |