Skip to content

evil-c/factory_scenarios

 
 

Repository files navigation

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

  • Add the gem to your gemfile group :development do gem 'factory_scenarios' end
  • Run bundle install

Tests

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

RAILS_VERSION=3.1.4 bundel exec rake test

Configuration

  • FactoryScenarios is a mountable engine. Add a line like this to your routes.rb file:

    if Rails.env.to_s != 'production'
      mount FactoryScenarios::Engine, :at => '/factory_scenarios'
    end
  • The current configuration options are as follows

    • iframe_width: sets the width of the iframe that your site will appear in, defaults to 1000px
    • user_class: your users class, defaults to User
    • open_in_iframe: by default factory_scenarios will open your site in an iframe leaving the scenarios on the left, if you don't desire this functionality you can set this option to false.
  • Important Note

    • You need to have active_reload installed in your application to utilize this gem successfully. The consequences of not having this gem install will be errors when trying to login using your factories.

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

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

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.

About

use your factory girl factories in dev mode

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 94.1%
  • CSS 4.5%
  • CoffeeScript 1.4%