Skip to content

Commit 46f2211

Browse files
committed
Support Rails 5.0
Highlights include: - Stop deprecation notices relating to: - `:back` for redirects - `render nothing: true` - Rails 5.0 on using `to_hash` - `static_cache_control` - `before_filter` -> `before_action` - Compatibility shim to support params keywords in controller specs - Upgrade CI SQLite to avoid Rails 5.0 migration bug rails/rails#24440 - Upgrade CI Ruby to 2.3.1 - Upgrade Rack to version required by Rails 5.0 - Dummy app upgrade to Rails 5 (and downgrades to 4.x when required for tests)
1 parent 009f1f4 commit 46f2211

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+656
-316
lines changed

Diff for: .gitignore

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
.bundle/
21
log/*.log
32
pkg/
43
spec/dummy/db/*.sqlite3
54
spec/dummy/db/*.sqlite3-journal
65
spec/dummy/log/*.log
76
spec/dummy/tmp/
87
spec/dummy/.sass-cache
9-
Gemfile.lock
108
coverage
119
.rspec
1210
*.sublime-*
1311
.idea
14-
vendor/bundle*
12+
13+
# Bundler-related
14+
.bundle/
15+
vendor/bundle
16+
Gemfile.lock
17+
gemfiles/*.lock

Diff for: Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ group :test do
88
end
99
gem 'rspec_junit_formatter'
1010

11-
gem 'rails', git: 'https://github.com/rails/rails', branch: '4-2-stable'
11+
gem 'rails', git: 'https://github.com/rails/rails', branch: '5-0-stable'

Diff for: Rakefile

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,22 @@ RDoc::Task.new(:rdoc) do |rdoc|
1010
rdoc.rdoc_dir = 'rdoc'
1111
rdoc.title = 'Payola'
1212
rdoc.options << '--line-numbers'
13-
rdoc.rdoc_files.include('README.rdoc')
13+
rdoc.rdoc_files.include('README.md')
1414
rdoc.rdoc_files.include('lib/**/*.rb')
1515
end
1616

1717
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
1818
load 'rails/tasks/engine.rake'
1919

20-
Bundler::GemHelper.install_tasks
20+
load 'rails/tasks/statistics.rake'
21+
require 'bundler/gem_tasks'
2122

2223
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
2324

2425
require 'rspec/core'
2526
require 'rspec/core/rake_task'
2627

2728
desc "Run all specs in spec directory (excluding plugin specs)"
28-
RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
29+
RSpec::Core::RakeTask.new(spec: 'app:db:test:prepare')
2930

30-
task :default => :spec
31+
task default: :spec

Diff for: app/assets/javascripts/payola/application.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
// listed below.
33
//
44
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5-
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
5+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
66
//
77
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8-
// compiled file.
8+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
99
//
10-
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
10+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
1111
// about supported directives.
1212
//
1313
//= require_tree .

Diff for: app/assets/stylesheets/payola/application.css

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
* listed below.
44
*
55
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6-
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
6+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
77
*
88
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
9-
* compiled file so the styles you add here take precedence over styles defined in any styles
10-
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11-
* file per style scope.
9+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10+
* files in this directory. Styles in this file should be added after the last require_* statement.
11+
* It is generally better to create a new file per style scope.
1212
*
1313
*= require_tree .
1414
*= require_self

Diff for: app/controllers/concerns/payola/affiliate_behavior.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module AffiliateBehavior
33
extend ActiveSupport::Concern
44

55
included do
6-
before_filter :find_affiliate
6+
before_action :find_affiliate
77
end
88

99
def find_affiliate

Diff for: app/controllers/concerns/payola/status_behavior.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module StatusBehavior
33
extend ActiveSupport::Concern
44

55
def render_payola_status(object)
6-
render nothing: true, status: 404 and return unless object
6+
head :not_found and return unless object
77

