spec/controllers/application_controller_spec.rb in breadcrumble-3.0.2 vs spec/controllers/application_controller_spec.rb in breadcrumble-3.0.3

- old
+ new

@@ -2,66 +2,91 @@ describe ApplicationController do controller do add_breadcrumbs ['root', '/'], ['nil', nil] add_breadcrumb -> c { c.examples_url }, -> c { c.examples_path } + add_breadcrumb_to -> c { c.examples_url }, -> c { c.examples_path }, 1 + add_breadcrumb_to 'multi third 1', 'multi third url 1', 2 def index add_breadcrumb 'examples', controller: 'examples', action: 'index', only_path: true add_breadcrumb 'example', example_path(123) add_breadcrumbs ['crumb1'], ['crumb2', -> c { example_path(1234) }] render text: 'test' end + + def show + add_breadcrumb_to 'examples', {controller: 'examples', action: 'index', only_path: true}, 1 + add_breadcrumb_to 'example', example_path(123), 1 + add_breadcrumb_to 'multi third 2', 'multi third url 2', 2 + add_breadcrumb_to 'multi third 3', 'multi third url 3', 2 + render text: 'test' + end end describe '#index' do subject do get :index end context '.add_breadcrumbs' do it 'having breadcrumbs' do should be_success - assigns(:breadcrumbs)[0][:name].should eq('root') - assigns(:breadcrumbs)[0][:url].should eq('/') + assigns(:breadcrumb_trails)[0][0].should eq({name: 'root', url: '/'}) end it 'url has nil value' do should be_success - assigns(:breadcrumbs)[1][:name].should eq('nil') - assigns(:breadcrumbs)[1][:url].should be_nil + assigns(:breadcrumb_trails)[0][1].should eq({name: 'nil', url: nil}) end end context '.add_breadcrumb' do it 'execute lambda in controller instance context' do should be_success - assigns(:breadcrumbs)[2][:name].should eq('http://test.host/examples') - assigns(:breadcrumbs)[2][:url].should eq('/examples') + assigns(:breadcrumb_trails)[0][2].should eq({name: 'http://test.host/examples', url: '/examples'}) end end context '#add_breadcrumb' do it 'url options' do should be_success - assigns(:breadcrumbs)[3][:name].should eq('examples') - assigns(:breadcrumbs)[3][:url].should eq('/examples') + assigns(:breadcrumb_trails)[0][3].should eq({name: 'examples', url: '/examples'}) end it 'example_path' do should be_success - assigns(:breadcrumbs)[4][:name].should eq('example') - assigns(:breadcrumbs)[4][:url].should eq('/examples/123') + assigns(:breadcrumb_trails)[0][4].should eq({name: 'example', url: '/examples/123'}) end end context '#add_breadcrumbs' do it 'sequence is starting from first argument' do should be_success - assigns(:breadcrumbs)[5][:name].should eq('crumb1') - assigns(:breadcrumbs)[5][:url].should be_nil - assigns(:breadcrumbs)[6][:name].should eq('crumb2') - assigns(:breadcrumbs)[6][:url].should eq('/examples/1234') + assigns(:breadcrumb_trails)[0][5].should eq({name: 'crumb1', url: nil}) + assigns(:breadcrumb_trails)[0][6].should eq({name: 'crumb2', url: '/examples/1234'}) + end + end + end + + describe '#show' do + subject do + get :show, id: 1 + end + + context 'multiple breadcrumbs' do + it 'having breadcrumbs in second trail' do + should be_success + assigns(:breadcrumb_trails)[1][0].should eq({name: 'http://test.host/examples', url: '/examples'}) + assigns(:breadcrumb_trails)[1][1].should eq({name: 'examples', url: '/examples'}) + assigns(:breadcrumb_trails)[1][2].should eq({name: 'example', url: '/examples/123'}) + end + + it 'having breadcrumbs in third trail' do + should be_success + assigns(:breadcrumb_trails)[2][0].should eq({name: 'multi third 1', url: 'multi third url 1'}) + assigns(:breadcrumb_trails)[2][1].should eq({name: 'multi third 2', url: 'multi third url 2'}) + assigns(:breadcrumb_trails)[2][2].should eq({name: 'multi third 3', url: 'multi third url 3'}) end end end end