Member-only story

Omniauth integration testing with Rails 6 Shopify App

Phil Girard
1 min readJul 23, 2020

--

In Rails 6, ActiveSupport::TestCase is deprecated in favor of ActionDispatch::IntegrationTest. This means that you can no longer change the cookies or the session in a test before making a HTTP query (DHH, the founder of Rails, supported this change). This can create lots of problems when you try to bypass authentification in integration tests.

Omniauth is a widely used OAuth library that happen to be used in the Shopify App gem that I am using to develop a Shopify app. Omniauth’s wiki has general instructions on how to bypass its authentification in test mode. In this post I will show how this apply to a Shopify app.

First add this code in test_helper.rb

Then, when you want to simulate a logged in Shop you just need to use this helper before hand. Here is an example in a controller integration test.

** Be extra careful to not add a parameter “shop” in the hash you send as POST param, because it is verified in Shopify’s Omniauth and will redirect to login page if it does not match the shop’s domain. (ex: do not do “{shop: @shop, …}”)[ref. ShopifyApp::login_protection.rb L71]

--

--

Phil Girard
Phil Girard

Responses (1)