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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.gitignore +4 -1
- data/.travis.yml +9 -0
- data/CHANGELOG +12 -1
- data/README.md +73 -108
- data/Rakefile +0 -1
- data/app/controllers/sessions_controller.rb +3 -0
- data/app/views/sessions/new.html.erb +17 -0
- data/config/routes.rb +10 -0
- data/lib/generators/shopify_app/controllers/controllers_generator.rb +29 -0
- data/lib/generators/shopify_app/install/install_generator.rb +83 -0
- data/lib/generators/shopify_app/install/templates/embedded_app.html.erb +22 -0
- data/lib/generators/shopify_app/install/templates/home_controller.rb +11 -0
- data/lib/generators/shopify_app/install/templates/index.html.erb +12 -0
- data/lib/generators/shopify_app/install/templates/omniauth.rb +2 -0
- data/lib/generators/shopify_app/install/templates/shopify_app.rb +6 -0
- data/lib/generators/shopify_app/install/templates/shopify_app_ready_script.html +8 -0
- data/lib/generators/shopify_app/install/templates/shopify_provider.rb +11 -0
- data/lib/generators/shopify_app/{templates/config/initializers → install/templates}/shopify_session_repository.rb +3 -3
- data/lib/generators/shopify_app/routes/routes_generator.rb +31 -0
- data/lib/generators/shopify_app/routes/templates/routes.rb +7 -0
- data/lib/generators/shopify_app/shop_model/shop_model_generator.rb +42 -0
- data/lib/generators/shopify_app/shop_model/templates/db/migrate/create_shops.rb +15 -0
- data/lib/generators/shopify_app/shop_model/templates/session_storage.rb +16 -0
- data/lib/generators/shopify_app/shop_model/templates/shop.rb +3 -0
- data/lib/generators/shopify_app/shop_model/templates/shopify_session_repository.rb +7 -0
- data/lib/generators/shopify_app/shopify_app_generator.rb +10 -63
- data/lib/generators/shopify_app/views/views_generator.rb +29 -0
- data/lib/shopify_app.rb +14 -13
- data/lib/shopify_app/configuration.rb +26 -36
- data/lib/shopify_app/controller.rb +18 -0
- data/lib/shopify_app/engine.rb +5 -0
- data/lib/shopify_app/login_protection.rb +34 -32
- data/lib/shopify_app/sessions_controller.rb +64 -0
- data/lib/shopify_app/shop.rb +15 -0
- data/lib/shopify_app/shopify_session_repository.rb +23 -21
- data/lib/shopify_app/version.rb +1 -1
- data/shopify_app.gemspec +5 -10
- data/test/app_templates/app/controllers/application_controller.rb +2 -0
- data/test/app_templates/config/application.rb +24 -0
- data/test/app_templates/config/initializers/shopify_app.rb +6 -0
- data/test/app_templates/config/routes.rb +3 -0
- data/test/controllers/sessions_controller_test.rb +82 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/home_controller.rb +7 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +26 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/shopify_app.rb +6 -0
- data/test/dummy/config/routes.rb +10 -0
- data/test/dummy/config/secrets.yml +17 -0
- data/test/generators/install_generator_test.rb +103 -0
- data/test/generators/routes_generator_test.rb +33 -0
- data/test/generators/shop_model_generator_test.rb +40 -0
- data/test/generators/shopify_app_generator.rb +15 -0
- data/test/generators/views_generator_test.rb +15 -0
- data/test/shopify_app/configuration_test.rb +17 -0
- data/test/{lib/shopify_app → shopify_app}/in_memory_session_store_test.rb +6 -6
- data/test/{lib/shopify_app → shopify_app}/login_protection_test.rb +10 -7
- data/test/shopify_app/shopify_session_repository_test.rb +73 -0
- data/test/support/generator_test_helpers.rb +29 -0
- data/test/test_helper.rb +11 -3
- metadata +79 -61
- metadata.gz.sig +0 -0
- data/install.rb +0 -25
- data/lib/generators/shopify_app/README +0 -23
- data/lib/generators/shopify_app/USAGE +0 -22
- data/lib/generators/shopify_app/templates/app/assets/images/favicon.png +0 -0
- data/lib/generators/shopify_app/templates/app/assets/images/grid-18px.png +0 -0
- data/lib/generators/shopify_app/templates/app/assets/images/shopify-114.png +0 -0
- data/lib/generators/shopify_app/templates/app/assets/images/shopify-57.png +0 -0
- data/lib/generators/shopify_app/templates/app/assets/images/shopify-72.png +0 -0
- data/lib/generators/shopify_app/templates/app/assets/images/shopify.png +0 -0
- data/lib/generators/shopify_app/templates/app/assets/javascripts/application.js +0 -15
- data/lib/generators/shopify_app/templates/app/assets/stylesheets/application.css +0 -10
- data/lib/generators/shopify_app/templates/app/assets/stylesheets/imports.css.less +0 -5
- data/lib/generators/shopify_app/templates/app/assets/stylesheets/shopify_app.css.scss +0 -150
- data/lib/generators/shopify_app/templates/app/assets/stylesheets/shopify_app_buttons.css.less +0 -77
- data/lib/generators/shopify_app/templates/app/controllers/application_controller.rb +0 -13
- data/lib/generators/shopify_app/templates/app/controllers/home_controller.rb +0 -18
- data/lib/generators/shopify_app/templates/app/controllers/sessions_controller.rb +0 -52
- data/lib/generators/shopify_app/templates/app/helpers/home_helper.rb +0 -9
- data/lib/generators/shopify_app/templates/app/helpers/login_helper.rb +0 -3
- data/lib/generators/shopify_app/templates/app/helpers/tabs_helper.rb +0 -11
- data/lib/generators/shopify_app/templates/app/views/home/design.html.erb +0 -3542
- data/lib/generators/shopify_app/templates/app/views/home/index.html.erb +0 -168
- data/lib/generators/shopify_app/templates/app/views/home/welcome.html.erb +0 -110
- data/lib/generators/shopify_app/templates/app/views/layouts/application.html.erb +0 -79
- data/lib/generators/shopify_app/templates/app/views/sessions/new.html.erb +0 -21
- data/lib/generators/shopify_app/templates/config/initializers/omniauth.rb +0 -14
- data/lib/generators/shopify_app/templates/config/initializers/rails_4_shim.rb +0 -1
- data/lib/generators/shopify_app/templates/public/404.html +0 -40
- data/lib/generators/shopify_app/templates/public/422.html +0 -40
- data/lib/generators/shopify_app/templates/public/500.html +0 -40
- data/lib/generators/shopify_app/templates/public/favicon.png +0 -0
- data/lib/generators/shopify_app/templates/public/shopify-114.png +0 -0
- data/lib/generators/shopify_app/templates/public/shopify-57.png +0 -0
- data/lib/generators/shopify_app/templates/public/shopify-72.png +0 -0
- data/lib/shopify_app/railtie.rb +0 -17
- data/test/config/development_config_file.yml +0 -8
- data/test/config/empty_config_file.yml +0 -1
- data/test/config/other_config_file.yml +0 -4
- data/test/config/shopify_app.yml +0 -4
- data/test/lib/shopify_app/configuration_test.rb +0 -91
- data/test/lib/shopify_app/shopify_session_repository_test.rb +0 -70
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'shopify_app/login_protection'
|
|
2
|
+
|
|
3
|
+
module ShopifyApp
|
|
4
|
+
module Controller
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
include ShopifyApp::LoginProtection
|
|
8
|
+
|
|
9
|
+
def fullpage_redirect_to(url)
|
|
10
|
+
if ShopifyApp.configuration.embedded_app?
|
|
11
|
+
render inline: %Q(<script type="text/javascript">window.top.location.href = #{url.to_json};</script>)
|
|
12
|
+
else
|
|
13
|
+
redirect_to url
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -1,44 +1,46 @@
|
|
|
1
|
-
module ShopifyApp
|
|
2
|
-
|
|
1
|
+
module ShopifyApp
|
|
2
|
+
module LoginProtection
|
|
3
|
+
extend ActiveSupport::Concern
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
included do
|
|
6
|
+
rescue_from ActiveResource::UnauthorizedAccess, :with => :close_session
|
|
7
|
+
end
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
def shopify_session
|
|
10
|
+
if shop_session
|
|
11
|
+
begin
|
|
12
|
+
ShopifyAPI::Base.activate_session(shop_session)
|
|
13
|
+
yield
|
|
14
|
+
ensure
|
|
15
|
+
ShopifyAPI::Base.clear_session
|
|
16
|
+
end
|
|
17
|
+
else
|
|
18
|
+
redirect_to_login
|
|
16
19
|
end
|
|
17
|
-
else
|
|
18
|
-
redirect_to_login
|
|
19
20
|
end
|
|
20
|
-
end
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
def shop_session
|
|
23
|
+
return unless session[:shopify]
|
|
24
|
+
@shop_session ||= ShopifyApp::SessionRepository.retrieve(session[:shopify])
|
|
25
|
+
end
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
def login_again_if_different_shop
|
|
28
|
+
if shop_session && params[:shop] && params[:shop].is_a?(String) && shop_session.url != params[:shop]
|
|
29
|
+
redirect_to_login
|
|
30
|
+
end
|
|
30
31
|
end
|
|
31
|
-
end
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
protected
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
def redirect_to_login
|
|
36
|
+
session[:return_to] = request.fullpath if request.get?
|
|
37
|
+
redirect_to login_path(shop: params[:shop])
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def close_session
|
|
41
|
+
session[:shopify] = nil
|
|
42
|
+
redirect_to login_path
|
|
43
|
+
end
|
|
39
44
|
|
|
40
|
-
def close_session
|
|
41
|
-
session[:shopify] = nil
|
|
42
|
-
redirect_to login_path
|
|
43
45
|
end
|
|
44
46
|
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
module ShopifyApp
|
|
2
|
+
module SessionsController
|
|
3
|
+
extend ActiveSupport::Concern
|
|
4
|
+
|
|
5
|
+
def new
|
|
6
|
+
authenticate if params[:shop].present?
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def create
|
|
10
|
+
authenticate
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def callback
|
|
14
|
+
if response = request.env['omniauth.auth']
|
|
15
|
+
sess = ShopifyAPI::Session.new(params[:shop], response['credentials']['token'])
|
|
16
|
+
session[:shopify] = ShopifyApp::SessionRepository.store(sess)
|
|
17
|
+
flash[:notice] = "Logged in"
|
|
18
|
+
redirect_to return_address
|
|
19
|
+
else
|
|
20
|
+
flash[:error] = "Could not log in to Shopify store."
|
|
21
|
+
redirect_to :action => 'new'
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def destroy
|
|
26
|
+
session[:shopify] = nil
|
|
27
|
+
flash[:notice] = "Successfully logged out."
|
|
28
|
+
|
|
29
|
+
redirect_to :action => 'new'
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
protected
|
|
33
|
+
|
|
34
|
+
def authenticate
|
|
35
|
+
if shop_name = sanitize_shop_param(params)
|
|
36
|
+
fullpage_redirect_to "/auth/shopify?shop=#{shop_name}"
|
|
37
|
+
else
|
|
38
|
+
redirect_to return_address
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def return_address
|
|
43
|
+
session[:return_to] || root_url
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def sanitized_shop_name
|
|
47
|
+
@sanitized_shop_name ||= sanitize_shop_param(params)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def sanitize_shop_param(params)
|
|
51
|
+
return unless params[:shop].present?
|
|
52
|
+
|
|
53
|
+
name = params[:shop].to_s.strip
|
|
54
|
+
name += ".myshopify.com" if !name.include?("myshopify.com") && !name.include?(".")
|
|
55
|
+
name.sub!(%r|https?://|, '')
|
|
56
|
+
|
|
57
|
+
u = URI("http://#{name}")
|
|
58
|
+
u.host && u.host.ends_with?(".myshopify.com") ? u.host : nil
|
|
59
|
+
rescue URI::InvalidURIError
|
|
60
|
+
nil
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module ShopifyApp
|
|
2
|
+
module Shop
|
|
3
|
+
extend ActiveSupport::Concern
|
|
4
|
+
|
|
5
|
+
included do
|
|
6
|
+
validates :shopify_domain, presence: true, uniqueness: true
|
|
7
|
+
validates :shopify_token, presence: true
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def with_shopify_session(&block)
|
|
11
|
+
ShopifyAPI::Session.temp(shopify_domain, shopify_token, &block)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -1,32 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
class
|
|
1
|
+
module ShopifyApp
|
|
2
|
+
class SessionRepository
|
|
3
|
+
class ConfigurationError < StandardError; end
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
class << self
|
|
6
|
+
def storage=(storage)
|
|
7
|
+
@storage = storage
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
unless storage.nil? || self.storage.respond_to?(:store) && self.storage.respond_to?(:retrieve)
|
|
10
|
+
raise ArgumentError, "storage must respond to :store and :retrieve"
|
|
11
|
+
end
|
|
10
12
|
end
|
|
11
|
-
end
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
def retrieve(id)
|
|
15
|
+
storage.retrieve(id)
|
|
16
|
+
end
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
def store(session)
|
|
19
|
+
storage.store(session)
|
|
20
|
+
end
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
def storage
|
|
23
|
+
load_storage || raise(ConfigurationError.new("ShopifySessionRepository.storage is not configured!"))
|
|
24
|
+
end
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
private
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
def load_storage
|
|
29
|
+
return unless @storage
|
|
30
|
+
@storage.respond_to?(:safe_constantize) ? @storage.safe_constantize : @storage
|
|
31
|
+
end
|
|
30
32
|
end
|
|
31
33
|
end
|
|
32
34
|
end
|
data/lib/shopify_app/version.rb
CHANGED
data/shopify_app.gemspec
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
|
1
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
|
3
2
|
require "shopify_app/version"
|
|
4
3
|
|
|
5
4
|
Gem::Specification.new do |s|
|
|
@@ -7,24 +6,20 @@ Gem::Specification.new do |s|
|
|
|
7
6
|
s.version = ShopifyApp::VERSION
|
|
8
7
|
s.platform = Gem::Platform::RUBY
|
|
9
8
|
s.author = "Shopify"
|
|
10
|
-
s.email = ["edward@shopify.com", "willem@shopify.com", "david.underwood@shopify.com"]
|
|
11
|
-
s.homepage = "http://www.shopify.com/developers"
|
|
12
9
|
s.summary = %q{This gem is used to get quickly started with the Shopify API}
|
|
13
|
-
s.description = %q{Creates a basic sessions controller for authenticating with your Shop and also a product controller which lets your edit your products easily.}
|
|
14
10
|
|
|
15
|
-
s.
|
|
11
|
+
s.add_dependency('rails', '>= 3.1', '< 5.0')
|
|
16
12
|
|
|
17
|
-
s.add_runtime_dependency('rails', '>= 3.1', '< 5.0')
|
|
18
13
|
s.add_runtime_dependency('shopify_api', '~> 3.2.0')
|
|
19
14
|
s.add_runtime_dependency('omniauth-shopify-oauth2', '~> 1.1.4')
|
|
20
|
-
s.add_runtime_dependency('less-rails-bootstrap', '~> 2.0')
|
|
21
15
|
|
|
22
16
|
s.add_development_dependency('rake')
|
|
17
|
+
s.add_development_dependency('byebug')
|
|
18
|
+
s.add_development_dependency('sqlite3')
|
|
23
19
|
s.add_development_dependency('minitest')
|
|
24
20
|
s.add_development_dependency('mocha')
|
|
25
21
|
|
|
26
22
|
s.files = `git ls-files`.split("\n")
|
|
27
|
-
s.test_files = `git ls-files -- {test
|
|
28
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
23
|
+
s.test_files = `git ls-files -- {test}/*`.split("\n")
|
|
29
24
|
s.require_paths = ["lib"]
|
|
30
25
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
|
2
|
+
|
|
3
|
+
require 'rails/all'
|
|
4
|
+
|
|
5
|
+
Bundler.require(*Rails.groups)
|
|
6
|
+
|
|
7
|
+
module AppTemplate
|
|
8
|
+
class Application < Rails::Application
|
|
9
|
+
# Settings in config/environments/* take precedence over those specified here.
|
|
10
|
+
# Application configuration should go into files in config/initializers
|
|
11
|
+
# -- all .rb files in that directory are automatically loaded.
|
|
12
|
+
|
|
13
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
|
14
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
|
15
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
|
16
|
+
|
|
17
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
|
18
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
|
19
|
+
# config.i18n.default_locale = :de
|
|
20
|
+
|
|
21
|
+
# Do not swallow errors in after_commit/after_rollback callbacks.
|
|
22
|
+
config.active_record.raise_in_transactional_callbacks = true
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class SessionsControllerTest < ActionController::TestCase
|
|
4
|
+
|
|
5
|
+
setup do
|
|
6
|
+
ShopifyApp::SessionRepository.storage = InMemorySessionStore
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
test "#new should authenticate the shop if the shop param exists" do
|
|
10
|
+
auth_url = '/auth/shopify?shop=my-shop.myshopify.com'
|
|
11
|
+
get :new, shop: 'my-shop'
|
|
12
|
+
assert response.body.match(/window\.top\.location\.href = "#{Regexp.escape(auth_url)}"/)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
test "#new should authenticate the shop if the shop param exists non embedded" do
|
|
16
|
+
ShopifyApp.configuration.stubs(:embedded_app?).returns(false)
|
|
17
|
+
auth_url = '/auth/shopify?shop=my-shop.myshopify.com'
|
|
18
|
+
get :new, shop: 'my-shop'
|
|
19
|
+
assert_match "http://test.host/auth/shopify?shop=my-shop.myshopify.com", response.body
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
test "#new should trust the shop param over the current session" do
|
|
23
|
+
previously_logged_in_shop_id = 1
|
|
24
|
+
session[:shopify] = previously_logged_in_shop_id
|
|
25
|
+
new_shop_domain = "new-shop.myshopify.com"
|
|
26
|
+
auth_url = "/auth/shopify?shop=#{new_shop_domain}"
|
|
27
|
+
get :new, shop: new_shop_domain
|
|
28
|
+
assert response.body.match(/window\.top\.location\.href = "#{Regexp.escape(auth_url)}"/)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
test "#new should render a full-page if the shop param doesn't exist" do
|
|
32
|
+
get :new
|
|
33
|
+
assert_response :ok
|
|
34
|
+
assert_template :new
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
['my-shop', 'my-shop.myshopify.com', 'https://my-shop.myshopify.com', 'http://my-shop.myshopify.com'].each do |good_url|
|
|
38
|
+
test "#create should authenticate the shop for the URL (#{good_url})" do
|
|
39
|
+
auth_url = '/auth/shopify?shop=my-shop.myshopify.com'
|
|
40
|
+
post :create, shop: good_url
|
|
41
|
+
assert response.body.match(/window\.top\.location\.href = "#{Regexp.escape(auth_url)}"/)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
['myshop.com', 'myshopify.com', 'shopify.com', 'two words', 'store.myshopify.com.evil.com', '/foo/bar'].each do |bad_url|
|
|
46
|
+
test "#create should return an error for a non-myshopify URL (#{bad_url})" do
|
|
47
|
+
post :create, shop: bad_url
|
|
48
|
+
assert_redirected_to root_url
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
test "#create should render the login page if the shop param doesn't exist" do
|
|
53
|
+
post :create
|
|
54
|
+
assert_redirected_to root_url
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
test "#callback should setup a shopify session" do
|
|
58
|
+
mock_shopify_omniauth
|
|
59
|
+
|
|
60
|
+
get :callback, shop: 'shop'
|
|
61
|
+
assert_not_nil session[:shopify]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
test "#destroy should clear shopify from session and redirect to login with notice" do
|
|
65
|
+
shop_id = 1
|
|
66
|
+
session[:shopify] = shop_id
|
|
67
|
+
|
|
68
|
+
get :destroy
|
|
69
|
+
assert_nil session[:shopify]
|
|
70
|
+
assert_redirected_to login_path
|
|
71
|
+
refute flash[:notice].empty?
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
private
|
|
75
|
+
|
|
76
|
+
def mock_shopify_omniauth
|
|
77
|
+
OmniAuth.config.add_mock(:shopify, provider: :shopify, credentials: {token: '1234'})
|
|
78
|
+
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:shopify] if request
|
|
79
|
+
request.env['omniauth.params'] = { shop: 'shop.myshopify.com' } if request
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
|
2
|
+
|
|
3
|
+
require 'rails/all'
|
|
4
|
+
|
|
5
|
+
Bundler.require(*Rails.groups)
|
|
6
|
+
require "shopify_app"
|
|
7
|
+
|
|
8
|
+
module Dummy
|
|
9
|
+
class Application < Rails::Application
|
|
10
|
+
# Settings in config/environments/* take precedence over those specified here.
|
|
11
|
+
# Application configuration should go into files in config/initializers
|
|
12
|
+
# -- all .rb files in that directory are automatically loaded.
|
|
13
|
+
|
|
14
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
|
15
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
|
16
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
|
17
|
+
|
|
18
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
|
19
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
|
20
|
+
# config.i18n.default_locale = :de
|
|
21
|
+
|
|
22
|
+
# Do not swallow errors in after_commit/after_rollback callbacks.
|
|
23
|
+
config.active_record.raise_in_transactional_callbacks = true
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|