[LRUG] Best practices for javascript in Rails apps

Ian Petzer ianpetzer at gmail.com
Wed Jul 17 05:29:32 PDT 2013


Hey Tim,

I wrote a blog post<http://ianpetzer.wordpress.com/2013/06/14/getting-started-with-integration-testing-ember-js-using-ember-testing-and-qunit-rails/>a
while ago on integration testing an Ember.js application running on a
Rails back-end.

Although it is specific to Ember.js, it utilises the
qunit-rails<https://github.com/frodsan/qunit-rails>gem under the hood

You can use that gem to create tests that will actually interact with the
output (HTML DOM + Javascript) of your application.

It is not opinionated about how you organise your JS code, only caring
about the actual output. Within the tests, you can click links and interact
with your page or interrogate the DOM using jQuery / CSS matchers to make
sure that the output conforms to your expectations.

Once cool little feature is that when you load up the tests in your
browser, you can actually see your app being driven through the paces.  For
example the tests for the app in my blog
post<http://emberjsbooks.herokuapp.com/qunit>





On Wed, Jul 17, 2013 at 2:13 PM, Tim Cowlishaw <tim at timcowlishaw.co.uk>wrote:

> Hi all,
>
> I've just finished working on the first rails app I've started from
> scratch in ages, and, took the opportunity to apply some of the ideas
> from Matt Wynne's Hexagonal Rails talk and Avdi Grimm's Objects on
> Rails book, in the process.
>
> I've been really happy with the result - I've been able to make
> changes with more confidence, and ship new features faster than I have
> taking  a more rails-y approach to application architecture, and my
> test coverage is vastly better.
>
> Whoever, there's a rather nasty skeleton in the
> "app/assets/javascript" closet in my app, as, while I'm aware of the
> proliferation of javascript testing frameworks and tools, and
> libraries for doing client-side models, data-binding, etc, I'm really
> not sure how best to structure my javascript code in order to take
> advantage of them (apart from throwing out the idea of server
> generated views entirely, and writing a thick-client js app which
> talks to an API, which I'm not keen on, as I'm a boring old
> stick-in-the-mud who likes things on the web to have proper URLs)
>
> Therefore, has anyone got any tips or tricks for writing maintainable,
> testable, well-factored javascript as part of a rails application
> which has reasonably complex client-side behaviour, but isn't a
> one-page app? Links to talks / blogposts / example codebases also
> gratefully appreciated!
>
> Cheers,
>
> Tim
> _______________________________________________
> 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/20130717/575c1b2d/attachment-0003.html>


More information about the Chat mailing list