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.
# 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 = 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