FactoryBot allows a :class option to its factory definitions, to set the class to construct. However, this option is not...
After loading a staging dump into development, you might get an ActiveRecord::EnvironmentMismatchError when trying to replace the database (like...
If another session is accessing your database you are trying to reset or drop you might have seen the following...
Use return to return from a method. return accepts a value that will be the return value of the...
I frequently find myself needing a combination of group_by, count and sort for quick statistics. Here's a method...
before(:all) runs the block once before all of the examples. before(:each) runs the block once before each...
There are many approaches out there how you can import data from a legacy application to a new application. Here...
You should prefer native promises to jQuery's Deferreds. Native promises are much faster than their jQuery equivalent. Native promises...
Native promises have no methods to inspect their state. You can use the promiseState function below to check whether a...
Use Traim to build a RESTful API for your ActiveRecord models with very little code. Traim assumes your API resources...
Sometimes you add Paperclip image styles, sometimes you remove some. In order to only keep the files you actually need...
In the ruby shell (IRB) and rails console the return value of the previous command is saved in _ (underscore). This...
You can not use the hash_including argument matcher with a nested hash: describe 'user' do let(:user) { {id: 1...
ActiveRecord::RecordNotFound errors provide quite meaningful error messages that can provide some insight on application details. Consider the following:
This card will show you a cool way to define a class using Struct.new. A common usecase for Structs are...
If you use the Better Errors gem, you will sometimes notice that it can be very slow. This is because...
Shoulda Matchers don't provide canditional validations (validations with if: option). Here is how to write tests for the condition...
When using GROUP BY, MySQL now complains if the SELECT includes columns which are not part of the GROUP BY...
Nowadays it is fairly easy to intercept and modify mails globally before they are sent. All you have to do...
Rails supports time zones, but there are several pitfalls. Most importantly because Time.now and Time.current are completely different things and...
Webmocks hash_including is similar to RSpec::Mocks::ArgumentMatchers#hash_including. Be aware that hash_including (webmock v3.0.1) doesn't...
TLDR: Browser implementations of HTTP/2 push are horrible. You might end up with worse performance than without pushing. However, the...
Dump this method into your Ruby console to quickly print data in columns. This is helpful for e.g. comparing attributes...
Database connections are not thread-safe. That's why ActiveRecord uses a separate database connection for each thread.