2019-09-30 08:06:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2012-09-26 16:13:23 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe TabHelper do
|
2012-09-26 16:13:23 -04:00
|
|
|
include ApplicationHelper
|
|
|
|
|
|
|
|
describe 'nav_link' do
|
2021-04-01 14:13:56 -04:00
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
2012-09-26 16:13:23 -04:00
|
|
|
before do
|
2015-02-12 13:17:35 -05:00
|
|
|
allow(controller).to receive(:controller_name).and_return('foo')
|
2013-12-14 08:43:48 -05:00
|
|
|
allow(self).to receive(:action_name).and_return('foo')
|
2012-09-26 16:13:23 -04:00
|
|
|
end
|
|
|
|
|
2018-09-18 12:12:37 -04:00
|
|
|
context 'with the content of the li' do
|
2021-04-01 14:13:56 -04:00
|
|
|
it 'captures block output' do
|
2018-09-18 12:12:37 -04:00
|
|
|
expect(nav_link { "Testing Blocks" }).to match(/Testing Blocks/)
|
|
|
|
end
|
2012-09-26 16:13:23 -04:00
|
|
|
end
|
|
|
|
|
2021-04-01 14:13:56 -04:00
|
|
|
it 'passes extra html options to the list element' do
|
|
|
|
expect(nav_link(action: :foo, html_options: { class: 'home' })).to match(/<li class="home active">/)
|
|
|
|
expect(nav_link(html_options: { class: 'active' })).to match(/<li class="active">/)
|
|
|
|
end
|
2018-09-18 12:12:37 -04:00
|
|
|
|
2021-04-01 14:13:56 -04:00
|
|
|
where(:controller_param, :action_param, :path_param, :active) do
|
|
|
|
nil | nil | nil | false
|
|
|
|
:foo | nil | nil | true
|
|
|
|
:bar | nil | nil | false
|
|
|
|
:bar | :foo | nil | false
|
|
|
|
:foo | :bar | nil | false
|
|
|
|
:foo | :foo | nil | true
|
|
|
|
:bar | nil | 'foo#foo' | true
|
|
|
|
:bar | nil | ['foo#foo', 'bar#bar'] | true
|
|
|
|
:bar | :bar | ['foo#foo', 'bar#bar'] | true
|
|
|
|
:foo | nil | 'bar#foo' | true
|
|
|
|
:bar | nil | 'bar#foo' | false
|
|
|
|
:foo | [:foo, :bar] | 'bar#foo' | true
|
|
|
|
:bar | :bar | 'foo#foo' | true
|
|
|
|
:foo | :foo | 'bar#foo' | true
|
|
|
|
:bar | :foo | 'bar#foo' | false
|
|
|
|
:foo | :bar | 'bar#foo' | false
|
|
|
|
[:foo, :bar] | nil | nil | true
|
|
|
|
[:foo, :bar] | nil | 'bar#foo' | true
|
|
|
|
[:foo, :bar] | :foo | 'bar#foo' | true
|
|
|
|
nil | :foo | nil | true
|
|
|
|
nil | :bar | nil | false
|
|
|
|
nil | nil | 'foo#bar' | false
|
|
|
|
nil | nil | 'foo#foo' | true
|
|
|
|
nil | :bar | ['foo#foo', 'bar#bar'] | true
|
|
|
|
nil | :bar | 'foo#foo' | true
|
|
|
|
nil | :foo | 'bar#foo' | true
|
|
|
|
nil | [:foo, :bar] | nil | true
|
|
|
|
nil | [:foo, :bar] | 'bar#foo' | true
|
|
|
|
nil | :bar | 'bar#foo' | false
|
|
|
|
end
|
2018-09-18 12:12:37 -04:00
|
|
|
|
2021-04-01 14:13:56 -04:00
|
|
|
with_them do
|
|
|
|
specify do
|
|
|
|
result = nav_link(controller: controller_param, action: action_param, path: path_param)
|
2012-09-26 16:13:23 -04:00
|
|
|
|
2021-04-01 14:13:56 -04:00
|
|
|
if active
|
|
|
|
expect(result).to match(/active/)
|
|
|
|
else
|
|
|
|
expect(result).not_to match(/active/)
|
2018-09-18 12:12:37 -04:00
|
|
|
end
|
|
|
|
end
|
2012-09-26 16:13:23 -04:00
|
|
|
end
|
|
|
|
|
2021-04-01 14:13:56 -04:00
|
|
|
context 'with namespace in path notation' do
|
|
|
|
before do
|
|
|
|
allow(controller).to receive(:controller_path).and_return('bar/foo')
|
2018-09-18 12:12:37 -04:00
|
|
|
end
|
2012-09-26 16:13:23 -04:00
|
|
|
|
2021-04-01 14:13:56 -04:00
|
|
|
where(:controller_param, :action_param, :path_param, :active) do
|
|
|
|
'foo/foo' | nil | nil | false
|
|
|
|
'bar/foo' | nil | nil | true
|
|
|
|
'foo/foo' | :foo | nil | false
|
|
|
|
'bar/foo' | :bar | nil | false
|
|
|
|
'bar/foo' | :foo | nil | true
|
|
|
|
nil | nil | 'foo/foo#foo' | false
|
|
|
|
nil | nil | 'bar/foo#foo' | true
|
2018-09-18 12:12:37 -04:00
|
|
|
end
|
|
|
|
|
2021-04-01 14:13:56 -04:00
|
|
|
with_them do
|
|
|
|
specify do
|
|
|
|
result = nav_link(controller: controller_param, action: action_param, path: path_param)
|
2018-09-18 12:12:37 -04:00
|
|
|
|
2021-04-01 14:13:56 -04:00
|
|
|
if active
|
|
|
|
expect(result).to match(/active/)
|
|
|
|
else
|
|
|
|
expect(result).not_to match(/active/)
|
|
|
|
end
|
2018-09-18 12:12:37 -04:00
|
|
|
end
|
|
|
|
end
|
2012-09-26 16:13:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|