Commit 60ac6a28a2f198427c2d1ad68421aee484e14028
1 parent
cada511f
Exists in
master
and in
4 other branches
Allow current_controller? helper to take an Array of options
Showing
2 changed files
with
12 additions
and
4 deletions
Show diff stats
app/helpers/application_helper.rb
... | ... | @@ -3,13 +3,16 @@ module ApplicationHelper |
3 | 3 | |
4 | 4 | # Check if a particular controller is the current one |
5 | 5 | # |
6 | + # args - One or more controller names to check | |
7 | + # | |
6 | 8 | # Examples |
7 | 9 | # |
8 | 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 | 16 | end |
14 | 17 | |
15 | 18 | def gravatar_icon(user_email = '', size = 40) | ... | ... |
spec/helpers/application_helper_spec.rb
... | ... | @@ -13,6 +13,11 @@ describe ApplicationHelper do |
13 | 13 | it "returns false when controller does not match argument" do |
14 | 14 | current_controller?(:bar).should_not be_true |
15 | 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 | 21 | end |
17 | 22 | |
18 | 23 | describe "gravatar_icon" do | ... | ... |