Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paths (as hash) with different controllers but the same action name should not be highlighted? #42

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/navigasmic/core/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def highlights_on?(path, params)
when FalseClass
false
when Hash
rule.except(*unwanted_keys).detect do |key, value|
rule.except(*unwanted_keys).all? do |key, value|
value = value.gsub(/^\//, '') if key == :controller
value == params[key].to_s
end
Expand Down
10 changes: 8 additions & 2 deletions spec/core/item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,24 @@
end

describe "#highlights_on?" do
it "uses it's own link (as a string)" do
it "uses its own link (as a string)" do
item = subject.new 'Label', '/path', true
item.highlights_on?('/path', {}).should be(true)
item.highlights_on?('/other_path', {}).should be(false)
end

it "uses it's own path (as hash)" do
it "uses its own path (as hash)" do
item = subject.new 'Label', {controller: 'foo'}, true
item.highlights_on?('/path', {controller: 'foo'}).should be(true)
item.highlights_on?('/other_path', {controller: 'bar'}).should be(false)
end

it "uses its own path (as hash) with actions" do
item = subject.new 'Label', {controller: 'foo', action: 'baz'}, true
item.highlights_on?('/path/action', {controller: 'foo', action: 'baz'}).should be(true)
item.highlights_on?('/other_path/action', {controller: 'bar', action: 'baz'}).should be(false)
end

it "highlights on multiple controllers" do
item = subject.new 'Label', '/foo', true, highlights_on: [{controller: 'foo'}, {controller: 'bar'}]
item.highlights_on?('/path', {controller: 'foo'}).should be(true)
Expand Down