Skip to content

Commit

Permalink
Merge pull request #109 from troynt/master
Browse files Browse the repository at this point in the history
Subpath shouldn't match partial URL segments. e.g. /resources/1 vs /resources_group/1
  • Loading branch information
andi committed Nov 26, 2012
2 parents 7f659a7 + d5e5418 commit 79ea081
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/simple_navigation/core/item.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def selected_by_condition?
when Proc when Proc
highlights_on.call highlights_on.call
when :subpath when :subpath
!!(SimpleNavigation.request_uri =~ /^#{Regexp.escape url_without_anchor}/) !!(SimpleNavigation.request_uri =~ /^#{Regexp.escape url_without_anchor}(\/|$|\?)/i)
else else
raise ArgumentError, ':highlights_on must be a Regexp, Proc or :subpath' raise ArgumentError, ':highlights_on must be a Regexp, Proc or :subpath'
end end
Expand Down
6 changes: 6 additions & 0 deletions spec/lib/simple_navigation/core/item_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -397,6 +397,12 @@
end end
it {@item.send(:selected_by_condition?).should be_true} it {@item.send(:selected_by_condition?).should be_true}
end end
context 'we are in a route that has a similar name' do
before(:each) do
SimpleNavigation.stub!(:request_uri => '/resources_group/id')
end
it {@item.send(:selected_by_condition?).should be_false}
end
context 'we are in a route not beginning with this item path' do context 'we are in a route not beginning with this item path' do
before(:each) do before(:each) do
SimpleNavigation.stub!(:request_uri => '/another_resource/id') SimpleNavigation.stub!(:request_uri => '/another_resource/id')
Expand Down

0 comments on commit 79ea081

Please sign in to comment.