@@ -381,55 +381,31 @@ describe("Rules", function() {
381381 expect ( R . activeRules [ 0 ] . id ) . to . eql ( "one" ) ;
382382 } ) ;
383383 } ) ;
384- describe ( ".toJSON() & .fromJSON " , function ( ) {
384+ describe ( "ignoreFactChanges " , function ( ) {
385385 var rules = [ {
386+ "name" : "rule1" ,
386387 "condition" : function ( R ) {
387- R . when ( 1 ) ;
388+ R . when ( this . value1 > 5 ) ;
388389 } ,
389390 "consequence" : function ( R ) {
390- R . stop ( ) ;
391- } ,
392- "on" : true
391+ this . result = false ;
392+ this . errors = this . errors || [ ] ;
393+ this . errors . push ( 'must be less than 5' ) ;
394+ R . next ( ) ;
395+ }
393396 } ] ;
394- it ( "rules after toJSON and fromJSON back should be equivalent to the old form" , function ( ) {
395- var R1 = new RuleEngine ( rules ) ;
396- var store = R1 . toJSON ( ) ;
397- var R2 = new RuleEngine ( ) ;
398- R2 . fromJSON ( store ) ;
399- expect ( R1 . rules ) . to . eql ( R2 . rules ) ;
400- } ) ;
401- it ( "rules serilisation & back working fine?" , function ( ) {
402- var R = new RuleEngine ( rules ) ;
403- var store = R . toJSON ( ) ;
404- R . fromJSON ( store ) ;
405- expect ( rules ) . to . eql ( R . rules ) ;
406- } ) ;
407- } ) ;
408- describe ( "ignoreFactChanges" , function ( ) {
409- var rules = [ {
410- "name" : "rule1" ,
411- "condition" : function ( R ) {
412- R . when ( this . value1 > 5 ) ;
413- } ,
414- "consequence" : function ( R ) {
415- this . result = false ;
416- this . errors = this . errors || [ ] ;
417- this . errors . push ( 'must be less than 5' ) ;
418- R . next ( ) ;
419- }
420- } ] ;
421397
422- var fact = {
423- "value1" : 6
424- } ;
398+ var fact = {
399+ "value1" : 6
400+ } ;
425401
426- it ( "doesn't rerun when a fact changes if ignoreFactChanges is true" , function ( done ) {
427- var R = new RuleEngine ( rules , { ignoreFactChanges : true } ) ;
402+ it ( "doesn't rerun when a fact changes if ignoreFactChanges is true" , function ( done ) {
403+ var R = new RuleEngine ( rules , { ignoreFactChanges : true } ) ;
428404
429- R . execute ( fact , function ( result ) {
430- expect ( result . errors ) . to . have . length ( 1 ) ;
431- done ( ) ;
405+ R . execute ( fact , function ( result ) {
406+ expect ( result . errors ) . to . have . length ( 1 ) ;
407+ done ( ) ;
408+ } ) ;
432409 } ) ;
433410 } ) ;
434- } ) ;
435411} ) ;
0 commit comments