2

I am currently using cucumber and databasecleaner to test my application. And currently in my env.rb i have the setup of the cleaner as:

DatabaseCleaner.strategy = :truncation, {:except => %w[TABLE]}
After do
  DatabaseCleaner.clean
end

This way I can keep the data in TABLE. But I would also like to keep a single entry in a different table between tests. Is there any way I can achieve that or do I have to recreate it all the time with a Before hook?

Martin Larsson
  • 1,008
  • 1
  • 8
  • 25

1 Answers1

0

I can think of this hack. Add a ON DELETE trigger on that table of your test ENV DB. The trigger invokes a function which inserts the row. You might need to add a check in the function to do nothing if row already exists.

Manish
  • 111
  • 4
  • could you give me an example? I am not sure of how you intend me to do, should I edit my DB?? – Martin Larsson Dec 12 '12 at 13:49
  • Yes you'll have to modify your test DB. For eg. to create trigger in postgres `CREATE TRIGGER my_trigger AFTER DELETE ON my_table FOR EACH ROW EXECUTE PROCEDURE add_row();` And you'll also have to create function add_row() in database which inserts the row if it does not already exists – Manish Dec 12 '12 at 14:23
  • I can't edit the DB it is out of my control so is all models views and controls. – Martin Larsson Jun 18 '13 at 13:21