Everything,
In some part of the technical binding.
I created a small, small Rails application that relies on some external databases (not defined in local migrations) to increase information about key applications. I am sitting to write some tests, and I am struggling to find a suitable solution to support this external data.
For example, let's say I have a DailyWidgetViews model in my new / current Rails application. At the table level, it looks like this:
id, widget_id, date, views, timestamps
Let's say that widgets live in a separate database. There are tools for working with this script in Rails. For example, when defining a Widget, you can do something like:
class Widget << ActiveRecord::Base establish_connection("some_legacy_db_name") set_table_name :crazy_widget_table_name
Now in DailyWidgetViews I can build belongs_to sympathy, and all is well.
However, what to do when the time comes for testing ???
Say I have a DailyWidgetViews resource and you want to test the / index action and return a Widget association for each DailyWidgetView. What is the recommended strategy for defining and interacting with this external data? Even if I mock everything, test: unit and rspec expect to find a definition for Widget in the test database. In addition, a few bits of caching optimization in the application also expects to find some data here (it may be empty) when loading the application.
Some possible options that I see:
Create a separate project that consists only of migrations. These migrations have a minimum minimum to support an outdated scheme. Run this project when you just need to configure the circuit. Change everything in the tests so that we never interact with this database.
Export obsolete schema and hack db: setting to load the schema into the corresponding test dbs before starting testing. Spread everything as in # 1.
I am inclined to option number 1, but I hoped that someone had dealt with this problem before. Is anyone
Thanks in advance!