Skip to content

Commit

Permalink
Merge pull request #263 from discolabs/upgrade_to_rails_600
Browse files Browse the repository at this point in the history
Upgrade to rails 6
  • Loading branch information
pillep authored Apr 14, 2020
2 parents 7a4a359 + a69dbac commit f9acf53
Show file tree
Hide file tree
Showing 49 changed files with 7,837 additions and 254 deletions.
206 changes: 115 additions & 91 deletions .rubocop.yml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby 2.5.0
ruby 2.6.5
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ gem 'timecop', '~> 0.8.0', group: [:development, :test]

# To continue using assigns and assert_template in Rails 5
gem 'rails-controller-testing', group: [:development, :test]

gem 'rb-readline', group: :development

gem 'webpacker'
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ SETUP_PROC = lambda do |env|
env['omniauth.strategy'].options[:per_user_permissions] = true
params = Rack::Utils.parse_query(env['QUERY_STRING'])
env['omniauth.strategy'].options[:client_options][:site] = "https://#{params['shop']}"
env['omniauth.strategy'].options[:old_client_secret] = ShopifyApp.configuration.old_secret
end
Rails.application.config.middleware.use OmniAuth::Builder do
Expand Down
45 changes: 25 additions & 20 deletions app/clients/disco_app/api_client.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
require 'rest-client'

class DiscoApp::ApiClient
module DiscoApp

SUBSCRIPTION_ENDPOINT = 'app_subscriptions.json'.freeze
class DiscoApiError < StandardError; end

def initialize(shop, url)
@shop = shop
@url = url
end
class ApiClient

SUBSCRIPTION_ENDPOINT = 'app_subscriptions.json'.freeze

def create_app_subscription
return if @url.blank?

url = @url + SUBSCRIPTION_ENDPOINT
begin
RestClient::Request.execute(
method: :post,
headers: { content_type: :json },
url: url,
payload: { shop: @shop, subscription: @shop.current_subscription }.to_json
)
rescue RestClient::BadRequest, RestClient::ResourceNotFound => e
raise DiscoApiError, e.message
def initialize(shop, url)
@shop = shop
@url = url
end
end

def create_app_subscription
return if @url.blank?

url = @url + SUBSCRIPTION_ENDPOINT
begin
RestClient::Request.execute(
method: :post,
headers: { content_type: :json },
url: url,
payload: { shop: @shop, subscription: @shop.current_subscription }.to_json
)
rescue RestClient::BadRequest, RestClient::ResourceNotFound => e
raise DiscoApiError, e.message
end
end

end
end
2 changes: 0 additions & 2 deletions app/clients/disco_app/disco_api_error.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module DiscoApp::Concerns::AuthenticatedController
included do
before_action :auto_login
before_action :check_shop_whitelist
before_action :login_again_if_different_shop
before_action :login_again_if_different_user_or_shop
before_action :shopify_shop
before_action :check_installed
before_action :check_current_subscription
Expand All @@ -29,7 +29,7 @@ def auto_login

def shopify_shop
if shop_session
@shop = DiscoApp::Shop.find_by!(shopify_domain: @shop_session.url)
@shop = DiscoApp::Shop.find_by!(shopify_domain: @shop_session.domain)
else
redirect_to_login
end
Expand Down
6 changes: 2 additions & 4 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
class SessionsController < ActionController::Base

include ShopifyApp::SessionsConcern
class SessionsController < ShopifyApp::SessionsController

def referral
cookies[DiscoApp::SOURCE_COOKIE_KEY] = params[:source] if params[:source].present?
Expand All @@ -22,7 +20,7 @@ def authenticate
if Rails.env.development? && DiscoApp.configuration.skip_oauth?
shop = DiscoApp::Shop.find_by!(shopify_domain: sanitized_shop_name)

sess = ShopifyAPI::Session.new(shop.shopify_domain, shop.shopify_token)
sess = ShopifyAPI::Session.new(domain: shop.shopify_domain, token: shop.shopify_token, api_version: shop.api_version)
session[:shopify] = ShopifyApp::SessionRepository.store(sess)
session[:shopify_domain] = sanitized_shop_name

Expand Down
4 changes: 1 addition & 3 deletions app/models/disco_app/concerns/renders_assets.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
require 'render_anywhere'
require 'uglifier'

module DiscoApp::Concerns::RendersAssets

extend ActiveSupport::Concern

included do
include RenderAnywhere
after_commit :queue_render_asset_group_job
end

Expand Down Expand Up @@ -138,7 +136,7 @@ def should_be_minified?(asset, options)
end

