shopify_app 5.0.2 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.gitignore +4 -1
  5. data/.travis.yml +9 -0
  6. data/CHANGELOG +12 -1
  7. data/README.md +73 -108
  8. data/Rakefile +0 -1
  9. data/app/controllers/sessions_controller.rb +3 -0
  10. data/app/views/sessions/new.html.erb +17 -0
  11. data/config/routes.rb +10 -0
  12. data/lib/generators/shopify_app/controllers/controllers_generator.rb +29 -0
  13. data/lib/generators/shopify_app/install/install_generator.rb +83 -0
  14. data/lib/generators/shopify_app/install/templates/embedded_app.html.erb +22 -0
  15. data/lib/generators/shopify_app/install/templates/home_controller.rb +11 -0
  16. data/lib/generators/shopify_app/install/templates/index.html.erb +12 -0
  17. data/lib/generators/shopify_app/install/templates/omniauth.rb +2 -0
  18. data/lib/generators/shopify_app/install/templates/shopify_app.rb +6 -0
  19. data/lib/generators/shopify_app/install/templates/shopify_app_ready_script.html +8 -0
  20. data/lib/generators/shopify_app/install/templates/shopify_provider.rb +11 -0
  21. data/lib/generators/shopify_app/{templates/config/initializers → install/templates}/shopify_session_repository.rb +3 -3
  22. data/lib/generators/shopify_app/routes/routes_generator.rb +31 -0
  23. data/lib/generators/shopify_app/routes/templates/routes.rb +7 -0
  24. data/lib/generators/shopify_app/shop_model/shop_model_generator.rb +42 -0
  25. data/lib/generators/shopify_app/shop_model/templates/db/migrate/create_shops.rb +15 -0
  26. data/lib/generators/shopify_app/shop_model/templates/session_storage.rb +16 -0
  27. data/lib/generators/shopify_app/shop_model/templates/shop.rb +3 -0
  28. data/lib/generators/shopify_app/shop_model/templates/shopify_session_repository.rb +7 -0
  29. data/lib/generators/shopify_app/shopify_app_generator.rb +10 -63
  30. data/lib/generators/shopify_app/views/views_generator.rb +29 -0
  31. data/lib/shopify_app.rb +14 -13
  32. data/lib/shopify_app/configuration.rb +26 -36
  33. data/lib/shopify_app/controller.rb +18 -0
  34. data/lib/shopify_app/engine.rb +5 -0
  35. data/lib/shopify_app/login_protection.rb +34 -32
  36. data/lib/shopify_app/sessions_controller.rb +64 -0
  37. data/lib/shopify_app/shop.rb +15 -0
  38. data/lib/shopify_app/shopify_session_repository.rb +23 -21
  39. data/lib/shopify_app/version.rb +1 -1
  40. data/shopify_app.gemspec +5 -10
  41. data/test/app_templates/app/controllers/application_controller.rb +2 -0
  42. data/test/app_templates/config/application.rb +24 -0
  43. data/test/app_templates/config/initializers/shopify_app.rb +6 -0
  44. data/test/app_templates/config/routes.rb +3 -0
  45. data/test/controllers/sessions_controller_test.rb +82 -0
  46. data/test/dummy/app/controllers/application_controller.rb +3 -0
  47. data/test/dummy/app/controllers/home_controller.rb +7 -0
  48. data/test/dummy/config.ru +4 -0
  49. data/test/dummy/config/application.rb +26 -0
  50. data/test/dummy/config/boot.rb +5 -0
  51. data/test/dummy/config/database.yml +25 -0
  52. data/test/dummy/config/environment.rb +5 -0
  53. data/test/dummy/config/environments/test.rb +42 -0
  54. data/test/dummy/config/initializers/shopify_app.rb +6 -0
  55. data/test/dummy/config/routes.rb +10 -0
  56. data/test/dummy/config/secrets.yml +17 -0
  57. data/test/generators/install_generator_test.rb +103 -0
  58. data/test/generators/routes_generator_test.rb +33 -0
  59. data/test/generators/shop_model_generator_test.rb +40 -0
  60. data/test/generators/shopify_app_generator.rb +15 -0
  61. data/test/generators/views_generator_test.rb +15 -0
  62. data/test/shopify_app/configuration_test.rb +17 -0
  63. data/test/{lib/shopify_app → shopify_app}/in_memory_session_store_test.rb +6 -6
  64. data/test/{lib/shopify_app → shopify_app}/login_protection_test.rb +10 -7
  65. data/test/shopify_app/shopify_session_repository_test.rb +73 -0
  66. data/test/support/generator_test_helpers.rb +29 -0
  67. data/test/test_helper.rb +11 -3
  68. metadata +79 -61
  69. metadata.gz.sig +0 -0
  70. data/install.rb +0 -25
  71. data/lib/generators/shopify_app/README +0 -23
  72. data/lib/generators/shopify_app/USAGE +0 -22
  73. data/lib/generators/shopify_app/templates/app/assets/images/favicon.png +0 -0
  74. data/lib/generators/shopify_app/templates/app/assets/images/grid-18px.png +0 -0
  75. data/lib/generators/shopify_app/templates/app/assets/images/shopify-114.png +0 -0
  76. data/lib/generators/shopify_app/templates/app/assets/images/shopify-57.png +0 -0
  77. data/lib/generators/shopify_app/templates/app/assets/images/shopify-72.png +0 -0
  78. data/lib/generators/shopify_app/templates/app/assets/images/shopify.png +0 -0
  79. data/lib/generators/shopify_app/templates/app/assets/javascripts/application.js +0 -15
  80. data/lib/generators/shopify_app/templates/app/assets/stylesheets/application.css +0 -10
  81. data/lib/generators/shopify_app/templates/app/assets/stylesheets/imports.css.less +0 -5
  82. data/lib/generators/shopify_app/templates/app/assets/stylesheets/shopify_app.css.scss +0 -150
  83. data/lib/generators/shopify_app/templates/app/assets/stylesheets/shopify_app_buttons.css.less +0 -77
  84. data/lib/generators/shopify_app/templates/app/controllers/application_controller.rb +0 -13
  85. data/lib/generators/shopify_app/templates/app/controllers/home_controller.rb +0 -18
  86. data/lib/generators/shopify_app/templates/app/controllers/sessions_controller.rb +0 -52
  87. data/lib/generators/shopify_app/templates/app/helpers/home_helper.rb +0 -9
  88. data/lib/generators/shopify_app/templates/app/helpers/login_helper.rb +0 -3
  89. data/lib/generators/shopify_app/templates/app/helpers/tabs_helper.rb +0 -11
  90. data/lib/generators/shopify_app/templates/app/views/home/design.html.erb +0 -3542
  91. data/lib/generators/shopify_app/templates/app/views/home/index.html.erb +0 -168
  92. data/lib/generators/shopify_app/templates/app/views/home/welcome.html.erb +0 -110
  93. data/lib/generators/shopify_app/templates/app/views/layouts/application.html.erb +0 -79
  94. data/lib/generators/shopify_app/templates/app/views/sessions/new.html.erb +0 -21
  95. data/lib/generators/shopify_app/templates/config/initializers/omniauth.rb +0 -14
  96. data/lib/generators/shopify_app/templates/config/initializers/rails_4_shim.rb +0 -1
  97. data/lib/generators/shopify_app/templates/public/404.html +0 -40
  98. data/lib/generators/shopify_app/templates/public/422.html +0 -40
  99. data/lib/generators/shopify_app/templates/public/500.html +0 -40
  100. data/lib/generators/shopify_app/templates/public/favicon.png +0 -0
  101. data/lib/generators/shopify_app/templates/public/shopify-114.png +0 -0
  102. data/lib/generators/shopify_app/templates/public/shopify-57.png +0 -0
  103. data/lib/generators/shopify_app/templates/public/shopify-72.png +0 -0
  104. data/lib/shopify_app/railtie.rb +0 -17
  105. data/test/config/development_config_file.yml +0 -8
  106. data/test/config/empty_config_file.yml +0 -1
  107. data/test/config/other_config_file.yml +0 -4
  108. data/test/config/shopify_app.yml +0 -4
  109. data/test/lib/shopify_app/configuration_test.rb +0 -91
  110. data/test/lib/shopify_app/shopify_session_repository_test.rb +0 -70
