From a2aacffcce3164eb18dc69a948a4a9b12cfebb12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 21 Dec 2021 03:42:26 +0000 Subject: [PATCH] Require Rails frameworks before using Jbuilder since #501 depends on Action View so we need to make it a dependency. Also we should be requiring both action_view and active_support before using it. Closes #518. --- jbuilder.gemspec | 1 + lib/jbuilder.rb | 1 + lib/jbuilder/collection_renderer.rb | 1 + lib/jbuilder/railtie.rb | 2 +- test/test_helper.rb | 7 ++----- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/jbuilder.gemspec b/jbuilder.gemspec index e29c8be..3ff00ef 100644 --- a/jbuilder.gemspec +++ b/jbuilder.gemspec @@ -10,6 +10,7 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 2.2.2' s.add_dependency 'activesupport', '>= 5.0.0' + s.add_dependency 'actionview', '>= 5.0.0' if RUBY_ENGINE == 'rbx' s.add_development_dependency('racc') diff --git a/lib/jbuilder.rb b/lib/jbuilder.rb index 37e776f..3cf41d8 100644 --- a/lib/jbuilder.rb +++ b/lib/jbuilder.rb @@ -1,3 +1,4 @@ +require 'active_support' require 'jbuilder/jbuilder' require 'jbuilder/blank' require 'jbuilder/key_formatter' diff --git a/lib/jbuilder/collection_renderer.rb b/lib/jbuilder/collection_renderer.rb index d46e903..5d1620d 100644 --- a/lib/jbuilder/collection_renderer.rb +++ b/lib/jbuilder/collection_renderer.rb @@ -1,5 +1,6 @@ require 'delegate' require 'active_support/concern' +require 'action_view' begin require 'action_view/renderer/collection_renderer' diff --git a/lib/jbuilder/railtie.rb b/lib/jbuilder/railtie.rb index ebb4a5f..7ae3ad7 100644 --- a/lib/jbuilder/railtie.rb +++ b/lib/jbuilder/railtie.rb @@ -1,4 +1,4 @@ -require 'rails/railtie' +require 'rails' require 'jbuilder/jbuilder_template' class Jbuilder diff --git a/test/test_helper.rb b/test/test_helper.rb index 78c86b1..1a230fd 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,14 +1,11 @@ require "bundler/setup" -require "active_support" +require "jbuilder" + require "active_support/core_ext/array/access" require "active_support/cache/memory_store" require "active_support/json" require "active_model" -require "action_view" -require "rails/version" - -require "jbuilder" require "active_support/testing/autorun" require "mocha/minitest"