#[1]gnikyt feed [2]gnikyt / Code ramblings [3]Ty King [4]About[5]Github[6]LinkedIn[7]CV[8]RSS Testing with shopify_app / [9]Logo of shopify [10]Logo of ruby [11]Logo of rails [12]shopify_app is a great Gem to quickly build a Shopify App with Rails. It handles all the verifications, authorizations, webhook, and more; leaving you to focus on developing your app. This post is to serve as a quick tip on how to unit-test your app with the Gem. Other than the install page, most likely your app will require a shop to be logged in for all routes. shopify_app, upon installation will create a fixture file in test/fixtures/shops.yml of your Rails application. Inspecting it you will see it's filled with one shop, regular-shop.myshopify.com, and a simple token. When running bundle exec rake test (after migrations are done for a test environment of course), it will populate the shop database table with the fixture data in shop.yml. Now that we have a shop we can "log into", let's create a support module for the unit tests. Create a file called shopify_session_support.rb inside test/support. # test/support/shopify_session_support.rb module ShopifySessionSupport # Make this module concernable extend ActiveSupport::Concern included do # On include, tell TestCase to use this setup block setup do # Set the shop to the test shop from fixtures # The key is `:shopify` and `:shopify_domain` which shopify_app needs # See: https://github.com/Shopify/shopify_app/blob/c7e50247a72a52b1d1e4d90 09ba997196a64e7e8/lib/shopify_app/login_protection.rb#L22 session[:shopify] = shops(:regular_shop).id session[:shopify_domain] = shops(:regular_shop).shopify_domain end end end Next, include your new support module in test_helper.rb before class ActiveSupport::TestCase with: # Include support modules Dir[Rails.root.join('test/support/**/*.rb')].each { |f| require f } Finally, in any of your controller tests where you require an authenticated shop, simply add include ShopifySessionSupport to your class as such: # ... class ImageControllerTest < ActionController::TestCase include ShopifySessionSupport # ... end Running bundle exec rake test should now pass your tests with the shop. Anchors * [1] [13]github.com/Shopify/shopify_app /^ Appendix This post is 9 years old and may contain outdated information. Copyright under [14]CC-4.0. Available in the following alternative formats: [15]MD / [16]TXT / [17]PDF * * * * * * * * References 1. /rss.xml 2. file:/// 3. file:///about 4. file:///about 5. https://github.com/gnikyt 6. https://linkedin.com/in/gnikyt 7. file:///assets/files/cv.pdf 8. file:///rss.xml 9. file:///category/shopify 10. file:///category/ruby 11. file:///category/rails 12. https://github.com/Shopify/shopify_app 13. https://github.com/Shopify/shopify_app 14. https://creativecommons.org/licenses/by/4.0/ 15. file:///testing-with-shopify-app/index.md 16. file:///testing-with-shopify-app/index.txt 17. file:///tmp/lynxXXXXAeSw7G/L11662-8021TMP.html