Skip to content
This repository has been archived by the owner on Mar 2, 2020. It is now read-only.

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

costa
Copy link

@costa costa commented Mar 30, 2014

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.

…database changes from persisting during the former
@Zeneixe
Copy link

Zeneixe commented Sep 17, 2014

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

ActiveRecord::Base.transaction do
mail = send(name)
raise ActiveRecord::Rollback
end
Mail.inform_interceptors(mail) if defined? Mail
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would need to be within the transaction, before rollback.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@jeremy
Copy link
Member

jeremy commented Sep 22, 2014

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 added a commit to costa/mail_view that referenced this pull request Oct 2, 2014
@costa
Copy link
Author

costa commented Oct 2, 2014

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants