Commit 3ad931ca9211d2ca0f345f97db00193ee5533dfd
1 parent
95f0a411
Exists in
master
and in
4 other branches
Add current_controller? helper method
Simplifies some of the "active tab" checks we're doing
Showing
2 changed files
with
25 additions
and
0 deletions
Show diff stats
app/helpers/application_helper.rb
1 | 1 | require 'digest/md5' |
2 | 2 | module ApplicationHelper |
3 | 3 | |
4 | + # Check if a particular controller is the current one | |
5 | + # | |
6 | + # Examples | |
7 | + # | |
8 | + # # On TreeController | |
9 | + # current_controller?(:tree) # => true | |
10 | + # current_controller?(:commits) # => false | |
11 | + def current_controller?(name) | |
12 | + controller.controller_name == name.to_s.downcase | |
13 | + end | |
14 | + | |
4 | 15 | def gravatar_icon(user_email = '', size = 40) |
5 | 16 | if Gitlab.config.disable_gravatar? || user_email.blank? |
6 | 17 | 'no_avatar.png' | ... | ... |
spec/helpers/application_helper_spec.rb
1 | 1 | require 'spec_helper' |
2 | 2 | |
3 | 3 | describe ApplicationHelper do |
4 | + describe 'current_controller?' do | |
5 | + before do | |
6 | + controller.stub!(:controller_name).and_return('foo') | |
7 | + end | |
8 | + | |
9 | + it "returns true when controller matches argument" do | |
10 | + current_controller?(:foo).should be_true | |
11 | + end | |
12 | + | |
13 | + it "returns false when controller does not match argument" do | |
14 | + current_controller?(:bar).should_not be_true | |
15 | + end | |
16 | + end | |
17 | + | |
4 | 18 | describe "gravatar_icon" do |
5 | 19 | let(:user_email) { 'user@email.com' } |
6 | 20 | ... | ... |