ajax 1.0.8 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. data/Gemfile +5 -3
  2. data/Gemfile.lock +34 -8
  3. data/README.rdoc +76 -63
  4. data/Rakefile +3 -1
  5. data/VERSION +1 -1
  6. data/app/controllers/ajax_controller.rb +6 -0
  7. data/init.rb +6 -0
  8. data/lib/ajax.rb +13 -24
  9. data/lib/ajax/action_controller.rb +120 -65
  10. data/lib/ajax/application.rb +62 -0
  11. data/lib/ajax/helpers/request_helper.rb +2 -2
  12. data/lib/ajax/helpers/task_helper.rb +2 -2
  13. data/lib/ajax/railtie.rb +25 -1
  14. data/lib/ajax/routes.rb +7 -3
  15. data/lib/ajax/rspec.rb +2 -0
  16. data/lib/ajax/{spec → rspec}/extension.rb +4 -11
  17. data/lib/ajax/{spec → rspec}/helpers.rb +10 -10
  18. data/lib/ajax/rspec/integration.rb +24 -0
  19. data/lib/rack-ajax.rb +1 -1
  20. data/lib/rack-ajax/parser.rb +2 -2
  21. data/public/javascripts/{jquery.address-1.2rc.js → jquery.address-1.3.js} +340 -197
  22. data/public/javascripts/jquery.address-1.3.min.js +32 -0
  23. data/rails/init.rb +1 -4
  24. data/rails/install.rb +1 -1
  25. data/rails/routes.rb +6 -0
  26. data/tasks/ajax_tasks.rake +11 -2
  27. metadata +41 -25
  28. data/app/views/ajax/_redirect_with_fragment.html.erb +0 -19
  29. data/public/javascripts/jquery.address-1.1.js +0 -450
  30. data/public/javascripts/jquery.address-1.1.min.js +0 -11
  31. data/public/javascripts/jquery.address-1.2.js +0 -528
  32. data/public/javascripts/jquery.address-1.2.min.js +0 -25
  33. data/public/javascripts/jquery.address-1.2rc.min.js +0 -27
  34. data/rails/uninstall.rb +0 -1
  35. data/spec/ajax/ajax_spec.rb +0 -23
  36. data/spec/ajax/helpers_spec.rb +0 -121
  37. data/spec/ajax/request_helper_spec.rb +0 -52
  38. data/spec/ajax/tasks_spec.rb +0 -48
  39. data/spec/integration/ajax_spec.rb +0 -146
  40. data/spec/rack-ajax/parser_spec.rb +0 -62
  41. data/spec/spec.opts +0 -1
  42. data/spec/spec_helper.rb +0 -17
  43. data/spec/support/file_macros.rb +0 -28
  44. data/spec/support/query_count.rb +0 -0
  45. data/spec/support/response_helpers.rb +0 -7
