Commit 3ad931ca authored by Robert Speicher's avatar Robert Speicher

Add current_controller? helper method

Simplifies some of the "active tab" checks we're doing
parent 95f0a411
require 'digest/md5' require 'digest/md5'
module ApplicationHelper module ApplicationHelper
# Check if a particular controller is the current one
#
# Examples
#
# # On TreeController
# current_controller?(:tree) # => true
# current_controller?(:commits) # => false
def current_controller?(name)
controller.controller_name == name.to_s.downcase
end
def gravatar_icon(user_email = '', size = 40) def gravatar_icon(user_email = '', size = 40)
if Gitlab.config.disable_gravatar? || user_email.blank? if Gitlab.config.disable_gravatar? || user_email.blank?
'no_avatar.png' 'no_avatar.png'
......
require 'spec_helper' require 'spec_helper'
describe ApplicationHelper do describe ApplicationHelper do
describe 'current_controller?' do
before do
controller.stub!(:controller_name).and_return('foo')
end
it "returns true when controller matches argument" do
current_controller?(:foo).should be_true
end
it "returns false when controller does not match argument" do
current_controller?(:bar).should_not be_true
end
end
describe "gravatar_icon" do describe "gravatar_icon" do
let(:user_email) { 'user@email.com' } let(:user_email) { 'user@email.com' }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment