Photo-1 Photo-2 Photo-3 Photo-4 Photo-5 Photo-6



Full-time web developer. Part-time smart ass.

I'm Brent Collier.

After a year and a half as an engineer on Twitter's Trust & Safety team, I'm looking for my next gig. Contact me if you know of something interesting.


Engine Controller Spec: No Route Matches... WTF?

Posted on 10/09/2015

I was working on a mountable Rails engine, and just as I began writing some controller specs I hit a small road block...

1) MyEngine::PostsController POST create creates a post
   Failure/Error: post :create
     No route matches {:action=>"create", :controller=>"my_engine/posts"}
   # ./spec/controllers/posts_controller_spec.rb:29:in `block (3 levels) in <top (required)>'
   # ./spec/spec_helper.rb:40:in `block (3 levels) in <top (required)>'
   # ./spec/spec_helper.rb:39:in `block (2 levels) in <top (required)>'

My controller spec looked something like this:

describe MyEngine::PostsController, type: :controller do
  context 'POST create' do
    it 'creates a post' do
      post :create
      expect(response.status).to eq(200)

After much cursing and googling, I discovered the solution was to add the following line to your controller spec:

routes { MyEngine::Engine.routes }

Once that was in place, everything worked as expected.


Got bit by an empty string in yaml

Posted on 02/26/2015

I had added a new key to the secrets.yml file in our Rails application. The value of that key was derived from an ENV variable within an erb tag. In order to avoid a nil value when the ENV variable isn't present, which it may or may not be depending on the particular environment, I used the fetch method like so...

foo: <%= ENV.fetch('MY_VAR_NAME', '') %>

My intent was to have foo default to an empty string, but sadly it didn't. Once the erb was evaluated, it resulted in yaml that looked like this...


And of course, when that yaml is loaded, foo becomes nil. Not what I wanted. Instead, my yaml needed to look like this...

foo: ""

So I updated the secrets.yml file to look like this...

foo: <%= ENV.fetch('MY_VAR_NAME', '""') %>

And everything worked as expected.


Postgres Post Yosemite

Posted on 11/10/2014

After updating OS X from Mavericks to Yosemite, I noticed that Postgres was no longer running. I checked to see if there was a running Postgress process...

ps aux | grep postgres
bcollier        19790   0.0  0.0  2432772    580 s007  R+   10:03AM   0:00.00 grep postgres

Nope. Ok, let's try to start it up...

pg_ctl -D /usr/local/var/postgres/ -l /usr/local/var/postgres/server.log start
server starting

It said, "server starting" but there was still no running process. So I checked the log...

less /usr/local/var/postgres/server.log

And I saw this repeated over and over...

FATAL:  could not open directory "pg_tblspc": No such file or directory
FATAL:  could not open directory "pg_tblspc": No such file or directory
FATAL:  could not open directory "pg_tblspc": No such file or directory
FATAL:  could not open directory "pg_tblspc": No such file or directory

Hmm, ok. A quick Google search revealed this Stack Overflow answer which explained that the postgres directory contains a number of empty, but necessary directories, and that the Yosemite installer may have failed to copy them over due to their emptiness.

So I created those directories...

mkdir -p /usr/local/var/postgres/pg_tblspc
mkdir -p /usr/local/var/postgres/pg_twophase
mkdir -p /usr/local/var/postgres/pg_stat_tmp

Tried to start it again, but with no luck. So I reset the transaction logs, as seen in this previous post...

pg_resetxlog /usr/local/var/postgres
Transaction log reset

Then, finally, Postgres was able to successfully start.


TypeError: expected Array (got String) for param WTF

Posted on 10/17/2014

I was in the middle of completely overhauling some backend code, while attempting to reuse as much as possible of the semi-complex frontend. The form and js were basically the same, but I had to do some minor modifications to make it jive with the new ActiveRecord model that was backing it.

I had made what appeared to be the necessary changes, so why not give it a try? It's not like you can write tests for this stuff, right? RIGHT? I mean, it's javascript, client-side code, c'mon...

Anyway, I clicked the submit button on my form, expecting to watch the dev log for my incoming request, expecting to verify that my input params were correct, expecting to see something. But I didn't.

Blank terminal window


In the browser there was a flash message with an error. That means there was definitely a request. But nothing in the dev log. How does that happen?

I checked the Network tab in the Chrome dev tools. There it was, a 500. Looking at the response, I could see the problem...

It had blown up in rack, not even making it to the Rails app. That explained why there was nothing in the dev log.

It was complaining about the source input, but what was the problem? I double-checked the input name...

<input name="source[]" type="text">

...made sure that it was the right format to return an array. It was. What the hell was going on? Finally, after searching through the view template, I realized the problem. There was another input - a hidden one, with the same name.

<input name="source" type="hidden">

That was it. Two inputs, both named "source". One a string, and the other an array. Fuck me.

I renamed one of the inputs, and BOOM, everything worked. Life goes on.