def render_asset_renderer
@render_asset_renderer ||= self.class.const_get('RenderingController').new
@render_asset_renderer ||= self.class.const_get('ApplicationController').new
end

# Render any script tags defined by the :script_tags options that we have
Expand Down
9 changes: 7 additions & 2 deletions app/models/disco_app/concerns/shop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module DiscoApp::Concerns::Shop
extend ActiveSupport::Concern

included do
include ShopifyApp::Shop
include ShopifyApp::SessionStorage
include ActionView::Helpers::DateHelper

# Define relationships to plans and subscriptions.
Expand Down Expand Up @@ -75,7 +75,7 @@ def protocol

# Return the absolute URL to the shop's admin.
def admin_url
"https://#{shopify_domain}/admin"
"https://#{shopify_domain}/admin/api/#{api_version}"
end

def installed_duration
Expand Down Expand Up @@ -107,6 +107,11 @@ def disco_api_client
def data
read_attribute(:data).with_indifferent_access
end

def api_version
ShopifyApp.configuration.api_version
end

end

end
4 changes: 2 additions & 2 deletions app/models/disco_app/session_storage.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module DiscoApp
class SessionStorage

def self.store(session)
def self.store(session, *args)
shop = Shop.find_or_initialize_by(shopify_domain: session.url)
shop.shopify_token = session.token
shop.save!
Expand All @@ -12,7 +12,7 @@ def self.retrieve(id)
return unless id

shop = Shop.find(id)
ShopifyAPI::Session.new(shop.shopify_domain, shop.shopify_token)
ShopifyAPI::Session.new(domain: shop.shopify_domain, token: shop.shopify_token, api_version: shop.api_version)
rescue ActiveRecord::RecordNotFound
nil
end
Expand Down
3 changes: 1 addition & 2 deletions app/views/layouts/admin.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
<head>
<title><%= yield(:title) %></title>
<%= stylesheet_link_tag 'disco_app/admin', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>

<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= csrf_meta_tags %>
</head>
<body class="next-ui">
Expand Down
3 changes: 1 addition & 2 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title><%= yield(:title) %></title>

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>

<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= csrf_meta_tags %>

<%= yield :extra_head %>
Expand All @@ -13,6 +13,5 @@

<%= yield %>

<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
</body>
</html>
6 changes: 2 additions & 4 deletions app/views/layouts/embedded_app.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
// Initialise the Shopify App.
ShopifyApp.init({
"apiKey": "<%= ShopifyApp.configuration.api_key %>",
"shopOrigin": "<%= "https://#{ @shop_session.url }" if @shop_session %>",
"shopOrigin": "<%= "https://#{ @shop_session.domain }" if @shop_session %>",
"debug": <%= Rails.env.development? ? 'true' : 'false' %>
});
</script>

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>

<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload', 'data-turbolinks-eval': false %>
<%= csrf_meta_tags %>

<%= yield :extra_head %>
Expand Down Expand Up @@ -43,8 +43,6 @@
</script>
<% end %>

<%= javascript_include_tag 'application', 'data-turbolinks-track' => true, 'data-turbolinks-eval' => false %>

<%= render 'disco_app/shared/icons' %>
</body>
</html>
5 changes: 2 additions & 3 deletions app/views/layouts/embedded_app_modal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
// Initialise the Shopify App.
ShopifyApp.init({
"apiKey": "<%= ShopifyApp.configuration.api_key %>",
"shopOrigin": "<%= "https://#{ @shop_session.url }" if @shop_session %>",
"shopOrigin": "<%= "https://#{ @shop_session.domain }" if @shop_session %>",
"debug": <%= Rails.env.development? ? 'true' : 'false' %>,
"forceRedirect": false
});
</script>

<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>

<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= csrf_meta_tags %>

<%= yield :extra_head %>
Expand Down
6 changes: 2 additions & 4 deletions app/views/shopify_app/sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<head>
<title>Install <%= DiscoApp.configuration.app_name %></title>

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= csrf_meta_tags %>

<%= yield :extra_head %>
Expand Down Expand Up @@ -36,7 +36,5 @@
</section>
</div>
<% end %>

