Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package rubygem-jbuilder for openSUSE:Factory checked in at 2021-12-25 20:16:46 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/rubygem-jbuilder (Old) and /work/SRC/openSUSE:Factory/.rubygem-jbuilder.new.2520 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "rubygem-jbuilder" Sat Dec 25 20:16:46 2021 rev:25 rq:942441 version:2.11.5 Changes: -------- --- /work/SRC/openSUSE:Factory/rubygem-jbuilder/rubygem-jbuilder.changes 2021-02-20 22:12:12.687034050 +0100 +++ /work/SRC/openSUSE:Factory/.rubygem-jbuilder.new.2520/rubygem-jbuilder.changes 2021-12-25 20:17:13.585277965 +0100 @@ -1,0 +2,9 @@ +Sat Dec 25 09:41:14 UTC 2021 - Manuel Schnitzer <mschnit...@suse.com> + +- updated to version 2.11.5 + + # What's Changed + + * Make sure action_view is loaded before using it. + +------------------------------------------------------------------- Old: ---- jbuilder-2.11.2.gem New: ---- jbuilder-2.11.5.gem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ rubygem-jbuilder.spec ++++++ --- /var/tmp/diff_new_pack.KzFXbz/_old 2021-12-25 20:17:14.061278353 +0100 +++ /var/tmp/diff_new_pack.KzFXbz/_new 2021-12-25 20:17:14.065278356 +0100 @@ -24,7 +24,7 @@ # Name: rubygem-jbuilder -Version: 2.11.2 +Version: 2.11.5 Release: 0 %define mod_name jbuilder %define mod_full_name %{mod_name}-%{version} @@ -48,7 +48,7 @@ %install %gem_install \ - --doc-files="CHANGELOG.md MIT-LICENSE README.md" \ + --doc-files="MIT-LICENSE README.md" \ -f %gem_packages ++++++ jbuilder-2.11.2.gem -> jbuilder-2.11.5.gem ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/.github/workflows/ruby.yml new/.github/workflows/ruby.yml --- old/.github/workflows/ruby.yml 1970-01-01 01:00:00.000000000 +0100 +++ new/.github/workflows/ruby.yml 2021-12-21 05:03:55.000000000 +0100 @@ -0,0 +1,108 @@ +name: Ruby test + +on: [push, pull_request] + +jobs: + test: + name: Ruby ${{ matrix.ruby }} (${{ matrix.gemfile }}) + runs-on: ubuntu-20.04 + continue-on-error: ${{ matrix.experimental }} + env: + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile + BUNDLE_JOBS: 4 + BUNDLE_RETRY: 3 + strategy: + fail-fast: false + matrix: + ruby: + - "2.2" + - "2.3" + - "2.4" + - "2.5" + - "2.6" + - "2.7" + - "3.0" + + gemfile: + - "rails_5_0" + - "rails_5_1" + - "rails_5_2" + - "rails_6_0" + - "rails_6_1" + - "rails_head" + + experimental: [false] + exclude: + - ruby: 2.7 + gemfile: rails_5_0 + - ruby: '3.0' + 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: head + gemfile: rails_5_1 + - ruby: 2.2 + gemfile: rails_5_2 + - ruby: 2.7 + gemfile: rails_5_2 + - ruby: '3.0' + 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 + gemfile: rails_6_0 + - ruby: '3.0' + 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_head + - ruby: 2.3 + gemfile: rails_head + - ruby: 2.4 + gemfile: rails_head + - ruby: 2.5 + gemfile: rails_head + - ruby: 2.6 + gemfile: rails_head + - ruby: 2.7 + gemfile: rails_head + experimental: false + - ruby: '3.0' + gemfile: rails_head + experimental: false + include: + - ruby: 2.7 + gemfile: rails_head + experimental: true + - ruby: '3.0' + gemfile: rails_head + experimental: true + - ruby: head + gemfile: rails_head + experimental: true + + steps: + - uses: actions/checkout@v2 + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + + - name: Ruby test + run: bundle exec rake diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/.travis.yml new/.travis.yml --- old/.travis.yml 2021-01-27 13:37:14.000000000 +0100 +++ new/.travis.yml 1970-01-01 01:00:00.000000000 +0100 @@ -1,52 +0,0 @@ -language: ruby - -cache: bundler - -before_install: - - "gem install bundler -v '<2'" - -rvm: - - 2.2.10 - - 2.3.8 - - 2.4.10 - - 2.5.8 - - 2.6.6 - - 2.7.1 - - ruby-head - -gemfile: - - gemfiles/rails_5_0.gemfile - - gemfiles/rails_5_1.gemfile - - gemfiles/rails_5_2.gemfile - - gemfiles/rails_6_0.gemfile - - gemfiles/rails_head.gemfile - -matrix: - exclude: - - rvm: 2.7.1 - gemfile: gemfiles/rails_5_0.gemfile - - rvm: 2.7.1 - gemfile: gemfiles/rails_5_1.gemfile - - rvm: 2.2.10 - gemfile: gemfiles/rails_5_2.gemfile - - rvm: 2.7.1 - gemfile: gemfiles/rails_5_2.gemfile - - rvm: 2.2.10 - gemfile: gemfiles/rails_6_0.gemfile - - rvm: 2.3.8 - gemfile: gemfiles/rails_6_0.gemfile - - rvm: 2.4.10 - gemfile: gemfiles/rails_6_0.gemfile - - rvm: 2.2.10 - gemfile: gemfiles/rails_head.gemfile - - rvm: 2.3.8 - gemfile: gemfiles/rails_head.gemfile - - rvm: 2.4.10 - gemfile: gemfiles/rails_head.gemfile - allow_failures: - - rvm: ruby-head - - gemfile: gemfiles/rails_head.gemfile - fast_finish: true - -notifications: - email: false diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Appraisals new/Appraisals --- old/Appraisals 2021-01-27 13:37:14.000000000 +0100 +++ new/Appraisals 2021-12-21 05:03:55.000000000 +0100 @@ -15,7 +15,11 @@ gem "rails", "~> 6.0.0" end + appraise "rails-6-1" do + gem "rails", "~> 6.1.0" + end + appraise "rails-head" do - gem "rails", github: "rails/rails" + gem "rails", github: "rails/rails", branch: "main" end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/CHANGELOG.md new/CHANGELOG.md --- old/CHANGELOG.md 2021-01-27 13:37:14.000000000 +0100 +++ new/CHANGELOG.md 1970-01-01 01:00:00.000000000 +0100 @@ -1,311 +0,0 @@ -# Changelog - -2.11.2 ------- - -* [Improve key formatting for nested hashes and disable by default](https://github.com/rails/jbuilder/pull/497) - -2.11.1 ------- - -* Use symbols instead of strings for before_action filters [DHH] -* Slim down comments in generated scaffold code [DHH] - -2.11.0 ------- - -* [Allow jbuilder instance to be passed to #merge!](https://github.com/rails/jbuilder/pull/485) -* [Fix for key_format! when using nested hashes](https://github.com/rails/jbuilder/pull/486) -* [Include rich_text, attachment, and attachments fields in json partial](https://github.com/rails/jbuilder/pull/459) - -2.10.2 ------- - -* Update scaffold generator to use double quotes, 422 form error responds, and modern string-of-arrays syntax [DHH] - -2.10.1 ------- - -* Fix keyword arguments warning on Ruby 2.7 - -2.10.0 ------- - -* Requires Rails 5+ and Ruby 2.2+ -* Nested hashes are deep-merged - -2.9.1 ------ - -* [Respect JSON encoding customizations](https://github.com/rails/jbuilder/commit/e2e8623b08078ad6a2323ce8ecaf642b7afe1166) - -2.9.0 ------ - -* [Fix passing object with partial without locals](https://github.com/rails/jbuilder/pull/435) -* [Fix deprecation warning in Rails 6.0](https://github.com/rails/jbuilder/pull/453) -* [Use quotes consistently in generated templates](https://github.com/rails/jbuilder/pull/455) -* [Allow omitting timestamps from generated partials](https://github.com/rails/jbuilder/pull/448) -* [Respect changing scaffold generator](https://github.com/rails/jbuilder/pull/458) -* [Use a symbolic default format for Rails 6.0 forward compatibility](https://github.com/rails/jbuilder/commit/3895a7243f3db292b0bf15513fc05494e6e50576) -* [Drop MultiJSON in favor of Ruby standard library JSON](https://github.com/rails/jbuilder/commit/b952ae096eb1828b0fcfde06e6ba62311494ec49) - -2.8.0 ------ - -* [Replace deprecated fragment_cache_key for Rails 5.2 support](https://github.com/rails/jbuilder/pull/430) - -2.7.0 ------ - -* [Requires Rails 4+](https://github.com/rails/jbuilder/commit/5207ff394533177fffdd768bfaa6413a0cd16dc8) -* [Fix implicitly rendering a JSON partial with the same name as an - HTML partial](https://github.com/rails/jbuilder/pull/400) - -2.6.4 ------ - -* Drop the pessimistic upper-bound restriction on Active Support and MultiJSON to prevent future gemfile resolution deadlocks *DHH* - -2.6.3 ------ - -* Support Rails 5.1 - -2.6.2 ------ - -* Fix thor warnings - -2.6.1 ------ - -* [Optimize root caches with cache_root!](https://github.com/rails/jbuilder/pull/370) - -2.6.0 ------ - -* [Rails 5 cache! with expire support](https://github.com/rails/jbuilder/commit/d61e3354563863731bc1f358f495b1dbb7ae9d32) -* [Generated view DRYed by using model partial](https://github.com/rails/jbuilder/commit/83256f4d7e9211c9dc47972feaed7fd31e4f7cac) - -2.5.0 ------ - -* [Rails 5 compatibility](https://github.com/rails/jbuilder/commit/64c510ec69d9e63b73ffd5942e802d21a7d14701) - -2.4.1 ------ - -* [Fix controller generators to be Rails 5 compatible](https://github.com/rails/jbuilder/commit/2dc6203c5c4a98701d5b64c2a5200835a48bb533) - -2.4.0 ------ - -* [Rails 5 compatibility](https://github.com/rails/jbuilder/commit/4aa2cfcc19a4634d65a28ffc75f0ac0cb8304115) - -2.3.2 ------ - -* [Remove Mime Types deprecation message](https://github.com/rails/jbuilder/commit/5ba4e4ac654cc8388619538f576fe234659b84ec) - -2.3.1 ------ - -* [Explicitly require ostruct to prevent NameError](https://github.com/rails/jbuilder/pull/281) - -2.3.0 ------ - -* [Add new in-place partial invocation support](https://github.com/rails/jbuilder/commit/1feda7ee605c136e59fb4de970f4674de518e6de) -* [Add implicit partial rendering for AM::Models](https://github.com/rails/jbuilder/commit/4d5bf7d0ea92765adb7be36834e84f9855a061df) -* [Generate API controller if Rails API option is enabled](https://github.com/rails/jbuilder/commit/db68f6bd327cf42b47ef22d455fb5721a8c2cf5f) -* [JBuilder's templates have less priority than app templates](https://github.com/rails/jbuilder/commit/7c1a5f25603ec1f4e51fba3dbba9db23726a5d69) -* [Add AC::Helpers module to jbuilder for api only apps](https://github.com/rails/jbuilder/commit/7cf1d1eb7d125caf38309b5427952030011c1aa0) - -2.2.16 ------- - -* [Fix NoMethodError around `api_only` in railtie](https://github.com/rails/jbuilder/commit/b08d1da10b14720b46d383b2917e336060fd9ffa) - -2.2.14 ------- - -* [Make Jbuilder compatible with Rails API](https://github.com/rails/jbuilder/commit/29c0014a9c954c990075d42c45c66075260e924b) - -2.2.13 ------- - -* Several performance optimizations: [#260](https://github.com/rails/jbuilder/pull/260) & [#261](https://github.com/rails/jbuilder/pull/261) - -2.2.12 ------- - -* [Replace explicit block calls with yield for performance](https://github.com/rails/jbuilder/commit/3184f941276ad03a071cf977133d1a32302afa47) - -2.2.11 ------- - -* Generate the templates for Rails 5+ [#258](https://github.com/rails/jbuilder/pull/258) [@amatsuda](https://github.com/amatsuda) - -2.2.10 ------- - -* Add Jbuilder::Blank#empty? to tell if attributes are empty [#257](https://github.com/rails/jbuilder/pull/257) [@a2ikm](https://github.com/a2ikm) - -2.2.9 ------ - -* Support `partial!` call with `locals` option in `JbuilderTemplate` [#251](https://github.com/rails/jbuilder/pull/251) - -2.2.8 ------ -* [Raise ArrayError when trying to add key to an array](https://github.com/rails/jbuilder/commit/869e4be1ad165ce986d8fca78311bdd3ed166087) - -2.2.7 ------ -* [Make Blank object serializable with Marshal](https://github.com/rails/jbuilder/commit/7083f28d8b665aa60d0d1b1927ae88bb5c6290ba) - -2.2.6 ------ -* [Make sure dependency tracker loads after template handler](https://github.com/rails/jbuilder/commit/3ba404b1207b557e14771c90b8832bc01ae67a42) - -2.2.5 ------ -* [Refactor merge block behavior to raise error for unexpected values](https://github.com/rails/jbuilder/commit/4503162fb26f53f613fc83ac081fd244748b6fe9) - -2.2.4 ------ -* [Typecast locals hash key during collection render](https://github.com/rails/jbuilder/commit/a6b0c8651a08e01cb53eee38e211c65423f275f7) - -2.2.3 ------ -* [Move template handler registration into railtie](https://github.com/rails/jbuilder/commit/c8acc5cea6da2a79b7b345adc301cb5ff2517647) -* [Do not capture the block where it is possible](https://github.com/rails/jbuilder/commit/973b382c3924cb59fc0e4e25266b18e74d41d646) - -2.2.2 ------ -* [Fix `Jbuilder#merge!` inside block](https://github.com/rails/jbuilder/commit/a7b328552eb0d36315f75bff813bea7eecf8c1d7) - -2.2.1 ------ -* [Fix empty block handling](https://github.com/rails/jbuilder/commit/972a11141403269e9b17b45b0c95f8a9788245ee) - -2.2.0 ------ -* [Allow to skip `array!` iterations by calling `next`](https://github.com/rails/jbuilder/commit/81a63308fb9d5002519dd871f829ccc58067251a) - -2.1.2 ------ -* [Cast array-like objects to array before merging](https://github.com/rails/jbuilder/commit/7b8c8a1cb09b7f3dd26e5643ebbd6b2ec67185db) - -2.1.1 ------ -* [Remove unused file](https://github.com/rails/jbuilder/commit/e49e1047976fac93b8242ab212c7b1a463b70809) - -2.1.0 ------ -* [Blocks and their extract! shortcuts are additive by default](https://github.com/rails/jbuilder/commit/a49390736c5f6e2d7a31111df6531bc28dba9fb1) - -2.0.8 ------ -* [Eliminate circular dependencies](https://github.com/rails/jbuilder/commit/0879484dc74e7be93b695f66e3708ba48cdb1be3) -* [Support cache key generation for complex objects](https://github.com/rails/jbuilder/commit/ca9622cca30c1112dd4408fcb2e658849abe1dd5) -* [Remove JbuilderProxy class](https://github.com/rails/jbuilder/commit/5877482fc7da3224e42d4f72a1386f7a3a08173b) -* [Move KeyFormatter into a separate file](https://github.com/rails/jbuilder/commit/13fee8464ff53ce853030114283c03c135c052b6) -* [Move NullError into a separate file](https://github.com/rails/jbuilder/commit/13fee8464ff53ce853030114283c03c135c052b6) - -2.0.7 ------ -* [Add destroy notice to scaffold generator](https://github.com/rails/jbuilder/commit/8448e86f8cdfa0f517bd59576947875775a1d43c) - -2.0.6 ------ -* [Use render short form in controller generator](https://github.com/rails/jbuilder/commit/acf37320a7cea7fcc70c791bc94bd5f46b8349ff) - -2.0.5 ------ -* [Fix edgecase when json is defined as a method](https://github.com/rails/jbuilder/commit/ca711a0c0a5760e26258ce2d93c14bef8fff0ead) - -2.0.4 ------ -* [Add cache_if! to conditionally cache JSON fragments](https://github.com/rails/jbuilder/commit/14a5afd8a2c939a6fd710d355a194c114db96eb2) - -2.0.3 ------ -* [Pass options when calling cache_fragment_name](https://github.com/rails/jbuilder/commit/07c2cc7486fe9ef423d7bc821b83f6d485f330e0) - -2.0.2 ------ -* [Fix Dependency Tracking fail to detect single-quoted partial correctly](https://github.com/rails/jbuilder/commit/448679a6d3098eb34d137f782a05f1767711991a) -* [Prevent Dependency Tracker constants leaking into global namespace](https://github.com/rails/jbuilder/commit/3544b288b63f504f46fa8aafd1d17ee198d77536) - -2.0.1 ------ -* [Dependency tracking support for Rails 3 with cache_digest gem](https://github.com/rails/jbuilder/commit/6b471d7a38118e8f7645abec21955ef793401daf) - -2.0.0 ------ -* [Respond to PUT/PATCH API request with :ok](https://github.com/rails/jbuilder/commit/9dbce9c12181e89f8f472ac23c764ffe8438040a) -* [Remove Ruby 1.8 support](https://github.com/rails/jbuilder/commit/d53fff42d91f33d662eafc2561c4236687ecf6c9) -* [Remove deprecated two argument block call](https://github.com/rails/jbuilder/commit/07a35ee7e79ae4b06dba9dbff5c4e07c1e627218) -* [Make Jbuilder object initialize with single hash](https://github.com/rails/jbuilder/commit/38bf551db0189327aaa90b9be010c0d1b792c007) -* [Track template dependencies](https://github.com/rails/jbuilder/commit/8e73cea39f60da1384afd687cc8e5e399630d8cc) -* [Expose merge! method](https://github.com/rails/jbuilder/commit/0e2eb47f6f3c01add06a1a59b37cdda8baf24f29) - -1.5.3 ------ -* [Generators add `:id` column by default](https://github.com/rails/jbuilder/commit/0b52b86773e48ac2ce35d4155c7b70ad8b3e8937) - -1.5.2 ------ -* [Nil-collection should be treated as empty array](https://github.com/rails/jbuilder/commit/2f700bb00ab663c6b7fcb28d2967aeb989bd43c7) - -1.5.1 ------ -* [Expose template lookup options](https://github.com/rails/jbuilder/commit/404c18dee1af96ac6d8052a04062629ef1db2945) - -1.5.0 ------ -* [Do not perform any caching when `controller.perform_caching` is false](https://github.com/rails/jbuilder/commit/94633facde1ac43580f8cd5e13ae9cc83e1da8f4) -* [Add partial collection rendering](https://github.com/rails/jbuilder/commit/e8c10fc885e41b18178aaf4dcbc176961c928d76) -* [Deprecate extract! calling private methods](https://github.com/rails/jbuilder/commit/b9e19536c2105d7f2e813006bbcb8ca5730d28a3) -* [Add array of partials rendering](https://github.com/rails/jbuilder/commit/7d7311071720548047f98f14ad013c560b8d9c3a) - -1.4.2 ------ -* [Require MIME dependency explicitly](https://github.com/rails/jbuilder/commit/b1ed5ac4f08b056f8839b4b19b43562e81e02a59) - -1.4.1 ------ -* [Removed deprecated positioned arguments initializer support](https://github.com/rails/jbuilder/commit/6e03e0452073eeda77e6dfe66aa31e5ec67a3531) -* [Deprecate two-arguments block calling](https://github.com/rails/jbuilder/commit/2b10bb058bb12bc782cbcc16f6ec67b489e5ed43) - -1.4.0 ------ -* [Add quick collection attribute extraction](https://github.com/rails/jbuilder/commit/c2b966cf653ea4264fbb008b8cc6ce5359ebe40a) -* [Block has priority over attributes extraction](https://github.com/rails/jbuilder/commit/77c24766362c02769d81dac000b1879a9e4d4a00) -* [Meaningful error messages when adding properties to null](https://github.com/rails/jbuilder/commit/e26764602e34b3772e57e730763d512e59489e3b) -* [Do not enforce template format, enforce handlers instead](https://github.com/rails/jbuilder/commit/72576755224b15da45e50cbea877679800ab1398) - -1.3.0 ------ -* [Add nil! method for nil JSON](https://github.com/rails/jbuilder/commit/822a906f68664f61a1209336bb681077692c8475) - -1.2.1 ------ -* [Added explicit dependency for MultiJson](https://github.com/rails/jbuilder/commit/4d58eacb6cd613679fb243484ff73a79bbbff2d2) - -1.2.0 ------ -* Multiple documentation improvements and internal refactoring -* [Fixes fragment caching to work with latest digests](https://github.com/rails/jbuilder/commit/da937d6b8732124074c612abb7ff38868d1d96c0) - -1.0.2 ------ -* [Support non-Enumerable collections](https://github.com/rails/jbuilder/commit/4c20c59bf8131a1e419bb4ebf84f2b6bdcb6b0cf) -* [Ensure that the default URL is in json format](https://github.com/rails/jbuilder/commit/0b46782fb7b8c34a3c96afa801fe27a5a97118a4) - -1.0.0 ------ -* Adopt Semantic Versioning -* Add rails generators diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/CONTRIBUTING.md new/CONTRIBUTING.md --- old/CONTRIBUTING.md 2021-01-27 13:37:14.000000000 +0100 +++ new/CONTRIBUTING.md 2021-12-21 05:03:55.000000000 +0100 @@ -1,11 +1,11 @@ Contributing to Jbuilder ===================== -[][travis] +[][test] [][gem] [][codeclimate] -[travis]: https://travis-ci.org/rails/jbuilder +[test]: https://github.com/rails/jbuilder/actions?query=branch%3Amaster [gem]: https://rubygems.org/gems/jbuilder [codeclimate]: https://codeclimate.com/github/rails/jbuilder @@ -95,7 +95,7 @@ #### Check on Your Pull Request -Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above. +Go back to your pull request after a few minutes and see whether it passed muster with GitHub Actions. Everything should look green, otherwise fix issues and amend your commit as described above. #### Be Patient diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/README.md new/README.md --- old/README.md 2021-01-27 13:37:14.000000000 +0100 +++ new/README.md 2021-12-21 05:03:55.000000000 +0100 @@ -108,6 +108,33 @@ # => [ { "id": 1, "name": "David" }, { "id": 2, "name": "Jamie" } ] ``` +To make a plain array without keys, construct and pass in a standard Ruby array. + +```ruby +my_array = %w(David Jamie) + +json.people my_array + +# => "people": [ "David", "Jamie" ] +``` + +You don't always have or need a collection when building an array. + +```ruby +json.people do + json.child! do + json.id 1 + json.name 'David' + end + json.child! do + json.id 2 + json.name 'Jamie' + end +end + +# => { "people": [ { "id": 1, "name": "David" }, { "id": 2, "name": "Jamie" } ] } +``` + Jbuilder objects can be directly nested inside each other. Useful for composing objects. ``` ruby @@ -137,7 +164,7 @@ ``` You can either use Jbuilder stand-alone or directly as an ActionView template -language. When required in Rails, you can create views a la show.json.jbuilder +language. When required in Rails, you can create views ?? la show.json.jbuilder (the json is already yielded): ``` ruby @@ -171,19 +198,19 @@ json.array! @posts, partial: 'posts/post', as: :post # or - json.partial! 'posts/post', collection: @posts, as: :post # or - json.partial! partial: 'posts/post', collection: @posts, as: :post # or - json.comments @post.comments, partial: 'comments/comment', as: :comment ``` -The `as: :some_symbol` is used with partials. It will take care of mapping the passed in object to a variable for the partial. If the value is a collection (either implicitly or explicitly by using the `collection:` option, then each value of the collection is passed to the partial as the variable `some_symbol`. If the value is a singular object, then the object is passed to the partial as the variable `some_symbol`. +The `as: :some_symbol` is used with partials. It will take care of mapping the passed in object to a variable for the +partial. If the value is a collection either implicitly or explicitly by using the `collection:` option, then each +value of the collection is passed to the partial as the variable `some_symbol`. If the value is a singular object, +then the object is passed to the partial as the variable `some_symbol`. Be sure not to confuse the `as:` option to mean nesting of the partial. For example: @@ -193,7 +220,7 @@ json.partial! @comment, as: :comment ``` -is quite different than: +is quite different from: ```ruby # comment attributes are nested under a "comment" property @@ -236,6 +263,8 @@ # => { "bar": "bar" } ``` +## Caching + Fragment caching is supported, it uses `Rails.cache` and works like caching in HTML templates: @@ -253,9 +282,25 @@ end ``` -If you are rendering fragments for a collection of objects, have a look at -`jbuilder_cache_multi` gem. It uses fetch_multi (>= Rails 4.1) to fetch -multiple keys at once. +Aside from that, the `:cached` options on collection rendering is available on Rails >= 6.0. This will cache the +rendered results effectively using the multi fetch feature. + +```ruby +json.array! @posts, partial: "posts/post", as: :post, cached: true + +# or: +json.comments @post.comments, partial: "comments/comment", as: :comment, cached: true +``` + +If your collection cache depends on multiple sources (try to avoid this to keep things simple), you can name all these dependencies as part of a block that returns an array: + +```ruby +json.array! @posts, partial: "posts/post", as: :post, cached: -> post { [post, current_user] } +``` + +This will include both records as part of the cache key and updating either of them will expire the cache. + +## Formatting Keys Keys can be auto formatted using `key_format!`, this can be used to convert keynames from the standard ruby_format to camelCase: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Rakefile new/Rakefile --- old/Rakefile 2021-01-27 13:37:14.000000000 +0100 +++ new/Rakefile 2021-12-21 05:03:55.000000000 +0100 @@ -2,7 +2,7 @@ require "bundler/gem_tasks" require "rake/testtask" -if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"] +if !ENV["APPRAISAL_INITIALIZED"] && !ENV["CI"] require "appraisal/task" Appraisal::Task.new task default: :appraisal Binary files old/checksums.yaml.gz and new/checksums.yaml.gz differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gemfiles/rails_6_1.gemfile new/gemfiles/rails_6_1.gemfile --- old/gemfiles/rails_6_1.gemfile 1970-01-01 01:00:00.000000000 +0100 +++ new/gemfiles/rails_6_1.gemfile 2021-12-21 05:03:55.000000000 +0100 @@ -0,0 +1,10 @@ +# 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: "../" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gemfiles/rails_head.gemfile new/gemfiles/rails_head.gemfile --- old/gemfiles/rails_head.gemfile 2021-01-27 13:37:14.000000000 +0100 +++ new/gemfiles/rails_head.gemfile 2021-12-21 05:03:55.000000000 +0100 @@ -5,6 +5,6 @@ gem "rake" gem "mocha", require: false gem "appraisal" -gem "rails", github: "rails/rails" +gem "rails", github: "rails/rails", branch: "main" gemspec path: "../" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/jbuilder.gemspec new/jbuilder.gemspec --- old/jbuilder.gemspec 2021-01-27 13:37:14.000000000 +0100 +++ new/jbuilder.gemspec 2021-12-21 05:03:55.000000000 +0100 @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'jbuilder' - s.version = '2.11.2' + s.version = '2.11.5' s.authors = 'David Heinemeier Hansson' s.email = 'da...@basecamp.com' s.summary = 'Create JSON structures via a Builder-style DSL' @@ -10,6 +10,7 @@ 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') @@ -19,4 +20,12 @@ s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- test/*`.split("\n") + + s.metadata = { + "bug_tracker_uri" => "https://github.com/rails/jbuilder/issues", + "changelog_uri" => "https://github.com/rails/jbuilder/releases/tag/v#{s.version}", + "mailing_list_uri" => "https://discuss.rubyonrails.org/c/rubyonrails-talk", + "source_code_uri" => "https://github.com/rails/jbuilder/tree/v#{s.version}", + "rubygems_mfa_required" => "true", + } end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/generators/rails/templates/controller.rb new/lib/generators/rails/templates/controller.rb --- old/lib/generators/rails/templates/controller.rb 2021-01-27 13:37:14.000000000 +0100 +++ new/lib/generators/rails/templates/controller.rb 2021-12-21 05:03:55.000000000 +0100 @@ -30,7 +30,7 @@ respond_to do |format| if @<%= orm_instance.save %> - format.html { redirect_to @<%= singular_table_name %>, notice: <%= %("#{human_name} was successfully created.") %> } + format.html { redirect_to <%= show_helper %>, 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 update respond_to do |format| if @<%= orm_instance.update("#{singular_table_name}_params") %> - format.html { redirect_to @<%= singular_table_name %>, notice: <%= %("#{human_name} was successfully updated.") %> } + format.html { redirect_to <%= show_helper %>, notice: <%= %("#{human_name} was successfully updated.") %> } format.json { render :show, status: :ok, location: <%= "@#{singular_table_name}" %> } else format.html { render :edit, status: :unprocessable_entity } @@ -55,6 +55,7 @@ # DELETE <%= route_url %>/1 or <%= route_url %>/1.json def destroy @<%= orm_instance.destroy %> + respond_to do |format| format.html { redirect_to <%= index_helper %>_url, notice: <%= %("#{human_name} was successfully destroyed.") %> } format.json { head :no_content } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/jbuilder/collection_renderer.rb new/lib/jbuilder/collection_renderer.rb --- old/lib/jbuilder/collection_renderer.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/jbuilder/collection_renderer.rb 2021-12-21 05:03:55.000000000 +0100 @@ -0,0 +1,109 @@ +require 'delegate' +require 'active_support/concern' +require 'action_view' + +begin + require 'action_view/renderer/collection_renderer' +rescue LoadError + require 'action_view/renderer/partial_renderer' +end + +class Jbuilder + module CollectionRenderable # :nodoc: + extend ActiveSupport::Concern + + class_methods do + def supported? + superclass.private_method_defined?(:build_rendered_template) && self.superclass.private_method_defined?(:build_rendered_collection) + end + end + + private + + def build_rendered_template(content, template, layout = nil) + super(content || json.attributes!, template) + end + + def build_rendered_collection(templates, _spacer) + json.merge!(templates.map(&:body)) + end + + def json + @options[:locals].fetch(:json) + end + + class ScopedIterator < ::SimpleDelegator # :nodoc: + include Enumerable + + def initialize(obj, scope) + super(obj) + @scope = scope + end + + # Rails 6.0 support: + def each + return enum_for(:each) unless block_given? + + __getobj__.each do |object| + @scope.call { yield(object) } + end + end + + # Rails 6.1 support: + def each_with_info + return enum_for(:each_with_info) unless block_given? + + __getobj__.each_with_info do |object, info| + @scope.call { yield(object, info) } + end + end + end + + private_constant :ScopedIterator + end + + if defined?(::ActionView::CollectionRenderer) + # Rails 6.1 support: + class CollectionRenderer < ::ActionView::CollectionRenderer # :nodoc: + include CollectionRenderable + + def initialize(lookup_context, options, &scope) + super(lookup_context, options) + @scope = scope + end + + private + def collection_with_template(view, template, layout, collection) + super(view, template, layout, ScopedIterator.new(collection, @scope)) + end + end + else + # Rails 6.0 support: + class CollectionRenderer < ::ActionView::PartialRenderer # :nodoc: + include CollectionRenderable + + def initialize(lookup_context, options, &scope) + super(lookup_context) + @options = options + @scope = scope + end + + def render_collection_with_partial(collection, partial, context, block) + render(context, @options.merge(collection: collection, partial: partial), block) + end + + private + def collection_without_template(view) + @collection = ScopedIterator.new(@collection, @scope) + + super(view) + end + + def collection_with_template(view, template) + @collection = ScopedIterator.new(@collection, @scope) + + super(view, template) + end + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/jbuilder/jbuilder_template.rb new/lib/jbuilder/jbuilder_template.rb --- old/lib/jbuilder/jbuilder_template.rb 2021-01-27 13:37:14.000000000 +0100 +++ new/lib/jbuilder/jbuilder_template.rb 2021-12-21 05:03:55.000000000 +0100 @@ -1,4 +1,5 @@ require 'jbuilder/jbuilder' +require 'jbuilder/collection_renderer' require 'action_dispatch/http/mime_type' require 'active_support/cache' @@ -15,6 +16,38 @@ super(*args) end + # Generates JSON using the template specified with the `:partial` option. For example, the code below will render + # the file `views/comments/_comments.json.jbuilder`, and set a local variable comments with all this message's + # comments, which can be used inside the partial. + # + # Example: + # + # json.partial! 'comments/comments', comments: @message.comments + # + # There are multiple ways to generate a collection of elements as JSON, as ilustrated below: + # + # Example: + # + # json.array! @posts, partial: 'posts/post', as: :post + # + # # or: + # json.partial! 'posts/post', collection: @posts, as: :post + # + # # or: + # json.partial! partial: 'posts/post', collection: @posts, as: :post + # + # # or: + # json.comments @post.comments, partial: 'comments/comment', as: :comment + # + # Aside from that, the `:cached` options is available on Rails >= 6.0. This will cache the rendered results + # effectively using the multi fetch feature. + # + # Example: + # + # json.array! @posts, partial: "posts/post", as: :post, cached: true + # + # json.comments @post.comments, partial: "comments/comment", as: :comment, cached: true + # def partial!(*args) if args.one? && _is_active_model?(args.first) _render_active_model_partial args.first @@ -104,11 +137,30 @@ private def _render_partial_with_options(options) - options.reverse_merge! locals: options.except(:partial, :as, :collection) + options.reverse_merge! locals: options.except(:partial, :as, :collection, :cached) options.reverse_merge! ::JbuilderTemplate.template_lookup_options as = options[:as] - if as && options.key?(:collection) + if as && options.key?(:collection) && CollectionRenderer.supported? + collection = options.delete(:collection) || [] + partial = options.delete(:partial) + options[:locals].merge!(json: self) + + if options.has_key?(:layout) + 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." + 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? + elsif as && options.key?(:collection) && !CollectionRenderer.supported? + # For Rails <= 5.2: as = as.to_sym collection = options.delete(:collection) locals = options.delete(:locals) @@ -162,12 +214,7 @@ def _fragment_name_with_digest(key, options) if @context.respond_to?(:cache_fragment_name) - # Current compatibility, fragment_name_with_digest is private again and cache_fragment_name - # should be used instead. @context.cache_fragment_name(key, **options) - elsif @context.respond_to?(:fragment_name_with_digest) - # Backwards compatibility for period of time when fragment_name_with_digest was made public. - @context.fragment_name_with_digest(key) else key end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/jbuilder/railtie.rb new/lib/jbuilder/railtie.rb --- old/lib/jbuilder/railtie.rb 2021-01-27 13:37:14.000000000 +0100 +++ new/lib/jbuilder/railtie.rb 2021-12-21 05:03:55.000000000 +0100 @@ -1,4 +1,4 @@ -require 'rails/railtie' +require 'rails' require 'jbuilder/jbuilder_template' class Jbuilder diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/jbuilder.rb new/lib/jbuilder.rb --- old/lib/jbuilder.rb 2021-01-27 13:37:14.000000000 +0100 +++ new/lib/jbuilder.rb 2021-12-21 05:03:55.000000000 +0100 @@ -1,3 +1,4 @@ +require 'active_support' require 'jbuilder/jbuilder' require 'jbuilder/blank' require 'jbuilder/key_formatter' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/metadata new/metadata --- old/metadata 2021-01-27 13:37:14.000000000 +0100 +++ new/metadata 2021-12-21 05:03:55.000000000 +0100 @@ -1,14 +1,14 @@ --- !ruby/object:Gem::Specification name: jbuilder version: !ruby/object:Gem::Version - version: 2.11.2 + version: 2.11.5 platform: ruby authors: - David Heinemeier Hansson autorequire: bindir: bin cert_chain: [] -date: 2021-01-27 00:00:00.000000000 Z +date: 2021-12-21 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: activesupport @@ -24,16 +24,29 @@ - - ">=" - !ruby/object:Gem::Version version: 5.0.0 +- !ruby/object:Gem::Dependency + name: actionview + requirement: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: 5.0.0 + type: :runtime + prerelease: false + version_requirements: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: 5.0.0 description: email: da...@basecamp.com executables: [] extensions: [] extra_rdoc_files: [] files: +- ".github/workflows/ruby.yml" - ".gitignore" -- ".travis.yml" - Appraisals -- CHANGELOG.md - CONTRIBUTING.md - Gemfile - MIT-LICENSE @@ -43,6 +56,7 @@ - gemfiles/rails_5_1.gemfile - gemfiles/rails_5_2.gemfile - gemfiles/rails_6_0.gemfile +- gemfiles/rails_6_1.gemfile - gemfiles/rails_head.gemfile - jbuilder.gemspec - lib/generators/rails/jbuilder_generator.rb @@ -54,6 +68,7 @@ - lib/generators/rails/templates/show.json.jbuilder - lib/jbuilder.rb - lib/jbuilder/blank.rb +- lib/jbuilder/collection_renderer.rb - lib/jbuilder/dependency_tracker.rb - lib/jbuilder/errors.rb - lib/jbuilder/jbuilder.rb @@ -70,7 +85,12 @@ homepage: https://github.com/rails/jbuilder licenses: - MIT -metadata: {} +metadata: + bug_tracker_uri: https://github.com/rails/jbuilder/issues + changelog_uri: https://github.com/rails/jbuilder/releases/tag/v2.11.5 + mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk + source_code_uri: https://github.com/rails/jbuilder/tree/v2.11.5 + rubygems_mfa_required: 'true' post_install_message: rdoc_options: [] require_paths: @@ -86,7 +106,7 @@ - !ruby/object:Gem::Version version: '0' requirements: [] -rubygems_version: 3.1.2 +rubygems_version: 3.2.32 signing_key: specification_version: 4 summary: Create JSON structures via a Builder-style DSL diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/jbuilder_dependency_tracker_test.rb new/test/jbuilder_dependency_tracker_test.rb --- old/test/jbuilder_dependency_tracker_test.rb 2021-01-27 13:37:14.000000000 +0100 +++ new/test/jbuilder_dependency_tracker_test.rb 2021-12-21 05:03:55.000000000 +0100 @@ -61,7 +61,7 @@ assert_equal %w[comments/comment], dependencies end - test 'detects explicit depedency' do + test 'detects explicit dependency' do dependencies = track_dependencies <<-RUBY # Template Dependency: path/to/partial json.foo 'bar' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/jbuilder_template_test.rb new/test/jbuilder_template_test.rb --- old/test/jbuilder_template_test.rb 2021-01-27 13:37:14.000000000 +0100 +++ new/test/jbuilder_template_test.rb 2021-12-21 05:03:55.000000000 +0100 @@ -159,7 +159,7 @@ end test "object fragment caching with expiry" do - travel_to "2018-05-12 11:29:00 -0400" + travel_to Time.iso8601("2018-05-12T11:29:00-04:00") render <<-JBUILDER json.cache! "cache-key", expires_in: 1.minute do @@ -283,6 +283,101 @@ assert_equal "David", result["firstName"] end + if JbuilderTemplate::CollectionRenderer.supported? + test "returns an empty array for an empty collection" do + 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. + assert_equal [], result + end + + 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) + end + end + + result = render('json.array! @posts, partial: "post", as: :post, cached: true', posts: enumerable_class.new) + + # Do not use #assert_empty as it is important to ensure that the type of the JSON result is an array. + assert_equal [], result + end + + test "supports the cached: true option" do + result = render('json.array! @posts, partial: "post", as: :post, cached: true', 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"] + + expected = { + "id" => 1, + "body" => "Post #1", + "author" => { + "first_name" => "David", + "last_name" => "Heinemeier Hansson" + } + } + + assert_equal expected, Rails.cache.read("post-1") + + result = render('json.array! @posts, partial: "post", as: :post, cached: true', 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 "supports the cached: ->() {} option" do + result = render('json.array! @posts, partial: "post", as: :post, cached: ->(post) { [post, "foo"] }', 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"] + + expected = { + "id" => 1, + "body" => "Post #1", + "author" => { + "first_name" => "David", + "last_name" => "Heinemeier Hansson" + } + } + + assert_equal expected, Rails.cache.read("post-1/foo") + + result = render('json.array! @posts, partial: "post", as: :post, cached: ->(post) { [post, "foo"] }', 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 "raises an error on a render call with the :layout option" do + error = assert_raises NotImplementedError do + render('json.array! @posts, partial: "post", as: :post, layout: "layout"', posts: POSTS) + end + + assert_equal "The `:layout' option is not supported in collection rendering.", error.message + end + + test "raises an error on a render call with the :spacer_template option" do + error = assert_raises NotImplementedError do + render('json.array! @posts, partial: "post", as: :post, spacer_template: "template"', posts: POSTS) + end + + assert_equal "The `:spacer_template' option is not supported in collection rendering.", error.message + end + end + private def render(*args) JSON.load render_without_parsing(*args) @@ -290,7 +385,7 @@ def render_without_parsing(source, assigns = {}) view = build_view(fixtures: PARTIALS.merge("source.json.jbuilder" => source), assigns: assigns) - view.render(template: "source.json.jbuilder") + view.render(template: "source") end def build_view(options = {}) @@ -306,6 +401,9 @@ end def view.view_cache_dependencies; []; end + def view.combined_fragment_cache_key(key) [ key ] end + def view.cache_fragment_name(key, *) key end + def view.fragment_name_with_digest(key) key end view end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/jbuilder_test.rb new/test/jbuilder_test.rb --- old/test/jbuilder_test.rb 2021-01-27 13:37:14.000000000 +0100 +++ new/test/jbuilder_test.rb 2021-12-21 05:03:55.000000000 +0100 @@ -312,7 +312,7 @@ assert_equal 'world', result['comments'].second['content'] end - test 'nesting multiple chilren from a non-Enumerable that responds to #map with inline loop' do + test 'nesting multiple children from a non-Enumerable that responds to #map with inline loop' do comments = NonEnumerable.new([ Comment.new('hello', 1), Comment.new('world', 2) ]) result = jbuild do |json| diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/scaffold_api_controller_generator_test.rb new/test/scaffold_api_controller_generator_test.rb --- old/test/scaffold_api_controller_generator_test.rb 2021-01-27 13:37:14.000000000 +0100 +++ new/test/scaffold_api_controller_generator_test.rb 2021-12-21 05:03:55.000000000 +0100 @@ -47,7 +47,7 @@ end end - test 'dont use require and permit if there are no attributes' do + test "don't use require and permit if there are no attributes" do run_generator %w(Post --api) assert_file 'app/controllers/posts_controller.rb' do |content| diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/scaffold_controller_generator_test.rb new/test/scaffold_controller_generator_test.rb --- old/test/scaffold_controller_generator_test.rb 2021-01-27 13:37:14.000000000 +0100 +++ new/test/scaffold_controller_generator_test.rb 2021-12-21 05:03:55.000000000 +0100 @@ -31,14 +31,14 @@ 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, notice: "Post was successfully created\." \}}, m + assert_match %r{format\.html \{ redirect_to post_url\(@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, notice: "Post was successfully updated\." \}}, m + assert_match %r{format\.html \{ redirect_to post_url\(@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 @@ -59,7 +59,26 @@ end end - test 'dont use require and permit if there are no attributes' do + if Rails::VERSION::MAJOR >= 6 + test 'controller with namespace' do + 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 + 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 + end + + assert_instance_method :destroy, content do |m| + assert_match %r{format\.html \{ redirect_to admin_posts_url, notice: "Post was successfully destroyed\." \}}, m + end + end + end + end + + test "don't use require and permit if there are no attributes" do run_generator %w(Post) assert_file 'app/controllers/posts_controller.rb' do |content| diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/test_helper.rb new/test/test_helper.rb --- old/test/test_helper.rb 2021-01-27 13:37:14.000000000 +0100 +++ new/test/test_helper.rb 2021-12-21 05:03:55.000000000 +0100 @@ -1,14 +1,13 @@ require "bundler/setup" -require "active_support" +require "rails" + +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" @@ -21,7 +20,13 @@ end end -class Post < Struct.new(:id, :body, :author_name); end +Jbuilder::CollectionRenderer.collection_cache = Rails.cache + +class Post < Struct.new(:id, :body, :author_name) + def cache_key + "post-#{id}" + end +end class Racer < Struct.new(:id, :name) extend ActiveModel::Naming @@ -29,6 +34,3 @@ end ActionView::Template.register_template_handler :jbuilder, JbuilderHandler - -ActionView::Base.remove_possible_method :fragment_name_with_digest -ActionView::Base.remove_possible_method :cache_fragment_name