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

Artan Sinani artisinani at gmail.com
Mon Jul 22 17:55:08 PDT 2013


I also have used the classes on `body` element, as it gives quite a good
context, especially for hiding/showing elements on specific pages.

As for the JS, I wouldn't fail the jQuery objects silently, as you may
create many of these unnecessarily. Even though they fail, if you have
cached them, they still occupy memory. I'd instantiate the page specific JS
classes in their respective pages. This way, you still load the JS all at
once via the asset pipeline, but use as much browser memory as needed by
the page.

Best,
Artan
lugolabs.com



On 23 July 2013 01:39, JB Steadman <jb at pivotallabs.com> wrote:

> If you decide to try this approach, consider setting the body class using
> a method exposed by your controllers, like this:
>
> <body class="<%= body_class %>">
>
> The default implementation can return "#{controller_name} #{action_name}",
> while subclasses have fine-grained, situation-specific control. For
> example, if there's a form error creating a new order, forcing a re-render
> of the new template, you probably don't want "orders create" as the body
> class, but rather "orders new". You can also easily add other classes aside
> from just controller name and action name.
>
>
> On Tue, Jul 23, 2013 at 1:13 AM, JB Steadman <jb at pivotallabs.com> wrote:
>
>> 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.
>>
>
>
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20130723/11d0180b/attachment.html>


More information about the Chat mailing list