Archive 2018

October 15, 2018

When testing ActiveJob, jobs performed with SomeJob.perform_now will not show up in the performed_jobs test helper method.

August 30, 2018

Today I was attempting to validate that three variables all held the same value. My clever approach was:

a = 1
b = 1
c = nil

[a, b, c]

I expected that to return false. It was returning true.


Showing my reasoning, elementary math style:

[a, b, c]

# becomes =>

[1, 1, nil]

# becomes =>

[1, nil].one?

There are two values, right? Here’s my mistake. In my quest for object-oriented-message-sending-purity I interpreted one? to be about the size of the array. But reading the docs, I’m reminded it’s not a message about the size of the array. It’s a message that passes each item in the array to a block, and returns true if exactly one of those return values is truthy. Without an explicit block, the implicit block is the element itself. 1 is truty. nil is not, so yes, there is one truthy value.

What I really wanted is [1, nil].count == 1. In the end, I reverted to some obvious as day boolean logic of a == b && b == c

I’m glad I wrote a test for something so small, because this particular error in this particular place would have led to a substantial security hole.

Lesson learned: just because there’s a nicely named message that sounds right doesn’t mean it’s the message I want to send. Also, quit trying to be clever.


August 28, 2018

Basecamp triples down on server rendered HTML with StimulusJS. Having built a similar pattern when transitioning away from BatmanJS years ago, I really appreciate the refinement of the ideas here.

My only complaint about this project is that they didn’t name it Sprinkles. That would have been awesome.

July 11, 2018

At some point in time Rails added a nicety to ActionMailer that I’ve really appreciated. The nicety I mention is that an html formatted email will be automatically translated into a plaintext email counterpart that is not perfect, but passable when iterating on a blossoming application.

As our applications mature we’re upping our efforts on accessibilty. Within that effort, the automatically generated plaintext emails are being replaced by artisinal plaintext emails.

We’re good about writing tests, but our tests broke when we moved from providing the single part to providing multiple parts.

Today I rel-learned how to get to the different parts of the email when they’re being provided explicitly.

-assert_includes email.body.encoded, "some expected text"
+assert_includes email.html_part.body, "some expected text"
+assert_includes email.text_part.body, "some expected text"

Thanks again Stackoverflow.