debian-mirror-gitlab/spec/helpers/tab_helper_spec.rb

85 lines
3 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
require 'spec_helper'
describe TabHelper do
include ApplicationHelper
describe 'nav_link' do
before do
2015-04-26 12:48:37 +05:30
allow(controller).to receive(:controller_name).and_return('foo')
2014-09-02 18:07:02 +05:30
allow(self).to receive(:action_name).and_return('foo')
end
2018-12-05 23:21:45 +05:30
context 'with the content of the li' do
it "captures block output" do
expect(nav_link { "Testing Blocks" }).to match(/Testing Blocks/)
end
2014-09-02 18:07:02 +05:30
end
2018-12-05 23:21:45 +05:30
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
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
context 'with namespace in path notation' do
before do
allow(controller).to receive(:controller_path).and_return('bar/foo')
end
2014-09-02 18:07:02 +05:30
2018-12-05 23:21:45 +05:30
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
end
end
2014-09-02 18:07:02 +05:30
end
2018-12-05 23:21:45 +05:30
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/)
end
2014-09-02 18:07:02 +05:30
end
2018-12-05 23:21:45 +05:30
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/)
end
context 'with namespace' do
before do
allow(controller).to receive(:controller_path).and_return('bar/foo')
end
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/)
end
end
2014-09-02 18:07:02 +05:30
end
it "passes extra html options to the list element" do
2015-09-11 14:41:01 +05:30
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">/)
2014-09-02 18:07:02 +05:30
end
end
end