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

Allow Emails to be view using actionmailer test deliveries #81

Open
grantspeelman opened this issue Mar 15, 2021 · 0 comments
Open

Allow Emails to be view using actionmailer test deliveries #81

grantspeelman opened this issue Mar 15, 2021 · 0 comments

Comments

@grantspeelman
Copy link
Collaborator

It's possible to add emails into test flows using actionmailer test deliveries.

The core code below:

config/initializers/cypress_on_rails.rb

if defined?(CypressOnRails)
  CypressOnRails.configure do |c|
    c.cypress_folder = File.expand_path("#{__dir__}/../../cypress")
    c.use_middleware = !Rails.env.production?
    c.logger = Rails.logger
  end

  if ENV['CYPRESS'].present?
    Rails.application.configure do
      config.active_job.queue_adapter = :inline
      ActionMailer::Base.delivery_method = :test
      config.action_mailer.delivery_method = :test
      config.action_mailer.default_url_options = { host: 'http://localhost:5017' }
    end
  end
end

routes.rb

Rails.application.routes.draw do
  scope path: '/__cypress__', controller: 'cypress' do
    get 'view_email', action: 'view_email'
  end
end

app/controllers/cypress_controller.rb

class CypressController < ActionController::Base # rubocop:disable Rails/ApplicationController
  def view_email
    email = params.require(:email)
    @mail = ActionMailer::Base.deliveries.reverse.find { |mail| mail.to.include?(email) }
    render layout: false
  end
end

app/views/cypress/view_email

<% if @mail %>
  Subject: <%= @mail.subject %>
  <hr>
  <%= raw(@mail.html_part ? @mail.html_part.body : @mail.body) %>
<% else %>
  No Email found
<% end %>

This needs to be converted to work automatically and README example needs to be added

@grantspeelman grantspeelman added this to To do in Cypress On Rails via automation Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

1 participant