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 against multiple Solidus versions and databases: MySQL and PostgreSQL. We use a CircleCI Orb to re-use and maintain a single configuration that will be executed against all Solidus extensions.
This Orb will take care of testing extensions against all versions of Solidus
that have not reached
End of Life
including the master
branch.
You can find an example .circleci/config.yml
file
here
.
It runs specs against all supported versions, databases and setups a weekly nightly build to be sure the extension works even when it has not been updated for a while since Solidus could change in the meantime.
To use the versions of Solidus specified from the CircleCI configuration,
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
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:
solidus_support
in the .gemspec
.
s.add_dependency 'solidus_core', ['>= 1.1', '< 3']
s.add_dependency 'solidus_support'
solidus_support
from the gem's /lib/your_gem.rb
file.
require 'solidus_core'
require 'solidus_support'
ActiveRecord::Migration
in the gem. This would
be in all of your db/migrate/*
migration files.
class MyAwesomeMigration < SolidusSupport::Migration[4.2]
...
end
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 solidus.io/extensions .
If you'd like to have your extension added, join the Solidus Slack team let us know in the #solidus channel .
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 Solidus 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.