Skip to content

Commit

Permalink
Merge pull request #848 from Shopify/use_string_const_setting_session…
Browse files Browse the repository at this point in the history
…_repository

Use a string when setting session_repository
  • Loading branch information
shawnfrench committed Jan 8, 2020
2 parents cdcb1c1 + 0ee39ae commit bb99916
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ provider :shopify,
per_user_permissions: true

# In the `shopify_app.rb` initializer:
config.session_repository = User
config.session_repository = 'User'
config.per_user_tokens = true
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
config.embedded_app = <%= embedded_app? %>
config.after_authenticate_job = false
config.api_version = "<%= @api_version %>"
config.session_repository = ShopifyApp::InMemorySessionStore
config.session_repository = 'ShopifyApp::InMemorySessionStore'
end

# ShopifyApp::Utils.fetch_known_api_versions # Uncomment to fetch known api versions from shopify servers on boot
Expand Down
11 changes: 3 additions & 8 deletions lib/shopify_app/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Configuration
attr_accessor :webhooks
attr_accessor :scripttags
attr_accessor :after_authenticate_job
attr_accessor :session_repository
attr_reader :session_repository
attr_accessor :per_user_tokens
alias_method :per_user_tokens?, :per_user_tokens
attr_accessor :api_version
Expand Down Expand Up @@ -50,13 +50,8 @@ def login_url
end

def session_repository=(klass)
if Rails.configuration.cache_classes
ShopifyApp::SessionRepository.storage = klass
else
ActiveSupport::Reloader.to_prepare do
ShopifyApp::SessionRepository.storage = klass
end
end
@session_repository = klass
ShopifyApp::SessionRepository.storage = klass
end

def has_webhooks?
Expand Down
2 changes: 1 addition & 1 deletion test/app_templates/config/initializers/shopify_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
config.secret = ENV['SHOPIFY_API_SECRET']
config.scope = 'read_orders, read_products'
config.embedded_app = true
config.session_repository = ShopifyApp::InMemorySessionStore
config.session_repository = 'ShopifyApp::InMemorySessionStore'
end
4 changes: 2 additions & 2 deletions test/generators/install_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class InstallGeneratorTest < Rails::Generators::TestCase
assert_match 'config.scope = "read_orders, write_products"', shopify_app
assert_match 'config.embedded_app = true', shopify_app
assert_match 'config.api_version = "unstable"', shopify_app
assert_match 'config.session_repository = ShopifyApp::InMemorySessionStore', shopify_app
assert_match "config.session_repository = 'ShopifyApp::InMemorySessionStore'", shopify_app
end
end

Expand All @@ -54,7 +54,7 @@ class InstallGeneratorTest < Rails::Generators::TestCase
assert_match "config.secret = ENV['SHOPIFY_API_SECRET']", shopify_app
assert_match 'config.scope = "read_orders, write_products"', shopify_app
assert_match 'config.embedded_app = true', shopify_app
assert_match 'config.session_repository = ShopifyApp::InMemorySessionStore', shopify_app
assert_match "config.session_repository = 'ShopifyApp::InMemorySessionStore'", shopify_app
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/generators/shop_model_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ShopModelGeneratorTest < Rails::Generators::TestCase
test "updates the shopify_app initializer" do
run_generator
assert_file "config/initializers/shopify_app.rb" do |file|
assert_match "config.session_repository = Shop", file
assert_match "config.session_repository = 'Shop'", file
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/generators/user_model_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class UserModelGeneratorTest < Rails::Generators::TestCase
test "updates the shopify_app initializer to use User to store session" do
run_generator
assert_file "config/initializers/shopify_app.rb" do |file|
assert_match "config.session_repository = User", file
assert_match "config.session_repository = 'User'", file
end
end

Expand Down
17 changes: 17 additions & 0 deletions test/shopify_app/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,21 @@ class ConfigurationTest < ActiveSupport::TestCase
assert_equal "Shopify::Webhooks::TestJob", ShopifyApp::WebhooksController.new.send(:webhook_job_klass_name, 'test')
end

test "can set session_repository with a string" do
ShopifyApp.configure do |config|
config.session_repository = 'ShopifyApp::InMemorySessionStore'
end

assert_equal 'ShopifyApp::InMemorySessionStore', ShopifyApp.configuration.session_repository
assert_equal ShopifyApp::InMemorySessionStore, ShopifyApp::SessionRepository.storage
end

test "can set session_repository with a class" do
ShopifyApp.configure do |config|
config.session_repository = ShopifyApp::InMemorySessionStore
end

assert_equal ShopifyApp::InMemorySessionStore, ShopifyApp.configuration.session_repository
assert_equal ShopifyApp::InMemorySessionStore, ShopifyApp::SessionRepository.storage
end
end

0 comments on commit bb99916

Please sign in to comment.