CucumberFactory 1.11 lets you use FactoryGirl traits
If you have FactoryGirl traits Show archive.org snapshot like this:
factory :movie do
title 'Sunshine'
year 2007
trait :vintage do
year 1951
end
trait :moody do
title 'Interstellar'
end
end
You can now call them from Cucumber Factory Show archive.org snapshot like this:
Given there is a movie (vintage, moody)
Related cards:
Get the initial username which you used to login to your Linux system
If you need the initial user which you used to login to your Linux system or the time when you login you can do:
whoami
One purpose of this could be the .bashrc to show different Bash Prompts for root to different users:
if [ $(whoa...
cucumber_factory 1.14 lets you set array fields, has_many associations, numbers without quotes
Setting array columns
When using PostgreSQL array columns, you can set an array attribute to a value with square brackets:
Given there is a movie with th...
Why you can't use timezone codes like "PST" or "BST" for Time objects
Rails' ActiveSupport::TimeWithZone
objects have both a timezone code and offset, e.g. Thu, 28 Mar 2019 16:00:00 CET +01:00
. Ruby's stdlib TZInfo
also has time zones, but with different identifiers.
Unfortunately, not all timezone codes can b...
What edge_rider offers you
edge_rider is Power tools for ActiveRecord relations (scopes). Please note that some of the functions edge_rider provides have native implementations in newer rails versions.
Useful in applications
Relation#traverse_association(*names)
---...
has_defaults 0.4.2 lets you use dagger lambdas
Starting with has_defaults
0.4.2, default values that are lambdas are no longer called with the current object as argument, but instance_exec
'd instead.
This means you can now use dagger lambdas like this:
has_defaults :full_name => ...
Rails and Postgres: How to test if your index is used as expected
This is a small example on how you can check if your Postgres index can be used by a specific query in you Rails application. For more complex execution plans it might still be a good idea to use the same path of proof.
1. Identify the...
Using ActiveRecord with threads might use more database connections than you think
Database connections are not thread-safe. That's why ActiveRecord uses a separate database connection for each thread.
For instance, the following code uses 3 database connections:
3.times do
Thread.new do
User.first # first databa...
Testing shared traits or modules without repeating yourself
When two classes implement the same behavior (methods, callbacks, etc.), you should extract that behavior into a trait or module. This card describes how to test that extracted behavior without repeating y...
Postgres: DISTINCT ON lets you select only one record per ordered attribute(s) for each group
-
To retrieve only unique combinations of the selected attributes: You can omit rows, where all selected columns are equal with the
DISTINCT
statement. - To retrieve the group wise maximum of certain columns: You can keep only one record fo...
MySQL will not use indexes if you query the wrong data type
When MySQL refuses to use your index, you can do a number of things wrong. One of them might be conditions with improper data types.
An example
For example, let's assume you have a users
table with an email
field (varchar
) which is index...