mirror of
https://github.com/kbparagua/paloma
synced 2023-03-27 23:21:17 -04:00
Jasmine spec for Router
This commit is contained in:
parent
e00b1dffa7
commit
efbba9d6b3
3 changed files with 144 additions and 54 deletions
|
@ -1,59 +1,6 @@
|
||||||
TestApp::Application.routes.draw do
|
TestApp::Application.routes.draw do
|
||||||
|
|
||||||
# The priority is based upon order of creation:
|
mount JasmineRails::Engine => "/specs" if defined?(JasmineRails)
|
||||||
# first created -> highest priority.
|
|
||||||
|
|
||||||
# Sample of regular route:
|
|
||||||
# match 'products/:id' => 'catalog#view'
|
|
||||||
# Keep in mind you can assign values other than :controller and :action
|
|
||||||
|
|
||||||
# Sample of named route:
|
|
||||||
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
|
|
||||||
# This route can be invoked with purchase_url(:id => product.id)
|
|
||||||
|
|
||||||
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
|
||||||
# resources :products
|
|
||||||
|
|
||||||
# Sample resource route with options:
|
|
||||||
# resources :products do
|
|
||||||
# member do
|
|
||||||
# get 'short'
|
|
||||||
# post 'toggle'
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
# collection do
|
|
||||||
# get 'sold'
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
|
|
||||||
# Sample resource route with sub-resources:
|
|
||||||
# resources :products do
|
|
||||||
# resources :comments, :sales
|
|
||||||
# resource :seller
|
|
||||||
# end
|
|
||||||
|
|
||||||
# Sample resource route with more complex sub-resources
|
|
||||||
# resources :products do
|
|
||||||
# resources :comments
|
|
||||||
# resources :sales do
|
|
||||||
# get 'recent', :on => :collection
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
|
|
||||||
# Sample resource route within a namespace:
|
|
||||||
# namespace :admin do
|
|
||||||
# # Directs /admin/products/* to Admin::ProductsController
|
|
||||||
# # (app/controllers/admin/products_controller.rb)
|
|
||||||
# resources :products
|
|
||||||
# end
|
|
||||||
|
|
||||||
# You can have the root of your site routed with "root"
|
|
||||||
# just remember to delete public/index.html.
|
|
||||||
root :to => 'main#index'
|
root :to => 'main#index'
|
||||||
|
|
||||||
# See how all your routes lay out with "rake routes"
|
|
||||||
|
|
||||||
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
|
||||||
# Note: This route will make all actions in every controller accessible via GET requests.
|
|
||||||
# match ':controller(/:action(/:id))(.:format)'
|
|
||||||
end
|
end
|
||||||
|
|
123
test_app/spec/javascripts/router_spec.js
Normal file
123
test_app/spec/javascripts/router_spec.js
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
|
||||||
|
describe('Paloma.Router', function(){
|
||||||
|
var delimiter = {namespace: '/', action: '#'},
|
||||||
|
router = new Paloma.Router(delimiter);
|
||||||
|
|
||||||
|
describe('#parse(path)', function(){
|
||||||
|
|
||||||
|
describe('when path has a namespace', function(){
|
||||||
|
var result;
|
||||||
|
|
||||||
|
beforeEach(function(){
|
||||||
|
result = router.parse('Foo/Bar/Baz/Controller#action');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the array of the namespaces', function(){
|
||||||
|
expect(result.namespaces).toEqual(['Foo', 'Bar', 'Baz']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the controller', function(){
|
||||||
|
expect(result.controller).toEqual('Controller');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the action', function(){
|
||||||
|
expect(result.action).toEqual('action');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the controllerPath', function(){
|
||||||
|
expect(result.controllerPath).toEqual(['Foo', 'Bar', 'Baz', 'Controller']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
describe('when path has no namespace', function(){
|
||||||
|
var result;
|
||||||
|
|
||||||
|
beforeEach(function(){
|
||||||
|
result = router.parse('Controller#action');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns an empty array of namespaces', function(){
|
||||||
|
expect(result.namespaces).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the controller', function(){
|
||||||
|
expect(result.controller).toEqual('Controller');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the action', function(){
|
||||||
|
expect(result.action).toEqual('action');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the controllerPath', function(){
|
||||||
|
expect(result.controllerPath).toEqual(['Controller']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
describe('#controllerFor(resource)', function(){
|
||||||
|
|
||||||
|
var resource = 'MySuperResource';
|
||||||
|
|
||||||
|
describe('when no route is found', function(){
|
||||||
|
it('returns the resource', function(){
|
||||||
|
var controller = router.controllerFor(resource);
|
||||||
|
expect(controller).toEqual(resource);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe('when route is found', function(){
|
||||||
|
it('returns the set controller', function(){
|
||||||
|
router.resource(resource, {controller: 'MyController'});
|
||||||
|
|
||||||
|
var controller = router.controllerFor(resource);
|
||||||
|
expect(controller).toEqual('MyController');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
describe('#redirectFor(resource, action)', function(){
|
||||||
|
var router = new Paloma.Router(delimiter),
|
||||||
|
result;
|
||||||
|
|
||||||
|
describe('when has a redirect', function(){
|
||||||
|
beforeEach(function(){
|
||||||
|
router.redirect('Foo#edit', {to: 'Bar#revise'});
|
||||||
|
result = router.redirectFor('Foo', 'edit');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns controller of the redirect', function(){
|
||||||
|
expect(result.controller).toEqual('Bar');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns action of the redirect', function(){
|
||||||
|
expect(result.action).toEqual('revise');
|
||||||
|
});
|
||||||
|
|
||||||
|
router.reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe('when has no redirect', function(){
|
||||||
|
var router = new Paloma.Router(delimiter),
|
||||||
|
result = router.redirectFor('Foo', 'edit');
|
||||||
|
|
||||||
|
it('returns null', function(){
|
||||||
|
expect(result).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
20
test_app/spec/javascripts/support/jasmine.yml
Normal file
20
test_app/spec/javascripts/support/jasmine.yml
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# path to parent directory of src_files
|
||||||
|
# relative path from Rails.root
|
||||||
|
# defaults to app/assets/javascripts
|
||||||
|
src_dir: "app/assets/javascripts"
|
||||||
|
# list of file expressions to include as source files
|
||||||
|
# relative path from scr_dir
|
||||||
|
src_files:
|
||||||
|
- "application.{js,coffee}"
|
||||||
|
# path to parent directory of spec_files
|
||||||
|
# relative path from Rails.root
|
||||||
|
# defaults to spec/javascripts
|
||||||
|
spec_dir: spec/javascripts
|
||||||
|
# list of file expressions to include as helpers into spec runner
|
||||||
|
# relative path from spec_dir
|
||||||
|
helpers:
|
||||||
|
- "helpers/**/*.{js,coffee}"
|
||||||
|
# list of file expressions to include as specs into spec runner
|
||||||
|
# relative path from spec_dir
|
||||||
|
spec_files:
|
||||||
|
- "**/*[Ss]pec.{js,coffee}"
|
Loading…
Reference in a new issue