@@ -0,0 +1,5 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ #
7
+ default: &default
8
+ adapter: sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ development:
13
+ <<: *default
14
+ database: db/development.sqlite3
15
+
16
+ # Warning: The database defined as "test" will be erased and
17
+ # re-generated from your development database when you run "rake".
18
+ # Do not set this db to the same as development or production.
19
+ test:
20
+ <<: *default
21
+ database: db/test.sqlite3
22
+
23
+ production:
24
+ <<: *default
25
+ database: db/production.sqlite3
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!
@@ -0,0 +1,42 @@
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Do not eager load code on boot. This avoids loading your whole application
11
+ # just for the purpose of running a single test. If you are using a tool that
12
+ # preloads Rails for running tests, you may have to set it to true.
13
+ config.eager_load = false
14
+
15
+ # Configure static file server for tests with Cache-Control for performance.
16
+ config.serve_static_files = true
17
+ config.static_cache_control = 'public, max-age=3600'
18
+
19
+ # Show full error reports and disable caching.
20
+ config.consider_all_requests_local = true
21
+ config.action_controller.perform_caching = false
22
+
23
+ # Raise exceptions instead of rendering exception templates.
24
+ config.action_dispatch.show_exceptions = false
25
+
26
+ # Disable request forgery protection in test environment.
27
+ config.action_controller.allow_forgery_protection = false
28
+
29
+ # Tell Action Mailer not to deliver emails to the real world.
30
+ # The :test delivery method accumulates sent emails in the
31
+ # ActionMailer::Base.deliveries array.
32
+ config.action_mailer.delivery_method = :test
33
+
34
+ # Randomize the order test cases are executed.
35
+ config.active_support.test_order = :random
36
+
37
+ # Print deprecation notices to the stderr.
38
+ config.active_support.deprecation = :stderr
39
+
40
+ # Raises error for missing translations
41
+ # config.action_view.raise_on_missing_translations = true
42
+ end
@@ -0,0 +1,6 @@
1
+ ShopifyApp.configure do |config|
2
+ config.api_key = "key"
3
+ config.secret = "secret"
4
+ config.scope = 'read_orders, read_products'
5
+ config.embedded_app = true
6
+ end
@@ -0,0 +1,10 @@
1
+ Rails.application.routes.draw do
2
+ root to: 'home#index'
3
+
4
+ controller :sessions do
5
+ get 'login' => :new, :as => :login
6
+ post 'login' => :create, :as => :authenticate
7
+ get 'auth/shopify/callback' => :callback
8
+ get 'logout' => :destroy, :as => :logout
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key is used for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+
6
+ # Make sure the secret is at least 30 characters and all random,
7
+ # no regular words or you'll be exposed to dictionary attacks.
8
+ # You can use `rake secret` to generate a secure secret key.
9
+
10
+ # Make sure the secrets in this file are kept private
11
+ # if you're sharing your code publicly.
12
+
13
+ development:
14
+ secret_key_base: aa26a2ea3384f82ea5ae33b4d80fc49ea0cda260418cf65a9c54958d02c4eadfba56e9e26728ee6e339c7f00628f0451abd7f0b0b042f5695097ec8b86b4e135
15
+
16
+ test:
17
+ secret_key_base: ed1af7104003edfc9f3f55ff6eaa0bc0c4a70c240128ca9c33d2f19d3ac326f63944b40488ef87118b53174601ce488e1ae6075f7f6e18e7968755c6d9decefb
@@ -0,0 +1,103 @@
1
+ require 'test_helper'
2
+ require 'generators/shopify_app/install/install_generator'
3
+
4
+ class InstallGeneratorTest < Rails::Generators::TestCase
5
+ tests ShopifyApp::Generators::InstallGenerator
6
+ destination File.expand_path("../tmp", File.dirname(__FILE__))
7
+
8
+ setup do
9
+ prepare_destination
10
+ provide_existing_application_file
11
+ provide_existing_routes_file
12
+ provide_existing_application_controller
13
+ end
14
+
15
+ test "creates the ShopifyApp initializer" do
16
+ run_generator
17
+ assert_file "config/initializers/shopify_app.rb" do |shopify_app|
18
+ assert_match 'config.api_key = "<api_key>"', shopify_app
19
+ assert_match 'config.secret = "<secret>"', shopify_app
20
+ assert_match 'config.scope = "read_orders, read_products"', shopify_app
21
+ assert_match "config.embedded_app = true", shopify_app
22
+ end
23
+ end
24
+
25
+ test "creats and injects into omniauth initializer" do
26
+ run_generator
27
+ assert_file "config/initializers/omniauth.rb" do |omniauth|
28
+ assert_match "provider :shopify", omniauth
29
+ end
30
+ end
31
+
32
+ test "creates the default shopify_session_repository" do
33
+ run_generator
34
+ assert_file "config/initializers/shopify_session_repository.rb" do |file|
35
+ assert_match "ShopifyApp::SessionRepository.storage = InMemorySessionStore", file
36
+ end
37
+ end
38
+
39
+ test "adds the embedded app options to application.rb" do
40
+ run_generator
41
+ assert_file "config/application.rb" do |application|
42
+ assert_match "config.action_dispatch.default_headers.delete('X-Frame-Options')", application
43
+ assert_match "config.action_dispatch.default_headers['P3P'] = 'CP=\"Not used\"'", application
44
+ end
45
+ end
46
+
47
+ test "doesn't add embedd options if -embedded false" do
48
+ stub_embedded_false
49
+ run_generator
50
+ assert_file "config/application.rb" do |application|
51
+ refute_match "config.action_dispatch.default_headers.delete('X-Frame-Options')", application
52
+ refute_match "config.action_dispatch.default_headers['P3P'] = 'CP=\"Not used\"'", application
53
+ end
54
+ end
55
+
56
+ test "injects into application controller" do
57
+ run_generator
58
+ assert_file "app/controllers/application_controller.rb" do |controller|
59
+ assert_match " include ShopifyApp::Controller\n", controller
60
+ end
61
+ end
62
+
63
+ test "creates the embedded_app layout" do
64
+ run_generator
65
+ assert_file "app/views/layouts/embedded_app.html.erb"
66
+ end
67
+
68
+ test "creates the home controller" do
69
+ run_generator
70
+ assert_file "app/controllers/home_controller.rb"
71
+ end
72
+
73
+ test "creates the home index view with embedded options" do
74
+ run_generator
75
+ assert_file "app/views/home/index.html.erb" do |index|
76
+ assert_match "ShopifyApp.ready", index
77
+ end
78
+ end
79
+
80
+ test "creates the home index view with embedded false" do
81
+ stub_embedded_false
82
+ run_generator
83
+ assert_file "app/views/home/index.html.erb" do |index|
84
+ refute_match "ShopifyApp.ready", index
85
+ end
86
+ end
87
+
88
+ test "adds home route to routes" do
89
+ run_generator
90
+ assert_file "config/routes.rb" do |routes|
91
+ assert_match "root :to => 'home#index'", routes
92
+ end
93
+ end
94
+
95
+ private
96
+
97
+ def stub_embedded_false
98
+ ShopifyApp::Generators::InstallGenerator.any_instance.stubs(:opts).returns(
99
+ {embedded: 'false'}
100
+ )
101
+ end
102
+
103
+ end
@@ -0,0 +1,33 @@
1
+ require 'test_helper'
2
+ require 'generators/shopify_app/routes/routes_generator'
3
+
4
+ class ControllerGeneratorTest < Rails::Generators::TestCase
5
+ tests ShopifyApp::Generators::RoutesGenerator
6
+ destination File.expand_path("../tmp", File.dirname(__FILE__))
7
+
8
+ setup do
9
+ prepare_destination
10
+ provide_existing_routes_file
11
+ provide_existing_initializer_file
12
+ end
13
+
14
+ test "copies ShopifyApp routes to the host application" do
15
+ run_generator
16
+
17
+ assert_file "config/routes.rb" do |routes|
18
+ assert_match "get 'login' => :new, :as => :login", routes
19
+ assert_match "post 'login' => :create, :as => :authenticate", routes
20
+ assert_match "get 'auth/shopify/callback' => :callback", routes
21
+ assert_match "get 'logout' => :destroy, :as => :logout", routes
22
+ end
23
+ end
24
+
25
+ test "adds routes false to ShopifyApp initializer" do
26
+ run_generator
27
+
28
+ assert_file "config/initializers/shopify_app.rb" do |initializer|
29
+ assert_match "config.routes = false", initializer
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,40 @@
1
+ require 'test_helper'
2
+ require 'generators/shopify_app/shop_model/shop_model_generator'
3
+
4
+ class ShopModelGeneratorTest < Rails::Generators::TestCase
5
+ tests ShopifyApp::Generators::ShopModelGenerator
6
+ destination File.expand_path("../tmp", File.dirname(__FILE__))
7
+ setup :prepare_destination
8
+
9
+ test "create the shop model" do
10
+ run_generator
11
+ assert_file "app/models/shop.rb" do |shop|
12
+ assert_match "class Shop < ActiveRecord::Base", shop
13
+ assert_match "include ShopifyApp::Shop", shop
14
+ end
15
+ end
16
+
17
+ test "creates ShopModel migration" do
18
+ run_generator
19
+ assert_migration "db/migrate/create_shops.rb" do |migration|
20
+ assert_match "create_table :shops do |t|", migration
21
+ end
22
+ end
23
+
24
+ test "adds the session_storage model" do
25
+ run_generator
26
+ assert_file "app/models/session_storage.rb" do |session_storage|
27
+ assert_match "class SessionStorage", session_storage
28
+ assert_match "def self.store(session)", session_storage
29
+ assert_match " def self.retrieve(id)", session_storage
30
+ end
31
+ end
32
+
33
+ test "adds the shopify_session_repository initializer" do
34
+ run_generator
35
+ assert_file "config/initializers/shopify_session_repository.rb" do |file|
36
+ assert_match "ShopifyApp::SessionRepository.storage = SessionStorage", file
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,15 @@
1
+ require 'test_helper'
2
+ require 'generators/shopify_app/shopify_app_generator'
3
+
4
+ class ViewsGeneratorTest < Rails::Generators::TestCase
5
+ tests ShopifyApp::Generators::ViewsGenerator
6
+ destination File.expand_path("../tmp", File.dirname(__FILE__))
7
+ setup :prepare_destination
8
+
9
+ test "copies ShopifyApp views to the host application" do
10
+ run_generator
11
+ assert_directory "app/views"
12
+ assert_file "app/views/sessions/new.html.erb"
13
+ end
14
+
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'test_helper'
2
+ require 'generators/shopify_app/views/views_generator'
3
+
4
+ class ViewsGeneratorTest < Rails::Generators::TestCase
5
+ tests ShopifyApp::Generators::ViewsGenerator
6
+ destination File.expand_path("../tmp", File.dirname(__FILE__))
7
+ setup :prepare_destination
8
+
9
+ test "copies ShopifyApp views to the host application" do
10
+ run_generator
11
+ assert_directory "app/views"
12
+ assert_file "app/views/sessions/new.html.erb"
13
+ end
14
+
15
+ end
@@ -0,0 +1,17 @@
1
+ require 'test_helper'
2
+
3
+ class ConfigurationTest < ActiveSupport::TestCase
4
+
5
+ test "configure" do
6
+ ShopifyApp.configure do |config|
7
+ config.embedded_app = true
8
+ end
9
+
10
+ assert_equal true, ShopifyApp.configuration.embedded_app
11
+ end
12
+
13
+ test "routes enabled" do
14
+ assert_equal true, ShopifyApp.configuration.routes_enabled?
15
+ end
16
+
17
+ end
@@ -1,28 +1,28 @@
1
1
  require 'test_helper'
