rspec-given is a very lightweight testing extension by Jim Weirich. It provides Given/When/Then syntax for rspec tests, to help provide some of the problem modeling of cucumber without having to write a bunch of regular expressions to translate them into actual code.
Given and When provide a fairly decent way of separating the purpose of the various
begin blocks. (plus I learned about Given!/let! reading the code) I found I didn’t use Then so much, because I’ve been using a very subject-oriented style and “it should” reads better than “Then should”
Some of the pages are feeling a little slower than I might like. Some of that is no-doubt spin-up time because I’ve got a very infrequently accessed Heroku application. I tried hooking up the basic New Relic monitoring plugin. Adding it on Heroku was extremely easy – they take care of installing and configuring the gem on the serve side. However, so far it’s not terribly enlightening – everything is dwarfed by request queuing time, which I’m taking to be dyno spin-up. I’d probably need heavier traffic to get any significant data.
I’ve got a list of rails things to check out some day. One of them was listed as “slow scrooge”. There is a project called scrooge, although it’s now recommending slim_scrooge. The idea is to automatically filter out unused fields from select statements. I haven’t installed slim_scrooge yet (don’t want to do too much at once) but I did cut down one query that really only needed a single value.
Rails Best Practices
Another item on my list was Rails Best Practices, a website of code tips. Perhaps more interestingly, a few of them have been encoded into a gem that hunts down violations of the advice. Several were niggling things, such as trailing whitespace. But, I learned about say_with_time for migrations, query attributes (
model.attribute?), and got a reminder to add a few indexes. It also called out the use of the tweet fields, so I finally extracted a wrapper class to put my own names on things.
Getting Styled – over and over and over again
Rails partials are a way to break up views into multiple files. One way to use partials involves having a partial for one item that can instantiated once for each instance in some list. I had one such partial, along with a related stylesheet. It’s possible to add case-specific items with
content_for(:head) (assuming that you have
I finally knuckled down and created a set of helpers that used set union to manage the list of required files, and include them once. A tricky point here is that content_for block gets delayed, but the surrounding code executes immediately, so any testing of the content (e.g. the list of files) has to be inside the block. Code placed in the head area of the layout will execute before the rest of the view has rendered and added it’s annotations.
Baby got backend
The other big experiment was ActiveAdmin It’s not the first rails admin generator I’ve heard of (and might even be built on another) but it certainly had the best website. ActiveAdmin provides a set of scaffold-like views. Since it’s an admin interface, it doesn’t require the kind of customization the front end interface does. That said, there is considerable configuration in terms of list display, as well as show and form views, and a fully custom dashboard.
I only ran into two difficulties setting up ActiveAdmin. The first was that it uses Devise, and Devise’s
sign_in method collided with my own. I renamed mine to
account_in, which though not so elegant better states what it is doing. The other was running Heroku; it appears ActiveAdmin live-generates SASS, so I had to dig a Heroku configuration adjustment for ActiveAdmin out of an issue tracker.
The last step was actually user-visible – I installed Twitter’s @Anywhere to auto-link usernames. Twitter’s frequent syndication to various websites has drawn out a number of useful tools (I’m already using Intents) that make adding many the little niceties to Siggnal too easy to pass up.