-
Notifications
You must be signed in to change notification settings - Fork 699
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #432 from Shopify/add_after_authenticate_job_option
Add after authenticate job option
- Loading branch information
Showing
12 changed files
with
181 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'rails/generators/base' | ||
|
||
module ShopifyApp | ||
module Generators | ||
class AddAfterAuthenticateJobGenerator < Rails::Generators::Base | ||
source_root File.expand_path('../templates', __FILE__) | ||
|
||
hook_for :test_framework, as: :job, in: :rails do |instance, generator| | ||
instance.invoke generator, [ instance.send(:job_file_name) ] | ||
end | ||
|
||
def init_after_authenticate_config | ||
initializer = load_initializer | ||
|
||
after_authenticate_job_config = " config.after_authenticate_job = { job: Shopify::AfterAuthenticateJob, inline: false }\n" | ||
|
||
inject_into_file( | ||
'config/initializers/shopify_app.rb', | ||
after_authenticate_job_config, | ||
before: 'end' | ||
) | ||
|
||
unless initializer.include?(after_authenticate_job_config) | ||
shell.say "Error adding after_authneticate_job to config. Add this line manually: #{after_authenticate_job_config}", :red | ||
end | ||
end | ||
|
||
def add_after_authenticate_job | ||
template 'after_authenticate_job.rb', "app/jobs/#{job_file_name}_job.rb" | ||
end | ||
|
||
private | ||
|
||
def load_initializer | ||
File.read(File.join(destination_root, 'config/initializers/shopify_app.rb')) | ||
end | ||
|
||
def job_file_name | ||
'shopify/after_authenticate' | ||
end | ||
end | ||
end | ||
end |
10 changes: 10 additions & 0 deletions
10
lib/generators/shopify_app/add_after_authenticate_job/templates/after_authenticate_job.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Shopify | ||
class AfterAuthenticateJob < ActiveJob::Base | ||
def perform(shop_domain:) | ||
shop = Shop.find_by(shopify_domain: shop_domain) | ||
|
||
shop.with_shopify_session do | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module ShopifyApp | ||
VERSION = '7.3.0' | ||
VERSION = '7.4.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
test/generators/add_after_authenticate_job_generator_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'test_helper' | ||
require 'generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator' | ||
|
||
class AddAfterAuthenticateJobGeneratorTest < Rails::Generators::TestCase | ||
tests ShopifyApp::Generators::AddAfterAuthenticateJobGenerator | ||
destination File.expand_path("../tmp", File.dirname(__FILE__)) | ||
|
||
setup do | ||
prepare_destination | ||
end | ||
|
||
test 'adds enable_after_authenticate_actions config' do | ||
provide_existing_initializer_file | ||
|
||
run_generator | ||
|
||
assert_file "config/initializers/shopify_app.rb" do |config| | ||
assert_match 'config.after_authenticate_job = { job: Shopify::AfterAuthenticateJob, inline: false }', config | ||
end | ||
end | ||
|
||
test "adds the after_authenticate job" do | ||
provide_existing_initializer_file | ||
|
||
run_generator | ||
|
||
assert_directory "app/jobs/shopify" | ||
assert_file "app/jobs/shopify/after_authenticate_job.rb" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters