Quick guide to multiple heroku accounts, and moving apps between them

The heroku-accounts plugin makes it a lot easier to have multiple heroku accounts (work, personal, consulting, etc) on the same machine… this quick how-to guide assumes your pre-existing heroku account will be heroku.work and you are adding a new account heroku.personal.

It also describes how to move an app from one to the other, for example, if you have hit your 25-app max and are creating a new account and want to move some of your side projects and experimental apps out of your main account.

  1. You probably need to use the plugin to create BOTH your old and your new accounts, eg, if you had one to start with you can’t just add a new heroku.personal, you need to create heroku.work to replace your old one
  2. You’ll need to reassign your old apps to your heroku.work
  3. if you are moving an app, don’t assign the app to heroku.personal (using heroku accounts:set personal) until after you transfer the app using the heroku sharing commmand as described https://devcenter.heroku.com/articles/transferring-apps

So the steps you probably need are:

  1. Install the heroku-account plugin
  2. Go to heroku.com and create your new acount (if you don’t have a second acount already)
  3. run heroku accounts:add work --auto to create a new heroku.work account to replace your old default account (so use the same credentials you’ve been using all along). You ALSO need to upload your new key to heroku: heroku keys:add ~/.ssh/identity.heroku.work.pub
  4. run heroku accounts:add personal --auto to create a new heroku.personal account (eg use your new credentials for your new heroku account). You ALSO need to upload your new key to heroku: heroku keys:add ~/.ssh/identity.heroku.personal.pub
  5. For each app, cd to the project root then run heroku accounts:set work (all that does it setup git to use your heroku.work, which is (unin this example) the same heroku account you’ve been using all along, only now it’s called heroku.work.
  6. If you want to move an app from heroku.work to heroku.personal,
    (a) add the new heroku account as a collaborator with heroku sharing:add <strong>new_email</strong>
    (b) in your local directory, switch the app to heroku.personal using heroku accounts:set personal
    (c) transfer** the app from the old account to the new account using heroku sharing:transfer <strong>new_email</strong> then
    (d) remove the old email address collaborator (if you want to) using heroku sharing:remove <strong>old_email</strong>

** Note the heroku link I provided says there are special requirements to move an app with any paid resources. Generally, remove the paid resoures, then add them back later, or have support do it.

How to specify traits for model associations in FactoryGirl

If you’re using RSpec and FactoryGirl to automate testing for your Rails app, you probably know that when creating a factory for a model that has association you can simply specify the factory of the associated model. For example, suppose your Contact model has associations with Phone and Store models:

FactoryGirl.define do factory :contact do |f| f.name { Faker::Name.name } phone store end end

And you probably know you can have traits for factories, for example, different settings for different types of stores:

FactoryGirl.define do 
  factory :store do |f| 
    after(:create) { |store| 
      store.update_attributes :name => Faker::Name.last_name + " LLC" 

    trait :unknown do 
      after(:build) { |store| store.init_blank(Settings.feature_set_unknown) } 

    trait :restaurant do 
      after(:build) { |store| store.init_blank(Settings.feature_set_restaurant) } 

    trait :retailer do 
      after(:build) { |store| store.init_blank(Settings.feature_set_retailer) } 

However, what we could not find documented anywhere was how to specify a trait for an associations. Say when you create a contact factory you want specify which type of store that contact belongs to:

Here’s the magic decoder ring… use
:factory => [:association_factory_name, :trait_name]

FactoryGirl.define do 
  factory :contact do |f| 
    f.name { Faker::Name.name } 
    phone association :store, :factory => [:store, :unknown] 

    trait :foodie_contact do 
      association :store, :factory => [:store, :restaurant] 

    trait :retailer_contact do 
      association :store, :factory => [:store, :retailer] 

Which you can then invoke as follows in your examples:

c = FactoryGirl.create(:contact, :retailer_contact)