From 1ee16e7df1e4f5ae36c2436e553a3381b86250f4 Mon Sep 17 00:00:00 2001 From: Corin Langosch Date: Wed, 13 Feb 2013 18:49:53 +0100 Subject: [PATCH] fixed handling of :highlights_on => false --- lib/navigasmic/core/item.rb | 6 +++--- spec/core/item_spec.rb | 20 ++++++++++++++------ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/navigasmic/core/item.rb b/lib/navigasmic/core/item.rb index 5225890..77366df 100644 --- a/lib/navigasmic/core/item.rb +++ b/lib/navigasmic/core/item.rb @@ -50,10 +50,10 @@ def highlights_on?(path, params) def calculate_highlighting_rules(rules) [].tap do |highlighting_rules| - if rules - highlighting_rules.concat Array(rules) - else + if rules.nil? highlighting_rules << @link if link? + else + highlighting_rules.concat Array(rules) end end end diff --git a/spec/core/item_spec.rb b/spec/core/item_spec.rb index cb32dd1..6b60503 100644 --- a/spec/core/item_spec.rb +++ b/spec/core/item_spec.rb @@ -5,7 +5,6 @@ subject { Navigasmic::Item } describe "#hidden?" do - it "returns true when it's not visible" do item = subject.new 'Label', {controller: 'controller'}, false item.hidden?.should be(true) @@ -15,11 +14,9 @@ item = subject.new 'Label', {controller: 'controller'}, true item.hidden?.should be(false) end - end describe "#disabled?" do - it "returns true when it's disabled" do item = subject.new 'Label', {controller: 'controller'}, true, disabled_if: true item.disabled?.should be(true) @@ -29,11 +26,9 @@ item = subject.new 'Label', {controller: 'controller'}, true, disabled_if: false item.disabled?.should be(false) end - end describe "#link?" do - it "returns true when there's a link" do item = subject.new 'Label', 'url', true item.link?.should be(true) @@ -48,11 +43,24 @@ item = subject.new 'Label', nil, true, disabled_if: true item.link?.should be(false) end + end + + describe "#calculate_highlighting_rules" do + it "uses the item's link when no rules given" do + item = subject.new 'Label', 'url', true + item.send(:calculate_highlighting_rules, nil).should eq(['url']) + end + it "uses the given rules if any given" do + item = subject.new 'Label', 'url', true, :highlights_on => false + item.send(:calculate_highlighting_rules, false).should eq([false]) + + item = subject.new 'Label', 'url', true, :highlights_on => false + item.send(:calculate_highlighting_rules, ["/a", "/b"]).should eq(["/a", "/b"]) + end end describe "#highlights_on?" do - it "uses it's own link (as a string)" do item = subject.new 'Label', '/path', true item.highlights_on?('/path', {}).should be(true)