Commit 115dfe3

mo khan <mo@mokhan.ca>
2016-05-01 23:20:48
extract helper method for feature toggles.
1 parent 81faa43
Changed files (3)
app/controllers/application_controller.rb
@@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base
   protect_from_forgery with: :exception
   before_action :authenticate!
   rescue_from ActiveRecord::RecordNotFound, with: :record_not_found
-  helper_method :current_user
+  helper_method :current_user, :feature_available?
 
   protected
 
@@ -16,6 +16,10 @@ class ApplicationController < ActionController::Base
     @current_user ||= current_session.try(:user)
   end
 
+  def feature_available?(feature)
+    $flipper[feature.to_sym].enabled?(current_user)
+  end
+
   def translate(key)
     I18n.translate("#{params[:controller]}.#{params[:action]}#{key}")
   end
app/views/layouts/application.html.erb
@@ -31,7 +31,7 @@
               <section class="top-bar-section">
                 <!-- Right Nav Section -->
                 <ul class="right">
-                  <% if $flipper[:gym].enabled?(current_user) %>
+                  <% if feature_available?(:gym) %>
                   <li class="divider"></li>
                   <li><%= link_to t(".gyms"), gyms_path %></li>
                   <% end %>
features/finding_a_gym.feature
@@ -3,11 +3,11 @@ Feature: Finding a gym
   So that I can get a good work out.
 
   Scenario: Find a gym
-    Given the user user is on the gyms page
+    Given the user is on the gyms page
     When I look at the page
     Then it lists all gyms
 
   Scenario: Find a gym in a city
-    Given the user user is on the gyms page
+    Given the user is on the gyms page
     When I choose a city
     Then it lists all gyms