diff --git a/.byebug_history b/.byebug_history new file mode 100644 index 000000000..0c11aad38 --- /dev/null +++ b/.byebug_history @@ -0,0 +1,5 @@ +exit +config[:inline].present? +config[:job].present? +config +next diff --git a/lib/shopify_app/sessions_concern.rb b/lib/shopify_app/sessions_concern.rb index 765ca9679..25f512cb1 100644 --- a/lib/shopify_app/sessions_concern.rb +++ b/lib/shopify_app/sessions_concern.rb @@ -91,7 +91,7 @@ def return_address def perform_after_authenticate_job config = ShopifyApp.configuration.after_authenticate_job - return unless config && config[:job].present? && config[:inline].present? + return unless config && config[:job].present? && config[:inline].in?([true, false]) if config[:inline] config[:job].perform_now(shop_domain: session[:shopify_domain]) diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb index 31fca152e..3bcfbe030 100644 --- a/test/controllers/sessions_controller_test.rb +++ b/test/controllers/sessions_controller_test.rb @@ -1,5 +1,11 @@ require 'test_helper' +module Shopify + class AfterAuthenticateJob < ActiveJob::Base + def perform; end + end +end + module ShopifyApp class SessionsControllerTest < ActionController::TestCase @@ -149,6 +155,51 @@ class SessionsControllerTest < ActionController::TestCase assert_equal 'Cerrar sesiĆ³n', flash[:notice] end + test "#callback calls #perform_after_authenticate_job inline when inline is true" do + ShopifyApp.configure do |config| + config.after_authenticate_job = { job: Shopify::AfterAuthenticateJob, inline: true } + end + + Shopify::AfterAuthenticateJob.expects(:perform_now) + + mock_shopify_omniauth + get :callback, params: { shop: 'shop' } + end + + test "#callback calls #perform_after_authenticate_job asynchronously when inline is false" do + ShopifyApp.configure do |config| + config.after_authenticate_job = { job: Shopify::AfterAuthenticateJob, inline: false } + end + + Shopify::AfterAuthenticateJob.expects(:perform_later) + + mock_shopify_omniauth + get :callback, params: { shop: 'shop' } + end + + test "#callback doesn't call #perform_after_authenticate_job if job is nil" do + ShopifyApp.configure do |config| + config.after_authenticate_job = { job: nil, inline: false } + end + + Shopify::AfterAuthenticateJob.expects(:perform_later).never + + mock_shopify_omniauth + get :callback, params: { shop: 'shop' } + end + + test "#callback doesn't call #perform_after_authenticate_job if inline is nil" do + ShopifyApp.configure do |config| + config.after_authenticate_job = { job: Shopify::AfterAuthenticateJob, inline: nil } + end + + Shopify::AfterAuthenticateJob.expects(:perform_later).never + Shopify::AfterAuthenticateJob.expects(:perform_now).never + + mock_shopify_omniauth + get :callback, params: { shop: 'shop' } + end + private def mock_shopify_omniauth