

Rails Tip : When You Are Testing Model Files without a Database Table Delete Fix...
source link: https://fuzzyblog.io/blog/rails/2022/07/20/rails-tip-when-you-are-testing-model-files-without-a-database-table-delete-fixtures-file.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Rails Tip : When You Are Testing Model Files without a Database Table Delete Fixtures File
Jul 20, 2022
I generate a lot of models without ActiveRecord backing. The reason for this is I try and follow a fairly functional style of Ruby coding where I use class methods. The reason I use models for this:
- I don't know what to call them other than a model
- The models directly is auto loaded so I can refresh it with reload! in Rails console
My normal process for this:
- rails g foo
- Delete the migration
- Delete the "< …" at the top i.e. the inherits from ActiveRecord stff; exact syntax varies from Rails version to Rails version
Today I hit this error when running a test and it puzzled me:
Error:
VolumeCommonTest#test_it_should_have_the_right_values_for_cubic_feet_of_water:
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "volume_commons" does not exist
LINE 9: WHERE a.attrelid = '"volume_commons"'::regclass
This actually took me a bit to figure out. Here's the tldr:
- It was coming from bin/rails test test/models/volume_common.rb
- It was the result of the test runner trying to load the fixture file.
The reason this was surprising was that I normally customize each Rails project with ThoughtBot's FactoryBot gem and this time I forgot. FactoryBot suppresses fixture file creation but since I screwed up, it was there and tried to get loaded into a missing table.
And, yes, the error is mine since I didn't read it well but at times like these I wish for a gem called abusive_error messages which sees "PG::UndefinedTable" and shouts out something like:
Yo! Hoser! Where be da database table ?
Ah if there were only infinite time to craft the software tools we really want …
Posted In: #rails #software_testing #flow_analytics
</article
Recommend
-
8
So You Want to Delete Temp Files - An Excursion into Software Engineering Suckitude May 9, 2019 So today was a day of epic software engineering failure. Let's consider, just for a second, this string of commit messages...
-
11
Linux Tip - Find All Files Older than 10 Days and Delete Them May 9, 2019 It is easy to forget at times just how powerful simple Linux shell commands here. Here’s one I used recently that finds all files in a...
-
9
Service objects as a way of testing Rails apps (without factory_girl)
-
7
Conversation Copy link Member ...
-
9
Find and delete files older than n days in LinuxIn this guide, we’ll look at how to Delete files older than n days in Linux. The most common use case for this is deleting rotated logs which are older than a certain number of days or removing...
-
5
Hello! RC took a few weeks ago, and it’s back now! I’m batching these posts a few days at a time, so here’s what happened on Tuesday. deployed docker-compose to production On Monday I set up a dev environment with Docker Compo...
-
12
Create, Edit, and Delete Arrows Shapes in PDF Files with Ease in WPFArrows are significant design elements. They serve as visual cues that guide and direct your users’ attention to related information and action...
-
11
-
7
For a very long time in Rails, it was not possible to combine delete statements with GROUP_BY and HAVING queries. It does seem like something that should have been supported out of the box, but unfortunately was overlooked — until now!
-
4
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and p...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK