how best to test modules for 'mixing-in' with AR classes?

Hi,

I'm converting some AR classes into modules and moving their attributes to whatever AR classes formerly held the association.

I'm finding it hard to test these modules.

I think I want to use a tableless AR model in my module tests. I just define one of these -- with the attributes the module needs -- in the test file and use it in the test. This works, but not for all AR methods. In particular, I run into errors when I invoke certain AR methods that seem to require the presence of a table.

So, simply put, how do I get a fully functional AR model for use in testing, without an accompanying migration?

Any thoughts?

Thanks,

Lille

Hi,

I'm converting some AR classes into modules and moving their attributes to whatever AR classes formerly held the association.

I'm finding it hard to test these modules.

I think I want to use a tableless AR model in my module tests. I just define one of these -- with the attributes the module needs -- in the test file and use it in the test. This works, but not for all AR methods. In particular, I run into errors when I invoke certain AR methods that seem to require the presence of a table.

So, simply put, how do I get a fully functional AR model for use in testing, without an accompanying migration?

not entirely what you ask, but how about creating an in memory sqlite3 database and creating tables in there (you don't need a migration file - you can have the table creating stuff in your test's setup) ?

Fred

Thanks!

So, maybe I automate the creation of the in-memory database with a rake task for the test? If not, what do you think?

I think an issue here is that my modules assuming their parents are AR classes. Is that really modular?

Lille

Thanks!

So, maybe I automate the creation of the in-memory database with a rake task for the test? If not, what do you think?

I think an issue here is that my modules assuming their parents are AR classes. Is that really modular?

Depends on what your code does - if it is inherently very active-recordy stuff then that's probably ok. If it is legitimate to include the module in a non activerecord class then I'd aim to do that in tests too.

Fred.