Commit 60ac6a28a2f198427c2d1ad68421aee484e14028

Authored by Robert Speicher
1 parent cada511f

Allow current_controller? helper to take an Array of options

app/helpers/application_helper.rb
@@ -3,13 +3,16 @@ module ApplicationHelper @@ -3,13 +3,16 @@ module ApplicationHelper
3 3
4 # Check if a particular controller is the current one 4 # Check if a particular controller is the current one
5 # 5 #
  6 + # args - One or more controller names to check
  7 + #
6 # Examples 8 # Examples
7 # 9 #
8 # # On TreeController 10 # # 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 11 + # current_controller?(:tree) # => true
  12 + # current_controller?(:commits) # => false
  13 + # current_controller?(:commits, :tree) # => true
  14 + def current_controller?(*args)
  15 + args.any? { |v| v.to_s.downcase == controller.controller_name }
13 end 16 end
14 17
15 def gravatar_icon(user_email = '', size = 40) 18 def gravatar_icon(user_email = '', size = 40)
spec/helpers/application_helper_spec.rb
@@ -13,6 +13,11 @@ describe ApplicationHelper do @@ -13,6 +13,11 @@ describe ApplicationHelper do
13 it "returns false when controller does not match argument" do 13 it "returns false when controller does not match argument" do
14 current_controller?(:bar).should_not be_true 14 current_controller?(:bar).should_not be_true
15 end 15 end
  16 +
  17 + it "should take any number of arguments" do
  18 + current_controller?(:baz, :bar).should_not be_true
  19 + current_controller?(:baz, :bar, :foo).should be_true
  20 + end
16 end 21 end
17 22
18 describe "gravatar_icon" do 23 describe "gravatar_icon" do