require 'spec_helper' describe 'routing' do context 'default' do describe 'pages' do it "routes '/pages/:id' to 'rails_pages/pages#show'" do expect(:get => '/pages/page').to route_to( :controller => 'rails_pages/pages', :action => 'show', :id => 'page' ) end it 'generates page_path helper' do expect(page_path 'page').to eq('/pages/page') end end describe 'nested pages' do it "routes '/pages/nested/:id' to 'rails_pages/pages#show'" do expect(:get => '/pages/nested/page').to route_to( :controller => 'rails_pages/pages', :action => 'show', :id => 'nested/page' ) end it 'generates page_path helper' do expect(page_path 'nested/page').to eq('/pages/nested/page') end end end context 'root' do before do Rails.application.routes.draw do get '/:id' => 'rails_pages/pages#show', :as => :page, :format => false, :constraints => { :id => /.+?/ } end end describe 'pages' do it "routes '/:id' to 'rails_pages/pages#show'" do expect(:get => '/page').to route_to( :controller => 'rails_pages/pages', :action => 'show', :id => 'page' ) end it 'generates page_path helper' do expect(page_path 'page').to eq('/page') end end describe 'nested pages' do it "routes '/nested/:id' to 'rails_pages/pages#show'" do expect(:get => '/nested/page').to route_to( :controller => 'rails_pages/pages', :action => 'show', :id => 'nested/page' ) end it 'generates page_path helper' do expect(page_path 'nested/page').to eq('/nested/page') end end after do Rails.application.reload_routes! end end context 'disabled' do before do RailsPages.configure { |c| c.default_routes = false } end describe 'pages' do it "does not route '/:id'" do expect(:get => '/page').not_to be_routable end end describe 'nested pages' do it "does not route '/nested/:id'" do expect(:get => '/nested/page').not_to be_routable end end end end