From 60ac6a28a2f198427c2d1ad68421aee484e14028 Mon Sep 17 00:00:00 2001 From: Robert Speicher <rspeicher@gmail.com> Date: Tue, 25 Sep 2012 21:18:00 -0400 Subject: [PATCH] Allow current_controller? helper to take an Array of options --- app/helpers/application_helper.rb | 11 +++++++---- spec/helpers/application_helper_spec.rb | 5 +++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 505f6067c5..d916d8874a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3,13 +3,16 @@ module ApplicationHelper # Check if a particular controller is the current one # + # args - One or more controller names to check + # # Examples # # # On TreeController - # current_controller?(:tree) # => true - # current_controller?(:commits) # => false - def current_controller?(name) - controller.controller_name == name.to_s.downcase + # current_controller?(:tree) # => true + # current_controller?(:commits) # => false + # current_controller?(:commits, :tree) # => true + def current_controller?(*args) + args.any? { |v| v.to_s.downcase == controller.controller_name } end def gravatar_icon(user_email = '', size = 40) diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 10250c9388..fb711dd8d7 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -13,6 +13,11 @@ describe ApplicationHelper do it "returns false when controller does not match argument" do current_controller?(:bar).should_not be_true end + + it "should take any number of arguments" do + current_controller?(:baz, :bar).should_not be_true + current_controller?(:baz, :bar, :foo).should be_true + end end describe "gravatar_icon" do -- 2.30.9