Skip to content

Commit

Permalink
Added a test for alias compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
fabn committed Oct 12, 2015
1 parent b5bbecd commit 213ef14
Showing 1 changed file with 41 additions and 16 deletions.
57 changes: 41 additions & 16 deletions spec/lib/breadcrumbs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,54 @@ def test_models_path
end
end

before do
options = { :scope => [:breadcrumbs, 'test'] }
[:class_i18n, :instance_i18n, :show, :symbolized].each do |name|
I18n.expects(:t).with(name, options).returns(name.to_s)
describe 'Breadcrumbs generation' do

before do
options = { :scope => [:breadcrumbs, 'test'] }
[:class_i18n, :instance_i18n, :show, :symbolized].each do |name|
I18n.expects(:t).with(name, options).returns(name.to_s)
end

name = :base_i18n
options = { :scope => [:breadcrumbs, 'base_test'] }
I18n.expects(:t).with(name, options).returns(name)

@controller = TestController.new
@controller.process(:show)
end

name = :base_i18n
options = { :scope => [:breadcrumbs, 'base_test'] }
I18n.expects(:t).with(name, options).returns(name)
it "have breadcrumbs" do
[:base, :base_i18n, :class, :class_i18n, :instance, :instance_i18n, :test_model, :symbolized].each do |name|
path = "/#{name}"
idx = @controller.breadcrumbs.index { |b| b[:name] == name.to_s && b[:url] == path }
expect(idx).to be, -> { name }
end

@controller = TestController.new
@controller.process(:show)
idx = @controller.breadcrumbs.index { |b| b[:name] == "show" && b[:url] == '' }
expect(idx).to be
end
end

it "have breadcrumbs" do
[:base, :base_i18n, :class, :class_i18n, :instance, :instance_i18n, :test_model, :symbolized].each do |name|
path = "/#{name}"
idx = @controller.breadcrumbs.index { |b| b[:name] == name.to_s && b[:url] == path }
expect(idx).to be, -> { name }
describe 'BreadcrumbsOnRails compatibility' do
class SomeController < AbstractController::Base
end
let(:logger) { double('logger').as_null_object }
before { allow(::Rails).to receive(:logger).and_return(logger) }

context 'when BreadcrumbsOnRails is defined' do
before do
stub_const('BreadcrumbsOnRails', 1)
expect(defined?(::BreadcrumbsOnRails)).to be_truthy
expect(logger).to receive(:info).with /BreadcrumbsOnRails detected/
SomeController.send(:include, Twitter::Bootstrap::Breadcrumbs)
end

it 'does not define aliases' do
expect(SomeController).to respond_to :add_bootstrap_breadcrumb
expect(SomeController).not_to respond_to :add_breadcrumb
end
end

idx = @controller.breadcrumbs.index { |b| b[:name] == "show" && b[:url] == '' }
expect(idx).to be
end

end

0 comments on commit 213ef14

Please sign in to comment.