View
Linked contentRepeats

How to let passenger restart after deployment with capistrano

Phusion Passenger changed the way how it gets restarted several times. Through the project's history, these all were valid:

  • touch tmp/restart.txt
  • sudo passenger-config restart-app /path/to/app
  • passenger-config restart-app /path/to/app

You should not need to know which one to use. Instead, the capistrano-passenger gem will choose the appropriate restart mechanism automatically based on your installed the passenger version.

Installation

  1. Add to your Gemfile:

    gem 'capistr...
    

Migrate gem tests from Travis CI to Github Actions with gemika

We currently test most of our gems on Travis CI, but want to migrate those tests to Github Actions. This is a step-by-step guide on how to do this.

Note that this guide requires the gem to use gemika.

  1. Go to a new "ci" branch:
    git checkout -b ci
    
  2. Update gemika to version >= 0.5.0.
  3. Have gemika generate a Github Actions workflow definition by running
    mkdir -p .github/workflows; bundle exec rake gemika:generate_github_actions_workflow > .github/workflows/test.yml
    

...

Installing old versions of mysql2 on Ubuntu 20.04+

On some of our older projects, we use the mysql2 gem. Unfortunately, versions 0.2.x (required for Rails 2.3) and versions 0.3.x (required for Rails 3.2) can no longer be installed on Ubuntu 20.04. Trying this either leads to errors when compiling the native extension, or a segfaults when using it.

For Rails 4.2, mysql2 version 0.4.10 seems to work okay.

To install it, you have to switch the mysql2 gem to our fork. In your Gemfile, change mysql2 to either

gem 'mysql2', :git =>'https://github.com/ma...
Repeats

How to fill in multiple lines in a textarea with cucumber

If you want to fill in textareas with multiple lines of text (containing line breaks) you can use Cucumber's docstrings:

And I fill in "Comment" with:

"""
This is a long comment.
With multiple lines.

And paragraphs.
"""

The step definition is part of the spreewald gem

VCR: Alternative way of mocking remote APIs

If you need to test interaction with a remote API, check out the VCR gem as an alternative to Webmock or stubbing hell.

The idea behind VCR is that is performs real HTTP requests and logs the interaction in a .yml file. When you run the test again, requests and responses are stubbed from the log and the test can run offline.

It's a great way to mock network requests to an external service without going through the pain of logg...

Auto-destruct in 32 days

Geordi 4.2.0 released

We released a new version of our gem geordi

4.2.0 2020-10-02

Compatible changes

  • Add auto_update_chromedriver as global setting option to automatically update chromedriver before cucumber
    tests, if Chrome and chromedriver versions don't match.
  • Dump command: Add support for multiple databases
  • Add Ruby 2.7 to list of supported Ruby versions
  • Fix #115: geordi cucumber --modified command, that corrupted filenames like:
    No such file or directory tures/pages.feature
    
  • Avoi...
Auto-destruct in 32 days

Spreewald 2.9, 2.99 and 3.0.0 released

Versions 2.9.0, 2.99.0 and 3.0.0 of our gem Spreewald have been released.

