Skip to content

Testing extensions against multiple Solidus versions

Benjamin Willems edited this page Mar 21, 2018 · 10 revisions

TravisCI

We usually test our extensions on TravisCI and make use of their build matrix feature to test across multiple Solidus version (as well as both MySQL and PostgreSQL databases).

Here's an example .travis.yml testing versions 1.4 through 2.1 and master:

language: ruby
rvm:
  - 2.3.1
env:
  matrix:
    - SOLIDUS_BRANCH=v1.4 DB=postgres
    - SOLIDUS_BRANCH=v2.0 DB=postgres
    - SOLIDUS_BRANCH=v2.1 DB=postgres
    - SOLIDUS_BRANCH=master DB=postgres
    - SOLIDUS_BRANCH=v1.4 DB=mysql
    - SOLIDUS_BRANCH=v2.0 DB=mysql
    - SOLIDUS_BRANCH=v2.1 DB=mysql
    - SOLIDUS_BRANCH=master DB=mysql

Gemfile

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
else
  gem "rails", '~> 4.2.7' # workaround for bundler resolution issue
  gem "rails_test_params_backport", group: :test
end

gem 'pg'
gem 'mysql2'

gemspec

Migrations

Rails 5.0 deprecates inheriting directly from ActiveRecord::Migration. Doing so is an error under Rails 5.1. To be able to support both Rails 5.1 and Rails 4.2 from the same extension, we use a helper from solidus_support.

  1. Add a dependency on solidus_support from the .gemspec
s.add_dependency 'solidus_core', ['>= 1.1', '< 3']
s.add_dependency 'solidus_support'
  1. Require solidus_support from the gem's top-level .rb file
require 'solidus_core'
require 'solidus_support'
  1. Replace all occurrences of ActiveRecord::Migration
class MyAwesomeMigration < SolidusSupport::Migration[4.2]
  # ...
end

This can be done automatically with

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

extensions.solidus.io

extensions.solidus.io provide an easy to read matrix of the status of various extensions across multiple versions. It's generated from a simple script.

If you'd like to have an extension added, please bring it up in the #solidus Slack.

Rails 5 request specs

Rails 5 changed the syntax for making requests in tests from

get :users, {id: '123'}, { user_id: 1 }

to

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.