basecamp / mail_view

Visual email testing
MIT License
1.33k stars 128 forks source link

Wrapping mail generation in rolled-back transaction to prevent database changes from persisting #71

Open costa opened 10 years ago

costa commented 10 years ago

I use factories for specs and I find them very convenient to use in mail_view's "actions". Factories — as well as other methods for generating sample data on the fly — need to be cleaned after. Since mail_view is supposed to be read-only, I see no disadvantage in actual prevention of data changes persistency — using transactions.

The first commit is kinda working draft for discussion, I'll add specs+docs if needed.

p.s. I've seen #69 but did neither like the solution nor understand the discussion there.

slightly-off-topic: Might be useful to include in the docs: mail_view for human — and also for automatic — testing.

Zeneixe commented 10 years ago

Will you guys ever integrate this in ActionMailer? It's pretty useful

jeremy commented 10 years ago

It's a nice idea. It's simple in the common case, but breaks down at the edges. Considering that seed data handles these cases nicely, or using MyModel.new without saving, there isn't great pressure to introduce an automatic transaction rollback.

costa commented 10 years ago

@jeremy Seed data? Using any other form of protection is great, but less convenient, that's the point of this discussion.