Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the mailer preview class to use a block statement method #131

Closed
Chocksy opened this issue May 25, 2016 · 0 comments
Closed

Update the mailer preview class to use a block statement method #131

Chocksy opened this issue May 25, 2016 · 0 comments

Comments

@Chocksy
Copy link
Member

Chocksy commented May 25, 2016

Here is an example of a mailer_preview that would be ideal for our code from now on. This would remove the duplicate code:

class InvitePreview < ActionMailer::Preview
  def accepted
    show_email do
      @mail = InviteMailer.accepted(@user, @organization, true).message
    end
  end

  protected

  def show_email(&block)
    @mail = nil
    Organization.transaction do
      @user = User.create!(name: 'Bob User', email: '[email protected]')

      @invite = Invite.create(user: @user, email: '[email protected]')

      yield

      raise ActiveRecord::Rollback
    end
    @mail
  end
end

That's an example code adapt it to our preview classes.

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

No branches or pull requests

2 participants