Skip to content

Commit df35060

Browse files
committed
Merge branch 'bisscomm-master'
2 parents 5edc7b4 + 479214a commit df35060

File tree

3 files changed

+40
-39
lines changed

3 files changed

+40
-39
lines changed

lib/active_link_to/active_link_to.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,16 @@ def is_active_link?(url, condition = nil)
7979
@is_active_link[[url, condition]] ||= begin
8080
original_url = url
8181
url = Addressable::URI::parse(url).path
82+
path = request.original_fullpath
8283
case condition
8384
when :inclusive, nil
84-
!request.fullpath.match(/^#{Regexp.escape(url).chomp('/')}(\/.*|\?.*)?$/).blank?
85+
!path.match(/^#{Regexp.escape(url).chomp('/')}(\/.*|\?.*)?$/).blank?
8586
when :exclusive
86-
!request.fullpath.match(/^#{Regexp.escape(url)}\/?(\?.*)?$/).blank?
87+
!path.match(/^#{Regexp.escape(url)}\/?(\?.*)?$/).blank?
8788
when :exact
88-
request.fullpath == original_url
89+
path == original_url
8990
when Regexp
90-
!request.fullpath.match(condition).blank?
91+
!path.match(condition).blank?
9192
when Array
9293
controllers = [*condition[0]]
9394
actions = [*condition[1]]

test/active_link_to_test.rb

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,82 +8,82 @@ def test_is_active_link_booleans_test
88
end
99

1010
def test_is_active_link_symbol_inclusive
11-
set_fullpath('/root')
11+
set_path('/root')
1212
assert is_active_link?('/root', :inclusive)
1313

14-
set_fullpath('/root?param=test')
14+
set_path('/root?param=test')
1515
assert is_active_link?('/root', :inclusive)
1616

17-
set_fullpath('/root/child/sub-child')
17+
set_path('/root/child/sub-child')
1818
assert is_active_link?('/root', :inclusive)
1919

20-
set_fullpath('/other')
20+
set_path('/other')
2121
refute is_active_link?('/root', :inclusive)
2222
end
2323

2424
def test_is_active_link_symbol_inclusive_implied
25-
set_fullpath('/root/child/sub-child')
25+
set_path('/root/child/sub-child')
2626
assert is_active_link?('/root')
2727
end
2828

2929
def test_is_active_link_symbol_inclusive_similar_path
30-
set_fullpath('/root/abc')
30+
set_path('/root/abc')
3131
refute is_active_link?('/root/a', :inclusive)
3232
end
3333

3434
def test_is_active_link_symbol_inclusive_with_last_slash
35-
set_fullpath('/root/abc')
35+
set_path('/root/abc')
3636
assert is_active_link?('/root/')
3737
end
3838

3939
def test_is_active_link_symbol_inclusive_with_last_slash_and_similar_path
40-
set_fullpath('/root_path')
40+
set_path('/root_path')
4141
refute is_active_link?('/root/')
4242
end
4343

4444
def test_is_active_link_symbol_inclusive_with_link_params
45-
set_fullpath('/root?param=test')
45+
set_path('/root?param=test')
4646
assert is_active_link?('/root?attr=example')
4747
end
4848

4949
def test_is_active_link_symbol_exclusive
50-
set_fullpath('/root')
50+
set_path('/root')
5151
assert is_active_link?('/root', :exclusive)
5252

53-
set_fullpath('/root?param=test')
53+
set_path('/root?param=test')
5454
assert is_active_link?('/root', :exclusive)
5555

56-
set_fullpath('/root/child')
56+
set_path('/root/child')
5757
refute is_active_link?('/root', :exclusive)
5858
end
5959

6060
def test_is_active_link_symbol_exclusive_with_link_params
61-
set_fullpath('/root?param=test')
61+
set_path('/root?param=test')
6262
assert is_active_link?('/root?attr=example', :exclusive)
6363
end
6464

6565
def test_is_active_link_symbol_exact
66-
set_fullpath('/root?param=test')
66+
set_path('/root?param=test')
6767
assert is_active_link?('/root?param=test', :exact)
6868

69-
set_fullpath('/root?param=test')
69+
set_path('/root?param=test')
7070
refute is_active_link?('/root?param=exact', :exact)
7171

72-
set_fullpath('/root')
72+
set_path('/root')
7373
refute is_active_link?('/root?param=test', :exact)
7474

75-
set_fullpath('/root?param=test')
75+
set_path('/root?param=test')
7676
refute is_active_link?('/root', :exact)
7777
end
7878

7979
def test_is_active_link_regex
80-
set_fullpath('/root')
80+
set_path('/root')
8181
assert is_active_link?('/', /^\/root/)
8282

83-
set_fullpath('/root/child')
83+
set_path('/root/child')
8484
assert is_active_link?('/', /^\/r/)
8585

86-
set_fullpath('/other')
86+
set_path('/other')
8787
refute is_active_link?('/', /^\/r/)
8888
end
8989

@@ -121,15 +121,15 @@ def test_is_active_link_hash
121121
end
122122

123123
def test_is_active_link_with_memoization
124-
set_fullpath('/')
124+
set_path('/')
125125
assert is_active_link?('/', :exclusive)
126126

127-
set_fullpath('/other', false)
127+
set_path('/other', false)
128128
assert is_active_link?('/', :exclusive)
129129
end
130130

131131
def test_active_link_to_class
132-
set_fullpath('/root')
132+
set_path('/root')
133133
assert_equal 'active', active_link_to_class('/root')
134134
assert_equal 'on', active_link_to_class('/root', class_active: 'on')
135135

@@ -138,7 +138,7 @@ def test_active_link_to_class
138138
end
139139

140140
def test_active_link_to
141-
set_fullpath('/root')
141+
set_path('/root')
142142
link = active_link_to('label', '/root')
143143
assert_html link, 'a.active[href="/root"]', 'label'
144144

@@ -147,7 +147,7 @@ def test_active_link_to
147147
end
148148

149149
def test_active_link_to_with_existing_class
150-
set_fullpath('/root')
150+
set_path('/root')
151151
link = active_link_to('label', '/root', class: 'current')
152152
assert_html link, 'a.current.active[href="/root"]', 'label'
153153

@@ -156,7 +156,7 @@ def test_active_link_to_with_existing_class
156156
end
157157

158158
def test_active_link_to_with_custom_classes
159-
set_fullpath('/root')
159+
set_path('/root')
160160
link = active_link_to('label', '/root', class_active: 'on')
161161
assert_html link, 'a.on[href="/root"]', 'label'
162162

@@ -165,7 +165,7 @@ def test_active_link_to_with_custom_classes
165165
end
166166

167167
def test_active_link_to_with_wrap_tag
168-
set_fullpath('/root')
168+
set_path('/root')
169169
link = active_link_to('label', '/root', wrap_tag: :li)
170170
assert_html link, 'li.active a.active[href="/root"]', 'label'
171171

@@ -177,21 +177,21 @@ def test_active_link_to_with_wrap_tag
177177
end
178178

179179
def test_active_link_to_with_active_disable
180-
set_fullpath('/root')
180+
set_path('/root')
181181
link = active_link_to('label', '/root', active_disable: true)
182182
assert_html link, 'span.active', 'label'
183183
end
184184

185185
def test_should_not_modify_passed_params
186-
set_fullpath('/root')
186+
set_path('/root')
187187
params = {class: 'testing', active: :inclusive}
188188
out = active_link_to 'label', '/root', params
189189
assert_html out, 'a.testing.active[href="/root"]', 'label'
190190
assert_equal ({class: 'testing', active: :inclusive }), params
191191
end
192192

193193
def test_active_link_to_wrap_tag_class
194-
set_fullpath('/root')
194+
set_path('/root')
195195
link = active_link_to('label', '/root', wrap_tag: :li)
196196
assert_html link, 'li.active a.active[href="/root"]', 'label'
197197

@@ -200,13 +200,13 @@ def test_active_link_to_wrap_tag_class
200200
end
201201

202202
def test_active_link_to_with_aria
203-
set_fullpath('/root')
203+
set_path('/root')
204204
link = active_link_to('label', '/root')
205205
assert_html link, 'a.active[href="/root"][aria-current="page"]', 'label'
206206
end
207207

208208
def test_active_link_to_with_utf8
209-
set_fullpath('/äöü')
209+
set_path('/äöü')
210210
link = active_link_to('label', '/äöü')
211211
assert_html link, 'a.active[href="/äöü"]', 'label'
212212
end

test/test_helper.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class MiniTest::Test
99
# need this to simulate requests that drive active_link_helper
1010
module FakeRequest
1111
class Request
12-
attr_accessor :fullpath
12+
attr_accessor :original_fullpath
1313
end
1414
def request
1515
@request ||= Request.new
@@ -25,8 +25,8 @@ def params
2525
include ActionView::Helpers::TagHelper
2626
include ActiveLinkTo
2727

28-
def set_fullpath(path, purge_cache = true)
29-
request.fullpath = path
28+
def set_path(path, purge_cache = true)
29+
request.original_fullpath = path
3030
if purge_cache && defined?(@is_active_link)
3131
remove_instance_variable(:@is_active_link)
3232
end

0 commit comments

Comments
 (0)