2
2
 
3
- class InMemorySessionStoreTest < Minitest::Test
4
- def teardown
3
+ class InMemorySessionStoreTest < ActiveSupport::TestCase
4
+ teardown do
5
5
  InMemorySessionStore.clear
6
6
  end
7
7
 
8
- def test_storing_a_session
8
+ test "storing a session" do
9
9
  uuid = InMemorySessionStore.store('something')
10
10
  assert_equal 'something', InMemorySessionStore.repo[uuid]
11
11
  end
12
12
 
13
- def test_retrieving_a_session
13
+ test "retrieving a session" do
14
14
  InMemorySessionStore.repo['abra'] = 'something'
15
15
  assert_equal 'something', InMemorySessionStore.retrieve('abra')
16
16
  end
17
17
 
18
- def test_clearing_the_store
18
+ test "clearing the store" do
19
19
  uuid = InMemorySessionStore.store('data')
20
20
  assert_equal 'data', InMemorySessionStore.retrieve(uuid)
21
21
  InMemorySessionStore.clear
22
22
  assert !InMemorySessionStore.retrieve(uuid), 'The sessions should have been removed'
23
23
  end
24
24
 
25
- def test_it_should_raise_when_the_environment_is_not_valid
25
+ test "it should raise when the environment is not valid" do
26
26
  Rails.env.stubs(:production?).returns(true)
