o: ActiveSupport::Cache::Entry :@compressedF:@expires_in0:@created_atf1357328897.614666: @value">T{I" class:EFI"ProcessedAsset;FI"logical_path;FI"jquery/resourcy_spec.js;FI" pathname;FI"T/Users/jejacks0n/Projects/resourcy/spec/javascripts/jquery/resourcy_spec.coffee;FI"content_type;FI"application/javascript;FI" mtime;FI"2013-01-04T12:44:18-07:00;FI" length;FiSMI" digest;F"%28b38b15d75230a5ee0c3a6428a4ac79I" source;FI"SM(function() { describe("Resourcy jQuery Adapter (1.8.0)", function() { beforeEach(function() { return R.removeAll(); }); describe("plugin signature", function() { it("has all the methods it should have", function() { expect(typeof $.resources).toBe('function'); expect(typeof $.resource).toBe('function'); expect(typeof $.routes).toBe('function'); return expect($.handleRequest).toBeUndefined(); }); return it("removes Resourcy", function() { return expect(window.Resourcy).toBeUndefined(); }); }); describe("plural resources", function() { beforeEach(function() { spyOn(window, 'XMLHttpRequest'); this.resource = $.resources('blogs/:blog_id/posts').add(RESOURCES.POSTS); return this.url = '/blogs/1/posts'; }); it("handles the index action", function() { var spy; spy = spyOn(this.resource.actions, 'index'); $.ajax(this.url, { type: 'get' }); return expect(spy.callCount).toBe(1); }); it("handles the show action", function() { var spy; spy = spyOn(this.resource.actions, 'show'); $.ajax("" + this.url + "/1", { type: 'get' }); return expect(spy.callCount).toBe(1); }); it("handles the new action", function() { var spy; spy = spyOn(this.resource.actions, 'new'); $.ajax("" + this.url + "/new", { type: 'get' }); return expect(spy.callCount).toBe(1); }); it("handles the create action", function() { var spy; spy = spyOn(this.resource.actions, 'create'); $.ajax(this.url, { type: 'post' }); return expect(spy.callCount).toBe(1); }); it("handles the edit action", function() { var spy; spy = spyOn(this.resource.actions, 'edit'); $.ajax("" + this.url + "/1/edit", { type: 'get' }); return expect(spy.callCount).toBe(1); }); it("handles the update action", function() { var spy; spy = spyOn(this.resource.actions, 'update'); $.ajax("" + this.url + "/1", { type: 'put' }); return expect(spy.callCount).toBe(1); }); it("handles the destroy action", function() { var spy; spy = spyOn(this.resource.actions, 'destroy'); $.ajax("" + this.url + "/1", { type: 'delete' }); return expect(spy.callCount).toBe(1); }); it("handles get members", function() { var spy; spy = spyOn(this.resource.actions.get, 'comments'); $.ajax("" + this.url + "/1/comments", { type: 'get' }); return expect(spy.callCount).toBe(1); }); it("handles put members", function() { var spy; spy = spyOn(this.resource.actions.put, 'publish'); $.ajax("" + this.url + "/1/publish", { type: 'put' }); return expect(spy.callCount).toBe(1); }); it("handles post members", function() { var spy; spy = spyOn(this.resource.actions.post, 'reorder'); $.ajax("" + this.url + "/1/reorder", { type: 'post' }); return expect(spy.callCount).toBe(1); }); it("handles delete members", function() { var spy; spy = spyOn(this.resource.actions["delete"], 'comments'); $.ajax("" + this.url + "/1/comments", { type: 'delete' }); return expect(spy.callCount).toBe(1); }); return describe("ajax arguments", function() { it("accepts the url in the options object", function() { var spy; spy = spyOn(this.resource.actions, 'index'); $.ajax({ url: this.url, type: 'get' }); return expect(spy.callCount).toBe(1); }); return it("falls back to _method if it's provided in the data", function() { var data, spy; spy = spyOn(this.resource.actions, 'create'); data = [ { name: '_method', value: 'post' } ]; $.ajax({ url: this.url, data: data }); return expect(spy.callCount).toBe(1); }); }); }); describe("singular resources", function() { beforeEach(function() { spyOn(window, 'XMLHttpRequest'); this.resource = $.resource('blogs/:blog_id/owner').add(RESOURCES.OWNER); return this.url = '/blogs/1/owner'; }); it("handles the show action", function() { var spy; spy = spyOn(this.resource.actions, 'show'); $.ajax(this.url, { type: 'get' }); return expect(spy.callCount).toBe(1); }); it("handles the new action", function() { var spy; spy = spyOn(this.resource.actions, 'new'); $.ajax("" + this.url + "/new", { type: 'get' }); return expect(spy.callCount).toBe(1); }); it("handles the create action", function() { var spy; spy = spyOn(this.resource.actions, 'create'); $.ajax(this.url, { type: 'post' }); return expect(spy.callCount).toBe(1); }); it("handles the edit action", function() { var spy; spy = spyOn(this.resource.actions, 'edit'); $.ajax(this.url + '/edit', { type: 'get' }); return expect(spy.callCount).toBe(1); }); it("handles the update action", function() { var spy; spy = spyOn(this.resource.actions, 'update'); $.ajax(this.url, { type: 'put' }); return expect(spy.callCount).toBe(1); }); it("handles the destroy action", function() { var spy; spy = spyOn(this.resource.actions, 'destroy'); $.ajax(this.url, { type: 'delete' }); return expect(spy.callCount).toBe(1); }); it("handles get members", function() { var spy; this.resource.add('get:blogs', function() {}); spy = spyOn(this.resource.actions.get, 'blogs'); $.ajax("" + this.url + "/blogs", { type: 'get' }); return expect(spy.callCount).toBe(1); }); it("handles put members", function() { var spy; this.resource.add('put:demote', function() {}); spy = spyOn(this.resource.actions.put, 'demote'); $.ajax("" + this.url + "/demote", { type: 'put' }); return expect(spy.callCount).toBe(1); }); it("handles post members", function() { var spy; this.resource.add('post:blogs', function() {}); spy = spyOn(this.resource.actions.post, 'blogs'); $.ajax("" + this.url + "/blogs", { type: 'post' }); return expect(spy.callCount).toBe(1); }); return it("handles delete members", function() { var spy; this.resource.add('delete:blog', function() {}); spy = spyOn(this.resource.actions["delete"], 'blog'); $.ajax("" + this.url + "/blog", { type: 'delete' }); return expect(spy.callCount).toBe(1); }); }); describe("callbacks", function() { beforeEach(function() { this.resource = $.resources('blogs/:blog_id/posts'); this.url = '/blogs/1/posts'; return this.callback = function() { return 'callback'; }; }); describe("passed arguments", function() { beforeEach(function() { var _this = this; spyOn(window, 'XMLHttpRequest'); this.resource.add('index', function() { return { success: _this.callback }; }); return this.actionSpy = spyOn(this.resource.actions, 'index').andCallThrough(); }); it("passes the proceed function", function() { $.ajax('/blogs/1/posts', { type: 'get' }); return expect(typeof this.actionSpy.argsForCall[0][0]).toEqual('function'); }); it("passes parsed path variables with their values", function() { $.ajax('/blogs/42/posts', { type: 'get' }); return expect(this.actionSpy.argsForCall[0][1]).toEqual({ blog_id: '42' }); }); return it("passes the requests url parts", function() { $.ajax('http://jejacks0n:password@localhost:3000/blogs/42/posts.json?foo=bar#hash', { type: 'get' }); return expect(this.actionSpy.argsForCall[0][2]).toEqual({ scheme: 'http', credentials: 'jejacks0n:password', host: 'localhost', port: '3000', path: '/blogs/42/posts', action: 'posts', format: 'json', query: 'foo=bar', hash: 'hash' }); }); }); return describe("returning values", function() { it("allows returning options that will be used for the request", function() { var spy, _this = this; this.resource.add('index', function() { return { success: _this.callback }; }); spy = spyOn(this, 'callback'); runs(function() { return $.ajax(this.url, { type: 'get' }); }); waitsFor(function() { return spy.callCount; }); return runs(function() { return expect(spy.callCount).toBe(1); }); }); it("handles the complete callback", function() { var spy, _this = this; this.resource.add('index', function() { return { success: _this.callback, complete: _this.callback }; }); spy = spyOn(this, 'callback'); runs(function() { return $.ajax(this.url, { type: 'get' }); }); waitsFor(function() { return spy.callCount === 2; }); return runs(function() { return expect(spy.callCount).toBe(2); }); }); it("handles the beforeSend callback", function() { var spy, _this = this; spyOn(window, 'XMLHttpRequest'); this.resource.add('index', function() { return { beforeSend: _this.callback }; }); spy = spyOn(this, 'callback'); $.ajax(this.url, { type: 'get' }); return expect(spy.callCount).toBe(1); }); it("handles the dataFilter callback", function() { var spy, _this = this; this.resource.add('index', function() { return { dataFilter: _this.callback }; }); spy = spyOn(this, 'callback'); runs(function() { return $.ajax(this.url, { type: 'get', dataType: 'json' }); }); waitsFor(function() { return spy.callCount; }); return runs(function() { return expect(spy.argsForCall[0][1]).toBe('json'); }); }); it("handles the error callback", function() { var spy, _this = this; this.resource = $.resources('blogs'); this.resource.add('index', function() { return { error: _this.callback }; }); spy = spyOn(this, 'callback'); runs(function() { return $.ajax('/blogs', { type: 'get' }); }); waitsFor(function() { return spy.callCount; }); return runs(function() { return expect(spy.callCount).toBe(1); }); }); return describe("and proceeding", function() { it("proceeds when you return an object", function() { var spy, _this = this; this.resource.add('index', function() { return { success: _this.callback }; }); spy = spyOn(this, 'callback'); runs(function() { return $.ajax(this.url, { method: 'get' }); }); waitsFor(function() { return spy.callCount; }); return runs(function() { return expect(spy.callCount).toBe(1); }); }); it("doesn't proceed when proceed is called", function() { var spy, _this = this; this.resource.add('index', function(proceed) { return proceed({ success: _this.callback }); }); spy = spyOn(this, 'callback'); runs(function() { return $.ajax(this.url, { method: 'get' }); }); waitsFor(function() { return spy.callCount; }); return runs(function() { return expect(spy.callCount).toBe(1); }); }); it("doesn't proceed when returning false", function() { var ajaxSpy, spy; spy = spyOn(this, 'callback').andCallFake(function() { return false; }); ajaxSpy = spyOn($, 'originalAjax'); this.resource.add('index', this.callback); $.ajax(this.url, { method: 'get' }); return expect(ajaxSpy.callCount).toBe(0); }); return it("doesn't call proceed more than once", function() { var spy, _this = this; this.resource.add('index', function(proceed) { proceed({ success: _this.callback }); return { success: _this.callback }; }); spy = spyOn(this, 'callback'); runs(function() { return $.ajax(this.url, { method: 'get' }); }); waitsFor(function() { return spy.callCount; }); return runs(function() { return expect(spy.callCount).toBe(1); }); }); }); }); }); describe("chained callbacks", function() { beforeEach(function() { this.resource = $.resources('blogs/:blog_id/posts'); this.url = '/blogs/1/posts'; return this.callback = function() { return 'callback'; }; }); it("calls both success callbacks", function() { var spy, _this = this; this.resource.add('index', function() { return { success: _this.callback }; }); spy = spyOn(this, 'callback'); runs(function() { return $.ajax(this.url, { method: 'get', success: this.callback }); }); waitsFor(function() { return spy.callCount === 2; }); return runs(function() { return expect(spy.callCount).toBe(2); }); }); it("calls both beforeSend callbacks", function() { var spy, _this = this; spyOn(window, 'XMLHttpRequest'); this.resource.add('index', function() { return { beforeSend: _this.callback }; }); spy = spyOn(this, 'callback'); $.ajax(this.url, { type: 'get', beforeSend: this.callback }); return expect(spy.callCount).toBe(2); }); it("calls both dataFilter callbacks", function() { var spy, _this = this; this.resource.add('index', function() { return { dataFilter: _this.callback }; }); spy = spyOn(this, 'callback'); runs(function() { return $.ajax(this.url, { type: 'get', dataType: 'json', dataFilter: this.callback }); }); waitsFor(function() { return spy.callCount === 2; }); return runs(function() { return expect(spy.argsForCall[1][1]).toBe('json'); }); }); it("calls both complete callbacks", function() { var spy, _this = this; this.resource.add('index', function() { return { complete: _this.callback }; }); spy = spyOn(this, 'callback'); runs(function() { return $.ajax(this.url, { type: 'get', dataType: 'json', complete: this.callback }); }); waitsFor(function() { return spy.callCount === 2; }); return runs(function() { return expect(spy.callCount).toBe(2); }); }); it("calls both error callbacks", function() { var spy, _this = this; this.resource = $.resources('blogs'); this.resource.add('index', function() { return { error: _this.callback }; }); spy = spyOn(this, 'callback'); runs(function() { return $.ajax('/blogs', { method: 'get', error: this.callback }); }); waitsFor(function() { return spy.callCount === 2; }); return runs(function() { return expect(spy.callCount).toBe(2); }); }); return it("allows mixing $.ajax().done() style callbacks", function() { var spy, _this = this; this.resource.add('index', function() { return { success: _this.callback }; }); spy = spyOn(this, 'callback'); runs(function() { return $.ajax(this.url, { method: 'get' }).done(this.callback); }); waitsFor(function() { return spy.callCount === 2; }); return runs(function() { return expect(spy.callCount).toBe(2); }); }); }); return describe("using UJS", function() { fixture.load('ujs.html'); beforeEach(function() { this.resource = $.resources('posts'); return this.callback = function() { return 'callback'; }; }); it("allows :remote => true", function() { var spy; spyOn(window, 'XMLHttpRequest'); spy = spyOn(this, 'callback'); this.resource.add('show', this.callback); this.resource.add('edit', this.callback); $('a#show').click(); expect(spy.callCount).toBe(1); $('a#edit').click(); return expect(spy.callCount).toBe(2); }); return it("allows :remote => true to call callbacks", function() { var spy, _this = this; spy = spyOn(this, 'callback'); this.resource.add('show', function() { return { success: _this.callback }; }); runs(function() { return $('a#show').click(); }); waitsFor(function() { return spy.callCount; }); return runs(function() { return expect(spy.callCount).toBe(1); }); }); }); }); }).call(this); ;TI"dependency_digest;F"%1bc8a2b4cf22ae0600ee8545efb9d035I"required_paths;F[ I"1$root/app/assets/javascripts/jquery-1.8.0.js;FI"T/Users/jejacks0n/Projects/resourcy/vendor/assets/javascripts/resourcy.js.coffee;FI"[/Users/jejacks0n/Projects/resourcy/vendor/assets/javascripts/jquery.resourcy.js.coffee;FI"/$root/app/assets/javascripts/jquery_ujs.js;FI"T/Users/jejacks0n/Projects/resourcy/spec/javascripts/jquery/resourcy_spec.coffee;FI"dependency_paths;F[ {I" path;FI"T/Users/jejacks0n/Projects/resourcy/spec/javascripts/jquery/resourcy_spec.coffee;FI" mtime;FI"2013-01-04T12:44:18-07:00;FI" digest;F"%b9997824ad02dd937b0cfee3df534043{I" path;FI"1$root/app/assets/javascripts/jquery-1.8.0.js;FI" mtime;FI"2012-09-11T20:15:29-06:00;FI" digest;F"%98dcf77888e68ac783c148b7d0f60154{I" path;FI"[/Users/jejacks0n/Projects/resourcy/vendor/assets/javascripts/jquery.resourcy.js.coffee;FI" mtime;FI"2012-10-23T10:22:31-06:00;FI" digest;F"%3b43eb59e05c3d3329ecbe02be585434{I" path;FI"T/Users/jejacks0n/Projects/resourcy/vendor/assets/javascripts/resourcy.js.coffee;FI" mtime;FI"2012-10-23T10:52:41-06:00;FI" digest;F"%fa23f1823eb271510001413a28ecd798{I" path;FI"/$root/app/assets/javascripts/jquery_ujs.js;FI" mtime;FI"2012-09-21T19:06:20-06:00;FI" digest;F"%633123195ed871d75d553f05f35d9702I" _version;F"%9f3b95dd7ea3030dc35985c0a8020862