Testing extensions

Solidus extensions should work with and be tested against multiple versions of Solidus. This article outlines how Solidus and the solidusio-contrib extensions are tested. Consider it a model as you develop your own Solidus extensions.


We usually test our extensions on TravisCI and make use of their build matrix feature to test across multiple Solidus versions. We also test against multiple databases: MySQL and PostgreSQL.

Solidus extensions should be tested across all versions of Solidus that have not reached End of Life including the master branch.

Here's an example .travis.yml testing versions 2.2 through 2.7 and the master branch:

      language: ruby
  - 2.3.1
    - SOLIDUS_BRANCH=v2.2 DB=postgres
    - SOLIDUS_BRANCH=v2.3 DB=postgres
    - SOLIDUS_BRANCH=v2.4 DB=postgres
    - SOLIDUS_BRANCH=v2.5 DB=postgres
    - SOLIDUS_BRANCH=v2.6 DB=postgres
    - SOLIDUS_BRANCH=v2.7 DB=postgres
    - SOLIDUS_BRANCH=master DB=postgres
    - SOLIDUS_BRANCH=v2.2 DB=mysql
    - SOLIDUS_BRANCH=v2.3 DB=mysql
    - SOLIDUS_BRANCH=v2.4 DB=mysql
    - SOLIDUS_BRANCH=v2.5 DB=mysql
    - SOLIDUS_BRANCH=v2.6 DB=mysql
    - SOLIDUS_BRANCH=v2.7 DB=mysql
    - SOLIDUS_BRANCH=master DB=mysql



To use the versions of Solidus specified from the TravisCI build matrix, we need to use those environment variables in the Gemfile. Here's an example:

      source "https://rubygems.org"

branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
gem "solidus", github: "solidusio/solidus", branch: branch

if branch == 'master' || branch >= "v2.0"
  gem "rails-controller-testing", group: :test
  gem "rails", '~> 4.2.7' # workaround for bundler resolution issue
  gem "rails_test_params_backport", group: :test

gem 'pg'
gem 'mysql2'




Directly inheriting from ActiveRecord::Migration is deprecated in Rails 5.0. Starting in 5.1, this is an error.

To be able to support both Rails 5.1 and Rails 4.2 from the same extension, we use a helper from the solidus_support gem.

Here is the processing for using the helper:

  1. Add a dependency on solidus_support in the .gemspec.
      s.add_dependency 'solidus_core', ['>= 1.1', '< 3']
s.add_dependency 'solidus_support'

  1. Require solidus_support from the gem's /lib/your_gem.rb file.
      require 'solidus_core'
require 'solidus_support'

  1. Replace all occurrences of ActiveRecord::Migration in the gem. This would be in all of your db/migrate/* migration files.
      class MyAwesomeMigration < SolidusSupport::Migration[4.2]


You can replace all of the ActiveRecord::Migration occurrences automatically with sed:

      sed -i 's/ActiveRecord::Migration/SolidusSupport::Migration[4.2]/' db/migrate/*.rb



You can see a list of Solidus extensions and their test suite statuses at extensions.solidus.io .

If you'd like to have your extension added, join the Solidus Slack team let us know in the #solidus channel .

Rails 5 request specs

In Rails 5, the syntax for making requests in tests has changed:

      # Pre-Rails 5
get :users, {id: '123'}, { user_id: 1 }

# Rails 5
get :users, params: { id: '123'}, session: { user_id: 1 }


To allow both of these in a test suite side by side, we make use of the rails_test_params_backport gem.

This can be fixed automatically using the rails5-spec-converter gem.


Solidus is an open source platform supported by the community. We encourage everyone using Solius to contribute back to the documentation and the code.

If you’re interested in contributing to the docs, get started with the contributing guidelines. If you see something that needs fixing and can’t do it yourself, please send us an email.