Permalink
Browse files

matching verb arrays

  • Loading branch information...
1 parent 6963cb3 commit 61b27270e6952c5ed5ff1513f1245eab741a5bd0 @endor endor committed May 25, 2011
Showing with 15 additions and 3 deletions.
  1. +6 −2 examples/backend/public/javascripts/sammy.js
  2. +5 −1 lib/sammy.js
  3. +4 −0 test/test_sammy_application.js
View
8 examples/backend/public/javascripts/sammy.js
@@ -1026,15 +1026,19 @@
}
var path_matched = true, verb_matched = true;
if (options.path) {
- // wierd regexp test
+ // weird regexp test
if ($.isFunction(options.path.test)) {
path_matched = options.path.test(context.path);
} else {
path_matched = (options.path.toString() === context.path);
}
}
if (options.verb) {
- verb_matched = options.verb === context.verb;
+ if(typeof options.verb === 'string') {
+ verb_matched = options.verb === context.verb;
+ } else {
+ verb_matched = options.verb.indexOf(context.verb) > -1;
+ }
}
return positive ? (verb_matched && path_matched) : !(verb_matched && path_matched);
},
View
6 lib/sammy.js
@@ -1102,7 +1102,11 @@
path_matched = options.path.test(context.path);
}
if (options.verb) {
- verb_matched = options.verb === context.verb;
+ if(typeof options.verb === 'string') {
+ verb_matched = options.verb === context.verb;
+ } else {
+ verb_matched = options.verb.indexOf(context.verb) > -1;
+ }
}
return positive ? (verb_matched && path_matched) : !(verb_matched && path_matched);
},
View
4 test/test_sammy_application.js
@@ -956,6 +956,10 @@
ok(this.app.contextMatchesOptions(this.route, {only: {verb: 'get'}}));
ok(!this.app.contextMatchesOptions(this.route, {only: {verb: 'put'}}));
})
+ .should('match against only with verb array', function() {
+ ok(this.app.contextMatchesOptions(this.route, {only: {verb: ['get', 'post']}}));
+ ok(!this.app.contextMatchesOptions(this.route, {only: {verb: ['put', 'post']}}));
+ })
.should('match against except with path and verb', function() {
ok(this.app.contextMatchesOptions(this.route, {except: {path: '#/', verb: 'get'}}));
ok(!this.app.contextMatchesOptions(this.route, {except: {path: '#/boosh', verb: 'get'}}));

0 comments on commit 61b2727

Please sign in to comment.