2012-09-26 16:13:23 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe TabHelper do
|
|
|
|
include ApplicationHelper
|
|
|
|
|
|
|
|
describe 'nav_link' do
|
|
|
|
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
|
|
|
|
|
|
|
|
it "captures block output" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(nav_link { "Testing Blocks" }).to match(/Testing Blocks/)
|
2012-09-26 16:13:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "performs checks on the current controller" do
|
2015-02-12 13:17:35 -05:00
|
|
|
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/)
|
2012-09-26 16:13:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "performs checks on the current action" do
|
2015-02-12 13:17:35 -05:00
|
|
|
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/)
|
2012-09-26 16:13:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "performs checks on both controller and action when both are present" do
|
2015-02-12 13:17:35 -05:00
|
|
|
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/)
|
2012-09-26 16:13:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "accepts a path shorthand" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(nav_link(path: 'foo#bar')).not_to match(/active/)
|
|
|
|
expect(nav_link(path: 'foo#foo')).to match(/active/)
|
2012-09-26 16:13:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "passes extra html options to the list element" do
|
2015-06-22 14:41:00 -04:00
|
|
|
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">/)
|
2012-09-26 16:13:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|