[LRUG] Best practises for jasmine-jquery testing of rails views

JB Steadman jb at pivotallabs.com
Mon Jul 22 17:13:03 PDT 2013


On Mon, Jul 22, 2013 at 8:25 PM, Sam Joseph <tansaku at gmail.com> wrote:

>
> 2) similarly: if i have N distinct pages in my app and each has its own
> quite distinct JS bits, given that the best practice is to combine all the
> JS and load it all at once and cache it (asset pipeline), is there a best
> practice for 'inhibiting' setup functions ($(document).ready()) that don't
> correspond to the 'current' page?  (ie, your setup function might be trying
> to bind the '#foo' element, but that element only exists on a particular
> page; do you let the setup function silently fail, or do you arrange to
> only run that particular setup function if you're on the page containing
> #foo, or do you condition the function so that it gracefuly fails in the
> absence of #foo?)
>
>
It can be helpful in many ways to encode the controller name and action
name as classes in a high-level element such as <body>, giving you, for
example:

<body class='orders new'>

You can use this to scope css as well as javascript. Continuing your
example, you might have:

$(document).ready(function() {

  $('body.orders.new #foo').bind(...);

});

On pages aside from orders new, the function does not fail per se, but it
has no effect. You can observe your app to determine whether accumulation
of such functions has any meaningful performance impact.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20130723/d3297140/attachment-0003.html>


More information about the Chat mailing list