Skip to content

Commit

Permalink
fire iteration with callRemote method test
Browse files Browse the repository at this point in the history
  • Loading branch information
Neeraj Singh authored and josevalim committed May 31, 2010
1 parent 86cf13e commit 5dd941a
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/index.html
Expand Up @@ -11,6 +11,7 @@
<script src="test/data-confirm.js" type="text/javascript"></script>
<script src="test/data-method.js_" type="text/javascript"></script>
<script src="test/data-disable.js" type="text/javascript"></script>
<script src="test/call-remote.js" type="text/javascript"></script>
</head>

<body id="body">
Expand Down
85 changes: 85 additions & 0 deletions test/test/call-remote.js
@@ -0,0 +1,85 @@
var App = App || {};

App.build_form = function(opt) {

console.log('opt is');
console.log(opt);

var defaults = {
action: 'http://example.com/address',
'data-remote': 'true'
};

var options = $.extend(defaults, opt);


console.log('options is');
console.log(options);

$(document.body).append($('<form />', options));

$('form').append($('<input />', {
id: 'user_name',
type: 'text',
size: '30',
'name': 'user_name',
'value': 'john'
}));
}

module('call-remote', {
teardown: function() {
$('form').remove();
}
});

test('method should be picked up from method attribute', function() {
expect(1);

App.build_form({'method': 'put', 'data-method': 'fail'});

var ajaxArgs;

jack(function() {
jack.expect('$.ajax').once().mock(function(args) {
ajaxArgs = args;
});
$('form[data-remote]').trigger('submit');
});

equals(ajaxArgs.type, 'PUT', 'ajax arguments should have PUT as request type');
});

test('method should be picked up from data-method attribute', function() {
expect(1);

App.build_form({'data-method': 'put'});

var ajaxArgs;

jack(function() {
jack.expect('$.ajax').once().mock(function(args) {
ajaxArgs = args;
});
$('form[data-remote]').trigger('submit');
});

equals(ajaxArgs.type, 'PUT', 'ajax arguments should have PUT as request type');
});

test('default method should be picked up', function() {
expect(1);

App.build_form({});

var ajaxArgs;

jack(function() {
jack.expect('$.ajax').once().mock(function(args) {
ajaxArgs = args;
});
$('form[data-remote]').trigger('submit');
});

equals(ajaxArgs.type, 'GET', 'ajax arguments should have PUT as request type');
});
1 change: 1 addition & 0 deletions test/test/data-method.js
@@ -1,3 +1,4 @@
//take into account CSRF stuff
module('data-remote', {

teardown: function() {
Expand Down

0 comments on commit 5dd941a

Please sign in to comment.