diff --git a/.rubocop.yml b/.rubocop.yml index e370a24d..77342e60 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,6 +3,7 @@ inherit_from: .rubocop_todo.yml AllCops: TargetRubyVersion: 2.2 Exclude: + - 'gemfiles/bin/*' - 'test/dummy/**/*' Metrics/BlockLength: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 60f12b71..7f29d257 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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 @@ -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 diff --git a/.travis.yml b/.travis.yml index e96e9597..89afb95e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/Rakefile b/Rakefile index 7d673bce..2f4c221e 100644 --- a/Rakefile +++ b/Rakefile @@ -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' diff --git a/gemfiles/4.0.gemfile b/gemfiles/4.0.gemfile index a96cfc80..7998fbcd 100644 --- a/gemfiles/4.0.gemfile +++ b/gemfiles/4.0.gemfile @@ -2,5 +2,6 @@ source "https://rubygems.org" gem 'rdoc' gem 'rails', '~> 4.0.0' +gem 'sqlite3', '~> 1.3.6' gemspec path: '../' \ No newline at end of file diff --git a/gemfiles/4.1.gemfile b/gemfiles/4.1.gemfile index 6e031d43..5cdbfd31 100644 --- a/gemfiles/4.1.gemfile +++ b/gemfiles/4.1.gemfile @@ -2,5 +2,6 @@ source 'https://rubygems.org' gem 'rdoc' gem 'rails', '~> 4.1.0' +gem 'sqlite3', '~> 1.3.6' gemspec path: '../' diff --git a/gemfiles/4.2.gemfile b/gemfiles/4.2.gemfile index 03ce1a6d..bcf9016f 100644 --- a/gemfiles/4.2.gemfile +++ b/gemfiles/4.2.gemfile @@ -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: '../' diff --git a/gemfiles/5.0.gemfile b/gemfiles/5.0.gemfile index dec3a766..d54f5553 100644 --- a/gemfiles/5.0.gemfile +++ b/gemfiles/5.0.gemfile @@ -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: '../' diff --git a/gemfiles/5.1.gemfile b/gemfiles/5.1.gemfile index af77e6bb..f32903a7 100644 --- a/gemfiles/5.1.gemfile +++ b/gemfiles/5.1.gemfile @@ -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: '../' diff --git a/gemfiles/5.2.gemfile b/gemfiles/5.2.gemfile index e419fe14..42ff4f12 100644 --- a/gemfiles/5.2.gemfile +++ b/gemfiles/5.2.gemfile @@ -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 diff --git a/gemfiles/6.0.gemfile b/gemfiles/6.0.gemfile new file mode 100644 index 00000000..e993b835 --- /dev/null +++ b/gemfiles/6.0.gemfile @@ -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: '../' diff --git a/gemfiles/rails_edge.gemfile b/gemfiles/rails_edge.gemfile index 1e646fa9..2b248a65 100644 --- a/gemfiles/rails_edge.gemfile +++ b/gemfiles/rails_edge.gemfile @@ -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 diff --git a/lib/wicked_pdf/railtie.rb b/lib/wicked_pdf/railtie.rb index 5d164299..30806c66 100644 --- a/lib/wicked_pdf/railtie.rb +++ b/lib/wicked_pdf/railtie.rb @@ -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 + 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 diff --git a/test/fixtures/manifest.js b/test/fixtures/manifest.js new file mode 100644 index 00000000..23f7a87c --- /dev/null +++ b/test/fixtures/manifest.js @@ -0,0 +1,3 @@ +//= link_tree ../images +//= link wicked.js +//= link wicked.css diff --git a/test/test_helper.rb b/test/test_helper.rb index 02a78ebb..15990f93 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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 diff --git a/wicked_pdf.gemspec b/wicked_pdf.gemspec index cb3394b8..f35cf369 100644 --- a/wicked_pdf.gemspec +++ b/wicked_pdf.gemspec @@ -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