27
27
  assert_raises InMemorySessionStore::EnvironmentError do
28
28
  InMemorySessionStore.store('data')
@@ -1,5 +1,6 @@
1
1
  require 'test_helper'
2
2
  require 'action_controller'
3
+ require 'action_controller/base'
3
4
 
4
5
  class LoginProtectionController < ActionController::Base
5
6
  include ShopifyApp::LoginProtection
@@ -13,11 +14,11 @@ end
13
14
  class LoginProtectionTest < ActionController::TestCase
14
15
  tests LoginProtectionController
15
16
 
16
- def setup
17
- ShopifySessionRepository.storage = InMemorySessionStore
17
+ setup do
18
+ ShopifyApp::SessionRepository.storage = InMemorySessionStore
18
19
  end
19
20
 
20
- def test_calling_shop_session_returns_nil_when_session_is_nil
21
+ test "calling shop session returns nil when session is nil" do
21
22
  with_application_test_routes do
22
23
  session[:shopify] = nil
23
24
  get :index
@@ -25,25 +26,27 @@ class LoginProtectionTest < ActionController::TestCase
25
26
  end
26
27
  end
27
28
 
28
- def test_calling_shop_session_retreives_session_from_storage
29
+ test "calling shop session retreives session from storage" do
29
30
  with_application_test_routes do
