Skip to content

Commit

Permalink
all tests pass; fixing bugs and shoring up test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregory Tomei committed Apr 22, 2011
1 parent 5dd93e2 commit 2dd2356
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 29 deletions.
10 changes: 3 additions & 7 deletions MobileHelpMe_appcelerator/Resources/app/models/task_request.js
Expand Up @@ -4,9 +4,9 @@
// t.string "location"
// t.datetime "created_at"
// t.datetime "updated_at"
// t.integer "amount"
//
mcv.create('model', 'TaskRequest', {
// var TaskRequest = {

categories: [
{title:"Roadside assistance", id: 123},
Expand Down Expand Up @@ -48,17 +48,13 @@ mcv.create('model', 'TaskRequest', {
};
try {
xhr.open("POST","http://localhost:3000/task_requests.js");

// xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
xhr.setRequestHeader("content-type", "application/json");
var json = JSON.stringify({task_request:this.attributes});

xhr.setRequestHeader("content-type", "application/json"); // need this because rails receives it string-escaped without it. see here: http://developer.appcelerator.com/question/111911/nested-json-to-rails-api
var json = JSON.stringify({task_request:this.attributes}); // rails likes its JSON with a root object
xhr.send(json);
} catch(e) {
Ti.API.error('TaskRequest.save :: exception encountered: ' + e.message);
return false;
}
return true;
},

isNewRecord: function()
Expand Down
2 changes: 1 addition & 1 deletion MobileHelpMe_appcelerator/Resources/test/enabled.js
@@ -1 +1 @@

App.tests_enabled = true;
Expand Up @@ -55,15 +55,26 @@
opts = {category_id:'qwerty cat', description:'functional desc here', location:'37.77018737792969, -122.4037094116211'};
tr = m.build(opts);
// mock out the API call to NOOPs instead
var xhr_mock = { open:function(){}, send:function(){} };
var xhr_mock = { open:function(){}, send:function(){}, setRequestHeader:function(){} };
spyOn(xhr_mock,'open');
spyOn(xhr_mock,'send');
spyOn(xhr_mock,'setRequestHeader');
// var callbacks = {
// callbackForOnLoad: function(){},
// callbackForOnError: function(){}
// };
// spyOn(callbacks,'callbackForOnLoad' );
// spyOn(callbacks,'callbackForOnError');

expect(tr.save(xhr_mock)).toBe(true);
var json = JSON.stringify(tr.attributes);
Ti.API.info("json=" + json);
expect(xhr_mock.open).toHaveBeenCalled();
tr.save(xhr_mock/*, callbackForOnLoad*/);
var json = JSON.stringify({task_request:tr.attributes}); // how rails likes its JSON
expect(xhr_mock.setRequestHeader).toHaveBeenCalled();
expect(xhr_mock.open).toHaveBeenCalledWith("POST","http://localhost:3000/task_requests.js");
expect(xhr_mock.send).toHaveBeenCalledWith(json);

// TODO: verify the callbacks
// expect(callbacks.callbackForOnLoad ).toHaveBeenCalled();
// expect(callbacks.callbackForOnError).toHaveBeenCalled();
});
});

Expand Down
32 changes: 16 additions & 16 deletions MobileHelpMe_appcelerator/Resources/test/tests.js
Expand Up @@ -3,23 +3,23 @@
Ti.include('test/lib/jasmine-1.0.2.js');
Ti.include('test/lib/jasmine-titanium.js');

// // controllers
// Ti.include('test/controllers/test_signin.js');
// Ti.include('test/controllers/test_dispatch.js');
// Ti.include('test/controllers/test_needHelp1.js');
// Ti.include('test/controllers/test_needHelp2.js');
// Ti.include('test/controllers/test_needHelp3.js');
// Ti.include('test/controllers/test_needHelp4.js');
// // models
// controllers
Ti.include('test/controllers/test_signin.js');
Ti.include('test/controllers/test_dispatch.js');
Ti.include('test/controllers/test_needHelp1.js');
Ti.include('test/controllers/test_needHelp2.js');
Ti.include('test/controllers/test_needHelp3.js');
Ti.include('test/controllers/test_needHelp4.js');
// models
Ti.include('test/models/test_task_request.js');
// // views
// Ti.include('test/views/test_signin.js');
// Ti.include('test/views/test_dispatch.js');
// Ti.include('test/views/test_needhelp1.js');
// Ti.include('test/views/test_needhelp2.js');
// Ti.include('test/views/test_needhelp3.js');
// Ti.include('test/views/test_needhelp4.js');
// Ti.include('test/views/test_needhelpend.js');
// views
Ti.include('test/views/test_signin.js');
Ti.include('test/views/test_dispatch.js');
Ti.include('test/views/test_needhelp1.js');
Ti.include('test/views/test_needhelp2.js');
Ti.include('test/views/test_needhelp3.js');
Ti.include('test/views/test_needhelp4.js');
Ti.include('test/views/test_needhelpend.js');


jasmine.getEnv().addReporter(new jasmine.TitaniumReporter());
Expand Down

0 comments on commit 2dd2356

Please sign in to comment.