Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/helpers/tab_helper_spec.rb')
-rw-r--r--spec/helpers/tab_helper_spec.rb115
1 files changed, 64 insertions, 51 deletions
diff --git a/spec/helpers/tab_helper_spec.rb b/spec/helpers/tab_helper_spec.rb
index f89d0ac0f5a..bd8a8fa174a 100644
--- a/spec/helpers/tab_helper_spec.rb
+++ b/spec/helpers/tab_helper_spec.rb
@@ -6,81 +6,94 @@ RSpec.describe TabHelper do
include ApplicationHelper
describe 'nav_link' do
+ using RSpec::Parameterized::TableSyntax
+
before do
allow(controller).to receive(:controller_name).and_return('foo')
allow(self).to receive(:action_name).and_return('foo')
end
context 'with the content of the li' do
- it "captures block output" do
+ it 'captures block output' do
expect(nav_link { "Testing Blocks" }).to match(/Testing Blocks/)
end
end
- context 'with controller param' do
- it "performs checks on the current controller" do
- expect(nav_link(controller: :foo)).to match(/<li class="active">/)
- expect(nav_link(controller: :bar)).not_to match(/active/)
- expect(nav_link(controller: [:foo, :bar])).to match(/active/)
- end
+ 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
- context 'with action param' do
- it "performs checks on both controller and action when both are present" do
- expect(nav_link(controller: :bar, action: :foo)).not_to match(/active/)
- expect(nav_link(controller: :foo, action: :bar)).not_to match(/active/)
- expect(nav_link(controller: :foo, action: :foo)).to match(/active/)
- end
- end
+ 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
- context 'with namespace in path notation' do
- before do
- allow(controller).to receive(:controller_path).and_return('bar/foo')
- end
+ with_them do
+ specify do
+ result = nav_link(controller: controller_param, action: action_param, path: path_param)
- it 'performs checks on both controller and namespace' do
- expect(nav_link(controller: 'foo/foo')).not_to match(/active/)
- expect(nav_link(controller: 'bar/foo')).to match(/active/)
- end
-
- context 'with action param' do
- it "performs checks on both namespace, controller and action when they are all present" do
- expect(nav_link(controller: 'foo/foo', action: :foo)).not_to match(/active/)
- expect(nav_link(controller: 'bar/foo', action: :bar)).not_to match(/active/)
- expect(nav_link(controller: 'bar/foo', action: :foo)).to match(/active/)
- end
+ if active
+ expect(result).to match(/active/)
+ else
+ expect(result).not_to match(/active/)
end
end
end
- context 'with action param' do
- it "performs checks on the current action" do
- expect(nav_link(action: :foo)).to match(/<li class="active">/)
- expect(nav_link(action: :bar)).not_to match(/active/)
- expect(nav_link(action: [:foo, :bar])).to match(/active/)
+ context 'with namespace in path notation' do
+ before do
+ allow(controller).to receive(:controller_path).and_return('bar/foo')
end
- end
- context 'with path param' do
- it "accepts a path shorthand" do
- expect(nav_link(path: 'foo#bar')).not_to match(/active/)
- expect(nav_link(path: 'foo#foo')).to match(/active/)
+ 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
end
- context 'with namespace' do
- before do
- allow(controller).to receive(:controller_path).and_return('bar/foo')
- end
+ with_them do
+ specify do
+ result = nav_link(controller: controller_param, action: action_param, path: path_param)
- it 'accepts a path shorthand with namespace' do
- expect(nav_link(path: 'bar/foo#foo')).to match(/active/)
- expect(nav_link(path: 'foo/foo#foo')).not_to match(/active/)
+ if active
+ expect(result).to match(/active/)
+ else
+ expect(result).not_to match(/active/)
+ end
end
end
end
-
- 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
end
end