@@ -1,25 +0,0 @@
1
- /*
2
- * jQuery Address Plugin v1.2
3
- * http://www.asual.com/jquery/address/
4
- *
5
- * Copyright (c) 2009-2010 Rostislav Hristov
6
- * Dual licensed under the MIT or GPL Version 2 licenses.
7
- * http://jquery.org/license
8
- *
9
- * Date: 2010-03-03 21:24:30 +0200 (Wed, 03 Mar 2010)
10
- */
11
- (function(d){d.address=function(){var z=function(a){d(d.address).trigger(d.extend(d.Event(a),function(){for(var b={},g=d.address.parameterNames(),e=0,p=g.length;e<p;e++)b[g[e]]=d.address.parameter(g[e]);return{value:d.address.value(),path:d.address.path(),pathNames:d.address.pathNames(),parameterNames:g,parameters:b,queryString:d.address.queryString()}}.call(d.address)))},t=function(a,b,g){if(g||b)d(d.address).bind(a,g||b,g&&b);return d.address},u=function(){var a=c.href.indexOf("#");return a!=-1?
12
- S(H(c.href.substr(a+1))):""},T=function(){return"javascript"},U=function(a,b){if(l.strict)a=b?a.substr(0,1)!="/"?"/"+a:a:a==""?"/":a;return a},I=function(a,b){return s&&c.protocol=="file:"?b?f.replace(/\?/,"%3F"):f.replace(/%253F/,"?"):a},V=function(a){for(var b,g,e=0,p=a.childNodes.length;e<p;e++){if(a.childNodes[e].src)b=String(a.childNodes[e].src);if(g=V(a.childNodes[e]))b=g}return b},F=function(){if(!J){var a=u(),b=f!=a;if(A&&m<523){if(B!=D.length){B=D.length;if(typeof v[B-1]!=w)f=v[B-1];E(h)}}else if(s&&
13
- m<7&&b)c.reload();else if(b){f=a;E(h)}}},E=function(a){z("change");z(a?"internalChange":"externalChange");C(W,10)},W=function(){var a=(c.pathname+(/\/$/.test(c.pathname)?"":"/")+d.address.value()).replace(/\/\//,"/").replace(/^\/$/,""),b=window[l.tracker];if(typeof b==K)b(a);else if(typeof _gaq!=w&&typeof _gaq.push==K)_gaq.push(["_trackPageview",a]);else if(typeof pageTracker!=w&&typeof pageTracker._trackPageview==K)pageTracker._trackPageview(a);else typeof urchinTracker==K&&urchinTracker(a)},X=function(){var a=
14
- i.contentWindow.document;a.open();a.write("<html><head><title>"+j.title+"</title><script>var "+q+' = "'+u()+'";<\/script></head></html>');a.close()},Z=function(){if(!Y){Y=k;if(s&&m<8){var a=j.getElementsByTagName("frameset")[0];i=j.createElement((a?"":"i")+"frame");if(a){a.insertAdjacentElement("beforeEnd",i);a[a.cols?"cols":"rows"]+=",0";i.src=T()+":"+h;i.noResize=k;i.frameBorder=i.frameSpacing=0}else{i.src=T()+":"+h;i.style.display="none";j.body.insertAdjacentElement("afterBegin",i)}C(function(){d(i).bind("load",
15
- function(){var b=i.contentWindow;f=typeof b[q]!=w?b[q]:"";if(f!=u()){E(h);c.hash=I(f,k)}});typeof i.contentWindow[q]==w&&X()},50)}else if(A){if(m<418){d(j.body).append('<form id="'+q+'" style="position:absolute;top:-9999px;" method="get"></form>');M=j.getElementById(q)}if(typeof c[q]==w)c[q]={};if(typeof c[q][c.pathname]!=w)v=c[q][c.pathname].split(",")}C(function(){z("init");E(h)},1);if(s&&m>7||!s&&"on"+G in o)if(o.addEventListener)o.addEventListener(G,F,false);else o.attachEvent&&o.attachEvent("on"+
16
- G,F);else ca(F,50);d("a[rel*=address:]").address()}},da=function(){if(o.removeEventListener)o.removeEventListener(G,F,false);else o.detachEvent&&o.detachEvent("on"+G,F)},q="jQueryAddress",K="function",w="undefined",G="hashchange",k=true,h=false,n=d.browser,m=parseFloat(d.browser.version),$=n.mozilla,s=n.msie,r=n.opera,A=n.safari,N=h,o=function(){try{return top.document!==undefined?top:window}catch(a){return window}}(),j=o.document,D=o.history,c=o.location,ca=setInterval,C=setTimeout,H=decodeURI,S=
17
- encodeURI;n=navigator.userAgent;var i,M,x=V(document),aa=x?x.indexOf("?"):-1,ea=j.title,B=D.length,J=h,Y=h,O=k,ba=k,L=h,v=[],f=u(),l={autoUpdate:k,history:k,strict:k};if(s){m=parseFloat(n.substr(n.indexOf("MSIE")+4));if(j.documentMode&&j.documentMode!=m)m=j.documentMode!=8?7:8}if(N=$&&m>=1||s&&m>=6||r&&m>=9.5||A&&m>=312){for(n=1;n<B;n++)v.push("");v.push(f);if(s&&c.hash!=f)c.hash="#"+I(f,k);if(r)history.navigationMode="compatible";if(x&&aa!=-1){x=x.substr(aa+1).split("&");for(n=0;n<x.length;n++){r=
18
- x[n].split("=");if(/^(autoUpdate|history|strict)$/.test(r[0]))l[r[0]]=isNaN(r[1])?/^(true|yes)$/i.test(r[1]):parseInt(r[1],10)!==0;if(/^tracker$/.test(r[0]))l[r[0]]=r[1]}}document.readyState=="complete"&&Z();d(Z);d(window).bind("unload",da)}else if(!N&&c.href.indexOf("#")!=-1||A&&m<418&&c.href.indexOf("#")!=-1&&c.search!=""){j.open();j.write('<html><head><meta http-equiv="refresh" content="0;url='+c.href.substr(0,c.href.indexOf("#"))+'" /></head></html>');j.close()}else W();return{init:function(a,
19
- b){return t("init",a,b)},change:function(a,b){return t("change",a,b)},internalChange:function(a,b){return t("internalChange",a,b)},externalChange:function(a,b){return t("externalChange",a,b)},baseURL:function(){var a=c.href;if(a.indexOf("#")!=-1)a=a.substr(0,a.indexOf("#"));if(a.substr(a.length-1)=="/")a=a.substr(0,a.length-1);return a},strict:function(a){if(a!==undefined){l.strict=a;return this}return l.strict},autoUpdate:function(a){if(a!==undefined){l.autoUpdate=a;return this}return l.autoUpdate},
20
- update:function(){L=k;this.value(f);L=h;return this},history:function(a){if(a!==undefined){l.history=a;return this}return l.history},tracker:function(a){if(a!==undefined){l.tracker=a;return this}return l.tracker},title:function(a){if(a!==undefined){a=H(a);C(function(){ea=j.title=a;if(ba&&i&&i.contentWindow&&i.contentWindow.document){i.contentWindow.document.title=a;ba=h}if(!O&&$)c.replace(c.href.indexOf("#")!=-1?c.href:c.href+"#");O=h},50);return this}return j.title},value:function(a){if(a!==undefined){a=
21
- S(H(U(a,k)));if(a=="/")a="";if(f==a&&!L)return;O=k;f=a;if(l.autoUpdate||L){J=k;E(k);v[D.length]=f;if(A)if(l.history){c[q][c.pathname]=v.toString();B=D.length+1;if(m<418){if(c.search==""){M.action="#"+f;M.submit()}}else if(m<523||f==""){a=j.createEvent("MouseEvents");a.initEvent("click",k,k);var b=j.createElement("a");b.href="#"+f;b.dispatchEvent(a)}else c.hash="#"+f}else c.replace("#"+f);else if(f!=u())if(l.history)c.hash="#"+I(f,k);else c.replace("#"+f);s&&m<8&&l.history&&C(X,50);if(A)C(function(){J=
22
- h},1);else J=h}return this}if(!N)return null;return H(U(I(f,h),h))},path:function(a){if(a!==undefined){var b=this.queryString();this.value(a+(b?"?"+b:""));return this}a=this.value();return a.indexOf("?")!=-1?a.split("?")[0]:a},queryString:function(a){if(a!==undefined){this.value(this.path()+(a?"?"+a:""));return this}a=this.value();var b=a.indexOf("?");if(b!=-1&&b<a.length)return a.substr(b+1)},parameter:function(a,b,g){var e,p;if(b!==undefined){var P=this.parameterNames();p=[];for(e=0;e<P.length;e++){var Q=
23
- P[e],y=this.parameter(Q);if(typeof y=="string")y=[y];if(Q==a)y=b===null||b==""?[]:g?y.concat([b]):[b];for(var R=0;R<y.length;R++)p.push(Q+"="+y[R])}d.inArray(a,P)==-1&&p.push(a+"="+b);this.queryString(p.join("&"));return this}b=this.value();e=b.indexOf("?");if(e!=-1){b=b.substr(e+1);p=b.split("&");b=[];for(e=0;e<p.length;e++){g=p[e].split("=");g[0]==a&&b.push(g[1])}if(b.length!==0)return b.length!=1?b:b[0]}},pathNames:function(){var a=this.path(),b=a.split("/");if(a.substr(0,1)=="/"||a.length===0)b.splice(0,
24
- 1);a.substr(a.length-1,1)=="/"&&b.splice(b.length-1,1);return b},parameterNames:function(){var a=this.value(),b=a.indexOf("?"),g=[];if(b!=-1){a=a.substr(b+1);if(a!=""&&a.indexOf("=")!=-1){a=a.split("&");for(b=0;b<a.length;b++){var e=a[b].split("=")[0];d.inArray(e,g)==-1&&g.push(e)}}}return g}}}();d.fn.address=function(z){var t=function(){var u=z?z.call(this):/address:/.test(d(this).attr("rel"))?d(this).attr("rel").split("address:")[1].split(" ")[0]:d(this).attr("href").replace(/^#/,"");d.address.value(u);
25
- return false};d(this).click(t).live("click",t)}})(jQuery);
@@ -1,27 +0,0 @@
1
- /*
2
- * jQuery Address Plugin v1.2rc
3
- * http://www.asual.com/jquery/address/
4
- *
5
- * Copyright (c) 2009-2010 Rostislav Hristov
6
- * Dual licensed under the MIT or GPL Version 2 licenses.
7
- * http://jquery.org/license
8
- *
9
- * Date: 2010-03-31 11:35:36 +0300 (Wed, 31 Mar 2010)
10
- */
11
- (function(c){c.address=function(){var v=function(a){c(c.address).trigger(c.extend(c.Event(a),function(){for(var b={},g=c.address.parameterNames(),h=0,q=g.length;h<q;h++)b[g[h]]=c.address.parameter(g[h]);return{value:c.address.value(),path:c.address.path(),pathNames:c.address.pathNames(),parameterNames:g,parameters:b,queryString:c.address.queryString()}}.call(c.address)))},y=function(a,b,g){if(g||b)c(c.address).bind(a,g||b,g&&b);return c.address},n=function(){var a=d.href.indexOf("#");return a!=-1?
12
- W(J(t(d.href.substr(a+1),j))):""},X=function(){return"javascript"},Y=function(a,b){if(i.strict)a=b?a.substr(0,1)!="/"?"/"+a:a:a==""?"/":a;return a},K=function(a,b){return u&&d.protocol=="file:"?b?f.replace(/\?/,"%3F"):f.replace(/%253F/,"?"):a},t=function(a,b){if(i.crawlable&&b)return(a!=""?"!":"")+a;return a.replace(/^\!/,"")},w=function(a,b){return parseInt(a.css(b),10)},Z=function(a){for(var b,g,h=0,q=a.childNodes.length;h<q;h++){if(a.childNodes[h].src)b=String(a.childNodes[h].src);if(g=Z(a.childNodes[h]))b=
13
- g}return b},H=function(){if(!L){var a=n(),b=f!=a;if(x&&m<523){if(D!=F.length){D=F.length;if(typeof z[D-1]!=A)f=z[D-1];G(j)}}else if(u&&m<7&&b)d.reload();else if(b){f=a;G(j)}}},G=function(a){v($);v(a?aa:ba);E(ca,10)},ca=function(){var a=(d.pathname+(/\/$/.test(d.pathname)?"":"/")+c.address.value()).replace(/\/\//,"/").replace(/^\/$/,""),b=window[i.tracker];if(typeof b==M)b(a);else if(typeof _gaq!=A&&typeof _gaq.push==M)_gaq.push(["_trackPageview",a]);else if(typeof pageTracker!=A&&typeof pageTracker._trackPageview==
14
- M)pageTracker._trackPageview(a);else typeof urchinTracker==M&&urchinTracker(a)},da=function(){var a=l.contentWindow.document;a.open();a.write("<html><head><title>"+k.title+"</title><script>var "+o+' = "'+n()+'";<\/script></head></html>');a.close()},fa=function(){if(!ea){ea=e;if(i.wrap){var a=c("body");wrap=c("body > *").wrapAll('<div style="padding:'+(w(a,"marginTop")+w(a,"paddingTop"))+"px "+(w(a,"marginRight")+w(a,"paddingRight"))+"px "+(w(a,"marginBottom")+w(a,"paddingBottom"))+"px "+(w(a,"marginLeft")+
15
- w(a,"paddingLeft"))+'px;" />').parent().wrap('<div id="'+o+'" style="height:100%; overflow:auto;'+(x?window.statusbar.visible&&!/chrome/i.test(O)?"":" resize:both;":"")+'" />');c("html, body").css({height:"100%",margin:0,padding:0,overflow:"hidden"});x&&c('<style type="text/css" />').appendTo("head").text("#"+o+"::-webkit-resizer { background-color: #fff; }")}if(u&&m<8){a=k.getElementsByTagName("frameset")[0];l=k.createElement((a?"":"i")+"frame");if(a){a.insertAdjacentElement("beforeEnd",l);a[a.cols?
16
- "cols":"rows"]+=",0";l.src=X()+":"+j;l.noResize=e;l.frameBorder=l.frameSpacing=0}else{l.src=X()+":"+j;l.style.display="none";k.body.insertAdjacentElement("afterBegin",l)}E(function(){c(l).bind("load",function(){var b=l.contentWindow;f=typeof b[o]!=A?b[o]:"";if(f!=n()){G(j);d.hash=K(t(f,e),e)}});typeof l.contentWindow[o]==A&&da()},50)}else if(x){if(m<418){c(k.body).append('<form id="'+o+'" style="position:absolute;top:-9999px;" method="get"></form>');P=k.getElementById(o)}if(typeof d[o]==A)d[o]={};
17
- if(typeof d[o][d.pathname]!=A)z=d[o][d.pathname].split(",")}E(function(){v("init");G(j)},1);if(u&&m>7||!u&&"on"+I in p)if(p.addEventListener)p.addEventListener(I,H,false);else p.attachEvent&&p.attachEvent("on"+I,H);else ja(H,50);c("a[rel*=address:]").address()}},ka=function(){if(p.removeEventListener)p.removeEventListener(I,H,false);else p.detachEvent&&p.detachEvent("on"+I,H)},o="jQueryAddress",M="function",A="undefined",I="hashchange",$="change",aa="internalChange",ba="externalChange",e=true,j=false,
18
- i={autoUpdate:e,crawlable:j,history:e,strict:e,wrap:j},r=c.browser,m=parseFloat(c.browser.version),ga=r.mozilla,u=r.msie,s=r.opera,x=r.safari,Q=j,p=function(){try{return top.document!==undefined?top:window}catch(a){return window}}(),k=p.document,F=p.history,d=p.location,ja=setInterval,E=setTimeout,J=decodeURI,W=encodeURI,O=navigator.userAgent,l,P,B=Z(document),ha=B?B.indexOf("?"):-1,R=k.title,D=F.length,L=j,ea=j,S=e,ia=e,N=j,z=[],f=n();if(u){m=parseFloat(O.substr(O.indexOf("MSIE")+4));if(k.documentMode&&
19
- k.documentMode!=m)m=k.documentMode!=8?7:8;c(document).bind("propertychange",function(){if(k.title!=R&&k.title.indexOf("#"+n())!=-1)k.title=R})}if(Q=ga&&m>=1||u&&m>=6||s&&m>=9.5||x&&m>=312){for(r=1;r<D;r++)z.push("");z.push(f);if(u&&d.hash!=f)d.hash="#"+K(t(f,e),e);if(s)history.navigationMode="compatible";if(B&&ha!=-1){B=B.substr(ha+1).split("&");for(r=0;r<B.length;r++){s=B[r].split("=");if(/^(autoUpdate|crawlable|history|strict|wrap)$/.test(s[0]))i[s[0]]=isNaN(s[1])?/^(true|yes)$/i.test(s[1]):parseInt(s[1],
20
- 10)!==0;if(/^tracker$/.test(s[0]))i[s[0]]=s[1]}}document.readyState=="complete"&&fa();c(fa);c(window).bind("unload",ka)}else if(!Q&&n()!=""||x&&m<418&&n()!=""&&d.search!=""){k.open();k.write('<html><head><meta http-equiv="refresh" content="0;url='+encodeURI(d.href.substr(0,d.href.indexOf("#")))+'" /></head></html>');k.close()}else ca();return{init:function(a,b){return y("init",a,b)},change:function(a,b){return y($,a,b)},internalChange:function(a,b){return y(aa,a,b)},externalChange:function(a,b){return y(ba,
21
- a,b)},baseURL:function(){var a=d.href;if(n()!="")a=a.substr(0,a.indexOf("#"));if(/\/$/.test(a))a=a.substr(0,a.length-1);return a},autoUpdate:function(a){if(a!==undefined){i.autoUpdate=a;return this}return i.autoUpdate},crawlable:function(a){if(a!==undefined){i.crawlable=a;return this}return i.crawlable},history:function(a){if(a!==undefined){i.history=a;return this}return i.history},strict:function(a){if(a!==undefined){i.strict=a;return this}return i.strict},tracker:function(a){if(a!==undefined){i.tracker=
22
- a;return this}return i.tracker},wrap:function(a){if(a!==undefined){i.wrap=a;return this}return i.wrap},update:function(){N=e;this.value(f);N=j;return this},title:function(a){if(a!==undefined){a=J(a);E(function(){R=k.title=a;if(ia&&l&&l.contentWindow&&l.contentWindow.document){l.contentWindow.document.title=a;ia=j}if(!S&&ga)d.replace(d.href.indexOf("#")!=-1?d.href:d.href+"#");S=j},50);return this}return k.title},value:function(a){if(a!==undefined){a=W(J(Y(a,e)));if(a=="/")a="";if(f==a&&!N)return;S=
23
- e;f=a;if(i.autoUpdate||N){L=e;G(e);z[F.length]=f;if(x)if(i.history){d[o][d.pathname]=z.toString();D=F.length+1;if(m<418){if(d.search==""){P.action="#"+t(f,e);P.submit()}}else if(m<523||f==""){a=k.createEvent("MouseEvents");a.initEvent("click",e,e);var b=k.createElement("a");b.href="#"+t(f,e);b.dispatchEvent(a)}else d.hash="#"+t(f,e)}else d.replace("#"+t(f,e));else if(f!=n())if(i.history)d.hash="#"+K(t(f,e),e);else d.replace("#"+t(f,e));u&&m<8&&i.history&&E(da,50);if(x)E(function(){L=j},1);else L=
24
- j}return this}if(!Q)return null;return J(Y(K(f,j),j))},path:function(a){if(a!==undefined){var b=this.queryString(),g=this.hash();this.value(a+(b?"?"+b:"")+(g?"#"+g:""));return this}return this.value().split("#")[0].split("?")[0]},queryString:function(a){if(a!==undefined){var b=this.hash();this.value(this.path()+(a?"?"+a:"")+(b?"#"+b:""));return this}a=this.value().split("?");return a.slice(1,a.length).join("?").split("#")[0]},parameter:function(a,b,g){var h,q;if(b!==undefined){var T=this.parameterNames();
25
- q=[];for(h=0;h<T.length;h++){var U=T[h],C=this.parameter(U);if(typeof C=="string")C=[C];if(U==a)C=b===null||b==""?[]:g?C.concat([b]):[b];for(var V=0;V<C.length;V++)q.push(U+"="+C[V])}c.inArray(a,T)==-1&&q.push(a+"="+b);this.queryString(q.join("&"));return this}if(b=this.queryString()){q=b.split("&");b=[];for(h=0;h<q.length;h++){g=q[h].split("=");g[0]==a&&b.push(g[1])}if(b.length!==0)return b.length!=1?b:b[0]}},pathNames:function(){var a=this.path(),b=a.replace(/\/{2,9}/g,"/").split("/");if(a.substr(0,
26
- 1)=="/"||a.length===0)b.splice(0,1);a.substr(a.length-1,1)=="/"&&b.splice(b.length-1,1);return b},parameterNames:function(){var a=this.queryString(),b=[];if(a&&a.indexOf("=")!=-1){a=a.split("&");for(var g=0;g<a.length;g++){var h=a[g].split("=")[0];c.inArray(h,b)==-1&&b.push(h)}}return b},hash:function(a){if(a!==undefined){this.value(this.value().split("#")[0]+(a?"#"+a:""));return this}a=this.value().split("#");return a.slice(1,a.length).join("#")}}}();c.fn.address=function(v){this.each(function(){if(this.tagName.toLowerCase()==
27
- "form")c("form").live("submit",function(){var n=v?v.call(this):c(this).attr("action")+"?"+c(this).serialize();c.address.value(n);return false});else{var y=function(){var n=v?v.call(this):/address:/.test(c(this).attr("rel"))?c(this).attr("rel").split("address:")[1].split(" ")[0]:c(this).attr("href").replace(/^#\!?/,"");c.address.value(n);return false};c(this).click(y).live("click",y)}})}})(jQuery);
@@ -1 +0,0 @@
1
- # Uninstall hook code here
@@ -1,23 +0,0 @@
1
- require 'spec_helper'
2
-
3
- context Ajax do
4
- context "framework path" do
5
- it "should be /ajax/framework by default" do
6
- Ajax.framework_path.should_not be_nil
7
- Ajax.framework_path.should == '/ajax/framework'
8
- end
9
-
10
- it "should be able to be changed" do
11
- Ajax.framework_path = '/my/path'
12
- Ajax.framework_path.should == '/my/path'
13
- end
14
- end
15
-
16
- it "should have a root method" do
17
- Ajax.root.should == File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
18
- end
19
-
20
- it "should tell you the version" do
21
- Ajax.version.should =~ /\d+\.\d+.\d+/
22
- end
23
- end
@@ -1,121 +0,0 @@
1
- # coding: utf-8
2
- require 'spec_helper'
3
-
4
- context 'Ajax::UrlHelpers' do
5
- DOMAINS = %w[musicsocial.com.local altnet.com amusicstreamingservice.com stage.altnet.com rails1.creagency.com.au]
6
-
7
- describe "(URL) hashed_url_from_traditional" do
8
- it "should handle a query string" do
9
- Ajax.hashed_url_from_traditional('/Beyonce?one=1').should == '/#/Beyonce?one=1'
10
- end
11
-
12
- it "should ignore the fragment" do
13
- Ajax.hashed_url_from_traditional('/Beyonce?one=1#fragment').should == '/#/Beyonce?one=1'
14
- end
15
-
16
- it "should handle no query string" do
17
- Ajax.hashed_url_from_traditional('/Beyonce').should == '/#/Beyonce'
18
- end
19
-
20
- it "should handle special characters" do
21
- Ajax.hashed_url_from_traditional('/beyoncé').should == '/#/beyonc%C3%A9'
22
- Ajax.hashed_url_from_traditional('/red hot').should == '/#/red%20hot'
23
- end
24
-
25
- DOMAINS.each do |domain|
26
- it "should work for domain #{domain}" do
27
- Ajax.hashed_url_from_traditional("http://#{domain}/playlists").should == "http://#{domain}/#/playlists"
28
- end
29
- end
30
- end
31
-
32
- describe "(URL) hashed_url_from_fragment" do
33
- it "should strip double slashes" do
34
- Ajax.hashed_url_from_fragment('/Beyonce#/Akon').should == '/#/Akon'
35
- Ajax.hashed_url_from_fragment('/Beyonce#Akon').should == '/#/Akon'
36
- end
37
-
38
- it "should handle special characters" do
39
- Ajax.hashed_url_from_fragment('/#/beyoncé').should == '/#/beyonc%C3%A9'
40
- Ajax.hashed_url_from_fragment('/#/red hot').should == '/#/red%20hot'
41
- end
42
-
43
- it "should handle no fragment" do
44
- Ajax.hashed_url_from_fragment('/Beyonce').should == '/#/'
45
- end
46
-
47
- DOMAINS.each do |domain|
48
- it "should work for domain #{domain}" do
49
- Ajax.hashed_url_from_fragment("http://#{domain}").should == "http://#{domain}/#/"
50
- Ajax.hashed_url_from_fragment("http://#{domain}/").should == "http://#{domain}/#/"
51
- Ajax.hashed_url_from_fragment("http://#{domain}/Beyonce/#/playlists").should == "http://#{domain}/#/playlists"
52
- end
53
- end
54
- end
55
-
56
- describe "(boolean) url_is_root?" do
57
- it "should detect root urls" do
58
- Ajax.url_is_root?('/#/Beyonce?query2').should be(true)
59
- Ajax.url_is_root?('/').should be(true)
60
- Ajax.url_is_root?('/#/beyoncé'). should be(true)
61
- end
62
-
63
- it "should detect non-root urls" do
64
- Ajax.url_is_root?('/Beyonce').should be(false)
65
- end
66
-
67
- it "should support full URLs" do
68
- Ajax.is_hashed_url?('http://musicsocial.com.local/#/playlists').should be(true)
69
- end
70
-
71
- it "should support special characters" do
72
- Ajax.is_hashed_url?('http://musicsocial.com.local/#/beyoncé').should be(true)
73
- end
74
- end
75
-
76
- describe "(boolean) is_hashed_url?" do
77
- it "should return false for fragments that don't start with /" do
78
- Ajax.is_hashed_url?('/Beyonce#Akon').should be(false)
79
- Ajax.is_hashed_url?('/Beyonce?query#Akon/').should be(false)
80
- Ajax.is_hashed_url?('/Beyonce?query%23').should be(false)
81
- end
82
-
83
- it "should return true if the fragment starts with /" do
84
- Ajax.is_hashed_url?('/Beyonce#/Akon').should be(true)
85
- Ajax.is_hashed_url?('/#/Akon').should be(true)
86
- Ajax.is_hashed_url?('/Beyonce?query%23/').should be(true) # KJV technically I don't think this behaviour is correct
87
- end
88
-
89
- DOMAINS.each do |domain|
90
- it "should work for domain #{domain}" do
91
- Ajax.is_hashed_url?("http://#{domain}/#/playlists").should be(true)
92
- Ajax.is_hashed_url?("http://#{domain}/playlists").should be(false)
93
- end
94
- end
95
- end
96
-
97
- describe "(URL) traditional_url_from_fragment" do
98
- it "should handle slashes" do
99
- Ajax.traditional_url_from_fragment('/Beyonce#Akon').should == '/Akon'
100
- Ajax.traditional_url_from_fragment('/Beyonce#/Akon').should == '/Akon'
101
- Ajax.traditional_url_from_fragment('/Beyonce#/Akon/').should == '/Akon/'
102
- end
103
-
104
- it "should handle no fragment" do
105
- Ajax.traditional_url_from_fragment('/Beyonce#/beyoncé').should == '/beyonc%C3%A9'
106
- Ajax.traditional_url_from_fragment('/#/red hot').should == '/red%20hot'
107
- end
108
-
109
- it "should handle special characters" do
110
- Ajax.traditional_url_from_fragment('/Beyonce#/Akon').should == '/Akon'
111
- end
112
-
113
- DOMAINS.each do |domain|
114
- it "should work for domain #{domain}" do
115
- Ajax.traditional_url_from_fragment("http://#{domain}/Beyonce/#playlists").should == "http://#{domain}/playlists"
116
- Ajax.traditional_url_from_fragment("http://#{domain}/Beyonce/#/playlists").should == "http://#{domain}/playlists"
117
- end
118
- end
119
- end
120
- end
121
-
@@ -1,52 +0,0 @@
1
- require 'spec_helper'
2
-
3
- include Ajax::Helpers::RequestHelper
4
-
5
- describe 'Ajax::Helpers::RequestHelpers' do
6
- describe 'set_header' do
7
- before :each do
8
- @headers = {}
9
- end
10
-
11
- it "should store headers as JSON" do
12
- set_header @headers, :tab, '#main .home_tab'
13
- get_header(@headers, :tab).should == '#main .home_tab'
14
- end
15
-
16
- it "should not fail on bad JSON" do
17
- @headers['Ajax-Info'] = 'invalid JSON!'
18
- get_header(@headers, :layout).should be_nil
19
-
20
- set_header(@headers, :layout, '')
21
- get_header(@headers, :layout).should == ''
22
- end
23
-
24
- it "should add headers" do
25
- set_header @headers, :tab, '#main .home_tab'
26
- get_header(@headers, :tab).should == '#main .home_tab'
27
- end
28
-
29
- it "should add assets" do
30
- set_header @headers, :assets, { :key => ['value'] }
31
- get_header(@headers, :assets).should == { 'key' => ['value'] }
32
- end
33
-
34
- it "should merge hashes" do
35
- set_header @headers, :assets, { :key1 => 'value1' }
36
- set_header @headers, :assets, { :key2 => 'value2' }
37
- get_header(@headers, :assets).should == { 'key1' => 'value1', 'key2' => 'value2' }
38
- end
39
-
40
- it "should concat arrays" do
41
- set_header @headers, :callbacks, ['one']
42
- set_header @headers, :callbacks, ['two']
43
- get_header(@headers, :callbacks).should == ['one', 'two']
44
- end
45
-
46
- it "should deep merge" do
47
- set_header @headers, :assets, { :key => ['value1'] }
48
- set_header @headers, :assets, { :key => ['value2'] }
49
- get_header(@headers, :assets).should == { 'key' => ['value1', 'value2'] }
50
- end
51
- end
52
- end
@@ -1,48 +0,0 @@
1
- require 'spec_helper'
2
- require 'fileutils'
3
-
4
- # Dummy Rails.root to tmp/
5
- TMP_DIR = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'tmp'))
6
- Rails = Class.new do
7
- def self.root
8
- TMP_DIR
9
- end
10
- end
11
-
12
- def verbose # silence the tasks
13
- false
14
- end
15
-
16
- require 'rake'
17
- load(File.join(Ajax.root, 'tasks', 'ajax_tasks.rake'))
18
-
19
- context 'task' do
20
- before :each do
21
- FileUtils.rm_r(TMP_DIR) if File.exists?(TMP_DIR)
22
- FileUtils.mkdir(TMP_DIR)
23
- end
24
-
25
- it "rails root should be tmp/" do
26
- Rails.root.should == TMP_DIR
27
- end
28
-
29
- context 'install' do
30
- it "should install files" do
31
- Rake::Task['ajax:install'].invoke
32
- INSTALL_FILES.each do |file|
33
- file_should_exist(File.join(Rails.root, file))
34
- end
35
- end
36
- end
37
-
38
- context 'update' do
39
- context 'javascript' do
40
- it "should update files" do
41
- Rake::Task['ajax:update:javascript'].invoke
42
- UPDATE_JAVASCRIPT_FILES.each do |file|
43
- file_should_exist(File.join(Rails.root, file))
44
- end
45
- end
46
- end
47
- end
48
- end
@@ -1,146 +0,0 @@
1
- require 'spec_helper'
2
- require 'uri'
3
- require 'ajax/spec/helpers'
4
-
5
- include Ajax::Spec::Helpers
6
-
7
- # Test the Rack::Ajax handling of urls according to our block from
8
- # <tt>config/initializers/ajax.rb</tt>
9
- #
10
- # Test Rack middleware using integration tests because the Spec controller tests
11
- # do not invoke Rack.
12
- context 'Rack::Ajax' do
13
- before :all do
14
- mock_ajax # Force a return from Rack::Ajax
15
- end
16
-
17
- after :all do
18
- unmock_ajax
19
- end
20
-
21
- context "XMLHttpRequest" do
22
- context "hashed url" do
23
- it "should rewrite GET request" do
24
- xhr(:get, '/?query1#/Beyonce?query2')
25
- should_rewrite_to('/Beyonce?query2')
26
- end
27
-
28
- it "should not modify POST" do
29
- xhr(:post, '/#/user_session/new?param1=1&param2=2')
30
- should_not_modify_request
31
- end
32
- end
33
-
34
- context "traditional url" do
35
- it "should not be modified" do
36
- xhr(:get, '/Beyonce')
37
- should_not_modify_request
38
- end
39
-
40
- it "should not be modified" do
41
- xhr(:post, '/user_session/new?param1=1&param2=2')
42
- should_not_modify_request
43
- end
44
- end
45
- end
46
-
47
- context "request for root url" do
48
- it "should not be modified" do
49
- get('/')
50
- should_not_modify_request
51
- end
52
-
53
- it "should not be modified" do
54
- get('/?query_string')
55
- should_not_modify_request
56
- end
57
-
58
- it "should be rewritten if it is hashed" do
59
- get('/?query1#/Beyonce?query2')
60
- should_rewrite_to('/Beyonce?query2')
61
- end
62
- end
63
-
64
- context "robot" do
65
- before :each do
66
- @user = login_robot_user
67
- end
68
-
69
- it "should not modify request for root" do
70
- get('/')
71
- should_not_modify_request
72
- end
73
-
74
- it "should not modify traditional requests" do
75
- get('/Beyonce')
76
- should_not_modify_request
77
- end
78
-
79
- context "request hashed" do
80
- context "non-root url" do
81
- it "should not modify the request" do
82
- get('/Akon/?query1#/Beyonce?query2')
83
- should_not_modify_request
84
- end
85
- end
86
-
87
- context "root url" do
88
- it "should rewrite to traditional url" do
89
- get('/#/Beyonce?query2')
90
- should_rewrite_to('/Beyonce?query2')
91
- end
92
- end
93
- end
94
- end
95
-
96
- context "regular user" do
97
- it "should not modify request for root" do
98
- get('/')
99
- should_not_modify_request
100
- end
101
-
102
- it "should ignore query string on root url" do
103
- get('/?query1#/Beyonce?query2')
104
- should_rewrite_to('/Beyonce?query2')
105
- end
106
-
107
- context "request hashed" do
108
- context "non-root url" do
109
- it "should redirect to hashed part at root" do
110
- get('/Akon/?query1#/Beyonce?query2')
111
- should_redirect_to('/#/Beyonce?query2')
112
- end
113
- end
114
-
115
- context "root url" do
116
- it "should rewrite to traditional url" do
117
- get('/#/Beyonce?query2')
118
- should_rewrite_to('/Beyonce?query2')
119
- end
120
- end
121
- end
122
-
123
- context "request traditional url" do
124
- it "should not be modified" do
125
- get('/')
126
- should_not_modify_request
127
- end
128
- it "should not be modified" do
129
- get('/?query_string')
130
- should_not_modify_request
131
- end
132
-
133
- it "should redirect GET request" do
134
- get('/Beyonce')
135
- should_redirect_to('/#/Beyonce')
136
- end
137
-
138
- it "should not modify non-GET request" do
139
- %w[post put delete].each do |method|
140
- send(method, '/')
141
- should_not_modify_request
142
- end
143
- end
144
- end
145
- end
146
- end