88
errors = ([object.error.presence] + object.errors.full_messages).compact.to_sentence
99

Diff for: app/controllers/payola/application_controller.rb

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
module Payola
22
class ApplicationController < ::ApplicationController
33
helper PriceHelper
4+
5+
private
6+
7+
def return_to
8+
return params[:return_to] if params[:return_to]
9+
request.headers["Referer"] or raise ActionController::RedirectBackError
10+
end
11+
412
end
513
end

Diff for: app/controllers/payola/cards_controller.rb

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
module Payola
22
class CardsController < ApplicationController
3-
4-
before_filter :check_modify_permissions, only: [:create, :destroy]
5-
3+
4+
before_action :check_modify_permissions, only: [:create, :destroy]
5+
66
def create
77
if params[:customer_id].present? && params[:stripeToken].present?
88
Payola::CreateCard.call(params[:customer_id], params[:stripeToken])
9-
redirect_to return_to, notice: t('payola.cards.created')
9+
flash_options = { notice: t('payola.cards.created') }
1010
else
11-
redirect_to return_to, alert: t('payola.cards.not_created')
12-
end
11+
flash_options = { alert: t('payola.cards.not_created') }
12+
end
13+
redirect_to return_to, flash: flash_options
1314
end
1415

1516
def destroy
1617
if params[:id].present? && params[:customer_id].present?
1718
Payola::DestroyCard.call(params[:id], params[:customer_id])
18-
redirect_to return_to, notice: t('payola.cards.destroyed')
19+
flash_options = { notice: t('payola.cards.destroyed') }
1920
else
20-
redirect_to return_to, alert: t('payola.cards.not_destroyed')
21-
end
21+
flash_options = { alert: t('payola.cards.not_destroyed') }
22+
end
23+
redirect_to return_to, flash: flash_options
2224
end
2325

2426
private
@@ -32,9 +34,5 @@ def check_modify_permissions
3234
end
3335
end
3436

35-
def return_to
36-
params[:return_to] || :back
37-
end
38-
3937
end
4038
end

Diff for: app/controllers/payola/customers_controller.rb

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
module Payola
22
class CustomersController < ApplicationController
33

4-
before_filter :check_modify_permissions, only: [:update]
4+
before_action :check_modify_permissions, only: [:update]
55

66
def update
77
if params[:id].present?
88
Payola::UpdateCustomer.call(params[:id], customer_params)
9-
redirect_to return_to, notice: t('payola.customers.updated')
9+
flash_options = { notice: t('payola.customers.updated') }
1010
else
11-
redirect_to return_to, alert: t('payola.customers.not_updated')
11+
flash_options = { alert: t('payola.customers.not_updated') }
1212
end
13+
redirect_to return_to, flash: flash_options
1314
end
1415

1516
private
@@ -29,9 +30,5 @@ def check_modify_permissions
2930
end
3031
end
3132

32-
def return_to
33-
params[:return_to] || :back
34-
end
35-
3633
end
3734
end

Diff for: app/controllers/payola/subscriptions_controller.rb

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ class SubscriptionsController < ApplicationController
44
include Payola::StatusBehavior
55
include Payola::AsyncBehavior
66

7-
before_filter :find_plan_coupon_and_quantity, only: [:create, :change_plan]
8-
before_filter :check_modify_permissions, only: [:destroy, :change_plan, :change_quantity, :update_card]
7+
before_action :find_plan_coupon_and_quantity, only: [:create, :change_plan]
8+
before_action :check_modify_permissions, only: [:destroy, :change_plan, :change_quantity, :update_card]
99

1010
def show
1111
show_object(Subscription)
@@ -21,7 +21,7 @@ def create
2121

2222
def destroy
2323
subscription = Subscription.find_by!(guid: params[:guid])
24-
Payola::CancelSubscription.call(subscription, at_period_end: ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(params[:at_period_end]))
24+
Payola::CancelSubscription.call(subscription, at_period_end: to_boolean(params[:at_period_end]))
2525
redirect_to confirm_subscription_path(subscription)
2626
end
2727

