Ad

Testing Controllers Of A Rails Shopify App

- 1 answer

I have a Rails app created through shopify_app gem and I'm trying to test my controllers using rspec. Since all my controllers inherit from ShopifyApp::AuthenticatedController, all testing requests get blocked by authentication, so I can't test my controllers.

I've seen a few suggestions of bypassing the authentication by stubbing the session like so:

session[:shopify] = ShopifyAPI::Session.new(domain)

But that still doesn't work for me. The requests seems to get redirected (response code 302).

I'm sure a lot of people stumbled upon this. But after a day of googling I couldn't find a working solution. Any help is appreciated!

Thanks!

Ad

Answer

The session object needs to be stubbed from @request, like so:

@request.session[:shopify] = shop.id
@request.session[:shopify_domain] = shop.shopify_domain

I received a detailed answer in this post on the Shopify forum.

Ad
source: stackoverflow.com
Ad