simple_active_link_to 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -2
- data/lib/simple_active_link_to/simple_active_link_to.rb +22 -16
- data/lib/simple_active_link_to/version.rb +1 -1
- data/lib/simple_active_link_to.rb +0 -1
- metadata +31 -15
- data/.github/workflows/build.yml +0 -33
- data/.gitignore +0 -6
- data/Gemfile +0 -3
- data/Rakefile +0 -13
- data/simple_active_link_to.gemspec +0 -26
- data/test/gemfiles/5.0.gemfile +0 -5
- data/test/gemfiles/5.1.gemfile +0 -5
- data/test/gemfiles/5.2.gemfile +0 -5
- data/test/gemfiles/6.0.gemfile +0 -5
- data/test/gemfiles/6.1.gemfile +0 -5
- data/test/simple_active_link_to_test.rb +0 -230
- data/test/test_helper.rb +0 -55
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b562f2384f992bd5a60fe58b437dadb2f2913a3c6086fd4d7299081fb1577d38
|
4
|
+
data.tar.gz: f858baef43ba051f5ed83930ea79879b7ef1f58f0550caf7822b5fb36b0fe21c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9d17ac58827a31b29f574686e4899046bb58a6008e13c1ff1cd8981421a75ab5a0df58b185ba130bf33de60bce2ea7d73f7d2237e6a76396abd7cbea684cd72
|
7
|
+
data.tar.gz: a40af6bcf2e777900cfb19ea93c4f6757fc1a6022b9c07f5c579fa2f2a46cabae592f4e08ca00537f5f0c71586b5c1721821914ef5c435177170d2dc8da819be
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# simple_active_link_to ![Build](https://github.com/frullah/simple_active_link_to/workflows/Build/badge.svg) [![Gem Version](https://img.shields.io/gem/v/simple_active_link_to.svg?style=flat)](http://rubygems.org/gems/simple_active_link_to)
|
1
|
+
# simple_active_link_to [![Build Rails < 7](https://github.com/frullah/simple_active_link_to/actions/workflows/test-rails-below-7.yml/badge.svg?branch=master)](https://github.com/frullah/simple_active_link_to/actions/workflows/test-rails-below-7.yml) [![Build Rails >= 7](https://github.com/frullah/simple_active_link_to/actions/workflows/test-rails-7.yml/badge.svg?branch=master)](https://github.com/frullah/simple_active_link_to/actions/workflows/test-rails-7.yml) [![Gem Version](https://img.shields.io/gem/v/simple_active_link_to.svg?style=flat)](http://rubygems.org/gems/simple_active_link_to)
|
2
2
|
|
3
3
|
`simple_active_link_to` is a wrapper for [link_to](http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to), with active state by adding an extra css class `active` by default.
|
4
4
|
|
5
5
|
This gem works like [active_link_to](https://github.com/comfy/active_link_to), but with additional ```active_disable``` option and without wrap tag.
|
6
6
|
|
7
|
-
Tested with ruby 2.5 to 3.0 and rails 5.0 to 6.1
|
7
|
+
Tested with ruby 2.5 to 3.0 and rails 5.0 to 6.1, and rails 7.0
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
add `gem 'simple_active_link_to'` to Gemfile and run `bundle install`.
|
@@ -145,3 +145,7 @@ is_active_link?(users_path, :inclusive)
|
|
145
145
|
active_link_to_class(users_path, active: :inclusive)
|
146
146
|
# => 'active'
|
147
147
|
```
|
148
|
+
|
149
|
+
## Contributing
|
150
|
+
|
151
|
+
Bug reports and pull requests are welcome.
|
@@ -15,31 +15,32 @@ module SimpleActiveLinkTo
|
|
15
15
|
# :active_disable => Boolean | :hash
|
16
16
|
# Example usage:
|
17
17
|
# simple_active_link_to('/users', class_active: 'enabled')
|
18
|
-
def simple_active_link_to(name = nil,
|
18
|
+
def simple_active_link_to(name = nil, url_options = nil, html_options = nil, &block)
|
19
19
|
if block_given?
|
20
|
-
html_options =
|
21
|
-
|
20
|
+
html_options = url_options
|
21
|
+
url_options = name
|
22
22
|
name = capture(&block)
|
23
23
|
end
|
24
24
|
|
25
|
-
html_options ||= {}
|
26
25
|
link_options = {}
|
27
26
|
active_options = {}
|
28
|
-
html_options.
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
if html_options.is_a?(Hash)
|
28
|
+
html_options.each do |k, v|
|
29
|
+
if ACTIVE_OPTIONS.include?(k)
|
30
|
+
active_options[k] = v
|
31
|
+
else
|
32
|
+
link_options[k] = v
|
33
|
+
end
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
36
|
-
url = url_for(
|
37
|
+
url = url_for(url_options)
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
link_options[:class] = "#{
|
39
|
+
activated = is_active_link?(url, active_options[:active])
|
40
|
+
state_class = link_state_class(activated, active_options)
|
41
|
+
link_options[:class] = "#{link_options[:class]} #{state_class}".strip
|
41
42
|
|
42
|
-
if
|
43
|
+
if activated
|
43
44
|
link_options[:'aria-current'] = 'page'
|
44
45
|
case active_options[:active_disable]
|
45
46
|
when true
|
@@ -57,7 +58,11 @@ module SimpleActiveLinkTo
|
|
57
58
|
# active_link_to_class('/root', class_active: 'on', class_inactive: 'off')
|
58
59
|
#
|
59
60
|
def active_link_to_class(url, options = {})
|
60
|
-
|
61
|
+
link_state_class(is_active_link?(url, options[:active]), options)
|
62
|
+
end
|
63
|
+
|
64
|
+
private def link_state_class(activated, options = {})
|
65
|
+
if activated
|
61
66
|
options[:class_active] || 'active'
|
62
67
|
else
|
63
68
|
options[:class_inactive] || ''
|
@@ -80,7 +85,8 @@ module SimpleActiveLinkTo
|
|
80
85
|
#
|
81
86
|
def is_active_link?(url, condition = nil)
|
82
87
|
@is_active_link ||= {}
|
83
|
-
@is_active_link[
|
88
|
+
@is_active_link[url] ||= {}
|
89
|
+
@is_active_link[url][condition] ||= begin
|
84
90
|
case condition
|
85
91
|
when :exclusive, :inclusive, nil
|
86
92
|
url_path = url.split('#').first.split('?').first
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_active_link_to
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fajarullah
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -66,6 +66,34 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: benchmark
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: benchmark-ips
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: actionpack
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,23 +131,11 @@ executables: []
|
|
103
131
|
extensions: []
|
104
132
|
extra_rdoc_files: []
|
105
133
|
files:
|
106
|
-
- ".github/workflows/build.yml"
|
107
|
-
- ".gitignore"
|
108
|
-
- Gemfile
|
109
134
|
- LICENSE
|
110
135
|
- README.md
|
111
|
-
- Rakefile
|
112
136
|
- lib/simple_active_link_to.rb
|
113
137
|
- lib/simple_active_link_to/simple_active_link_to.rb
|
114
138
|
- lib/simple_active_link_to/version.rb
|
115
|
-
- simple_active_link_to.gemspec
|
116
|
-
- test/gemfiles/5.0.gemfile
|
117
|
-
- test/gemfiles/5.1.gemfile
|
118
|
-
- test/gemfiles/5.2.gemfile
|
119
|
-
- test/gemfiles/6.0.gemfile
|
120
|
-
- test/gemfiles/6.1.gemfile
|
121
|
-
- test/simple_active_link_to_test.rb
|
122
|
-
- test/test_helper.rb
|
123
139
|
homepage: http://github.com/frullah/simple_active_link_to
|
124
140
|
licenses:
|
125
141
|
- MIT
|
@@ -139,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
155
|
- !ruby/object:Gem::Version
|
140
156
|
version: '0'
|
141
157
|
requirements: []
|
142
|
-
rubygems_version: 3.2.
|
158
|
+
rubygems_version: 3.2.22
|
143
159
|
signing_key:
|
144
160
|
specification_version: 4
|
145
161
|
summary: ActionView helper to render currently active links
|
data/.github/workflows/build.yml
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
name: Build
|
2
|
-
|
3
|
-
on:
|
4
|
-
push:
|
5
|
-
branches: [ master, dev ]
|
6
|
-
paths-ignore:
|
7
|
-
- "**/README.md"
|
8
|
-
- lib/simple_active_link_to/version.rb
|
9
|
-
pull_request:
|
10
|
-
branches: [ master, dev ]
|
11
|
-
paths-ignore:
|
12
|
-
- "**/README.md"
|
13
|
-
- lib/simple_active_link_to/version.rb
|
14
|
-
|
15
|
-
jobs:
|
16
|
-
tests:
|
17
|
-
name: Tests
|
18
|
-
runs-on: ubuntu-latest
|
19
|
-
strategy:
|
20
|
-
matrix:
|
21
|
-
ruby: [2.5, 2.6, 2.7, 3.0]
|
22
|
-
rails: ['5.0', '5.1', '5.2', '6.0', '6.1']
|
23
|
-
env:
|
24
|
-
BUNDLE_PATH: vendor/bundle
|
25
|
-
BUNDLE_GEMFILE: test/gemfiles/${{ matrix.rails }}.gemfile
|
26
|
-
steps:
|
27
|
-
- uses: actions/checkout@v2
|
28
|
-
- name: Set up Ruby
|
29
|
-
uses: ruby/setup-ruby@v1
|
30
|
-
with:
|
31
|
-
ruby-version: ${{ matrix.ruby }}
|
32
|
-
bundler-cache: true
|
33
|
-
- run: bundle exec rake
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'rake/testtask'
|
5
|
-
require 'bundler/setup'
|
6
|
-
|
7
|
-
Rake::TestTask.new(:test) do |test|
|
8
|
-
test.libs << 'lib' << 'test'
|
9
|
-
test.pattern = 'test/**/*_test.rb'
|
10
|
-
test.verbose = true
|
11
|
-
end
|
12
|
-
|
13
|
-
task default: :test
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
$:.unshift File.expand_path('lib', __dir__)
|
4
|
-
require 'simple_active_link_to/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = 'simple_active_link_to'
|
8
|
-
s.version = SimpleActiveLinkTo::VERSION
|
9
|
-
s.authors = ['Fajarullah']
|
10
|
-
s.email = ['frullah12@gmail.com']
|
11
|
-
s.homepage = 'http://github.com/frullah/simple_active_link_to'
|
12
|
-
s.summary = 'ActionView helper to render currently active links'
|
13
|
-
s.description = 'Helpful method when you need to add some logic that figures out if the link (or more often navigation item) is selected based on the current page or other arbitrary condition'
|
14
|
-
s.license = 'MIT'
|
15
|
-
|
16
|
-
s.files = `git ls-files`.split("\n")
|
17
|
-
|
18
|
-
s.required_ruby_version = '>= 2.4.0'
|
19
|
-
s.add_development_dependency 'minitest'
|
20
|
-
s.add_development_dependency 'nokogiri'
|
21
|
-
s.add_development_dependency 'rack-test'
|
22
|
-
s.add_development_dependency 'rake'
|
23
|
-
|
24
|
-
s.add_dependency 'actionpack', '>= 5.0'
|
25
|
-
s.add_dependency 'activesupport', '>= 5.0'
|
26
|
-
end
|
data/test/gemfiles/5.0.gemfile
DELETED
data/test/gemfiles/5.1.gemfile
DELETED
data/test/gemfiles/5.2.gemfile
DELETED
data/test/gemfiles/6.0.gemfile
DELETED
data/test/gemfiles/6.1.gemfile
DELETED
@@ -1,230 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'test_helper'
|
4
|
-
|
5
|
-
class SimpleActiveLinkToTest < MiniTest::Test
|
6
|
-
|
7
|
-
def test_is_active_link_booleans_test
|
8
|
-
assert is_active_link?('/', true)
|
9
|
-
refute is_active_link?('/', false)
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_is_active_link_handle_empty_string
|
13
|
-
assert is_active_link?('', true)
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_is_active_link_symbol_inclusive
|
17
|
-
set_path('/root')
|
18
|
-
assert is_active_link?('/root', :inclusive)
|
19
|
-
|
20
|
-
set_path('/root?param=test')
|
21
|
-
assert is_active_link?('/root', :inclusive)
|
22
|
-
|
23
|
-
set_path('/root/child/sub-child')
|
24
|
-
assert is_active_link?('/root', :inclusive)
|
25
|
-
|
26
|
-
set_path('/other')
|
27
|
-
refute is_active_link?('/root', :inclusive)
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_is_active_link_symbol_inclusive_implied
|
31
|
-
set_path('/root/child/sub-child')
|
32
|
-
assert is_active_link?('/root')
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_is_active_link_symbol_inclusive_similar_path
|
36
|
-
set_path('/root/abc')
|
37
|
-
refute is_active_link?('/root/a', :inclusive)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_is_active_link_symbol_inclusive_with_last_slash
|
41
|
-
set_path('/root/abc')
|
42
|
-
assert is_active_link?('/root/')
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_is_active_link_symbol_inclusive_with_last_slash_and_similar_path
|
46
|
-
set_path('/root_path')
|
47
|
-
refute is_active_link?('/root/')
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_is_active_link_symbol_inclusive_with_link_params
|
51
|
-
set_path('/root?param=test')
|
52
|
-
assert is_active_link?('/root?attr=example')
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_is_active_link_symbol_exclusive
|
56
|
-
set_path('/root')
|
57
|
-
assert is_active_link?('/root', :exclusive)
|
58
|
-
|
59
|
-
set_path('/root?param=test')
|
60
|
-
assert is_active_link?('/root', :exclusive)
|
61
|
-
|
62
|
-
set_path('/root/child')
|
63
|
-
refute is_active_link?('/root', :exclusive)
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_is_active_link_symbol_exclusive_with_link_params
|
67
|
-
set_path('/root?param=test')
|
68
|
-
assert is_active_link?('/root?attr=example', :exclusive)
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_is_active_link_symbol_exact
|
72
|
-
set_path('/root?param=test')
|
73
|
-
assert is_active_link?('/root?param=test', :exact)
|
74
|
-
|
75
|
-
set_path('/root?param=test')
|
76
|
-
refute is_active_link?('/root?param=exact', :exact)
|
77
|
-
|
78
|
-
set_path('/root')
|
79
|
-
refute is_active_link?('/root?param=test', :exact)
|
80
|
-
|
81
|
-
set_path('/root?param=test')
|
82
|
-
refute is_active_link?('/root', :exact)
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_is_active_link_regex
|
86
|
-
set_path('/root')
|
87
|
-
assert is_active_link?('/', /^\/root/)
|
88
|
-
|
89
|
-
set_path('/root/child')
|
90
|
-
assert is_active_link?('/', /^\/r/)
|
91
|
-
|
92
|
-
set_path('/other')
|
93
|
-
refute is_active_link?('/', /^\/r/)
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_is_active_link_array
|
97
|
-
params[:controller], params[:action] = 'controller', 'action'
|
98
|
-
|
99
|
-
assert is_active_link?('/', [['controller'], ['action']])
|
100
|
-
assert is_active_link?('/', [['controller'], ['action', 'action_b']])
|
101
|
-
assert is_active_link?('/', [['controller', 'controller_b'], ['action']])
|
102
|
-
assert is_active_link?('/', [['controller', 'controller_b'], ['action', 'action_b']])
|
103
|
-
assert is_active_link?('/', ['controller', 'action'])
|
104
|
-
assert is_active_link?('/', ['controller', ['action', 'action_b']])
|
105
|
-
assert is_active_link?('/', [['controller', 'controller_b'], 'action'])
|
106
|
-
|
107
|
-
refute is_active_link?('/', ['controller_a', 'action'])
|
108
|
-
refute is_active_link?('/', ['controller', 'action_a'])
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_is_active_link_array_with_hash
|
112
|
-
params[:controller], params[:action] = 'controller', 'action'
|
113
|
-
|
114
|
-
assert is_active_link?('/', [controller: :action])
|
115
|
-
assert is_active_link?('/', ['controller' => 'action'])
|
116
|
-
|
117
|
-
refute is_active_link?('/', [controller_b: :action])
|
118
|
-
refute is_active_link?('/', [controller: :action_b])
|
119
|
-
refute is_active_link?('/', [controller_b: :action_b])
|
120
|
-
|
121
|
-
params[:controller], params[:action] = 'controller_b', 'action_b'
|
122
|
-
|
123
|
-
assert is_active_link?('/', [controller: :action, controller_b: :action_b])
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_is_active_link_hash
|
127
|
-
params[:a] = 1
|
128
|
-
|
129
|
-
assert is_active_link?('/', {a: 1})
|
130
|
-
assert is_active_link?('/', {a: 1, b: nil})
|
131
|
-
|
132
|
-
refute is_active_link?('/', {a: 1, b: 2})
|
133
|
-
refute is_active_link?('/', {a: 2})
|
134
|
-
|
135
|
-
params[:b] = 2
|
136
|
-
|
137
|
-
assert is_active_link?('/', {a: 1, b: 2})
|
138
|
-
assert is_active_link?('/', {a: 1, b: 2, c: nil})
|
139
|
-
|
140
|
-
assert is_active_link?('/', {a: 1})
|
141
|
-
assert is_active_link?('/', {b: 2})
|
142
|
-
end
|
143
|
-
|
144
|
-
def test_is_active_link_with_anchor
|
145
|
-
set_path('/foo')
|
146
|
-
assert is_active_link?('/foo#anchor', :exclusive)
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_is_active_link_with_memoization
|
150
|
-
set_path('/')
|
151
|
-
assert is_active_link?('/', :exclusive)
|
152
|
-
|
153
|
-
set_path('/other', false)
|
154
|
-
assert is_active_link?('/', :exclusive)
|
155
|
-
end
|
156
|
-
|
157
|
-
def test_active_link_to_class
|
158
|
-
set_path('/root')
|
159
|
-
assert_equal 'active', active_link_to_class('/root')
|
160
|
-
assert_equal 'on', active_link_to_class('/root', class_active: 'on')
|
161
|
-
|
162
|
-
assert_equal '', active_link_to_class('/other')
|
163
|
-
assert_equal 'off', active_link_to_class('/other', class_inactive: 'off')
|
164
|
-
end
|
165
|
-
|
166
|
-
def test_active_link_to
|
167
|
-
set_path('/root')
|
168
|
-
link = simple_active_link_to('label', '/root')
|
169
|
-
assert_html link, 'a.active[href="/root"]', 'label'
|
170
|
-
|
171
|
-
link = simple_active_link_to('label', '/other')
|
172
|
-
assert_html link, 'a[href="/other"]', 'label'
|
173
|
-
end
|
174
|
-
|
175
|
-
def test_active_link_to_with_existing_class
|
176
|
-
set_path('/root')
|
177
|
-
link = simple_active_link_to('label', '/root', class: 'current')
|
178
|
-
assert_html link, 'a.current.active[href="/root"]', 'label'
|
179
|
-
|
180
|
-
link = simple_active_link_to('label', '/other', class: 'current')
|
181
|
-
assert_html link, 'a.current[href="/other"]', 'label'
|
182
|
-
end
|
183
|
-
|
184
|
-
def test_active_link_to_with_custom_classes
|
185
|
-
set_path('/root')
|
186
|
-
link = simple_active_link_to('label', '/root', class_active: 'on')
|
187
|
-
assert_html link, 'a.on[href="/root"]', 'label'
|
188
|
-
|
189
|
-
link = simple_active_link_to('label', '/other', class_inactive: 'off')
|
190
|
-
assert_html link, 'a.off[href="/other"]', 'label'
|
191
|
-
end
|
192
|
-
|
193
|
-
def test_active_link_to_with_active_disable_as_true
|
194
|
-
set_path('/root')
|
195
|
-
link = simple_active_link_to('label', '/root', active_disable: true)
|
196
|
-
assert_html link, 'span.active', 'label'
|
197
|
-
end
|
198
|
-
|
199
|
-
def test_active_link_to_with_active_disable_as_hash
|
200
|
-
set_path('/root')
|
201
|
-
link = simple_active_link_to('label', '/root', active_disable: :hash)
|
202
|
-
assert_html link, 'a.active[href="/root#"]', 'label'
|
203
|
-
end
|
204
|
-
|
205
|
-
def test_should_not_modify_passed_params
|
206
|
-
set_path('/root')
|
207
|
-
params = {class: 'testing', active: :inclusive}
|
208
|
-
out = simple_active_link_to 'label', '/root', params
|
209
|
-
assert_html out, 'a.testing.active[href="/root"]', 'label'
|
210
|
-
assert_equal ({class: 'testing', active: :inclusive }), params
|
211
|
-
end
|
212
|
-
|
213
|
-
def test_active_link_to_with_aria
|
214
|
-
set_path('/root')
|
215
|
-
link = simple_active_link_to('label', '/root')
|
216
|
-
assert_html link, 'a.active[href="/root"][aria-current="page"]', 'label'
|
217
|
-
end
|
218
|
-
|
219
|
-
def test_active_link_to_with_utf8
|
220
|
-
set_path('/äöü')
|
221
|
-
link = simple_active_link_to('label', '/äöü')
|
222
|
-
assert_html link, 'a.active[href="/äöü"]', 'label'
|
223
|
-
end
|
224
|
-
|
225
|
-
def test_active_link_to_with_block
|
226
|
-
set_path('/root')
|
227
|
-
link = simple_active_link_to('/root') { 'label' }
|
228
|
-
assert_html link, 'a.active[href="/root"]', 'label'
|
229
|
-
end
|
230
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'minitest/autorun'
|
5
|
-
require 'uri'
|
6
|
-
require 'action_view'
|
7
|
-
require 'simple_active_link_to'
|
8
|
-
|
9
|
-
class MiniTest::Test
|
10
|
-
# need this to simulate requests that drive active_link_helper
|
11
|
-
module FakeRequest
|
12
|
-
class Request
|
13
|
-
attr_accessor :original_fullpath
|
14
|
-
|
15
|
-
def path
|
16
|
-
return original_fullpath unless original_fullpath&.include?('?')
|
17
|
-
|
18
|
-
@path ||= original_fullpath.split('?').first
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def request
|
23
|
-
@request ||= Request.new
|
24
|
-
end
|
25
|
-
|
26
|
-
def params
|
27
|
-
@params ||= {}
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
module FakeCapture
|
32
|
-
def capture
|
33
|
-
yield
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
SimpleActiveLinkTo.include FakeRequest
|
38
|
-
SimpleActiveLinkTo.include FakeCapture
|
39
|
-
|
40
|
-
include ActionView::Helpers::UrlHelper
|
41
|
-
include ActionView::Helpers::TagHelper
|
42
|
-
include SimpleActiveLinkTo
|
43
|
-
|
44
|
-
def set_path(path, purge_cache = true)
|
45
|
-
request.original_fullpath = path
|
46
|
-
remove_instance_variable(:@is_active_link) if purge_cache && defined?(@is_active_link)
|
47
|
-
end
|
48
|
-
|
49
|
-
def assert_html(html, selector, value = nil)
|
50
|
-
doc = Nokogiri::HTML(html)
|
51
|
-
element = doc.at_css(selector)
|
52
|
-
assert element, "No element found at: `#{selector}`"
|
53
|
-
assert_equal value, element.text if value
|
54
|
-
end
|
55
|
-
end
|