2.9.0: Rework email steps

  • The step an email should have been sent with: does now support wildcards (* at the end of a line to ignore the rest of the line, * as single character in a line to ignore multiple lines). The step also has better error messages if an email could not be found.
  • The step show me the emails got an option to display only the email headers. Additionally, a new step `show me the email( header)?s...

Rails: How to restore a postgres dump from the past

It sometimes happen that a database dump, that would want to insert into your development database, does not match the current schema of the database. This often happens when you have an old dump, but your current setup is up to date with the the master.

Hint: In most cases it is sufficient to delete and recreate the local database in order to import the dump. If any problems occur, proceed as follows:

1. Figure out the original migration status of the dumpfile

  • Convert your dump to plaintext: psql some.dump > some.dump.plain
  • ...
Auto-destruct in 35 days

QueryDiet 0.7.0 released

We released a new version of our gem QueryDiet.

0.7.0 2020-09-24

Compatible changes

  • Added: CSP support for query diet widget (#23)
  • Added the CHANGELOG file.

You can pass whether to use a nonce for style and script tags.
Note that the key must be a symbol like in the example below, otherwise it defaults to false.

<%= query_diet_widget(nonce: true) if Rails.env.development? %>

In your content security policy initializer of...

Auto-destruct in 31 days

Cucumber Factory 2.3.0 and 2.3.1 released

Versions 2.3.0 and 2.3.1 of our gem Cucumber Factory have been released.

2.3.0

  • Added a step to add file objects to a model:
    Given there is a user with the avatar file:"path/to/avatar.jpg"
    
    Both single and double quotes are supported.

2.3.1

  • Lowered the priority of all steps in this gem to avoid issues with overlapping steps.

How to implement simple queue limiting/throttling for Sidekiq

The sidekiq-rate-limiter gem allows rate-limiting Sidekiq jobs and works like a charm. However, it needs to be integrated on a per-worker basis.

If you want to limit a whole queue instead, and if your requirements are simple enough, you can do it via a Sidekiq middleware yourself.

Here is an example that limits concurrency of the "mailers" queue to 1. It uses a database mutex via the [with_advisory_lock](https://github.com/ClosureTree/wit...

VCR and the webdrivers gem

If you're using the webdrivers gem and VCR together, depending on your configuration, VCR will yell at you regulary.
The webdrivers gem tries to update your webdrivers on your local machine. To do so, it checks the internet for newer versions, firing an HTTP-request to e.g. https://chromedriver.storage.googleapis.com

You can "fix" this in multiple ways:

  1. Update your drivers on your machine with
    RAILS_ENV=test rake webdrivers:chromedriver:update

  2. Ignore the driver update-URL in your ...

Auto-destruct in 23 days

Cucumber Factory 2.2.0 released

Version 2.2.0 of our gem Cucumber Factory has been released.

  • A step was added that allows modifying existing records with a similar syntax to creating new records:
    (Given "Bob" is a user)
      And "Bob" has the email "foo@bar.com" and is subscribed
    
    • This step will also work with doc strings or tables:
    (Given "Bob" is a user)
      And the user above has these attributes:
      | name  | Bob         |
      | email | foo@bar.com | 
    
Linked content

Pagy

Pagy is a gem for pagination.
They make some bold claims:

Pagy is the ultimate pagination gem that outperforms the others in each and every benchmark and comparison.

Maybe this is worth trying out.

Linked content

Workflow: How to use a key management service to encrypt passwords in the database

This is an extract from the linked article. It shows an approach on how to implement encrypted passwords with the AWS Key Management Service (KMS).

For most applications it's enough to use a hashed password with a salt (e.g. the gem devise defaults to this).

Upon password creation

  1. Generate hash as hash of password + salt.

  2. Encrypt the hash with a public key from KMS (you can store the public key in your server code).

  3. In your database sto...

How to fix: Rails query logs always show lib/active_record/log_subscriber.rb as source

Rails 5.2+ supports "verbose query logs" where it shows the source of a query in the application log.
Normally, it looks like this:

  User Load (0.5ms)  SELECT "users".* FROM "users" WHERE ...
  ↳ app/controllers/users_controller.rb:42:in `load_users'

However, you may encounter ActiveRecord's LogSubscriber as the source for all/most queries which is not helpful at all:

  User Load (0.5ms)  SELECT "users".* FROM "users" WHERE ...
  ↳ activerecord (6.0.3.3) lib/active_record/log_subscriber.rb:100:in `debug'

While th...

Repeats

Rails < 5: How to get after_commit callbacks fired in tests

If you use transactional_fixtures or the database_cleaner gem with strategy :transaction, after_commit callbacks will not be fired in your tests.

Rails 5

Rails 5 has a fix for this issue and no further action is needed.

Rails 3+

Add the gem test_after_commit to your test group in the Gemfile and you are done. You don't need to change the database strategy to deletion (which might...

Repeats

Selenium: How to debug the communication with the Webdriver API

Selenium allows you to log all requests to the Webdriver API. Therefore add the following line to e.g. features/support/selenium.rb:

Selenium::WebDriver.logger.level = :debug

If you want to see the output of the driver itself, here is an example on how to enable Chromedriver logging.

Example output

When you run a command like bundle exec cucumber --format=pretty features/some.feature you will see the API communication before the step is printed (here you see the log for the step And I press "Save").

...

This website uses short-lived cookies to improve usability.
Accept or learn more