Skip to content

Instantly share code, notes, and snippets.

@jrallison
Created May 17, 2011 21:02
Show Gist options
  • Save jrallison/977391 to your computer and use it in GitHub Desktop.
Save jrallison/977391 to your computer and use it in GitHub Desktop.
Everything you need to know about rollout

1) Rollout configuration is in models

/web/models/lib/models/config/rollout.rb

$rollout = Rollout.new(REDIS)

$rollout.define_group(:admin) do |user|
  user.admin?
end

class Rollout
  def self.defaults!
    # Put current state of rollouts here
    # Example: $rollout.activate_group(:fb_connect, :admin)
  end
end

2) Wrap user-facing feature endpoints with rollout

some view

<% if $rollout.active?(:fb_connect, current_user) %>
  <%= render "facebook_connect_bar" %>
<% end %>

3) Backend logic doesn't need to be wrapped with rollout.

It should function correctly whether the feature is active or not (tested!)

4) That's great and all, but what about testing stuff, yo?

Test with the feature activated and deactivated

/web/devise/spec/support/rollout.rb

module RolloutHelperMethods
  def feature_on(feature)
    $rollout.activate_group(feature, :all)
  end

  def feature_off(feature)
    $rollout.deactivate_all(feature)
  end
end

RSpec.configuration.include RolloutHelperMethods

/web/devise/spec/acceptance/login_spec.rb

require File.dirname(__FILE__) + '/acceptance_helper'

feature "Log in: " do
  background do
    @bob = Factory(:user, :email => "bob@challengepost.com", :screen_name => "Bob")
    feature_off(:fb_connect)
  end

  scenario "user logs in with its challengepost account" do
    ...
  end

  scenario "user fails to log in" do
    ...
  end

  scenario "user choose not to login after all" do
    ...
  end

  scenario "fb connect should not be active" do
    # replace with an actual test
    $rollout.active?(:fb_connect, AnonymousUser.new).should be_false
  end

  context "fb connect is enabled" do
    background do
      feature_on(:fb_connect)
    end

    scenario "fb connect should be active" do
      # replace with an actual test
      $rollout.active?(:fb_connect, AnonymousUser.new).should be_true
    end
  end
end

Thank you, enjoy your day.

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