collin / factory_scenarios

use your factory girl factories in dev mode
MIT License
4 stars 4 forks source link

factory_scenarios/mail_preview

Build Status

Login as users defined in your FactoryGirl factories.

Preview email while logged in as users defined in your FactoryGirl factories.

Installation

Tests

To test with your desired version of rails, do this:

RAILS_VERSION=3.1.4 bundel exec rake test

Configuration

Example Configuration

Create an initializer file called app/config/initializers/factory_scenarios.rb, add the following:

    if Rails.env.to_s != 'production'
      FactoryScenarios.config.user_class = 'Spree::User'
      FactoryScenarios.config.iframe_width = '1400px'
    end

To redirect to a specific location in your application after logging in as a scenario define handle_factory_scenario in your ApplicationController.

  # Be sure to use main_app for url_generation as this method will be called
  # from inside the engine controllers
  def handle_factory_scenario
    redirect_to main_app.root_url(subdomain: current_user.subdomain)  
  end

( Seems like this should be a configuration option rather than a method defined on the app controller no?)

Specify your mail previews in a file "config/mail_preview.rb"

  FactoryScenarios::Mail.registrations do
    register "Org Membership Invitation (no login)" do
      mailer MembershipMailer
      message :approval_message
      message_args { Factory.create(:membership) }
    end

    register "Org Membership Invitation (correct login)" do
      mailer MembershipMailer
      message :approval_message
      message_args { Factory.create(:membership) }

      # Arguments to login_as block are the return value of the message_args block.
      login_as { |membership| membership.user }
    end

    register "Org Membership Invitation (wrong login)" do
      mailer MembershipMailer
      message :approval_message
      message_args { Factory.create(:membership) }
      login_as { Factory.create :user }
    end

    register "User registration" do
      mailer Devise::Mailer
      message :confirmation_instructions
      message_args { Factory.create(:unconfirmed_user) }
    end

    register "Reset password instructions" do
      mailer Devise::Mailer
      message :reset_password_instructions
      message_args { Factory.create(:recoverable_user) }
    end
  end

Factory Scenarios Screenshot

Facotory Scenarios

Mail Preview Screenshot

Mail Preview

Todo

Contributing to factory_scenarios

Contributors

Original gem written by Collin Miller. Updated for Rails 3.1 by David Guthu.

Copyright

Copyright (c) 2011 Collin Miller. See LICENSE.txt for further details.