Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for rails 6 #869

Merged
merged 2 commits into from
Dec 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ inherit_from: .rubocop_todo.yml
AllCops:
TargetRubyVersion: 2.2
Exclude:
- 'gemfiles/bin/*'
- 'test/dummy/**/*'

Metrics/BlockLength:
Expand Down
2 changes: 2 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Bundler/OrderedGems:
- 'gemfiles/5.0.gemfile'
- 'gemfiles/5.1.gemfile'
- 'gemfiles/5.2.gemfile'
- 'gemfiles/6.0.gemfile'
- 'gemfiles/rails_edge.gemfile'

# Offense count: 2
Expand Down Expand Up @@ -140,6 +141,7 @@ Style/HashSyntax:
- 'gemfiles/5.0.gemfile'
- 'gemfiles/5.1.gemfile'
- 'gemfiles/5.2.gemfile'
- 'gemfiles/6.0.gemfile'
- 'gemfiles/rails_edge.gemfile'

# Offense count: 3
Expand Down
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ matrix:
before_install:
- gem update --system
- gem install bundler
- rvm: 2.6
gemfile: gemfiles/6.0.gemfile
before_install:
- gem update --system
- gem install bundler
- rvm: 2.6
gemfile: gemfiles/rails_edge.gemfile
before_install:
Expand Down
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ task :dummy_generate do
system('touch test/dummy/db/schema.rb')
FileUtils.cp 'test/fixtures/database.yml', 'test/dummy/config/'
FileUtils.rm_r Dir.glob('test/dummy/test/*')

# rails 6 needs this to be present before start:
FileUtils.mkdir_p('test/dummy/app/assets/config')
FileUtils.mkdir_p('test/dummy/app/assets/javascripts')
FileUtils.cp 'test/fixtures/manifest.js', 'test/dummy/app/assets/config/'
FileUtils.cp 'test/fixtures/wicked.js', 'test/dummy/app/assets/javascripts/'
end

desc 'Remove dummy application'
Expand Down
1 change: 1 addition & 0 deletions gemfiles/4.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ source "https://rubygems.org"

gem 'rdoc'
gem 'rails', '~> 4.0.0'
gem 'sqlite3', '~> 1.3.6'

gemspec path: '../'
1 change: 1 addition & 0 deletions gemfiles/4.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ source 'https://rubygems.org'

gem 'rdoc'
gem 'rails', '~> 4.1.0'
gem 'sqlite3', '~> 1.3.6'

gemspec path: '../'
3 changes: 3 additions & 0 deletions gemfiles/4.2.gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
source 'https://rubygems.org'

gem 'rdoc'
gem 'bundler', '~>1.3'
gem 'sqlite3', '~> 1.3.6'
gem 'sprockets', '~>3.0'
gem 'rails', '~> 4.2.0'

gemspec path: '../'
2 changes: 2 additions & 0 deletions gemfiles/5.0.gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
source 'https://rubygems.org'

gem 'rdoc'
gem 'sqlite3', '~> 1.3.6'
gem 'sprockets', '~>3.0' # v4 strips newlines from assets causing tests to fail
gem 'rails', '~> 5.0.0'

gemspec path: '../'
2 changes: 2 additions & 0 deletions gemfiles/5.1.gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
source 'https://rubygems.org'

gem 'rdoc'
gem 'sqlite3', '~> 1.3.6'
gem 'sprockets', '~>3.0' # v4 strips newlines from assets causing tests to fail
gem 'rails', '~> 5.1.0'

gemspec path: '../'
1 change: 1 addition & 0 deletions gemfiles/5.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ source 'https://rubygems.org'
gem 'rdoc'
gem 'rails', '~> 5.2'
gem 'sqlite3', '~> 1.3.6'
gem 'sprockets', '~>3.0' # v4 strips newlines from assets causing tests to fail
gem 'bootsnap' # required to run `rake test` in Rails 5.2
gem 'mocha', '= 1.3' # newer versions blow up

Expand Down
11 changes: 11 additions & 0 deletions gemfiles/6.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
source 'https://rubygems.org'

gem 'bundler', '~>2'
gem 'rdoc'
gem 'rails', '~>6.0.1'
gem 'sqlite3', '~> 1.4'
gem 'sprockets', '~>3.0'
gem 'bootsnap' # required to run `rake test` in Rails 6.0
gem 'mocha', '= 1.3' # newer versions blow up

gemspec path: '../'
2 changes: 1 addition & 1 deletion gemfiles/rails_edge.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ source 'https://rubygems.org'

gem 'rdoc'
gem 'rails', git: 'https://github.com/rails/rails.git'
gem 'sqlite3', '~> 1.3.6'
gem 'sqlite3', '~> 1.4'
gem 'bootsnap' # required to run `rake test` in Rails 6.0
gem 'mocha', '= 1.3' # newer versions blow up

Expand Down
14 changes: 8 additions & 6 deletions lib/wicked_pdf/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ class WickedPdf
if defined?(Rails.env)
class WickedRailtie < Rails::Railtie
initializer 'wicked_pdf.register', :after => 'remotipart.controller_helper' do |_app|
if ActionController::Base.respond_to?(:prepend) &&
Object.method(:new).respond_to?(:super_method)
ActionController::Base.send :prepend, PdfHelper
else
ActionController::Base.send :include, PdfHelper
ActiveSupport.on_load(:action_controller) do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this new approach break the compatibility of wicked_pdf and remotipart? I do observe a bug if wicked_pdf 2.0.x is used with remotipart. In Ruby 2.6, the bug is announced as a FrozenError. We get more information under Ruby <2.5 to see that there is indeed a loop of rendering.

Copy link

@darrenterhune darrenterhune Mar 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm this does break our app. I forked this repo and simply rolled back to a simpler version of railtie.rb just to debug this and we are working again darrenterhune@ccc8615 that said, wicked_pdf still worked locally, it was just barfing on CircleCI with this #891

if ActionController::Base.respond_to?(:prepend) &&
Object.method(:new).respond_to?(:super_method)
ActionController::Base.send :prepend, PdfHelper
else
ActionController::Base.send :include, PdfHelper
end
ActionView::Base.send :include, WickedPdfHelper::Assets
end
ActionView::Base.send :include, WickedPdfHelper::Assets
end
end

Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//= link_tree ../images
//= link wicked.js
//= link wicked.css
10 changes: 9 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@
File.open(destination, 'w') { |f| f.write(source) }

# Copy JS file
destination = assets_dir.join('javascripts/wicked.js')
js_dir = assets_dir.join('javascripts')
Dir.mkdir(js_dir) unless File.directory?(js_dir)
destination = js_dir.join('wicked.js')
source = File.read('test/fixtures/wicked.js')
File.open(destination, 'w') { |f| f.write(source) }

config_dir = assets_dir.join('config')
Dir.mkdir(config_dir) unless File.directory?(config_dir)
source = File.read('test/fixtures/manifest.js')
destination = config_dir.join('manifest.js')
File.open(destination, 'w') { |f| f.write(source) }
end
4 changes: 2 additions & 2 deletions wicked_pdf.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ DESC
spec.add_dependency 'activesupport'

spec.add_development_dependency 'rails'
spec.add_development_dependency 'bundler', RUBY_VERSION >= '2.5' ? '~> 2' : '~> 1.3'
spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rubocop', '~> 0.68.0'
spec.add_development_dependency 'sqlite3', '~> 1.3.6'
spec.add_development_dependency 'sqlite3', '~> 1.3'
spec.add_development_dependency 'mocha', '= 1.3'
spec.add_development_dependency 'test-unit'
end