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

Sam Joseph tansaku at gmail.com
Wed Jul 24 11:51:18 PDT 2013


JB, Mark, Artan,

Thanks so much for the advice - much appreciated.

JB, regarding the jasmine fixtures issue, is the approach you blogged 
about back in 2010 still the best approach?

http://pivotallabs.com/javascriptspecs-bind-reality/

Many thanks in advance
CHEERS> SAM

On 23/07/2013 01:39, JB Steadman 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 newtemplate, 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 
> <mailto:jb at pivotallabs.com>> wrote:
>
>     On Mon, Jul 22, 2013 at 8:25 PM, Sam Joseph <tansaku at gmail.com
>     <mailto: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.
>
>


-- 
Technical blog: http://linklens.blogspot.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20130724/ffc404c6/attachment-0003.html>


More information about the Chat mailing list