<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
</body>
</html>
38 changes: 17 additions & 21 deletions disco_app.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,34 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'activemodel-serializers-xml', '~> 1.0'
s.add_runtime_dependency 'activerecord-session_store', '~> 1.0'
s.add_runtime_dependency 'acts_as_singleton', '~> 0.0.8'
s.add_runtime_dependency 'appsignal', '~> 2.7'
s.add_runtime_dependency 'appsignal', '~> 2.9'
s.add_runtime_dependency 'classnames-rails', '~> 2.1'
s.add_runtime_dependency 'coffee-rails', '~> 4.2'
s.add_runtime_dependency 'interactor'
s.add_runtime_dependency 'interactor-rails'
s.add_runtime_dependency 'jquery-rails', '~> 4.3'
s.add_runtime_dependency 'jsonapi-resources', '~> 0.8'
s.add_runtime_dependency 'jsonapi-resources', '~> 0.9'
s.add_runtime_dependency 'mailgun_rails', '~> 0.8'
s.add_runtime_dependency 'newrelic_rpm', '~> 3.15'
s.add_runtime_dependency 'nokogiri', '~> 1.7'
s.add_runtime_dependency 'oj', '~> 2.14'
s.add_runtime_dependency 'pg', '~> 0.21.0'
s.add_runtime_dependency 'premailer-rails', '~> 1.8'
s.add_runtime_dependency 'puma', '~> 3.9'
s.add_runtime_dependency 'rails', '~> 5.2.2'
s.add_runtime_dependency 'puma', '>= 3.9'
s.add_runtime_dependency 'rails', '~> 6.0'
s.add_runtime_dependency 'rails_12factor', '~> 0.0.3'
s.add_runtime_dependency 'react-rails', '~> 1.10'
s.add_runtime_dependency 'render_anywhere', '~> 0.0.12'
s.add_runtime_dependency 'react-rails', '~> 2.5'
s.add_runtime_dependency 'sass-rails', '~> 5.0'
s.add_runtime_dependency 'shopify_api', '~> 6.0'
s.add_runtime_dependency 'shopify_app', '~> 7.2', '>= 7.2.3'
s.add_runtime_dependency 'sidekiq', '~> 5.0'
s.add_runtime_dependency 'shopify_api', '~> 9.0'
s.add_runtime_dependency 'shopify_app', '~> 12.0.7'
s.add_runtime_dependency 'sidekiq', '~> 6.0'
s.add_runtime_dependency 'sinatra', '~> 2.0'
s.add_runtime_dependency 'turbolinks', '~> 5.0'
s.add_runtime_dependency 'uglifier', '>= 3.2'
s.add_runtime_dependency 'turbolinks', '~> 5.2'
s.add_runtime_dependency 'uglifier', '~> 4.1'

s.add_development_dependency 'dotenv-rails', '~> 2.0'
s.add_development_dependency 'minitest', '5.10.1'
s.add_development_dependency 'minitest-reporters', '1.1.9'
s.add_development_dependency 'rubocop', '~> 0.72'
s.add_development_dependency 'rubocop-performance', '~> 1.4.0'
s.add_development_dependency 'rubocop-rails', '~> 2.2.0'
s.add_development_dependency 'vcr', '~> 3.0'
s.add_development_dependency 'webmock', '~> 2.3'
s.add_development_dependency 'minitest', '5.11.3'
s.add_development_dependency 'minitest-reporters', '1.3'
s.add_development_dependency 'rubocop', '~> 0.77'
s.add_development_dependency 'rubocop-performance', '~> 1.5.1'
s.add_development_dependency 'rubocop-rails', '~> 2.4.0'
s.add_development_dependency 'vcr', '~> 5.0'
s.add_development_dependency 'webmock', '~> 3.6'
end
6 changes: 3 additions & 3 deletions initialise.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Usage: initialise.sh example_app

APP_NAME="$1"
RAILS_VERSION="${RAILS_VERSION:-5.2.0}"
RUBY_VERSION="${RUBY_VERSION:-2.5.0}"
RAILS_VERSION="${RAILS_VERSION:-6.0.1}"
RUBY_VERSION="${RUBY_VERSION:-2.6.5}"
DISCO_APP_VERSION="${DISCO_APP_VERSION:-0.17.0}"

if [ -z $APP_NAME ]; then
Expand All @@ -16,7 +16,7 @@ mkdir $APP_NAME
cd $APP_NAME
echo "source 'https://rubygems.org'" > Gemfile
echo "gem 'rails', '~> $RAILS_VERSION'" >> Gemfile
echo "$RUBY_VERSION" > .ruby-version
echo "ruby $RUBY_VERSION" > .tool-versions
bundle install
bundle exec rails _"$RAILS_VERSION"_ new . --force --skip-bundle
echo "gem 'disco_app', '$DISCO_APP_VERSION', source: \"https://gem.fury.io/discolabs/\"" >> Gemfile
Expand Down
Loading

0 comments on commit f9acf53

Please sign in to comment.