Thursday, October 30, 2008

Re: Test Suite and HABTM Models - Not Working

Hi Mike,

I think the RC3 bake script still generates old style code, like the following -

App::import('Model', 'Post');

class TestPost extends Post {
    var $cacheSources = false;
    var $useDbConfig  = 'test_suite';
}

class PostTestCase extends CakeTestCase {
    var $Post = null;
    var $fixtures = array('app.post', 'app.tag');

    function start() {
        parent::start();
        $this->Post = new TestPost();
    }
.....
.....
.....

Unfortunately this old style is redundant and does not work with associations (without some hacks). But GOOD news is that - Tim and Nate have come up with an even better solution and that works with associations flawlessly. Edit your test files and make it like the following - it's gonna work like a charm.
 
App::import('Model', 'Post');

class PostTestCase extends CakeTestCase {
    var $Post = null;
    var $fixtures = array('app.post', 'app.tag');

    function start() {
        parent::start();
        $this->Post =& ClassRegistry::init('Post');
    }
.....
.....
.....

Read Tim's blog on this for more info.
http://debuggable.com/posts/testing-models-in-cakephp---now-let%27s-get-rid-of-the-unnecessary-modeltest-classes-!:4890ed55-be28-4d4a-ba4c-7fd64834cda3

On Fri, Oct 31, 2008 at 3:18 AM, MikeB <bernat3@gmail.com> wrote:

I'm having a problem with the Cake Test Suite throwing errors about
HABTM join tables not being found. I've successfully recreated the
problem on a much smaller scale.

I've created a very basic 3 table database:

posts (id, name)
posts_tags (post_id, tag_id)
tags (id, name)

I've baked each model without incident. When I go to test.php and try
to run the post.test.php test that was generated for me, it gives me
this error:

Error:  Database table posts_tags for model PostsTag was not found.

I'm using a default AND test db connection.
Cake 1.2 rc3
CakePHP Test Suite v 1.2.0.0
SimpleTest v1.0.1

Keep in mind that I have not touched any of these files. They are all
freshly baked out the oven.

Any ideas?




--
Anupom Syam
http://syamantics.com/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: