A not so august August
I took over a new codebase at the start of the month. Yay! Well, it was for about the first day. The codebase has the highest WTF Factor™ I have come across. I have literally used up my expletives quota in the last 4 weeks. Part of the reason why rails is so easy to pickup is its “convention over configuration”. Once you’ve picked it up, you can usually jump into any rails codebase and be immediately at home. Each project will usually break that convention in some way, but as long as enough care is taken, a new dev can be onboarded very quickly. This one, this one is special and not in a good way.
The repo README? Never got an update after rails new
. Nice, we get to setup blind! But at least there’s a Dockerfile, no docker-compose file though.
Which of course was updated never, still runs as the root user and does some apt-key, gpg magic to install nodejs and yarn. That wasn’t going to be much use.
Luckily I had a project with docker files I had updated recently. Copied those over then tried to build the image, over and over and …
Lesson learnt - before install, bundler processes all gems in Gemfile, even those in
--without
ed groups
I kept running into a missing gem error. The gem in question is a local gem - under lib/
- which was of course not available to the particular build step.
What threw me for a loop was that the gem was listed in an :omit
group, which was explicitly omitted from install with a bundle config --local without 'production omit'
.
Wish I could say I took less than an hour before I figured out what bundler was doing.
The solution? Wrapping the line in the Gemfile with a check for if the folder exists. Hacky, but image built and on to the next challenge.
I created the database, ran migrations, loaded the seeds and built the assets. All good. Then I ran the server, and checked the seeds file for the development user logins and nothing! Not a deal breaker, just need to register. Even better to get a feel of the process a user follows to get started.
I filled in the registration form, hit submit and 500. Jumped to the logs and WTF! A network error? How? Why? Yes my internet had dropped but, what? I checked where the error was ocurring and I immediately knew this code was going to be a pain to work with. The plan, attached to the default subscription on an account was being fetched from the payment provider! That’s despite having a plans model and plans being the only objects created in the seeds file. If I was smarter, I would have quit the project there and then!
Tests? Hah! There was an error on running rake test
, and I don’t mean an error on a test case! The test_helper could not even load.
Hopes of upgrading from rails 7.0 quickly evaporated. If you’re the type to learn a codebase through tests, you feel my pain.
The last batch of model tests were written in 2022. The only other tests are those generated by rails.
Light controllers? Yeah, no! If they were any heavier, there would be a shift in the earth’s rotation axis. And as if all that computation is not enough, we’re literally doing math in the views!
To be continued…