Mark Gargan wrote:
The problem arises when unit testing. We want to be able to mock out the
database if possible but because the implementation of the object is, I
guess, done introspectively against the database table so we've no model
to work with and the structure depends on the table.
Should we just forgo the introspective nature of the object and
explicitly map attributes on the Alert object to columns in teh
DB so that we can create dummy objects at unit test time or is there a
better way of doing this i.e. mocking out the database?
I would write the program so it can run in two modes. In one mode, objects plug into an ActiveRecord db for their data. This gives you fixture support for your tests.
In the other mode, objects plug into a wrapper that calls these external services.
Either way, you will need Mocha to provide mock-objects in your tests. And your design should obey "Construction Encapsulation", so tests can pass in mock objects without the production code creating its own objects.