mirror of
https://github.com/kbparagua/paloma
synced 2023-03-27 23:21:17 -04:00
Create test for Paloma.ControllerBuilder
This commit is contained in:
parent
853ba9c614
commit
9cf086df22
2 changed files with 50 additions and 1 deletions
49
test_app/spec/javascripts/controller_builder_spec.js
Normal file
49
test_app/spec/javascripts/controller_builder_spec.js
Normal file
|
@ -0,0 +1,49 @@
|
|||
describe('Paloma.ControllerBuilder', function(){
|
||||
|
||||
var TestController = Paloma.controller('Test');
|
||||
|
||||
|
||||
describe('#build(options)', function(){
|
||||
|
||||
describe('when options.controller has no match', function(){
|
||||
var factory = {get: function(controller){ return null; }},
|
||||
builder = new Paloma.ControllerBuilder(factory);
|
||||
|
||||
it('returns null', function(){
|
||||
var options = {controller: 'Test', action: 'show'};
|
||||
expect( builder.build(options) ).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when options.controller has a match', function(){
|
||||
var factory = {get: function(controller){ return TestController; }},
|
||||
builder = new Paloma.ControllerBuilder(factory);
|
||||
|
||||
var options = {
|
||||
controller: 'Test',
|
||||
action: 'show',
|
||||
params: {a: 1, b: 2}
|
||||
};
|
||||
|
||||
var controller = builder.build(options);
|
||||
|
||||
it('returns a new instance of the controller class', function(){
|
||||
expect(controller instanceof TestController).toBeTruthy();
|
||||
});
|
||||
|
||||
it("initializes controller instance's params", function(){
|
||||
var expectedParams = {_controller: 'Test', _action: 'show', a: 1, b: 2};
|
||||
var correct = true;
|
||||
|
||||
for (var k in expectedParams){
|
||||
if (controller.params[k] != expectedParams[k])
|
||||
correct = false;
|
||||
}
|
||||
|
||||
expect(correct).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
|
@ -25,7 +25,7 @@ Paloma.ControllerBuilder.prototype = {
|
|||
};
|
||||
|
||||
for (var k in this.options.params)
|
||||
if (this.options.hasOwnProperty(k))
|
||||
if (this.options.params.hasOwnProperty(k))
|
||||
params[k] = this.options.params[k];
|
||||
|
||||
return params;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue