Skip to content

Commit

Permalink
verified .ready not needed for some transport tests, fixes regression…
Browse files Browse the repository at this point in the history
… from async options load
  • Loading branch information
rjrodger committed Jan 24, 2016
1 parent 5ea1ec7 commit 9303be3
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 58 deletions.
47 changes: 24 additions & 23 deletions seneca.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,38 +524,39 @@ function make_seneca (initial_options) {
}
}

var methods = private$.actrouter.list(pattern)
thispin.ready(function () {
var methods = private$.actrouter.list(pattern)

methods.forEach(function (method) {
var mpat = method.match
methods.forEach(function (method) {
var mpat = method.match

var methodname = ''
for (var mkI = 0; mkI < methodkeys.length; mkI++) {
methodname += ((0 < mkI ? '_' : '')) + mpat[methodkeys[mkI]]
}
var methodname = ''
for (var mkI = 0; mkI < methodkeys.length; mkI++) {
methodname += ((0 < mkI ? '_' : '')) + mpat[methodkeys[mkI]]
}

api[methodname] = function (args, cb) {
var si = this && this.seneca ? this : thispin
api[methodname] = function (args, cb) {
var si = this && this.seneca ? this : thispin

var fullargs = _.extend({}, args, mpat)
si.act(fullargs, cb)
}
var fullargs = _.extend({}, args, mpat)
si.act(fullargs, cb)
}

api[methodname].pattern$ = method.match
api[methodname].name$ = methodname
})
api[methodname].pattern$ = method.match
api[methodname].name$ = methodname
})

if (pinopts) {
if (pinopts.include) {
for (var i = 0; i < pinopts.include.length; i++) {
var methodname = pinopts.include[i]
if (thispin[methodname]) {
api[methodname] = Common.delegate(thispin, thispin[methodname])
if (pinopts) {
if (pinopts.include) {
for (var i = 0; i < pinopts.include.length; i++) {
var methodname = pinopts.include[i]
if (thispin[methodname]) {
api[methodname] = Common.delegate(thispin, thispin[methodname])
}
}
}
}
}

})
return api
}

Expand Down
13 changes: 7 additions & 6 deletions test/plugin/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ var assert = Assert

describe('basic', function () {
it('action.generate_id', function (fin) {
var si = Seneca({log: 'silent'})
si.options({errhandler: fin})
si.ready(function () {
var basic = si.pin({role: 'basic', cmd: '*'})
var si = Seneca({log: 'test'}).error(fin)

// .pin call can happen before ready, but will only be usable after ready
var basic = si.pin({role: 'basic', cmd: '*'})

si.ready(function () {
basic.generate_id({}, function (err, code) {
assert.equal(err, null)
assert.equal(6, code.length)
Expand All @@ -34,7 +35,7 @@ describe('basic', function () {
})

it('ensure_entity', function (fin) {
var si = Seneca({log: 'silent'})
var si = Seneca({log: 'test'})
si.options({errhandler: fin})

var foo_ent = si.make$('util_foo')
Expand Down Expand Up @@ -79,7 +80,7 @@ describe('basic', function () {
})

it('note', function (fin) {
var si = Seneca({log: 'silent'})
var si = Seneca({log: 'test'})
si
.start(fin)
.wait('role:util,note:true,cmd:set,key:foo,value:red')
Expand Down
51 changes: 22 additions & 29 deletions test/transport.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,21 +638,18 @@ describe('transport', function () {

.client({type: 'test', pin: 'foo:1'})

.ready(function () {
this
.add('foo:1', function (args, done) { done(null, {foo: 1, local: 1}) })

.start()
.add('foo:1', function (args, done) { done(null, {foo: 1, local: 1}) })

.wait('foo:1,bar:1')
.step(function (out) {
expect(tt.outmsgs.length).to.equal(0)
expect(out).to.deep.equal({foo: 1, local: 1})
return true
})
.start()

.end(done)
.wait('foo:1,bar:1')
.step(function (out) {
expect(tt.outmsgs.length).to.equal(0)
expect(out).to.deep.equal({foo: 1, local: 1})
return true
})

.end(done)
})
})

Expand All @@ -669,26 +666,22 @@ describe('transport', function () {

.client({type: 'test', pin: 'foo:1'})

.add('foo:1', function (args, done) {
args.local = 1
args.qaz = 1
this.prior(args, done)
})

.ready(function () {
this
.add('foo:1', function (args, done) {
args.local = 1
args.qaz = 1
this.prior(args, done)
})

.start()

.wait('foo:1,bar:1')
.step(function (out) {
expect(tt.outmsgs.length).to.equal(1)
expect(out).to.deep.equal({foo: 1, bar: 2, local: 1, qaz: 1})
return true
})
.start()

.end(done)
.wait('foo:1,bar:1')
.step(function (out) {
expect(tt.outmsgs.length).to.equal(1)
expect(out).to.deep.equal({foo: 1, bar: 2, local: 1, qaz: 1})
return true
})

.end(done)
})
})

Expand Down

0 comments on commit 9303be3

Please sign in to comment.