@@ -89,5 +89,11 @@ def confirm_with_message(message)
8989
end
9090
end
9191

92+
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON'].to_set
93+
94+
def to_boolean(value)
95+
TRUE_VALUES.include?(value)
96+
end
97+
9298
end
9399
end

Diff for: app/controllers/payola/transactions_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class TransactionsController < ApplicationController
44
include Payola::StatusBehavior
55
include Payola::AsyncBehavior
66

7-
before_filter :find_product_and_coupon, only: [:create]
7+
before_action :find_product_and_coupon, only: [:create]
88

99
def show
1010
show_object(Sale)

Diff for: app/services/payola/update_customer.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class UpdateCustomer
33
def self.call(stripe_customer_id, options)
44
secret_key = Payola.secret_key
55
customer = Stripe::Customer.retrieve(stripe_customer_id, secret_key)
6-
customer.save(options)
6+
customer.save(options.to_h)
77
end
88
end
99
end

Diff for: bin/rails

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env ruby
2-
# This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
2+
# This command will automatically be run when you run "rails" with Rails gems
3+
# installed from the root of your application.
34

45
ENGINE_ROOT = File.expand_path('../..', __FILE__)
56
ENGINE_PATH = File.expand_path('../../lib/payola/engine', __FILE__)

Diff for: circle.yml

+20-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
1+
machine:
2+
environment:
3+
RAILS_ENV: test
4+
ruby:
5+
version: 2.3.1
6+
17
dependencies:
8+
pre:
9+
# Sqlite version should be > 3.7.9 to avoid issues with Rails 5.0
10+
# https://github.com/rails/rails/pull/24440
11+
- sudo apt-get install --only-upgrade sqlite3 libsqlite3-dev
12+
- sqlite3 --version
13+
214
cache_directories:
3-
- "vendor/bundle_rails-4.2"
4-
- "vendor/bundle_rails-4.1"
15+
- "vendor/bundle"
516

617
override:
7-
- bundle install --path=vendor/bundle_rails-4.2
8-
- bundle install --gemfile=gemfiles/rails-4.1.gemfile --path=../vendor/bundle_rails-4.1
18+
- bundle install --gemfile=Gemfile --path=vendor/bundle
19+
- bundle install --gemfile=gemfiles/rails_4_2.gemfile --path=../vendor/bundle
20+
- bundle install --gemfile=gemfiles/rails_4_1.gemfile --path=../vendor/bundle
921

1022
database:
1123
override:
12-
- cp config/database.yml.ci config/database.yml
13-
- bundle exec rake db:create db:migrate db:seed --trace
24+
- echo "Do nothing in database step, default rake default task sets up db."
1425

1526
test:
1627
override:
17-
- bundle exec rake
18-
- BUNDLE_GEMFILE=gemfiles/rails-4.1.gemfile bundle exec rake
28+
- BUNDLE_GEMFILE=Gemfile bundle exec rake
29+
- BUNDLE_GEMFILE=gemfiles/rails_4_2.gemfile bundle exec rake
30+
- BUNDLE_GEMFILE=gemfiles/rails_4_1.gemfile bundle exec rake

Diff for: config/database.yml.ci

-6
This file was deleted.
File renamed without changes.

Diff for: gemfiles/rails_4_2.gemfile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
source 'https://rubygems.org'
2+
3+
gemspec path: '..'
4+
5+
group :test do
6+
gem 'rspec-rails', '~> 3.5'
7+
gem 'simplecov', require: false
8+
gem 'codeclimate-test-reporter', require: nil
9+
end
10+
gem 'rspec_junit_formatter'
11+
12+
gem 'rails', git: 'https://github.com/rails/rails', branch: '4-2-stable'

0 commit comments

Comments
 (0)