30
31
  session[:shopify] = "foobar"
31
32
  get :index
32
- ShopifySessionRepository.expects(:retrieve).returns(session).once
33
+ ShopifyApp::SessionRepository.expects(:retrieve).returns(session).once
33
34
  assert @controller.shop_session
34
35
  end
35
36
  end
36
37
 
37
- def test_shop_session_is_memoized_and_does_not_retreive_session_twice
38
+ test "shop session is memoized and does not retreive session twice" do
38
39
  with_application_test_routes do
39
40
  session[:shopify] = "foobar"
40
41
  get :index
41
- ShopifySessionRepository.expects(:retrieve).returns(session).once
42
+ ShopifyApp::SessionRepository.expects(:retrieve).returns(session).once
42
43
  assert @controller.shop_session
43
44
  assert @controller.shop_session
44
45
  end
45
46
  end
46
47
 
48
+ private
49
+
47
50
  def with_application_test_routes
48
51
  with_routing do |set|
49
52
  set.draw do
@@ -0,0 +1,73 @@
1
+ require 'test_helper'
2
+
3
+ class TestSessionStore
4
+ attr_reader :storage
5
+
6
+ def initialize
7
+ @storage = []
8
+ end
9
+
10
+ def retrieve(id)
11
+ storage[id]
12
+ end
13
+
14
+ def store(session)
15
+ id = storage.length
16
+ storage[id] = session
17
+ id
18
+ end
19
+ end
20
+
21
+ class TestSessionStoreClass
22
+ def self.store(session)
23
+ end
24
+
25
+ def self.retrieve(id)
26
+ end
27
+ end
28
+
29
+ class ShopifySessionRepositoryTest < ActiveSupport::TestCase
30
+ attr_reader :session_store, :session
31
+
32
+ setup do
33
+ @session_store = TestSessionStore.new
34
+ @session = ShopifyAPI::Session.new('shop.myshopify.com', 'abracadabra')
35
+ ShopifyApp::SessionRepository.storage = session_store
36
+ end
37
+
38
+ teardown do
39
+ ShopifyApp::SessionRepository.storage = nil
40
+ end
41
+
42
+ test "adding a session to the repository" do
43
+ assert_equal 0, ShopifyApp::SessionRepository.store(session)
44
+ assert_equal session, session_store.retrieve(0)
45
+ end
46
+
47
+ test "retrieving a session from the repository" do
48
+ session_store.storage[9] = session
49
+ assert_equal session, ShopifyApp::SessionRepository.retrieve(9)
50
+ end
51
+
52
+ test "retrieving a session for an id that does not exist" do
53
+ ShopifyApp::SessionRepository.store(session)
54
+ assert !ShopifyApp::SessionRepository.retrieve(100), "The session with id 100 should not exist in the Repository"
55
+ end
56
+
57
+ test "retrieving a session for a misconfigured shops repository" do
58
+ ShopifyApp::SessionRepository.storage = nil
59
+ assert_raises ShopifyApp::SessionRepository::ConfigurationError do
60
+ ShopifyApp::SessionRepository.retrieve(0)
61
+ end
62
+
63
+ assert_raises ShopifyApp::SessionRepository::ConfigurationError do
64
+ ShopifyApp::SessionRepository.store(session)
65
+ end
66
+ end
67
+
68
+ test "accepts a string and constantizes it" do
69
+ ShopifyApp::SessionRepository.storage = 'TestSessionStoreClass'
70
+ assert_equal TestSessionStoreClass, ShopifyApp::SessionRepository.storage
71
+ end
72
+
73
+ end