From d11c5b6e36b115fd6ef4daa42afec8cf8ab0d1a7 Mon Sep 17 00:00:00 2001 From: OKURA Masafumi Date: Thu, 23 Dec 2021 17:57:44 +0900 Subject: [PATCH 01/46] Run CI against Rails 7.0 --- .github/workflows/ruby.yml | 15 +++++++++++++-- gemfiles/rails_7_0.gemfile | 10 ++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 gemfiles/rails_7_0.gemfile diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 1bb6adc5..97cb7be7 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - ruby: + ruby: - "2.2" - "2.3" - "2.4" @@ -29,8 +29,9 @@ jobs: - "rails_5_2" - "rails_6_0" - "rails_6_1" + - "rails_7_0" - "rails_head" - + experimental: [false] exclude: - ruby: 2.7 @@ -69,6 +70,16 @@ jobs: gemfile: rails_6_1 - ruby: 2.4 gemfile: rails_6_1 + - ruby: 2.2 + gemfile: rails_7_0 + - ruby: 2.3 + gemfile: rails_7_0 + - ruby: 2.4 + gemfile: rails_7_0 + - ruby: 2.5 + gemfile: rails_7_0 + - ruby: 2.6 + gemfile: rails_7_0 - ruby: 2.2 gemfile: rails_head - ruby: 2.3 diff --git a/gemfiles/rails_7_0.gemfile b/gemfiles/rails_7_0.gemfile new file mode 100644 index 00000000..7c101935 --- /dev/null +++ b/gemfiles/rails_7_0.gemfile @@ -0,0 +1,10 @@ +# This file was generated by Appraisal + +source "https://rubygems.org/" + +gem "rake" +gem "mocha", require: false +gem "appraisal" +gem "rails", "~> 7.0.0" + +gemspec path: "../" From 96a8a397f1cc12b223c1c08c340d2edde754c649 Mon Sep 17 00:00:00 2001 From: Nikita Vasilevsky Date: Mon, 7 Feb 2022 14:34:59 -0500 Subject: [PATCH 02/46] Avoid loading `ActionController::API` constant --- lib/jbuilder/railtie.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/jbuilder/railtie.rb b/lib/jbuilder/railtie.rb index 7ae3ad7c..c4ed57a0 100644 --- a/lib/jbuilder/railtie.rb +++ b/lib/jbuilder/railtie.rb @@ -16,11 +16,9 @@ module ApiRendering end end - ActiveSupport.on_load :action_controller do - if self == ActionController::API - include ActionController::Helpers - include ActionController::ImplicitRender - end + ActiveSupport.on_load :action_controller_api do + include ActionController::Helpers + include ActionController::ImplicitRender end end end From 63244d56f56a3d6164a4cb9f8ee620c57e217e4d Mon Sep 17 00:00:00 2001 From: Yuki Nishijima Date: Fri, 18 Feb 2022 00:14:10 +0900 Subject: [PATCH 03/46] Fixed a bug where #501 broke compatibility with Enumerable (#531) --- lib/jbuilder/collection_renderer.rb | 7 +++++++ lib/jbuilder/jbuilder_template.rb | 1 + test/jbuilder_template_test.rb | 1 - 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/jbuilder/collection_renderer.rb b/lib/jbuilder/collection_renderer.rb index 5d1620da..48707bfe 100644 --- a/lib/jbuilder/collection_renderer.rb +++ b/lib/jbuilder/collection_renderer.rb @@ -106,4 +106,11 @@ def collection_with_template(view, template) end end end + + class EnumerableCompat < ::SimpleDelegator + # Rails 6.1 requires this. + def size(*args, &block) + __getobj__.count(*args, &block) + end + end end diff --git a/lib/jbuilder/jbuilder_template.rb b/lib/jbuilder/jbuilder_template.rb index 2b90d745..b13e85fc 100644 --- a/lib/jbuilder/jbuilder_template.rb +++ b/lib/jbuilder/jbuilder_template.rb @@ -145,6 +145,7 @@ def _render_partial_with_options(options) collection = options.delete(:collection) || [] partial = options.delete(:partial) options[:locals].merge!(json: self) + collection = EnumerableCompat.new(collection) if collection.respond_to?(:count) && !collection.respond_to?(:size) if options.has_key?(:layout) raise ::NotImplementedError, "The `:layout' option is not supported in collection rendering." diff --git a/test/jbuilder_template_test.rb b/test/jbuilder_template_test.rb index eaac5051..86f0b1eb 100644 --- a/test/jbuilder_template_test.rb +++ b/test/jbuilder_template_test.rb @@ -294,7 +294,6 @@ class JbuilderTemplateTest < ActiveSupport::TestCase test "works with an enumerable object" do enumerable_class = Class.new do include Enumerable - alias length count # Rails 6.1 requires this. def each(&block) [].each(&block) From 69906ba22d84cc2d775f75db40badf77c0fd6a92 Mon Sep 17 00:00:00 2001 From: Antonis Berkakis Date: Thu, 13 Jan 2022 20:22:01 +0000 Subject: [PATCH 04/46] Support Ruby 3.1 and Rails 7.0 --- .github/workflows/ruby.yml | 31 +++++++++++++++++++++++++++++-- Appraisals | 6 ++++++ gemfiles/rails_7_0.gemfile | 10 ++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 gemfiles/rails_7_0.gemfile diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 1bb6adc5..a29a1fe2 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - ruby: + ruby: - "2.2" - "2.3" - "2.4" @@ -22,6 +22,7 @@ jobs: - "2.6" - "2.7" - "3.0" + - "3.1" gemfile: - "rails_5_0" @@ -29,20 +30,25 @@ jobs: - "rails_5_2" - "rails_6_0" - "rails_6_1" + - "rails_7_0" - "rails_head" - + experimental: [false] exclude: - ruby: 2.7 gemfile: rails_5_0 - ruby: '3.0' gemfile: rails_5_0 + - ruby: '3.1' + gemfile: rails_5_0 - ruby: head gemfile: rails_5_0 - ruby: 2.7 gemfile: rails_5_1 - ruby: '3.0' gemfile: rails_5_1 + - ruby: '3.1' + gemfile: rails_5_1 - ruby: head gemfile: rails_5_1 - ruby: 2.2 @@ -51,6 +57,8 @@ jobs: gemfile: rails_5_2 - ruby: '3.0' gemfile: rails_5_2 + - ruby: '3.1' + gemfile: rails_5_2 - ruby: head gemfile: rails_5_2 - ruby: 2.2 @@ -61,6 +69,8 @@ jobs: gemfile: rails_6_0 - ruby: '3.0' gemfile: rails_6_0 + - ruby: '3.1' + gemfile: rails_6_0 - ruby: head gemfile: rails_6_0 - ruby: 2.2 @@ -69,6 +79,16 @@ jobs: gemfile: rails_6_1 - ruby: 2.4 gemfile: rails_6_1 + - ruby: 2.2 + gemfile: rails_7_0 + - ruby: 2.3 + gemfile: rails_7_0 + - ruby: 2.4 + gemfile: rails_7_0 + - ruby: 2.5 + gemfile: rails_7_0 + - ruby: 2.6 + gemfile: rails_7_0 - ruby: 2.2 gemfile: rails_head - ruby: 2.3 @@ -85,6 +105,10 @@ jobs: - ruby: '3.0' gemfile: rails_head experimental: false + - ruby: '3.1' + gemfile: rails_head + experimental: false + include: - ruby: 2.7 gemfile: rails_head @@ -92,6 +116,9 @@ jobs: - ruby: '3.0' gemfile: rails_head experimental: true + - ruby: '3.1' + gemfile: rails_head + experimental: true - ruby: head gemfile: rails_head experimental: true diff --git a/Appraisals b/Appraisals index cdbf059d..14b56cd2 100644 --- a/Appraisals +++ b/Appraisals @@ -18,6 +18,12 @@ if RUBY_VERSION >= "2.5.0" appraise "rails-6-1" do gem "rails", "~> 6.1.0" end +end + +if RUBY_VERSION >= "2.7.0" + appraise "rails-7-0" do + gem "rails", "~> 7.0.0" + end appraise "rails-head" do gem "rails", github: "rails/rails", branch: "main" diff --git a/gemfiles/rails_7_0.gemfile b/gemfiles/rails_7_0.gemfile new file mode 100644 index 00000000..7c101935 --- /dev/null +++ b/gemfiles/rails_7_0.gemfile @@ -0,0 +1,10 @@ +# This file was generated by Appraisal + +source "https://rubygems.org/" + +gem "rake" +gem "mocha", require: false +gem "appraisal" +gem "rails", "~> 7.0.0" + +gemspec path: "../" From 710979958aa012f4ff21800abf5bd50b717df0a6 Mon Sep 17 00:00:00 2001 From: HParker Date: Fri, 25 Jun 2021 10:21:56 -0700 Subject: [PATCH 05/46] Remove reliance on ERBTracker from rails Use dependency tracker that does not rely on a rails dependency tracker. This prevents problems if rails chooses to remove or change ERBTracker. --- lib/jbuilder/dependency_tracker.rb | 61 ----------------- lib/jbuilder/jbuilder_dependency_tracker.rb | 73 +++++++++++++++++++++ test/jbuilder_dependency_tracker_test.rb | 3 +- 3 files changed, 74 insertions(+), 63 deletions(-) delete mode 100644 lib/jbuilder/dependency_tracker.rb create mode 100644 lib/jbuilder/jbuilder_dependency_tracker.rb diff --git a/lib/jbuilder/dependency_tracker.rb b/lib/jbuilder/dependency_tracker.rb deleted file mode 100644 index 83c8dbbb..00000000 --- a/lib/jbuilder/dependency_tracker.rb +++ /dev/null @@ -1,61 +0,0 @@ -require 'jbuilder/jbuilder' - -dependency_tracker = false - -begin - require 'action_view' - require 'action_view/dependency_tracker' - dependency_tracker = ::ActionView::DependencyTracker -rescue LoadError - begin - require 'cache_digests' - dependency_tracker = ::CacheDigests::DependencyTracker - rescue LoadError - end -end - -if dependency_tracker - class Jbuilder - module DependencyTrackerMethods - # Matches: - # json.partial! "messages/message" - # json.partial!('messages/message') - # - DIRECT_RENDERS = / - \w+\.partial! # json.partial! - \(?\s* # optional parenthesis - (['"])([^'"]+)\1 # quoted value - /x - - # Matches: - # json.partial! partial: "comments/comment" - # json.comments @post.comments, partial: "comments/comment", as: :comment - # json.array! @posts, partial: "posts/post", as: :post - # = render partial: "account" - # - INDIRECT_RENDERS = / - (?::partial\s*=>|partial:) # partial: or :partial => - \s* # optional whitespace - (['"])([^'"]+)\1 # quoted value - /x - - def dependencies - direct_dependencies + indirect_dependencies + explicit_dependencies - end - - private - - def direct_dependencies - source.scan(DIRECT_RENDERS).map(&:second) - end - - def indirect_dependencies - source.scan(INDIRECT_RENDERS).map(&:second) - end - end - end - - ::Jbuilder::DependencyTracker = Class.new(dependency_tracker::ERBTracker) - ::Jbuilder::DependencyTracker.send :include, ::Jbuilder::DependencyTrackerMethods - dependency_tracker.register_tracker :jbuilder, ::Jbuilder::DependencyTracker -end diff --git a/lib/jbuilder/jbuilder_dependency_tracker.rb b/lib/jbuilder/jbuilder_dependency_tracker.rb new file mode 100644 index 00000000..62b6dbf2 --- /dev/null +++ b/lib/jbuilder/jbuilder_dependency_tracker.rb @@ -0,0 +1,73 @@ +class Jbuilder::DependencyTracker + EXPLICIT_DEPENDENCY = /# Template Dependency: (\S+)/ + + # Matches: + # json.partial! "messages/message" + # json.partial!('messages/message') + # + DIRECT_RENDERS = / + \w+\.partial! # json.partial! + \(?\s* # optional parenthesis + (['"])([^'"]+)\1 # quoted value + /x + + # Matches: + # json.partial! partial: "comments/comment" + # json.comments @post.comments, partial: "comments/comment", as: :comment + # json.array! @posts, partial: "posts/post", as: :post + # = render partial: "account" + # + INDIRECT_RENDERS = / + (?::partial\s*=>|partial:) # partial: or :partial => + \s* # optional whitespace + (['"])([^'"]+)\1 # quoted value + /x + + def self.call(name, template, view_paths = nil) + new(name, template, view_paths).dependencies + end + + def initialize(name, template, view_paths = nil) + @name, @template, @view_paths = name, template, view_paths + end + + def dependencies + direct_dependencies + indirect_dependencies + explicit_dependencies + end + + private + + attr_reader :name, :template + + def direct_dependencies + source.scan(DIRECT_RENDERS).map(&:second) + end + + def indirect_dependencies + source.scan(INDIRECT_RENDERS).map(&:second) + end + + def explicit_dependencies + dependencies = source.scan(EXPLICIT_DEPENDENCY).flatten.uniq + + wildcards, explicits = dependencies.partition { |dependency| dependency.end_with?("/*") } + + (explicits + resolve_directories(wildcards)).uniq + end + + def resolve_directories(wildcard_dependencies) + return [] unless @view_paths + return [] if wildcard_dependencies.empty? + + # Remove trailing "/*" + prefixes = wildcard_dependencies.map { |query| query[0..-3] } + + @view_paths.flat_map(&:all_template_paths).uniq.filter_map { |path| + path.to_s if prefixes.include?(path.prefix) + }.sort + end + + def source + template.source + end +end diff --git a/test/jbuilder_dependency_tracker_test.rb b/test/jbuilder_dependency_tracker_test.rb index d89be37a..df30ea29 100644 --- a/test/jbuilder_dependency_tracker_test.rb +++ b/test/jbuilder_dependency_tracker_test.rb @@ -1,6 +1,5 @@ require 'test_helper' -require 'jbuilder/dependency_tracker' - +require 'jbuilder/jbuilder_dependency_tracker' class FakeTemplate attr_reader :source, :handler From f67dacb2eeed81cb370824f4584596eff811e0c6 Mon Sep 17 00:00:00 2001 From: Haroon Ahmed Date: Tue, 24 May 2022 21:52:26 +0100 Subject: [PATCH 06/46] Fix issue when generating jbuilder views with namespaces. Co-authored-by: Hanna --- lib/generators/rails/jbuilder_generator.rb | 4 ++++ lib/generators/rails/templates/index.json.jbuilder | 2 +- lib/generators/rails/templates/show.json.jbuilder | 2 +- test/jbuilder_generator_test.rb | 12 ++++++++++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/generators/rails/jbuilder_generator.rb b/lib/generators/rails/jbuilder_generator.rb index 0691f499..79f742e8 100644 --- a/lib/generators/rails/jbuilder_generator.rb +++ b/lib/generators/rails/jbuilder_generator.rb @@ -54,6 +54,10 @@ def attributes_list(attributes = attributes_names) def virtual_attributes attributes.select {|name| name.respond_to?(:virtual?) && name.virtual? } end + + def partial_path_name + [controller_file_path, singular_table_name].join("/") + end end end end diff --git a/lib/generators/rails/templates/index.json.jbuilder b/lib/generators/rails/templates/index.json.jbuilder index 955b0954..4e0a14e0 100644 --- a/lib/generators/rails/templates/index.json.jbuilder +++ b/lib/generators/rails/templates/index.json.jbuilder @@ -1 +1 @@ -json.array! @<%= plural_table_name %>, partial: "<%= plural_table_name %>/<%= singular_table_name %>", as: :<%= singular_table_name %> +json.array! @<%= plural_table_name %>, partial: "<%= partial_path_name %>", as: :<%= singular_table_name %> diff --git a/lib/generators/rails/templates/show.json.jbuilder b/lib/generators/rails/templates/show.json.jbuilder index 4723e6bd..4f3bf738 100644 --- a/lib/generators/rails/templates/show.json.jbuilder +++ b/lib/generators/rails/templates/show.json.jbuilder @@ -1 +1 @@ -json.partial! "<%= plural_table_name %>/<%= singular_table_name %>", <%= singular_table_name %>: @<%= singular_table_name %> +json.partial! "<%= partial_path_name %>", <%= singular_table_name %>: @<%= singular_table_name %> diff --git a/test/jbuilder_generator_test.rb b/test/jbuilder_generator_test.rb index 4884b6c7..e4a2f165 100644 --- a/test/jbuilder_generator_test.rb +++ b/test/jbuilder_generator_test.rb @@ -44,6 +44,18 @@ class JbuilderGeneratorTest < Rails::Generators::TestCase end end + test 'namespaced views are generated correctly for index' do + run_generator %w(Admin::Post --model-name=Post) + + assert_file 'app/views/admin/posts/index.json.jbuilder' do |content| + assert_match %r{json\.array! @posts, partial: "admin/posts/post", as: :post}, content + end + + assert_file 'app/views/admin/posts/show.json.jbuilder' do |content| + assert_match %r{json\.partial! "admin/posts/post", post: @post}, content + end + end + if Rails::VERSION::MAJOR >= 6 test 'handles virtual attributes' do run_generator %w(Message content:rich_text video:attachment photos:attachments) From 76b0625a0c0d719b0de8fa9d12486254b5eb7d08 Mon Sep 17 00:00:00 2001 From: Peter Goldstein Date: Mon, 16 Jan 2023 15:34:17 -0500 Subject: [PATCH 07/46] Adds Ruby 3.2 to CI. Update checkout action version. --- .github/workflows/ruby.yml | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index a29a1fe2..c62fca1f 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -23,6 +23,7 @@ jobs: - "2.7" - "3.0" - "3.1" + - "3.2" gemfile: - "rails_5_0" @@ -41,6 +42,8 @@ jobs: gemfile: rails_5_0 - ruby: '3.1' gemfile: rails_5_0 + - ruby: '3.2' + gemfile: rails_5_0 - ruby: head gemfile: rails_5_0 - ruby: 2.7 @@ -49,6 +52,8 @@ jobs: gemfile: rails_5_1 - ruby: '3.1' gemfile: rails_5_1 + - ruby: '3.2' + gemfile: rails_5_1 - ruby: head gemfile: rails_5_1 - ruby: 2.2 @@ -59,6 +64,8 @@ jobs: gemfile: rails_5_2 - ruby: '3.1' gemfile: rails_5_2 + - ruby: '3.2' + gemfile: rails_5_2 - ruby: head gemfile: rails_5_2 - ruby: 2.2 @@ -71,6 +78,8 @@ jobs: gemfile: rails_6_0 - ruby: '3.1' gemfile: rails_6_0 + - ruby: '3.2' + gemfile: rails_6_0 - ruby: head gemfile: rails_6_0 - ruby: 2.2 @@ -108,15 +117,15 @@ jobs: - ruby: '3.1' gemfile: rails_head experimental: false + - ruby: '3.2' + gemfile: rails_head + experimental: false include: - - ruby: 2.7 - gemfile: rails_head - experimental: true - - ruby: '3.0' + - ruby: '3.1' gemfile: rails_head experimental: true - - ruby: '3.1' + - ruby: '3.2' gemfile: rails_head experimental: true - ruby: head @@ -124,7 +133,7 @@ jobs: experimental: true steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: ruby/setup-ruby@v1 with: From 5a483e6e14eff644f2150d36a52f42d4221ae502 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Mon, 14 Aug 2023 11:27:28 +0200 Subject: [PATCH 08/46] Add a test for `render collection:, cached: true` Ref: https://github.com/rails/rails/pull/48936 `jbuilder` template bodies not being String tend to make Action View much more tricky than it need to be. I'm very unfamiliar with `jbuilder`, but it seems to me that in theory it could cache actual `json` fragments rather than complex ruby objects. That would be both faster and stop breaking assumptions in Action View. --- test/jbuilder_template_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/jbuilder_template_test.rb b/test/jbuilder_template_test.rb index 86f0b1eb..276fa74e 100644 --- a/test/jbuilder_template_test.rb +++ b/test/jbuilder_template_test.rb @@ -73,6 +73,14 @@ class JbuilderTemplateTest < ActiveSupport::TestCase assert_equal "Pavel", result[5]["author"]["first_name"] end + test "partial collection by name with caching" do + result = render('json.partial! "post", collection: @posts, cached: true, as: :post', posts: POSTS) + assert_equal 10, result.count + assert_equal "Post #5", result[4]["body"] + assert_equal "Heinemeier Hansson", result[2]["author"]["last_name"] + assert_equal "Pavel", result[5]["author"]["first_name"] + end + test "partial collection by name with string local" do result = render('json.partial! "post", collection: @posts, as: "post"', posts: POSTS) assert_equal 10, result.count From aaa68bb0139e38235949c9193bdbc59597eb4509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 22 Aug 2023 01:00:44 +0000 Subject: [PATCH 09/46] Test against 7-0-stable We need https://github.com/rails/rails/pull/48936 that isn't released yet to make tests on this gem to pass. --- Appraisals | 20 +++++++++++--------- gemfiles/rails_7_0.gemfile | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Appraisals b/Appraisals index 14b56cd2..8142d9ec 100644 --- a/Appraisals +++ b/Appraisals @@ -1,13 +1,15 @@ -appraise "rails-5-0" do - gem "rails", "~> 5.0.0" -end +if RUBY_VERSION < "2.7.0" + appraise "rails-5-0" do + gem "rails", "~> 5.0.0" + end -appraise "rails-5-1" do - gem "rails", "~> 5.1.0" -end + appraise "rails-5-1" do + gem "rails", "~> 5.1.0" + end -appraise "rails-5-2" do - gem "rails", "~> 5.2.0" + appraise "rails-5-2" do + gem "rails", "~> 5.2.0" + end end if RUBY_VERSION >= "2.5.0" @@ -22,7 +24,7 @@ end if RUBY_VERSION >= "2.7.0" appraise "rails-7-0" do - gem "rails", "~> 7.0.0" + gem "rails", github: "rails/rails", branch: "7-0-stable" end appraise "rails-head" do diff --git a/gemfiles/rails_7_0.gemfile b/gemfiles/rails_7_0.gemfile index 7c101935..24265009 100644 --- a/gemfiles/rails_7_0.gemfile +++ b/gemfiles/rails_7_0.gemfile @@ -5,6 +5,6 @@ source "https://rubygems.org/" gem "rake" gem "mocha", require: false gem "appraisal" -gem "rails", "~> 7.0.0" +gem "rails", github: "rails/rails", branch: "7-0-stable" gemspec path: "../" From 08a4154543f021b08ae839b612ec3eb3d0f27cfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 22 Aug 2023 01:18:39 +0000 Subject: [PATCH 10/46] Make sure Rails 5 is tested with supported Nokogiri --- Appraisals | 3 +++ gemfiles/rails_5_0.gemfile | 1 + gemfiles/rails_5_1.gemfile | 1 + gemfiles/rails_5_2.gemfile | 1 + 4 files changed, 6 insertions(+) diff --git a/Appraisals b/Appraisals index 8142d9ec..4e619f66 100644 --- a/Appraisals +++ b/Appraisals @@ -1,14 +1,17 @@ if RUBY_VERSION < "2.7.0" appraise "rails-5-0" do gem "rails", "~> 5.0.0" + gem "loofah", "< 2.21.0" end appraise "rails-5-1" do gem "rails", "~> 5.1.0" + gem "loofah", "< 2.21.0" end appraise "rails-5-2" do gem "rails", "~> 5.2.0" + gem "loofah", "< 2.21.0" end end diff --git a/gemfiles/rails_5_0.gemfile b/gemfiles/rails_5_0.gemfile index 488a5bc2..ff1598e3 100644 --- a/gemfiles/rails_5_0.gemfile +++ b/gemfiles/rails_5_0.gemfile @@ -6,5 +6,6 @@ gem "rake" gem "mocha", require: false gem "appraisal" gem "rails", "~> 5.0.0" +gem "loofah", "< 2.21.0" gemspec path: "../" diff --git a/gemfiles/rails_5_1.gemfile b/gemfiles/rails_5_1.gemfile index fff877ae..38d927a2 100644 --- a/gemfiles/rails_5_1.gemfile +++ b/gemfiles/rails_5_1.gemfile @@ -6,5 +6,6 @@ gem "rake" gem "mocha", require: false gem "appraisal" gem "rails", "~> 5.1.0" +gem "loofah", "< 2.21.0" gemspec path: "../" diff --git a/gemfiles/rails_5_2.gemfile b/gemfiles/rails_5_2.gemfile index 78272105..4b5cc02c 100644 --- a/gemfiles/rails_5_2.gemfile +++ b/gemfiles/rails_5_2.gemfile @@ -6,5 +6,6 @@ gem "rake" gem "mocha", require: false gem "appraisal" gem "rails", "~> 5.2.0" +gem "loofah", "< 2.21.0" gemspec path: "../" From 03f89202dd192e22f6bd6cbfebdd05b90ce23bcb Mon Sep 17 00:00:00 2001 From: Jalyna Date: Mon, 28 Aug 2023 14:51:44 +0200 Subject: [PATCH 11/46] Fix require path of dependency_tracker in railtie.rb Introduced in https://github.com/rails/jbuilder/commit/710979958aa012f4ff21800abf5bd50b717df0a6 --- lib/jbuilder/railtie.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jbuilder/railtie.rb b/lib/jbuilder/railtie.rb index c4ed57a0..8828b052 100644 --- a/lib/jbuilder/railtie.rb +++ b/lib/jbuilder/railtie.rb @@ -6,7 +6,7 @@ class Railtie < ::Rails::Railtie initializer :jbuilder do ActiveSupport.on_load :action_view do ActionView::Template.register_template_handler :jbuilder, JbuilderHandler - require 'jbuilder/dependency_tracker' + require 'jbuilder/jbuilder_dependency_tracker' end if Rails::VERSION::MAJOR >= 5 From 74ba8b9fad5d1f1b5b957d7ee217e8430ddfdee3 Mon Sep 17 00:00:00 2001 From: Peter Goldstein Date: Fri, 6 Oct 2023 14:48:32 -0400 Subject: [PATCH 12/46] Test against Rails 7.1 --- .github/workflows/ruby.yml | 13 ++++++++++++- Appraisals | 6 +++++- gemfiles/rails_7_0.gemfile | 2 +- gemfiles/rails_7_1.gemfile | 10 ++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 gemfiles/rails_7_1.gemfile diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index c62fca1f..4675f88c 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -32,6 +32,7 @@ jobs: - "rails_6_0" - "rails_6_1" - "rails_7_0" + - "rails_7_1" - "rails_head" experimental: [false] @@ -98,6 +99,16 @@ jobs: gemfile: rails_7_0 - ruby: 2.6 gemfile: rails_7_0 + - ruby: 2.2 + gemfile: rails_7_1 + - ruby: 2.3 + gemfile: rails_7_1 + - ruby: 2.4 + gemfile: rails_7_1 + - ruby: 2.5 + gemfile: rails_7_1 + - ruby: 2.6 + gemfile: rails_7_1 - ruby: 2.2 gemfile: rails_head - ruby: 2.3 @@ -133,7 +144,7 @@ jobs: experimental: true steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: diff --git a/Appraisals b/Appraisals index 4e619f66..1b1d2167 100644 --- a/Appraisals +++ b/Appraisals @@ -27,7 +27,11 @@ end if RUBY_VERSION >= "2.7.0" appraise "rails-7-0" do - gem "rails", github: "rails/rails", branch: "7-0-stable" + gem "rails", "~> 7.0.0" + end + + appraise "rails-7-1" do + gem "rails", "~> 7.1.0" end appraise "rails-head" do diff --git a/gemfiles/rails_7_0.gemfile b/gemfiles/rails_7_0.gemfile index 24265009..7c101935 100644 --- a/gemfiles/rails_7_0.gemfile +++ b/gemfiles/rails_7_0.gemfile @@ -5,6 +5,6 @@ source "https://rubygems.org/" gem "rake" gem "mocha", require: false gem "appraisal" -gem "rails", github: "rails/rails", branch: "7-0-stable" +gem "rails", "~> 7.0.0" gemspec path: "../" diff --git a/gemfiles/rails_7_1.gemfile b/gemfiles/rails_7_1.gemfile new file mode 100644 index 00000000..cb7710cb --- /dev/null +++ b/gemfiles/rails_7_1.gemfile @@ -0,0 +1,10 @@ +# This file was generated by Appraisal + +source "https://rubygems.org/" + +gem "rake" +gem "mocha", require: false +gem "appraisal" +gem "rails", "~> 7.1.0" + +gemspec path: "../" From 5f0ec0242d24d7c26ea9f835cfd61091ccb08575 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 3 Jan 2024 17:16:01 +0900 Subject: [PATCH 13/46] [CI] Simplify the experimental matrix --- .github/workflows/ruby.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 4675f88c..fcc5977d 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -6,7 +6,7 @@ jobs: test: name: Ruby ${{ matrix.ruby }} (${{ matrix.gemfile }}) runs-on: ubuntu-20.04 - continue-on-error: ${{ matrix.experimental }} + continue-on-error: ${{ matrix.gemfile == 'rails_head' }} env: BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile BUNDLE_JOBS: 4 @@ -35,7 +35,6 @@ jobs: - "rails_7_1" - "rails_head" - experimental: [false] exclude: - ruby: 2.7 gemfile: rails_5_0 @@ -121,27 +120,20 @@ jobs: gemfile: rails_head - ruby: 2.7 gemfile: rails_head - experimental: false - ruby: '3.0' gemfile: rails_head - experimental: false - ruby: '3.1' gemfile: rails_head - experimental: false - ruby: '3.2' gemfile: rails_head - experimental: false include: - ruby: '3.1' gemfile: rails_head - experimental: true - ruby: '3.2' gemfile: rails_head - experimental: true - ruby: head gemfile: rails_head - experimental: true steps: - uses: actions/checkout@v4 From 15171f12dc46bbd1a87f1b1a1d8666b3330d9b9d Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 3 Jan 2024 16:40:29 +0900 Subject: [PATCH 14/46] [CI] Move ruby 2.2 from matrix to include --- .github/workflows/ruby.yml | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index fcc5977d..eca306a3 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -15,7 +15,6 @@ jobs: fail-fast: false matrix: ruby: - - "2.2" - "2.3" - "2.4" - "2.5" @@ -56,8 +55,6 @@ jobs: gemfile: rails_5_1 - ruby: head gemfile: rails_5_1 - - ruby: 2.2 - gemfile: rails_5_2 - ruby: 2.7 gemfile: rails_5_2 - ruby: '3.0' @@ -68,8 +65,6 @@ jobs: gemfile: rails_5_2 - ruby: head gemfile: rails_5_2 - - ruby: 2.2 - gemfile: rails_6_0 - ruby: 2.3 gemfile: rails_6_0 - ruby: 2.4 @@ -82,14 +77,10 @@ jobs: gemfile: rails_6_0 - ruby: head gemfile: rails_6_0 - - ruby: 2.2 - gemfile: rails_6_1 - ruby: 2.3 gemfile: rails_6_1 - ruby: 2.4 gemfile: rails_6_1 - - ruby: 2.2 - gemfile: rails_7_0 - ruby: 2.3 gemfile: rails_7_0 - ruby: 2.4 @@ -98,8 +89,6 @@ jobs: gemfile: rails_7_0 - ruby: 2.6 gemfile: rails_7_0 - - ruby: 2.2 - gemfile: rails_7_1 - ruby: 2.3 gemfile: rails_7_1 - ruby: 2.4 @@ -108,8 +97,6 @@ jobs: gemfile: rails_7_1 - ruby: 2.6 gemfile: rails_7_1 - - ruby: 2.2 - gemfile: rails_head - ruby: 2.3 gemfile: rails_head - ruby: 2.4 @@ -128,6 +115,11 @@ jobs: gemfile: rails_head include: + - ruby: 2.2 + gemfile: rails_5_0 + - ruby: 2.2 + gemfile: rails_5_1 + - ruby: '3.1' gemfile: rails_head - ruby: '3.2' From c22c0c2730aac126ab2d7ce30f390fdce6137812 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 3 Jan 2024 16:44:16 +0900 Subject: [PATCH 15/46] [CI] Move ruby 2.3 from matrix to include --- .github/workflows/ruby.yml | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index eca306a3..f49b7ec8 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -15,7 +15,6 @@ jobs: fail-fast: false matrix: ruby: - - "2.3" - "2.4" - "2.5" - "2.6" @@ -65,8 +64,6 @@ jobs: gemfile: rails_5_2 - ruby: head gemfile: rails_5_2 - - ruby: 2.3 - gemfile: rails_6_0 - ruby: 2.4 gemfile: rails_6_0 - ruby: '3.0' @@ -77,28 +74,20 @@ jobs: gemfile: rails_6_0 - ruby: head gemfile: rails_6_0 - - ruby: 2.3 - gemfile: rails_6_1 - ruby: 2.4 gemfile: rails_6_1 - - ruby: 2.3 - gemfile: rails_7_0 - ruby: 2.4 gemfile: rails_7_0 - ruby: 2.5 gemfile: rails_7_0 - ruby: 2.6 gemfile: rails_7_0 - - ruby: 2.3 - gemfile: rails_7_1 - ruby: 2.4 gemfile: rails_7_1 - ruby: 2.5 gemfile: rails_7_1 - ruby: 2.6 gemfile: rails_7_1 - - ruby: 2.3 - gemfile: rails_head - ruby: 2.4 gemfile: rails_head - ruby: 2.5 @@ -119,6 +108,12 @@ jobs: gemfile: rails_5_0 - ruby: 2.2 gemfile: rails_5_1 + - ruby: 2.3 + gemfile: rails_5_0 + - ruby: 2.3 + gemfile: rails_5_1 + - ruby: 2.3 + gemfile: rails_5_2 - ruby: '3.1' gemfile: rails_head From 653c52e356cd4506522038860d2e4d81293bd355 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 3 Jan 2024 16:48:55 +0900 Subject: [PATCH 16/46] [CI] Move ruby 2.4 from matrix to include --- .github/workflows/ruby.yml | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index f49b7ec8..f1a6e2be 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -15,7 +15,6 @@ jobs: fail-fast: false matrix: ruby: - - "2.4" - "2.5" - "2.6" - "2.7" @@ -64,8 +63,6 @@ jobs: gemfile: rails_5_2 - ruby: head gemfile: rails_5_2 - - ruby: 2.4 - gemfile: rails_6_0 - ruby: '3.0' gemfile: rails_6_0 - ruby: '3.1' @@ -74,22 +71,14 @@ jobs: gemfile: rails_6_0 - ruby: head gemfile: rails_6_0 - - ruby: 2.4 - gemfile: rails_6_1 - - ruby: 2.4 - gemfile: rails_7_0 - ruby: 2.5 gemfile: rails_7_0 - ruby: 2.6 gemfile: rails_7_0 - - ruby: 2.4 - gemfile: rails_7_1 - ruby: 2.5 gemfile: rails_7_1 - ruby: 2.6 gemfile: rails_7_1 - - ruby: 2.4 - gemfile: rails_head - ruby: 2.5 gemfile: rails_head - ruby: 2.6 @@ -114,6 +103,12 @@ jobs: gemfile: rails_5_1 - ruby: 2.3 gemfile: rails_5_2 + - ruby: 2.4 + gemfile: rails_5_0 + - ruby: 2.4 + gemfile: rails_5_1 + - ruby: 2.4 + gemfile: rails_5_2 - ruby: '3.1' gemfile: rails_head From 7ba58c898a73151cfec29845383643527ec0b96a Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 3 Jan 2024 16:52:22 +0900 Subject: [PATCH 17/46] [CI] Move rails_5_0 from matrix to include --- .github/workflows/ruby.yml | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index f1a6e2be..966d28a6 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -23,7 +23,6 @@ jobs: - "3.2" gemfile: - - "rails_5_0" - "rails_5_1" - "rails_5_2" - "rails_6_0" @@ -33,16 +32,6 @@ jobs: - "rails_head" exclude: - - ruby: 2.7 - gemfile: rails_5_0 - - ruby: '3.0' - gemfile: rails_5_0 - - ruby: '3.1' - gemfile: rails_5_0 - - ruby: '3.2' - gemfile: rails_5_0 - - ruby: head - gemfile: rails_5_0 - ruby: 2.7 gemfile: rails_5_1 - ruby: '3.0' @@ -109,6 +98,10 @@ jobs: gemfile: rails_5_1 - ruby: 2.4 gemfile: rails_5_2 + - ruby: 2.5 + gemfile: rails_5_0 + - ruby: 2.6 + gemfile: rails_5_0 - ruby: '3.1' gemfile: rails_head From 9e71dfd695b78a38a71965b7eb5fe616f7ab2f12 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 3 Jan 2024 16:53:57 +0900 Subject: [PATCH 18/46] [CI] Move rails_5_1 from matrix to include --- .github/workflows/ruby.yml | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 966d28a6..d94e251e 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -23,7 +23,6 @@ jobs: - "3.2" gemfile: - - "rails_5_1" - "rails_5_2" - "rails_6_0" - "rails_6_1" @@ -32,16 +31,6 @@ jobs: - "rails_head" exclude: - - ruby: 2.7 - gemfile: rails_5_1 - - ruby: '3.0' - gemfile: rails_5_1 - - ruby: '3.1' - gemfile: rails_5_1 - - ruby: '3.2' - gemfile: rails_5_1 - - ruby: head - gemfile: rails_5_1 - ruby: 2.7 gemfile: rails_5_2 - ruby: '3.0' @@ -100,8 +89,12 @@ jobs: gemfile: rails_5_2 - ruby: 2.5 gemfile: rails_5_0 + - ruby: 2.5 + gemfile: rails_5_1 - ruby: 2.6 gemfile: rails_5_0 + - ruby: 2.6 + gemfile: rails_5_1 - ruby: '3.1' gemfile: rails_head From b153024127e115604941a791f0303b38a146d54a Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 3 Jan 2024 16:55:07 +0900 Subject: [PATCH 19/46] [CI] Move rails_5_2 from matrix to include --- .github/workflows/ruby.yml | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index d94e251e..b959bc37 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -23,7 +23,6 @@ jobs: - "3.2" gemfile: - - "rails_5_2" - "rails_6_0" - "rails_6_1" - "rails_7_0" @@ -31,16 +30,6 @@ jobs: - "rails_head" exclude: - - ruby: 2.7 - gemfile: rails_5_2 - - ruby: '3.0' - gemfile: rails_5_2 - - ruby: '3.1' - gemfile: rails_5_2 - - ruby: '3.2' - gemfile: rails_5_2 - - ruby: head - gemfile: rails_5_2 - ruby: '3.0' gemfile: rails_6_0 - ruby: '3.1' @@ -91,10 +80,14 @@ jobs: gemfile: rails_5_0 - ruby: 2.5 gemfile: rails_5_1 + - ruby: 2.5 + gemfile: rails_5_2 - ruby: 2.6 gemfile: rails_5_0 - ruby: 2.6 gemfile: rails_5_1 + - ruby: 2.6 + gemfile: rails_5_2 - ruby: '3.1' gemfile: rails_head From 353c21b677543482512d913e99a5914258710b87 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 3 Jan 2024 17:49:09 +0900 Subject: [PATCH 20/46] [CI] No need to exclude rubies that we're going include below --- .github/workflows/ruby.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index b959bc37..01df564d 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -54,10 +54,6 @@ jobs: gemfile: rails_head - ruby: '3.0' gemfile: rails_head - - ruby: '3.1' - gemfile: rails_head - - ruby: '3.2' - gemfile: rails_head include: - ruby: 2.2 From 250e6dd9a5b9775b3ec4ee9b7f0a721bb3c5dd6c Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 3 Jan 2024 16:57:19 +0900 Subject: [PATCH 21/46] [CI] Move ruby 2.5 from matrix to include --- .github/workflows/ruby.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 01df564d..72a9806a 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -15,7 +15,6 @@ jobs: fail-fast: false matrix: ruby: - - "2.5" - "2.6" - "2.7" - "3.0" @@ -38,16 +37,10 @@ jobs: gemfile: rails_6_0 - ruby: head gemfile: rails_6_0 - - ruby: 2.5 - gemfile: rails_7_0 - ruby: 2.6 gemfile: rails_7_0 - - ruby: 2.5 - gemfile: rails_7_1 - ruby: 2.6 gemfile: rails_7_1 - - ruby: 2.5 - gemfile: rails_head - ruby: 2.6 gemfile: rails_head - ruby: 2.7 @@ -78,6 +71,10 @@ jobs: gemfile: rails_5_1 - ruby: 2.5 gemfile: rails_5_2 + - ruby: 2.5 + gemfile: rails_6_0 + - ruby: 2.5 + gemfile: rails_6_1 - ruby: 2.6 gemfile: rails_5_0 - ruby: 2.6 From 7ee0adb7449b75d5afcbf63ead87cefdadf5547a Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 3 Jan 2024 16:58:24 +0900 Subject: [PATCH 22/46] [CI] Move ruby 2.6 from matrix to include --- .github/workflows/ruby.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 72a9806a..61159fcd 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -15,7 +15,6 @@ jobs: fail-fast: false matrix: ruby: - - "2.6" - "2.7" - "3.0" - "3.1" @@ -37,12 +36,6 @@ jobs: gemfile: rails_6_0 - ruby: head gemfile: rails_6_0 - - ruby: 2.6 - gemfile: rails_7_0 - - ruby: 2.6 - gemfile: rails_7_1 - - ruby: 2.6 - gemfile: rails_head - ruby: 2.7 gemfile: rails_head - ruby: '3.0' @@ -81,6 +74,10 @@ jobs: gemfile: rails_5_1 - ruby: 2.6 gemfile: rails_5_2 + - ruby: 2.6 + gemfile: rails_6_0 + - ruby: 2.6 + gemfile: rails_6_1 - ruby: '3.1' gemfile: rails_head From 7583dd0d364b4b58c5456f6464f716ab27dc7d8f Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 3 Jan 2024 17:33:23 +0900 Subject: [PATCH 23/46] [CI] Move rails_6_0 from matrix to include --- .github/workflows/ruby.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 61159fcd..3c0f86fe 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -21,21 +21,12 @@ jobs: - "3.2" gemfile: - - "rails_6_0" - "rails_6_1" - "rails_7_0" - "rails_7_1" - "rails_head" exclude: - - ruby: '3.0' - gemfile: rails_6_0 - - ruby: '3.1' - gemfile: rails_6_0 - - ruby: '3.2' - gemfile: rails_6_0 - - ruby: head - gemfile: rails_6_0 - ruby: 2.7 gemfile: rails_head - ruby: '3.0' @@ -78,6 +69,8 @@ jobs: gemfile: rails_6_0 - ruby: 2.6 gemfile: rails_6_1 + - ruby: 2.7 + gemfile: rails_6_0 - ruby: '3.1' gemfile: rails_head From e9c4ea575a0cf16681f65a76c836ca716e307a52 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 3 Jan 2024 17:55:23 +0900 Subject: [PATCH 24/46] CI against Ruby 3.3 --- .github/workflows/ruby.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 3c0f86fe..7bc85e3f 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -19,6 +19,7 @@ jobs: - "3.0" - "3.1" - "3.2" + - "3.3" gemfile: - "rails_6_1" From 814eb7f42081100721ae8d3f1513c57808efacdf Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 3 Jan 2024 19:11:00 +0900 Subject: [PATCH 25/46] Ignore log files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1ecd0e80..709e61b7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ tmp +/log gemfiles/.bundle gemfiles/*.lock Gemfile.lock From bada0f1b31247685142c75c8a4dcbd1c34a0dfc7 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 3 Jan 2024 19:14:08 +0900 Subject: [PATCH 26/46] Run tests under "test" RAILS_ENV --- test/test_helper.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_helper.rb b/test/test_helper.rb index 5fb9e7c5..299ff8db 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -14,6 +14,8 @@ ActiveSupport.test_order = :random +ENV["RAILS_ENV"] ||= "test" + class << Rails def cache @cache ||= ActiveSupport::Cache::MemoryStore.new From 6d1dc920d625195795f0fa0e1746564f36707495 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 3 Jan 2024 19:16:42 +0900 Subject: [PATCH 27/46] This has to be done in the railtie, and is already written there --- test/test_helper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 299ff8db..6ddbc418 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -35,4 +35,3 @@ class Racer < Struct.new(:id, :name) include ActiveModel::Conversion end -ActionView::Template.register_template_handler :jbuilder, JbuilderHandler From b1156705158c99ca80b7bc5f6ac1fc0703ca601e Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 3 Jan 2024 19:18:53 +0900 Subject: [PATCH 28/46] Trigger :jbuilder initializer before starting the tests and let's see if the initializer is healthly working refs #552 --- test/test_helper.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/test_helper.rb b/test/test_helper.rb index 6ddbc418..813a0e59 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -35,3 +35,11 @@ class Racer < Struct.new(:id, :name) include ActiveModel::Conversion end +# Instantiate an Application in order to trigger the initializers +Class.new(Rails::Application) do + config.secret_key_base = 'secret' + config.eager_load = false +end.initialize! + +# Touch AV::Base in order to trigger :action_view on_load hook before running the tests +ActionView::Base.inspect From 9db282b5aef2e79134ecfa6340984547e365e681 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Thu, 4 Jan 2024 03:25:20 +0900 Subject: [PATCH 29/46] Run AC & AV railties on the testing app --- test/test_helper.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_helper.rb b/test/test_helper.rb index 813a0e59..d985da9c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,6 +8,8 @@ require "active_support/cache/memory_store" require "active_support/json" require "active_model" +require 'action_controller/railtie' +require 'action_view/railtie' require "active_support/testing/autorun" require "mocha/minitest" From 5af3835446988dab84d66ce00521c68d1cd1a53e Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 3 Jan 2024 23:44:49 +0900 Subject: [PATCH 30/46] Rails 5.0 doesn't equip :action_controller_api on_load hook this reverts 96a8a397f1cc12b223c1c08c340d2edde754c649 with an improvement --- lib/jbuilder/railtie.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/jbuilder/railtie.rb b/lib/jbuilder/railtie.rb index 8828b052..2aeefbb6 100644 --- a/lib/jbuilder/railtie.rb +++ b/lib/jbuilder/railtie.rb @@ -16,9 +16,11 @@ module ApiRendering end end - ActiveSupport.on_load :action_controller_api do - include ActionController::Helpers - include ActionController::ImplicitRender + ActiveSupport.on_load :action_controller do + if name == 'ActionController::API' + include ActionController::Helpers + include ActionController::ImplicitRender + end end end end From 0919e3ffdbb6cbcc65d918470e4855f19d33a300 Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Mon, 29 Apr 2024 09:44:50 +0900 Subject: [PATCH 31/46] Use OpenStruct only if available (#562) This commit uses OpenStruct only if available because of the following reasons: - Starting from Ruby 3.4.0dev, Using `ostruct` raises the following warning. > ostruct was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0. Add ostruct to your Gemfile or gemspec. - And when the warning category is `:performance` it also raises this warning. > "OpenStruct use is discouraged for performance reasons Refer to https://bugs.ruby-lang.org/issues/20309 https://github.com/ruby/ruby/pull/10428 https://github.com/ruby/ostruct/pull/56 Fix #561 --- lib/jbuilder.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/jbuilder.rb b/lib/jbuilder.rb index 3cf41d8a..b6258c71 100644 --- a/lib/jbuilder.rb +++ b/lib/jbuilder.rb @@ -4,8 +4,11 @@ require 'jbuilder/key_formatter' require 'jbuilder/errors' require 'json' -require 'ostruct' require 'active_support/core_ext/hash/deep_merge' +begin + require 'ostruct' +rescue LoadError +end class Jbuilder @@key_formatter = nil @@ -28,7 +31,7 @@ def self.encode(*args, &block) end BLANK = Blank.new - NON_ENUMERABLES = [ ::Struct, ::OpenStruct ].to_set + NON_ENUMERABLES = defined?(::OpenStruct) ? [::Struct, ::OpenStruct].to_set : [::Struct].to_set def set!(key, value = BLANK, *args, &block) result = if ::Kernel.block_given? From 6732db4054f3a5be580d61863501c023905586a6 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Mon, 29 Apr 2024 02:46:16 +0200 Subject: [PATCH 32/46] Replace deprecated `ProxyObject` with `BasicObject` (#563) --- lib/jbuilder.rb | 8 ++++---- lib/jbuilder/jbuilder.rb | 8 +------- lib/jbuilder/jbuilder_template.rb | 6 +++--- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/jbuilder.rb b/lib/jbuilder.rb index b6258c71..51389216 100644 --- a/lib/jbuilder.rb +++ b/lib/jbuilder.rb @@ -295,7 +295,7 @@ def _extract_method_values(object, attributes) def _merge_block(key) current_value = _blank? ? BLANK : @attributes.fetch(_key(key), BLANK) - raise NullError.build(key) if current_value.nil? + ::Kernel.raise NullError.build(key) if current_value.nil? new_value = _scope{ yield self } _merge_values(current_value, new_value) end @@ -310,7 +310,7 @@ def _merge_values(current_value, updates) elsif ::Hash === current_value && ::Hash === updates current_value.deep_merge(updates) else - raise MergeError.build(current_value, updates) + ::Kernel.raise MergeError.build(current_value, updates) end end @@ -331,8 +331,8 @@ def _format_keys(hash_or_array) end def _set_value(key, value) - raise NullError.build(key) if @attributes.nil? - raise ArrayError.build(key) if ::Array === @attributes + ::Kernel.raise NullError.build(key) if @attributes.nil? + ::Kernel.raise ArrayError.build(key) if ::Array === @attributes return if @ignore_nil && value.nil? or _blank?(value) @attributes = {} if _blank? @attributes[_key(key)] = value diff --git a/lib/jbuilder/jbuilder.rb b/lib/jbuilder/jbuilder.rb index 57d23e81..22b0ac4e 100644 --- a/lib/jbuilder/jbuilder.rb +++ b/lib/jbuilder/jbuilder.rb @@ -1,7 +1 @@ -Jbuilder = Class.new(begin - require 'active_support/proxy_object' - ActiveSupport::ProxyObject -rescue LoadError - require 'active_support/basic_object' - ActiveSupport::BasicObject -end) +Jbuilder = Class.new(BasicObject) diff --git a/lib/jbuilder/jbuilder_template.rb b/lib/jbuilder/jbuilder_template.rb index b13e85fc..a9abc837 100644 --- a/lib/jbuilder/jbuilder_template.rb +++ b/lib/jbuilder/jbuilder_template.rb @@ -89,7 +89,7 @@ def cache!(key=nil, options={}) # # json.extra 'This will not work either, the root must be exclusive' def cache_root!(key=nil, options={}) if @context.controller.perform_caching - raise "cache_root! can't be used after JSON structures have been defined" if @attributes.present? + ::Kernel.raise "cache_root! can't be used after JSON structures have been defined" if @attributes.present? @cached_root = _cache_fragment_for([ :root, key ], options) { yield; target! } else @@ -148,11 +148,11 @@ def _render_partial_with_options(options) collection = EnumerableCompat.new(collection) if collection.respond_to?(:count) && !collection.respond_to?(:size) if options.has_key?(:layout) - raise ::NotImplementedError, "The `:layout' option is not supported in collection rendering." + ::Kernel.raise ::NotImplementedError, "The `:layout' option is not supported in collection rendering." end if options.has_key?(:spacer_template) - raise ::NotImplementedError, "The `:spacer_template' option is not supported in collection rendering." + ::Kernel.raise ::NotImplementedError, "The `:spacer_template' option is not supported in collection rendering." end results = CollectionRenderer From 0463bde5f3790c7a2ecfdf878b522802024b02a4 Mon Sep 17 00:00:00 2001 From: Stefanni Brasil Date: Sun, 28 Apr 2024 18:46:40 -0600 Subject: [PATCH 33/46] Document Testing configuration for RSpec users (#539) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Document testing configuration for RSpec users Jbuilder documentation does not guide users to any extra configuration to test the response body of a template. Searching for "Rspec" in the project, we see that there are lots of closed issues related to this issue. Although this extra configuration is not related to JBuilder, I believe this is an important thing to have in the documentation. Including a note about it in the documentation would save users hours of trying to debug JBuilder, and maintainer's hours that could be used on another features. * Update README.md * Link docs to rspec official docs instead of relish app Co-authored-by: Cezary Kłos --------- Co-authored-by: Cezary Kłos --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index be2b3c6e..16535ed1 100644 --- a/README.md +++ b/README.md @@ -338,6 +338,10 @@ environment.rb for example): Jbuilder.deep_format_keys true ``` +## Testing JBuilder Response body with RSpec + +To test the response body of your controller spec, enable `render_views` in your RSpec context. This [configuration](https://rspec.info/features/6-0/rspec-rails/controller-specs/render-views) renders the views in a controller test. + ## Contributing to Jbuilder Jbuilder is the work of many contributors. You're encouraged to submit pull requests, propose From 080ce0b4d142715e1b6ba5ae3735b440ef9020a4 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 28 Apr 2024 17:50:27 -0700 Subject: [PATCH 34/46] Prepare for 2.12.0 --- jbuilder.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jbuilder.gemspec b/jbuilder.gemspec index 1191ad05..50bfc9e6 100644 --- a/jbuilder.gemspec +++ b/jbuilder.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'jbuilder' - s.version = '2.11.5' + s.version = '2.12.0' s.authors = 'David Heinemeier Hansson' s.email = 'david@basecamp.com' s.summary = 'Create JSON structures via a Builder-style DSL' From 2ca1f4c1ab96393b33daba63627a1c81899fca03 Mon Sep 17 00:00:00 2001 From: Jerome Dalbert Date: Sat, 14 Sep 2024 09:12:09 -0700 Subject: [PATCH 35/46] Drop support for End of Life Ruby and Rails versions (#570) - Ruby 2.7 is EOL - Rails 5.x and 6.0 are EOL - Rails 6.1 active support is over, and security support ends in 4 weeks https://endoflife.date/rails --- .github/workflows/ruby.yml | 43 -------------------------------------- Appraisals | 27 ------------------------ gemfiles/rails_5_0.gemfile | 11 ---------- gemfiles/rails_5_1.gemfile | 11 ---------- gemfiles/rails_5_2.gemfile | 11 ---------- gemfiles/rails_6_0.gemfile | 10 --------- gemfiles/rails_6_1.gemfile | 10 --------- 7 files changed, 123 deletions(-) delete mode 100644 gemfiles/rails_5_0.gemfile delete mode 100644 gemfiles/rails_5_1.gemfile delete mode 100644 gemfiles/rails_5_2.gemfile delete mode 100644 gemfiles/rails_6_0.gemfile delete mode 100644 gemfiles/rails_6_1.gemfile diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 7bc85e3f..8e4daa70 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -15,64 +15,21 @@ jobs: fail-fast: false matrix: ruby: - - "2.7" - "3.0" - "3.1" - "3.2" - "3.3" gemfile: - - "rails_6_1" - "rails_7_0" - "rails_7_1" - "rails_head" exclude: - - ruby: 2.7 - gemfile: rails_head - ruby: '3.0' gemfile: rails_head include: - - ruby: 2.2 - gemfile: rails_5_0 - - ruby: 2.2 - gemfile: rails_5_1 - - ruby: 2.3 - gemfile: rails_5_0 - - ruby: 2.3 - gemfile: rails_5_1 - - ruby: 2.3 - gemfile: rails_5_2 - - ruby: 2.4 - gemfile: rails_5_0 - - ruby: 2.4 - gemfile: rails_5_1 - - ruby: 2.4 - gemfile: rails_5_2 - - ruby: 2.5 - gemfile: rails_5_0 - - ruby: 2.5 - gemfile: rails_5_1 - - ruby: 2.5 - gemfile: rails_5_2 - - ruby: 2.5 - gemfile: rails_6_0 - - ruby: 2.5 - gemfile: rails_6_1 - - ruby: 2.6 - gemfile: rails_5_0 - - ruby: 2.6 - gemfile: rails_5_1 - - ruby: 2.6 - gemfile: rails_5_2 - - ruby: 2.6 - gemfile: rails_6_0 - - ruby: 2.6 - gemfile: rails_6_1 - - ruby: 2.7 - gemfile: rails_6_0 - - ruby: '3.1' gemfile: rails_head - ruby: '3.2' diff --git a/Appraisals b/Appraisals index 1b1d2167..93167335 100644 --- a/Appraisals +++ b/Appraisals @@ -1,30 +1,3 @@ -if RUBY_VERSION < "2.7.0" - appraise "rails-5-0" do - gem "rails", "~> 5.0.0" - gem "loofah", "< 2.21.0" - end - - appraise "rails-5-1" do - gem "rails", "~> 5.1.0" - gem "loofah", "< 2.21.0" - end - - appraise "rails-5-2" do - gem "rails", "~> 5.2.0" - gem "loofah", "< 2.21.0" - end -end - -if RUBY_VERSION >= "2.5.0" - appraise "rails-6-0" do - gem "rails", "~> 6.0.0" - end - - appraise "rails-6-1" do - gem "rails", "~> 6.1.0" - end -end - if RUBY_VERSION >= "2.7.0" appraise "rails-7-0" do gem "rails", "~> 7.0.0" diff --git a/gemfiles/rails_5_0.gemfile b/gemfiles/rails_5_0.gemfile deleted file mode 100644 index ff1598e3..00000000 --- a/gemfiles/rails_5_0.gemfile +++ /dev/null @@ -1,11 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org/" - -gem "rake" -gem "mocha", require: false -gem "appraisal" -gem "rails", "~> 5.0.0" -gem "loofah", "< 2.21.0" - -gemspec path: "../" diff --git a/gemfiles/rails_5_1.gemfile b/gemfiles/rails_5_1.gemfile deleted file mode 100644 index 38d927a2..00000000 --- a/gemfiles/rails_5_1.gemfile +++ /dev/null @@ -1,11 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org/" - -gem "rake" -gem "mocha", require: false -gem "appraisal" -gem "rails", "~> 5.1.0" -gem "loofah", "< 2.21.0" - -gemspec path: "../" diff --git a/gemfiles/rails_5_2.gemfile b/gemfiles/rails_5_2.gemfile deleted file mode 100644 index 4b5cc02c..00000000 --- a/gemfiles/rails_5_2.gemfile +++ /dev/null @@ -1,11 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org/" - -gem "rake" -gem "mocha", require: false -gem "appraisal" -gem "rails", "~> 5.2.0" -gem "loofah", "< 2.21.0" - -gemspec path: "../" diff --git a/gemfiles/rails_6_0.gemfile b/gemfiles/rails_6_0.gemfile deleted file mode 100644 index 9bc0085f..00000000 --- a/gemfiles/rails_6_0.gemfile +++ /dev/null @@ -1,10 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org/" - -gem "rake" -gem "mocha", require: false -gem "appraisal" -gem "rails", "~> 6.0.0" - -gemspec path: "../" diff --git a/gemfiles/rails_6_1.gemfile b/gemfiles/rails_6_1.gemfile deleted file mode 100644 index d2856264..00000000 --- a/gemfiles/rails_6_1.gemfile +++ /dev/null @@ -1,10 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org/" - -gem "rake" -gem "mocha", require: false -gem "appraisal" -gem "rails", "~> 6.1.0" - -gemspec path: "../" From 8dbc23fec2cea02d24e7ab3d9629c3423ec4dcfe Mon Sep 17 00:00:00 2001 From: Jerome Dalbert Date: Sat, 14 Sep 2024 09:15:17 -0700 Subject: [PATCH 36/46] Redirect to `@record` or path in controller generator (#569) --- lib/generators/rails/templates/controller.rb | 6 +++--- test/scaffold_controller_generator_test.rb | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/generators/rails/templates/controller.rb b/lib/generators/rails/templates/controller.rb index 92f5da78..7a2e231d 100644 --- a/lib/generators/rails/templates/controller.rb +++ b/lib/generators/rails/templates/controller.rb @@ -30,7 +30,7 @@ def create respond_to do |format| if @<%= orm_instance.save %> - format.html { redirect_to <%= show_helper %>, notice: <%= %("#{human_name} was successfully created.") %> } + format.html { redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully created.") %> } format.json { render :show, status: :created, location: <%= "@#{singular_table_name}" %> } else format.html { render :new, status: :unprocessable_entity } @@ -43,7 +43,7 @@ def create def update respond_to do |format| if @<%= orm_instance.update("#{singular_table_name}_params") %> - format.html { redirect_to <%= show_helper %>, notice: <%= %("#{human_name} was successfully updated.") %> } + format.html { redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully updated.") %> } format.json { render :show, status: :ok, location: <%= "@#{singular_table_name}" %> } else format.html { render :edit, status: :unprocessable_entity } @@ -57,7 +57,7 @@ def destroy @<%= orm_instance.destroy %> respond_to do |format| - format.html { redirect_to <%= index_helper %>_url, notice: <%= %("#{human_name} was successfully destroyed.") %> } + format.html { redirect_to <%= index_helper %>_path, notice: <%= %("#{human_name} was successfully destroyed.") %> } format.json { head :no_content } end end diff --git a/test/scaffold_controller_generator_test.rb b/test/scaffold_controller_generator_test.rb index 10bf26bf..b8478aec 100644 --- a/test/scaffold_controller_generator_test.rb +++ b/test/scaffold_controller_generator_test.rb @@ -31,14 +31,14 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase assert_instance_method :create, content do |m| assert_match %r{@post = Post\.new\(post_params\)}, m assert_match %r{@post\.save}, m - assert_match %r{format\.html \{ redirect_to post_url\(@post\), notice: "Post was successfully created\." \}}, m + assert_match %r{format\.html \{ redirect_to @post, notice: "Post was successfully created\." \}}, m assert_match %r{format\.json \{ render :show, status: :created, location: @post \}}, m assert_match %r{format\.html \{ render :new, status: :unprocessable_entity \}}, m assert_match %r{format\.json \{ render json: @post\.errors, status: :unprocessable_entity \}}, m end assert_instance_method :update, content do |m| - assert_match %r{format\.html \{ redirect_to post_url\(@post\), notice: "Post was successfully updated\." \}}, m + assert_match %r{format\.html \{ redirect_to @post, notice: "Post was successfully updated\." \}}, m assert_match %r{format\.json \{ render :show, status: :ok, location: @post \}}, m assert_match %r{format\.html \{ render :edit, status: :unprocessable_entity \}}, m assert_match %r{format\.json \{ render json: @post.errors, status: :unprocessable_entity \}}, m @@ -46,7 +46,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase assert_instance_method :destroy, content do |m| assert_match %r{@post\.destroy}, m - assert_match %r{format\.html \{ redirect_to posts_url, notice: "Post was successfully destroyed\." \}}, m + assert_match %r{format\.html \{ redirect_to posts_path, notice: "Post was successfully destroyed\." \}}, m assert_match %r{format\.json \{ head :no_content \}}, m end @@ -64,15 +64,15 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase run_generator %w(Admin::Post --model-name=Post) assert_file 'app/controllers/admin/posts_controller.rb' do |content| assert_instance_method :create, content do |m| - assert_match %r{format\.html \{ redirect_to admin_post_url\(@post\), notice: "Post was successfully created\." \}}, m + assert_match %r{format\.html \{ redirect_to \[:admin, @post\], notice: "Post was successfully created\." \}}, m end assert_instance_method :update, content do |m| - assert_match %r{format\.html \{ redirect_to admin_post_url\(@post\), notice: "Post was successfully updated\." \}}, m + assert_match %r{format\.html \{ redirect_to \[:admin, @post\], notice: "Post was successfully updated\." \}}, m end assert_instance_method :destroy, content do |m| - assert_match %r{format\.html \{ redirect_to admin_posts_url, notice: "Post was successfully destroyed\." \}}, m + assert_match %r{format\.html \{ redirect_to admin_posts_path, notice: "Post was successfully destroyed\." \}}, m end end end From 0adeb9625bdafb706cab8891c065c3d987772a14 Mon Sep 17 00:00:00 2001 From: Tyler Cook <87337138+tylerjc@users.noreply.github.com> Date: Sat, 14 Sep 2024 11:32:33 -0500 Subject: [PATCH 37/46] Suggestion: Return early from collection partial rendering if blank. (#560) * Suggestion: Return early from collection partial rendering if blank. Co-authored-by: David Heinemeier Hansson --- lib/jbuilder/jbuilder_template.rb | 31 ++++++++++++++++++++----------- test/jbuilder_template_test.rb | 16 ++++++++++++++++ 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/lib/jbuilder/jbuilder_template.rb b/lib/jbuilder/jbuilder_template.rb index a9abc837..c88a6791 100644 --- a/lib/jbuilder/jbuilder_template.rb +++ b/lib/jbuilder/jbuilder_template.rb @@ -155,21 +155,30 @@ def _render_partial_with_options(options) ::Kernel.raise ::NotImplementedError, "The `:spacer_template' option is not supported in collection rendering." end - results = CollectionRenderer - .new(@context.lookup_context, options) { |&block| _scope(&block) } - .render_collection_with_partial(collection, partial, @context, nil) - - array! if results.respond_to?(:body) && results.body.nil? + if collection.present? + results = CollectionRenderer + .new(@context.lookup_context, options) { |&block| _scope(&block) } + .render_collection_with_partial(collection, partial, @context, nil) + + array! if results.respond_to?(:body) && results.body.nil? + else + array! + end elsif as && options.key?(:collection) && !CollectionRenderer.supported? # For Rails <= 5.2: as = as.to_sym collection = options.delete(:collection) - locals = options.delete(:locals) - array! collection do |member| - member_locals = locals.clone - member_locals.merge! collection: collection - member_locals.merge! as => member - _render_partial options.merge(locals: member_locals) + + if collection.present? + locals = options.delete(:locals) + array! collection do |member| + member_locals = locals.clone + member_locals.merge! collection: collection + member_locals.merge! as => member + _render_partial options.merge(locals: member_locals) + end + else + array! end else _render_partial options diff --git a/test/jbuilder_template_test.rb b/test/jbuilder_template_test.rb index 276fa74e..6b8ac82f 100644 --- a/test/jbuilder_template_test.rb +++ b/test/jbuilder_template_test.rb @@ -98,10 +98,12 @@ class JbuilderTemplateTest < ActiveSupport::TestCase end test "nil partial collection by name" do + Jbuilder::CollectionRenderer.expects(:new).never assert_equal [], render('json.partial! "post", collection: @posts, as: :post', posts: nil) end test "nil partial collection by options" do + Jbuilder::CollectionRenderer.expects(:new).never assert_equal [], render('json.partial! partial: "post", collection: @posts, as: :post', posts: nil) end @@ -113,7 +115,13 @@ class JbuilderTemplateTest < ActiveSupport::TestCase assert_equal "Pavel", result[5]["author"]["first_name"] end + test "empty array of partials from empty collection" do + Jbuilder::CollectionRenderer.expects(:new).never + assert_equal [], render('json.array! @posts, partial: "post", as: :post', posts: []) + end + test "empty array of partials from nil collection" do + Jbuilder::CollectionRenderer.expects(:new).never assert_equal [], render('json.array! @posts, partial: "post", as: :post', posts: nil) end @@ -126,10 +134,17 @@ class JbuilderTemplateTest < ActiveSupport::TestCase end test "empty array of partials under key from nil collection" do + Jbuilder::CollectionRenderer.expects(:new).never result = render('json.posts @posts, partial: "post", as: :post', posts: nil) assert_equal [], result["posts"] end + test "empty array of partials under key from an empy collection" do + Jbuilder::CollectionRenderer.expects(:new).never + result = render('json.posts @posts, partial: "post", as: :post', posts: []) + assert_equal [], result["posts"] + end + test "object fragment caching" do render(<<-JBUILDER) json.cache! "cache-key" do @@ -293,6 +308,7 @@ class JbuilderTemplateTest < ActiveSupport::TestCase if JbuilderTemplate::CollectionRenderer.supported? test "returns an empty array for an empty collection" do + Jbuilder::CollectionRenderer.expects(:new).never result = render('json.array! @posts, partial: "post", as: :post, cached: true', posts: []) # Do not use #assert_empty as it is important to ensure that the type of the JSON result is an array. From acf44b86eebeb229dea651f2a8ec4bdd64a5328c Mon Sep 17 00:00:00 2001 From: Lorenzo Del Castillo Date: Sat, 14 Sep 2024 18:33:01 +0200 Subject: [PATCH 38/46] Add missing ':see_other' status code in generated destroy controller method (#538) * Add missing ':see_other' status code when redirecting in the generated destroy controller method * Mistake --------- Co-authored-by: David Heinemeier Hansson --- lib/generators/rails/templates/controller.rb | 2 +- test/scaffold_controller_generator_test.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/generators/rails/templates/controller.rb b/lib/generators/rails/templates/controller.rb index 7a2e231d..f694d412 100644 --- a/lib/generators/rails/templates/controller.rb +++ b/lib/generators/rails/templates/controller.rb @@ -57,7 +57,7 @@ def destroy @<%= orm_instance.destroy %> respond_to do |format| - format.html { redirect_to <%= index_helper %>_path, notice: <%= %("#{human_name} was successfully destroyed.") %> } + format.html { redirect_to <%= index_helper %>_path, status: :see_other, notice: <%= %("#{human_name} was successfully destroyed.") %> } format.json { head :no_content } end end diff --git a/test/scaffold_controller_generator_test.rb b/test/scaffold_controller_generator_test.rb index b8478aec..f46b69b0 100644 --- a/test/scaffold_controller_generator_test.rb +++ b/test/scaffold_controller_generator_test.rb @@ -46,7 +46,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase assert_instance_method :destroy, content do |m| assert_match %r{@post\.destroy}, m - assert_match %r{format\.html \{ redirect_to posts_path, notice: "Post was successfully destroyed\." \}}, m + assert_match %r{format\.html \{ redirect_to posts_path, status: :see_other, notice: "Post was successfully destroyed\." \}}, m assert_match %r{format\.json \{ head :no_content \}}, m end @@ -72,7 +72,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase end assert_instance_method :destroy, content do |m| - assert_match %r{format\.html \{ redirect_to admin_posts_path, notice: "Post was successfully destroyed\." \}}, m + assert_match %r{format\.html \{ redirect_to admin_posts_path, status: :see_other, notice: "Post was successfully destroyed\." \}}, m end end end From 5288e8a7c0040a5cbe29e0742c83e4844c73d9b9 Mon Sep 17 00:00:00 2001 From: Fumiaki MATSUSHIMA Date: Sun, 15 Sep 2024 23:12:53 +0900 Subject: [PATCH 39/46] Remove OpenStruct references from Jbuilder (#567) --- lib/jbuilder.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/jbuilder.rb b/lib/jbuilder.rb index 51389216..04180b36 100644 --- a/lib/jbuilder.rb +++ b/lib/jbuilder.rb @@ -5,10 +5,6 @@ require 'jbuilder/errors' require 'json' require 'active_support/core_ext/hash/deep_merge' -begin - require 'ostruct' -rescue LoadError -end class Jbuilder @@key_formatter = nil @@ -31,7 +27,6 @@ def self.encode(*args, &block) end BLANK = Blank.new - NON_ENUMERABLES = defined?(::OpenStruct) ? [::Struct, ::OpenStruct].to_set : [::Struct].to_set def set!(key, value = BLANK, *args, &block) result = if ::Kernel.block_given? @@ -354,7 +349,7 @@ def _scope end def _is_collection?(object) - _object_respond_to?(object, :map, :count) && NON_ENUMERABLES.none?{ |klass| klass === object } + _object_respond_to?(object, :map, :count) && !(::Struct === object) end def _blank?(value=@attributes) From 1a18149bd012d8820d7607ace2f97a3d8c0e9817 Mon Sep 17 00:00:00 2001 From: Jerome Dalbert Date: Sun, 15 Sep 2024 07:13:36 -0700 Subject: [PATCH 40/46] Use new `params.expect` syntax (#573) --- .../rails/templates/api_controller.rb | 6 ++++++ lib/generators/rails/templates/controller.rb | 6 ++++++ test/scaffold_api_controller_generator_test.rb | 17 +++++++++++++++-- test/scaffold_controller_generator_test.rb | 17 +++++++++++++++-- 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/lib/generators/rails/templates/api_controller.rb b/lib/generators/rails/templates/api_controller.rb index c41c744c..5c2222cc 100644 --- a/lib/generators/rails/templates/api_controller.rb +++ b/lib/generators/rails/templates/api_controller.rb @@ -48,13 +48,19 @@ def destroy private # Use callbacks to share common setup or constraints between actions. def set_<%= singular_table_name %> + <%- if Rails::VERSION::MAJOR >= 8 -%> + @<%= singular_table_name %> = <%= orm_class.find(class_name, "params.expect(:id)") %> + <%- else -%> @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %> + <%- end -%> end # Only allow a list of trusted parameters through. def <%= "#{singular_table_name}_params" %> <%- if attributes_names.empty? -%> params.fetch(<%= ":#{singular_table_name}" %>, {}) + <%- elsif Rails::VERSION::MAJOR >= 8 -%> + params.expect(<%= singular_table_name %>: [ <%= permitted_params %> ]) <%- else -%> params.require(<%= ":#{singular_table_name}" %>).permit(<%= permitted_params %>) <%- end -%> diff --git a/lib/generators/rails/templates/controller.rb b/lib/generators/rails/templates/controller.rb index f694d412..4771067a 100644 --- a/lib/generators/rails/templates/controller.rb +++ b/lib/generators/rails/templates/controller.rb @@ -65,13 +65,19 @@ def destroy private # Use callbacks to share common setup or constraints between actions. def set_<%= singular_table_name %> + <%- if Rails::VERSION::MAJOR >= 8 -%> + @<%= singular_table_name %> = <%= orm_class.find(class_name, "params.expect(:id)") %> + <%- else -%> @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %> + <%- end -%> end # Only allow a list of trusted parameters through. def <%= "#{singular_table_name}_params" %> <%- if attributes_names.empty? -%> params.fetch(<%= ":#{singular_table_name}" %>, {}) + <%- elsif Rails::VERSION::MAJOR >= 8 -%> + params.expect(<%= singular_table_name %>: [ <%= permitted_params %> ]) <%- else -%> params.require(<%= ":#{singular_table_name}" %>).permit(<%= permitted_params %>) <%- end -%> diff --git a/test/scaffold_api_controller_generator_test.rb b/test/scaffold_api_controller_generator_test.rb index 2c8f8ef8..e7e2b355 100644 --- a/test/scaffold_api_controller_generator_test.rb +++ b/test/scaffold_api_controller_generator_test.rb @@ -38,8 +38,17 @@ class ScaffoldApiControllerGeneratorTest < Rails::Generators::TestCase assert_match %r{@post\.destroy}, m end + assert_match %r{def set_post}, content + if Rails::VERSION::MAJOR >= 8 + assert_match %r{params\.expect\(:id\)}, content + else + assert_match %r{params\[:id\]}, content + end + assert_match %r{def post_params}, content - if Rails::VERSION::MAJOR >= 6 + if Rails::VERSION::MAJOR >= 8 + assert_match %r{params\.expect\(post: \[ :title, :body, images: \[\] \]\)}, content + elsif Rails::VERSION::MAJOR >= 6 assert_match %r{params\.require\(:post\)\.permit\(:title, :body, images: \[\]\)}, content else assert_match %r{params\.require\(:post\)\.permit\(:title, :body, :images\)}, content @@ -62,7 +71,11 @@ class ScaffoldApiControllerGeneratorTest < Rails::Generators::TestCase run_generator ["Message", "content:rich_text", "video:attachment", "photos:attachments"] assert_file 'app/controllers/messages_controller.rb' do |content| - assert_match %r{params\.require\(:message\)\.permit\(:content, :video, photos: \[\]\)}, content + if Rails::VERSION::MAJOR >= 8 + assert_match %r{params\.expect\(message: \[ :content, :video, photos: \[\] \]\)}, content + else + assert_match %r{params\.require\(:message\)\.permit\(:content, :video, photos: \[\]\)}, content + end end end end diff --git a/test/scaffold_controller_generator_test.rb b/test/scaffold_controller_generator_test.rb index f46b69b0..f2a06f9a 100644 --- a/test/scaffold_controller_generator_test.rb +++ b/test/scaffold_controller_generator_test.rb @@ -50,8 +50,17 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase assert_match %r{format\.json \{ head :no_content \}}, m end + assert_match %r{def set_post}, content + if Rails::VERSION::MAJOR >= 8 + assert_match %r{params\.expect\(:id\)}, content + else + assert_match %r{params\[:id\]}, content + end + assert_match %r{def post_params}, content - if Rails::VERSION::MAJOR >= 6 + if Rails::VERSION::MAJOR >= 8 + assert_match %r{params\.expect\(post: \[ :title, :body, images: \[\] \]\)}, content + elsif Rails::VERSION::MAJOR >= 6 assert_match %r{params\.require\(:post\)\.permit\(:title, :body, images: \[\]\)}, content else assert_match %r{params\.require\(:post\)\.permit\(:title, :body, :images\)}, content @@ -92,7 +101,11 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase run_generator %w(Message content:rich_text video:attachment photos:attachments) assert_file 'app/controllers/messages_controller.rb' do |content| - assert_match %r{params\.require\(:message\)\.permit\(:content, :video, photos: \[\]\)}, content + if Rails::VERSION::MAJOR >= 8 + assert_match %r{params\.expect\(message: \[ :content, :video, photos: \[\] \]\)}, content + else + assert_match %r{params\.require\(:message\)\.permit\(:content, :video, photos: \[\]\)}, content + end end end end From e18fe2ab38026320e6ea0afd5a6ed291be40f216 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 15 Sep 2024 07:29:38 -0700 Subject: [PATCH 41/46] Give Jbuilder a programmatically accessible version --- lib/jbuilder.rb | 1 + lib/jbuilder/version.rb | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 lib/jbuilder/version.rb diff --git a/lib/jbuilder.rb b/lib/jbuilder.rb index 04180b36..b12624be 100644 --- a/lib/jbuilder.rb +++ b/lib/jbuilder.rb @@ -3,6 +3,7 @@ require 'jbuilder/blank' require 'jbuilder/key_formatter' require 'jbuilder/errors' +require 'jbuilder/version' require 'json' require 'active_support/core_ext/hash/deep_merge' diff --git a/lib/jbuilder/version.rb b/lib/jbuilder/version.rb new file mode 100644 index 00000000..f9e500e6 --- /dev/null +++ b/lib/jbuilder/version.rb @@ -0,0 +1,3 @@ +class Jbuilder + VERSION = "2.12.0" +end From 99c42bdd3dc8bcc0d4e685418478019481c95a4e Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 15 Sep 2024 07:29:48 -0700 Subject: [PATCH 42/46] Add release binstub --- bin/release | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 bin/release diff --git a/bin/release b/bin/release new file mode 100755 index 00000000..eec14c94 --- /dev/null +++ b/bin/release @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +VERSION=$1 + +printf "class Jbuilder\n VERSION = \"$VERSION\"\nend\n" > ./lib/jbuilder/version.rb +bundle +git add Gemfile.lock lib/jbuilder/version.rb +git commit -m "Bump version for $VERSION" +git push +git tag v$VERSION +git push --tags +gem build jbuilder.gemspec +gem push "jbuilder-$VERSION.gem" --host https://rubygems.org +rm "jbuilder-$VERSION.gem" From 9bcd653c166f09faeee5fe1934500340576f32f0 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 15 Sep 2024 07:29:54 -0700 Subject: [PATCH 43/46] Add test binstub --- CONTRIBUTING.md | 8 +------- bin/test | 6 ++++++ 2 files changed, 7 insertions(+), 7 deletions(-) create mode 100755 bin/test diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0ecd004d..35e5f960 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -33,13 +33,7 @@ git checkout -b my-feature-branch #### Bundle Install and Test -Ensure that you can build the project and run tests. - -``` -bundle install -appraisal install -appraisal rake test -``` +Ensure that you can build the project and run tests using `bin/test`. #### Write Tests diff --git a/bin/test b/bin/test new file mode 100755 index 00000000..45d4fe95 --- /dev/null +++ b/bin/test @@ -0,0 +1,6 @@ +#!/bin/env bash +set -e + +bundle install +appraisal install +appraisal rake test From d4698962069424a87ebdd2d3c2d649e15c431ca4 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 15 Sep 2024 07:33:46 -0700 Subject: [PATCH 44/46] Bump version for 2.13.0 --- lib/jbuilder/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jbuilder/version.rb b/lib/jbuilder/version.rb index f9e500e6..2a62782f 100644 --- a/lib/jbuilder/version.rb +++ b/lib/jbuilder/version.rb @@ -1,3 +1,3 @@ class Jbuilder - VERSION = "2.12.0" + VERSION = "2.13.0" end From acf7a46cc63ae74f5e84c0ccf11dbe97c21ebd48 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 15 Sep 2024 07:36:33 -0700 Subject: [PATCH 45/46] No lock committed --- bin/release | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/release b/bin/release index eec14c94..97dbe40d 100755 --- a/bin/release +++ b/bin/release @@ -4,7 +4,7 @@ VERSION=$1 printf "class Jbuilder\n VERSION = \"$VERSION\"\nend\n" > ./lib/jbuilder/version.rb bundle -git add Gemfile.lock lib/jbuilder/version.rb +git add lib/jbuilder/version.rb git commit -m "Bump version for $VERSION" git push git tag v$VERSION From 9aa3dd9d0e8142d58108ea00fdcc6cabda1df18d Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 15 Sep 2024 07:36:46 -0700 Subject: [PATCH 46/46] Use new version const --- jbuilder.gemspec | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jbuilder.gemspec b/jbuilder.gemspec index 50bfc9e6..0b519531 100644 --- a/jbuilder.gemspec +++ b/jbuilder.gemspec @@ -1,6 +1,8 @@ +require_relative "lib/jbuilder/version" + Gem::Specification.new do |s| s.name = 'jbuilder' - s.version = '2.12.0' + s.version = Jbuilder::VERSION s.authors = 'David Heinemeier Hansson' s.email = 'david@basecamp.com' s.summary = 'Create JSON structures via a Builder-style DSL'