Dave Schweisguth in a Bottle

How many meanings of that can you think of?

Specialist: A pattern for carving up fat ActiveRecord models

leave a comment »

All roads to a well-factored Rails application lead from fat controllers through fat models. Where to head next is less well mapped. Many patterns move non-model code into separate layers. When you’ve gone down that path as far as you can, your models can still be weighed down with code that would belong in a model — if there weren’t so much of it. Specialist is a pattern that makes it surprisingly easy to slice up your fat models into lean modules.

Read the rest of this entry »

Advertisement

Written by dschweisguth

August 23, 2016 at 14:21

Posted in Programming, Rails, Ruby

Using and testing automatic accessors and virtual attributes of ActiveRecord models

leave a comment »

An ordinary ActiveRecord model object has an attribute for each column in its table. Each attribute has a reader method and a writer method. However, ActiveRecord also defines accessors on the fly to hold non-column query results. Also, sometimes it’s useful to define a new attribute, one not corresponding to a column or even to a field in a query result. These different kinds of extra attributes can interfere with one another, making them tricky to use and test. The best defense is to understand all of them well before using any of them. Let’s have a look.

Read the rest of this entry »

Written by dschweisguth

August 11, 2016 at 09:44

Posted in Programming, Rails, Ruby, Testing

What I did on my working vacation, 2016 edition

leave a comment »

Indiegogo’s long-lived Rails application used many gems, causing issues in development and deployment. I wrote a couple of posts on Indiegogo’s engineering blog about solving those issues:

Also, I helped my colleague Mike Luby with How we get coverage on parallelized test builds.

Written by dschweisguth

April 18, 2016 at 05:19

Posted in Programming, Rails, Ruby

More scattered sightings

leave a comment »

For the foreseeable future, Indiegogo’s engineering blog is the place to look for posts on Ruby, Rails and the like by my colleagues and by me.

Written by dschweisguth

November 24, 2014 at 09:32

Posted in Uncategorized

Controlling database usage in RSpec and factory_girl, part 2: association strategy and unstubbed queries

leave a comment »

An important part of testing a Rails application is establishing the correct relationship between the specs of each layer and the database. To correctly test the layer that they test, some types of specs (model and feature specs) should run against the database; other types should not. As well as ensuring correctness, policing database usage optimizes performance: tests that use the database are slower.

This post, part 2 in a two-part series, describes two measures that you can take to minimize incorrect and unnecessary database usage in RSpec specs that use factory_girl.

Read the rest of this entry »

Written by dschweisguth

June 21, 2014 at 15:45

Posted in Programming, Rails, Ruby, Testing

Controlling database usage in RSpec and factory_girl, part 1: Choosing and allowing appropriate strategies

leave a comment »

When testing each layer of a Rails application, it’s important to create test model instances in the right way for that layer. Some specs need model instances that have been saved in the database, or that appear to have been; others need instances that have not. It’s also important to not use the database when you don’t have to, because every use makes your tests take a little bit longer.

This post, part 1 in a two-part series, lays out the appropriate use of factory_girl in specs of each layer of Rails, and gives a way to enforce that usage.

Read the rest of this entry »

Written by dschweisguth

June 21, 2014 at 12:27

Posted in Programming, Rails, Ruby, Testing

Dark corners of unit-testing lore

leave a comment »

The software community’s understanding of developer testing (unit testing, acceptance testing, etc.) has come a long way since “Extreme Programming Explained” and “Refactoring” and JUnit got everyone interested almost fifteen years ago. There was a time when developers argued whether unit testing was valuable (never mind TDD); now it’s taught in code camps as an essential skill.

But some testing techniques have remained out of the mainstream, for whatever reason. A couple of them came up on Stack Overflow recently and I was inspired to give long answers. Whether or not these techniques eventually become part of standard practice, they’re interesting to know about and possibly useful in shaping your thinking about mainstream practices.

Read the rest of this entry »

Written by dschweisguth

June 3, 2014 at 14:13

Posted in Java, Programming, Testing

How I spent my working vacation

leave a comment »

While at Fandor (still the finest independent and international film streaming service) I had almost no time for personal projects, but I did manage to write a few blog posts on Fandor’s late engineering blog, “Behind the Fan Door” (as my Fandor doppelgänger, fandave). These fit the best with my own interests and the rest of this blog:

Also, the idea of data testing is interesting, although its context in that post is less so. And, for completeness, here’s every single one.

[2017 update: “Behind the Fan Door” is gone, so I’ve replaced links to it with links to archived copies on my own site. Links in the copies are, unfortunately, mostly broken.]

Written by dschweisguth

March 2, 2014 at 08:31

Posted in Programming, Testing

Scattered sightings

leave a comment »

While waiting for another message in a bottle to drift your way from this blog, you might want to check out Behind the Fan Door, where Fandor‘s engineering team — of which I am one — relates our experiences with Ruby and Rails and other things while bringing you fine independent and international films on line.

Written by dschweisguth

September 12, 2011 at 20:05

Posted in Uncategorized

Essential reading for the modern programmer

leave a comment »

Software is a uniquely plastic medium, and the practice of software development changes constantly and quickly. All software engineers are self-taught; even the college-trained learn most of their trade on the job. Though we learn by doing and by watching others and studying their work, I’ve found that reading has consistently been the most powerful way I can understand what I’m doing and learn new methods. So I’m constantly recommending to colleagues one book or another, hoping that they’ll get from it the same value that I did.

To make that easier, here’s a list I’ve been meaning to put together for a long time, of books and other writings that have been essential in shaping my practice of programming. Well-read programmers will find few surprises here, but can be sure that any of these that they’ve missed will be worth their time.

Read the rest of this entry »

Written by dschweisguth

July 16, 2011 at 23:04

Posted in Programming