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!
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.