commit rubygem-jbuilder for openSUSE:Factory
Hello community, here is the log from the commit of package rubygem-jbuilder for openSUSE:Factory checked in at 2019-05-17 23:44:31 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/rubygem-jbuilder (Old) and /work/SRC/openSUSE:Factory/.rubygem-jbuilder.new.5148 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "rubygem-jbuilder" Fri May 17 23:44:31 2019 rev:21 rq:703703 version:2.9.1 Changes: -------- --- /work/SRC/openSUSE:Factory/rubygem-jbuilder/rubygem-jbuilder.changes 2018-11-10 17:02:17.183540376 +0100 +++ /work/SRC/openSUSE:Factory/.rubygem-jbuilder.new.5148/rubygem-jbuilder.changes 2019-05-17 23:44:38.673863996 +0200 @@ -1,0 +2,20 @@ +Fri May 17 11:25:31 UTC 2019 - Lukas Krause <lukas.krause@suse.com> + +- update to version 2.9.1 + see installed CHANGELOG.md + + 2.9.1 + ----- + * Respect JSON encoding customizations + + 2.9.0 + ----- + * Fix passing object with partial without locals + * Fix deprecation warning in Rails 6.0 + * Use quotes consistently in generated templates + * Allow omitting timestamps from generated partials + * Respect changing scaffold generator + * Use a symbolic default format for Rails 6.0 forward compatibility + * Drop MultiJSON in favor of Ruby standard library JSON + +------------------------------------------------------------------- Old: ---- jbuilder-2.8.0.gem New: ---- jbuilder-2.9.1.gem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ rubygem-jbuilder.spec ++++++ --- /var/tmp/diff_new_pack.bF9qNZ/_old 2019-05-17 23:44:39.097863763 +0200 +++ /var/tmp/diff_new_pack.bF9qNZ/_new 2019-05-17 23:44:39.101863761 +0200 @@ -1,7 +1,7 @@ # # spec file for package rubygem-jbuilder # -# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -24,7 +24,7 @@ # Name: rubygem-jbuilder -Version: 2.8.0 +Version: 2.9.1 Release: 0 %define mod_name jbuilder %define mod_full_name %{mod_name}-%{version} ++++++ jbuilder-2.8.0.gem -> jbuilder-2.9.1.gem ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/.gitignore new/.gitignore --- old/.gitignore 2018-11-05 16:49:16.000000000 +0100 +++ new/.gitignore 2019-05-14 19:38:31.000000000 +0200 @@ -3,3 +3,4 @@ Gemfile.lock .ruby-version pkg +*.gem diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/.travis.yml new/.travis.yml --- old/.travis.yml 2018-11-05 16:49:16.000000000 +0100 +++ new/.travis.yml 2019-05-14 19:38:31.000000000 +0200 @@ -1,56 +1,67 @@ language: ruby -sudo: false cache: bundler before_install: - - gem update --system - - gem install bundler + - "gem update --system 2.7.9" + - "gem install bundler -v '<2'" rvm: - - 1.9 - - 2.0 - - 2.1 - 2.2.10 - - 2.3.7 - - 2.4.4 - - 2.5.1 + - 2.3.8 + - 2.4.6 + - 2.5.5 + - 2.6.2 - ruby-head - - jruby-19mode - - rbx + - rbx-3.107 gemfile: - gemfiles/rails_4_2.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: - allow_failures: - - rvm: jruby-19mode - - rvm: rbx - - rvm: ruby-head - fast_finish: true - exclude: - - rvm: 1.9 - gemfile: gemfiles/rails_5_0.gemfile + include: - rvm: 1.9 - gemfile: gemfiles/rails_5_1.gemfile + gemfile: gemfiles/rails_4_2.gemfile - rvm: 2.0 - gemfile: gemfiles/rails_5_0.gemfile - - rvm: 2.0 - gemfile: gemfiles/rails_5_1.gemfile - - rvm: 2.1 - gemfile: gemfiles/rails_5_0.gemfile + gemfile: gemfiles/rails_4_2.gemfile - rvm: 2.1 - gemfile: gemfiles/rails_5_1.gemfile + gemfile: gemfiles/rails_4_2.gemfile + - rvm: 2.3 + gemfile: gemfiles/rails_4_2.gemfile - rvm: jruby-19mode - gemfile: gemfiles/rails_5_0.gemfile + gemfile: gemfiles/rails_4_2.gemfile + - rvm: rbx-3.107 + gemfile: gemfiles/rails_4_2.gemfile + exclude: + - rvm: 2.4.6 + gemfile: gemfiles/rails_4_2.gemfile + - rvm: 2.5.5 + gemfile: gemfiles/rails_4_2.gemfile + - rvm: 2.6.2 + gemfile: gemfiles/rails_4_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.6 + 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.6 + gemfile: gemfiles/rails_head.gemfile + allow_failures: - rvm: jruby-19mode - gemfile: gemfiles/rails_5_1.gemfile - - rvm: rbx - gemfile: gemfiles/rails_5_0.gemfile - - rvm: rbx - gemfile: gemfiles/rails_5_1.gemfile + - rvm: rbx-3.107 + - 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 2018-11-05 16:49:16.000000000 +0100 +++ new/Appraisals 2019-05-14 19:38:31.000000000 +0200 @@ -1,13 +1,27 @@ appraise "rails-4-2" do - gem "rails", "~> 4.2.0" + gem "rails", "~> 4.2.0" end if RUBY_VERSION >= "2.2.2" appraise "rails-5-0" do - gem "rails", ">= 5.0.0", "< 5.1" + gem "rails", "~> 5.0.0" end appraise "rails-5-1" do - gem "rails", ">= 5.1.0", "< 5.2" + gem "rails", "~> 5.1.0" + end + + appraise "rails-5-2" do + gem "rails", "~> 5.2.0" + end +end + +if RUBY_VERSION >= "2.5.0" + appraise "rails-6-0" do + gem "rails", "~> 6.0.0.rc1" + end + + appraise "rails-head" do + gem "rails", github: "rails/rails" end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/CHANGELOG.md new/CHANGELOG.md --- old/CHANGELOG.md 2018-11-05 16:49:16.000000000 +0100 +++ new/CHANGELOG.md 2019-05-14 19:38:31.000000000 +0200 @@ -1,5 +1,21 @@ # Changelog +2.9.1 +----- + +* [Respect JSON encoding customizations](https://github.com/rails/jbuilder/commit/e2e8623b08078ad6a2323ce8ecaf642b7af...) + +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/3895a7243f3db292b0bf15513fc05494e6e...) +* [Drop MultiJSON in favor of Ruby standard library JSON](https://github.com/rails/jbuilder/commit/b952ae096eb1828b0fcfde06e6ba6231149...) + 2.8.0 ----- diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Gemfile new/Gemfile --- old/Gemfile 2018-11-05 16:49:16.000000000 +0100 +++ new/Gemfile 2019-05-14 19:38:31.000000000 +0200 @@ -5,4 +5,3 @@ gem "rake" gem "mocha", require: false gem "appraisal" -gem "pry" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/README.md new/README.md --- old/README.md 2018-11-05 16:49:16.000000000 +0100 +++ new/README.md 2019-05-14 19:38:31.000000000 +0200 @@ -156,7 +156,6 @@ end ``` - You can use partials as well. The following will render the file `views/comments/_comments.json.jbuilder`, and set a local variable `comments` with all this message's comments, which you can use inside @@ -184,6 +183,25 @@ 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`. + +Be sure not to confuse the `as:` option to mean nesting of the partial. For example: + +```ruby + # Use the default `views/comments/_comment.json.jbuilder`, putting @comment as the comment local variable. + # Note, `comment` attributes are "inlined". + json.partial! @comment, as: :comment +``` + +is quite different than: + +```ruby + # comment attributes are nested under a "comment" property +json.comment do + json.partial! "/comments/comment.json.jbuilder", comment: @comment +end +``` + You can pass any objects into partial templates with or without `:locals` option. ```ruby @@ -256,21 +274,6 @@ Jbuilder.key_format camelize: :lower ``` -Faster JSON backends --------------------- - -Jbuilder uses MultiJson, which by default will use the JSON gem. That gem is -currently tangled with ActiveSupport's all-Ruby `#to_json` implementation, -which is slow (fixed in Rails >= 4.1). For faster Jbuilder rendering, you can -specify something like the Yajl JSON generator instead. You'll need to include -the `yajl-ruby` gem in your Gemfile and then set the following configuration -for MultiJson: - -``` ruby -require 'multi_json' -MultiJson.use :yajl - ``` - ## Contributing to Jbuilder Jbuilder is the work of many contributors. You're encouraged to submit pull requests, propose 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_4_2.gemfile new/gemfiles/rails_4_2.gemfile --- old/gemfiles/rails_4_2.gemfile 2018-11-05 16:49:16.000000000 +0100 +++ new/gemfiles/rails_4_2.gemfile 2019-05-14 19:38:31.000000000 +0200 @@ -5,7 +5,6 @@ gem "rake" gem "mocha", require: false gem "appraisal" -gem "pry" gem "rails", "~> 4.2.0" gemspec path: "../" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gemfiles/rails_5_0.gemfile new/gemfiles/rails_5_0.gemfile --- old/gemfiles/rails_5_0.gemfile 2018-11-05 16:49:16.000000000 +0100 +++ new/gemfiles/rails_5_0.gemfile 2019-05-14 19:38:31.000000000 +0200 @@ -5,7 +5,6 @@ gem "rake" gem "mocha", require: false gem "appraisal" -gem "pry" -gem "rails", ">= 5.0.0", "< 5.1" +gem "rails", "~> 5.0.0" gemspec path: "../" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gemfiles/rails_5_1.gemfile new/gemfiles/rails_5_1.gemfile --- old/gemfiles/rails_5_1.gemfile 2018-11-05 16:49:16.000000000 +0100 +++ new/gemfiles/rails_5_1.gemfile 2019-05-14 19:38:31.000000000 +0200 @@ -5,7 +5,6 @@ gem "rake" gem "mocha", require: false gem "appraisal" -gem "pry" -gem "rails", ">= 5.1.0", "< 5.2" +gem "rails", "~> 5.1.0" gemspec path: "../" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gemfiles/rails_5_2.gemfile new/gemfiles/rails_5_2.gemfile --- old/gemfiles/rails_5_2.gemfile 1970-01-01 01:00:00.000000000 +0100 +++ new/gemfiles/rails_5_2.gemfile 2019-05-14 19:38:31.000000000 +0200 @@ -0,0 +1,10 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rake" +gem "mocha", require: false +gem "appraisal" +gem "rails", "~> 5.2.0" + +gemspec path: "../" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gemfiles/rails_6_0.gemfile new/gemfiles/rails_6_0.gemfile --- old/gemfiles/rails_6_0.gemfile 1970-01-01 01:00:00.000000000 +0100 +++ new/gemfiles/rails_6_0.gemfile 2019-05-14 19:38:31.000000000 +0200 @@ -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.0.0.rc1" + +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 1970-01-01 01:00:00.000000000 +0100 +++ new/gemfiles/rails_head.gemfile 2019-05-14 19:38:31.000000000 +0200 @@ -0,0 +1,10 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rake" +gem "mocha", require: false +gem "appraisal" +gem "rails", github: "rails/rails" + +gemspec path: "../" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/jbuilder.gemspec new/jbuilder.gemspec --- old/jbuilder.gemspec 2018-11-05 16:49:16.000000000 +0100 +++ new/jbuilder.gemspec 2019-05-14 19:38:31.000000000 +0200 @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'jbuilder' - s.version = '2.8.0' + s.version = '2.9.1' s.authors = 'David Heinemeier Hansson' s.email = 'david@basecamp.com' s.summary = 'Create JSON structures via a Builder-style DSL' @@ -10,7 +10,6 @@ s.required_ruby_version = '>= 1.9.3' s.add_dependency 'activesupport', '>= 4.2.0' - s.add_dependency 'multi_json', '>= 1.2' s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- test/*`.split("\n") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/generators/rails/jbuilder_generator.rb new/lib/generators/rails/jbuilder_generator.rb --- old/lib/generators/rails/jbuilder_generator.rb 2018-11-05 16:49:16.000000000 +0100 +++ new/lib/generators/rails/jbuilder_generator.rb 2019-05-14 19:38:31.000000000 +0200 @@ -10,6 +10,8 @@ argument :attributes, type: :array, default: [], banner: 'field:type field:type' + class_option :timestamps, type: :boolean, default: true + def create_root_folder path = File.join('app/views', controller_file_path) empty_directory path unless File.directory?(path) @@ -33,8 +35,12 @@ [name, :json, :jbuilder] * '.' end - def attributes_list_with_timestamps - attributes_list(attributes_names + %w(created_at updated_at)) + def full_attributes_list + if options[:timestamps] + attributes_list(attributes_names + %w(created_at updated_at)) + else + attributes_list(attributes_names) + end end def attributes_list(attributes = attributes_names) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/generators/rails/scaffold_controller_generator.rb new/lib/generators/rails/scaffold_controller_generator.rb --- old/lib/generators/rails/scaffold_controller_generator.rb 2018-11-05 16:49:16.000000000 +0100 +++ new/lib/generators/rails/scaffold_controller_generator.rb 2019-05-14 19:38:31.000000000 +0200 @@ -7,6 +7,12 @@ source_paths << File.expand_path('../templates', __FILE__) hook_for :jbuilder, type: :boolean, default: true + + private + + def permitted_params + attributes_names.map { |name| ":#{name}" }.join(', ') + end unless private_method_defined? :permitted_params end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/generators/rails/templates/api_controller.rb new/lib/generators/rails/templates/api_controller.rb --- old/lib/generators/rails/templates/api_controller.rb 2018-11-05 16:49:16.000000000 +0100 +++ new/lib/generators/rails/templates/api_controller.rb 2019-05-14 19:38:31.000000000 +0200 @@ -56,7 +56,7 @@ <%- if attributes_names.empty? -%> params.fetch(<%= ":#{singular_table_name}" %>, {}) <%- else -%> - params.require(<%= ":#{singular_table_name}" %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>) + params.require(<%= ":#{singular_table_name}" %>).permit(<%= permitted_params %>) <%- end -%> end 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 2018-11-05 16:49:16.000000000 +0100 +++ new/lib/generators/rails/templates/controller.rb 2019-05-14 19:38:31.000000000 +0200 @@ -77,7 +77,7 @@ <%- if attributes_names.empty? -%> params.fetch(<%= ":#{singular_table_name}" %>, {}) <%- else -%> - params.require(<%= ":#{singular_table_name}" %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>) + params.require(<%= ":#{singular_table_name}" %>).permit(<%= permitted_params %>) <%- end -%> end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/generators/rails/templates/index.json.jbuilder new/lib/generators/rails/templates/index.json.jbuilder --- old/lib/generators/rails/templates/index.json.jbuilder 2018-11-05 16:49:16.000000000 +0100 +++ new/lib/generators/rails/templates/index.json.jbuilder 2019-05-14 19:38:31.000000000 +0200 @@ -1 +1 @@ -json.array! @<%= plural_table_name %>, partial: '<%= plural_table_name %>/<%= singular_table_name %>', as: :<%= singular_table_name %> +json.array! @<%= plural_table_name %>, partial: "<%= plural_table_name %>/<%= singular_table_name %>", as: :<%= singular_table_name %> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/generators/rails/templates/partial.json.jbuilder new/lib/generators/rails/templates/partial.json.jbuilder --- old/lib/generators/rails/templates/partial.json.jbuilder 2018-11-05 16:49:16.000000000 +0100 +++ new/lib/generators/rails/templates/partial.json.jbuilder 2019-05-14 19:38:31.000000000 +0200 @@ -1,2 +1,2 @@ -json.extract! <%= singular_table_name %>, <%= attributes_list_with_timestamps %> +json.extract! <%= singular_table_name %>, <%= full_attributes_list %> json.url <%= singular_table_name %>_url(<%= singular_table_name %>, format: :json) 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 2018-11-05 16:49:16.000000000 +0100 +++ new/lib/jbuilder/jbuilder_template.rb 2019-05-14 19:38:31.000000000 +0200 @@ -104,7 +104,7 @@ private def _render_partial_with_options(options) - options.reverse_merge! locals: {} + options.reverse_merge! locals: options.except(:partial, :as, :collection) options.reverse_merge! ::JbuilderTemplate.template_lookup_options as = options[:as] @@ -222,11 +222,12 @@ class JbuilderHandler cattr_accessor :default_format - self.default_format = Mime[:json] + self.default_format = :json - def self.call(template) + def self.call(template, source = nil) + source ||= template.source # this juggling is required to keep line numbers right in the error - %{__already_defined = defined?(json); json||=JbuilderTemplate.new(self); #{template.source} + %{__already_defined = defined?(json); json||=JbuilderTemplate.new(self); #{source} json.target! unless (__already_defined && __already_defined != "method")} end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/jbuilder.rb new/lib/jbuilder.rb --- old/lib/jbuilder.rb 2018-11-05 16:49:16.000000000 +0100 +++ new/lib/jbuilder.rb 2019-05-14 19:38:31.000000000 +0200 @@ -2,7 +2,7 @@ require 'jbuilder/blank' require 'jbuilder/key_formatter' require 'jbuilder/errors' -require 'multi_json' +require 'json' require 'ostruct' class Jbuilder @@ -247,7 +247,7 @@ # Encodes the current builder as JSON. def target! - ::MultiJson.dump(@attributes) + @attributes.to_json end private diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/metadata new/metadata --- old/metadata 2018-11-05 16:49:16.000000000 +0100 +++ new/metadata 2019-05-14 19:38:31.000000000 +0200 @@ -1,14 +1,14 @@ --- !ruby/object:Gem::Specification name: jbuilder version: !ruby/object:Gem::Version - version: 2.8.0 + version: 2.9.1 platform: ruby authors: - David Heinemeier Hansson autorequire: bindir: bin cert_chain: [] -date: 2018-11-05 00:00:00.000000000 Z +date: 2019-05-14 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: activesupport @@ -24,20 +24,6 @@ - - ">=" - !ruby/object:Gem::Version version: 4.2.0 -- !ruby/object:Gem::Dependency - name: multi_json - requirement: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: '1.2' - type: :runtime - prerelease: false - version_requirements: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: '1.2' description: email: david@basecamp.com executables: [] @@ -56,6 +42,9 @@ - gemfiles/rails_4_2.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 - jbuilder.gemspec - lib/generators/rails/jbuilder_generator.rb - lib/generators/rails/scaffold_controller_generator.rb @@ -98,8 +87,7 @@ - !ruby/object:Gem::Version version: '0' requirements: [] -rubyforge_project: -rubygems_version: 2.7.6 +rubygems_version: 3.0.3 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_generator_test.rb new/test/jbuilder_generator_test.rb --- old/test/jbuilder_generator_test.rb 2018-11-05 16:49:16.000000000 +0100 +++ new/test/jbuilder_generator_test.rb 2019-05-14 19:38:31.000000000 +0200 @@ -21,18 +21,26 @@ run_generator assert_file 'app/views/posts/index.json.jbuilder' do |content| - assert_match %r{json.array! @posts, partial: 'posts/post', as: :post}, content + assert_match %r{json\.array! @posts, partial: "posts/post", as: :post}, content end assert_file 'app/views/posts/show.json.jbuilder' do |content| - assert_match %r{json.partial! \"posts/post\", post: @post}, content + assert_match %r{json\.partial! "posts/post", post: @post}, content end - - assert_file 'app/views/posts/_post.json.jbuilder' do |content| + + assert_file 'app/views/posts/_post.json.jbuilder' do |content| assert_match %r{json\.extract! post, :id, :title, :body}, content + assert_match %r{:created_at, :updated_at}, content assert_match %r{json\.url post_url\(post, format: :json\)}, content end - + end + test 'timestamps are not generated in partial with --no-timestamps' do + run_generator %w(Post title body:text --no-timestamps) + + assert_file 'app/views/posts/_post.json.jbuilder' do |content| + assert_match %r{json\.extract! post, :id, :title, :body$}, content + assert_no_match %r{:created_at, :updated_at}, content + end end end 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 2018-11-05 16:49:16.000000000 +0100 +++ new/test/jbuilder_template_test.rb 2019-05-14 19:38:31.000000000 +0200 @@ -1,457 +1,312 @@ require "test_helper" -require "mocha/setup" -require "active_model" -require "action_view" require "action_view/testing/resolvers" -require "active_support/cache" -require "jbuilder/jbuilder_template" -BLOG_POST_PARTIAL = <<-JBUILDER - json.extract! blog_post, :id, :body - json.author do - first_name, last_name = blog_post.author_name.split(nil, 2) - json.first_name first_name - json.last_name last_name - end -JBUILDER - -COLLECTION_PARTIAL = <<-JBUILDER - json.extract! collection, :id, :name -JBUILDER - -RACER_PARTIAL = <<-JBUILDER - json.extract! racer, :id, :name -JBUILDER - -class Racer - extend ActiveModel::Naming - include ActiveModel::Conversion - - def initialize(id, name) - @id, @name = id, name - end - - attr_reader :id, :name -end +class JbuilderTemplateTest < ActiveSupport::TestCase + POST_PARTIAL = <<-JBUILDER + json.extract! post, :id, :body + json.author do + first_name, last_name = post.author_name.split(nil, 2) + json.first_name first_name + json.last_name last_name + end + JBUILDER + COLLECTION_PARTIAL = <<-JBUILDER + json.extract! collection, :id, :name + JBUILDER -BlogPost = Struct.new(:id, :body, :author_name) -Collection = Struct.new(:id, :name) -blog_authors = [ "David Heinemeier Hansson", "Pavel Pravosud" ].cycle -BLOG_POST_COLLECTION = Array.new(10){ |i| BlogPost.new(i+1, "post body #{i+1}", blog_authors.next) } -COLLECTION_COLLECTION = Array.new(5){ |i| Collection.new(i+1, "collection #{i+1}") } - -ActionView::Template.register_template_handler :jbuilder, JbuilderHandler - -PARTIALS = { - "_partial.json.jbuilder" => "foo ||= 'hello'; json.content foo", - "_blog_post.json.jbuilder" => BLOG_POST_PARTIAL, - "racers/_racer.json.jbuilder" => RACER_PARTIAL, - "_collection.json.jbuilder" => COLLECTION_PARTIAL -} - -module Rails - def self.cache - @cache ||= ActiveSupport::Cache::MemoryStore.new - end -end + RACER_PARTIAL = <<-JBUILDER + json.extract! racer, :id, :name + JBUILDER -class JbuilderTemplateTest < ActionView::TestCase - setup do - @context = self - Rails.cache.clear - end - - def jbuild(source, options = {}) - @rendered = [] - partials = options.fetch(:partials, PARTIALS).clone - partials["test.json.jbuilder"] = source - resolver = ActionView::FixtureResolver.new(partials) - lookup_context.view_paths = [resolver] - template = ActionView::Template.new(source, "test", JbuilderHandler, virtual_path: "test") - json = template.render(self, {}).strip - MultiJson.load(json) - end - - def undef_context_methods(*names) - self.class_eval do - names.each do |name| - undef_method name.to_sym if method_defined?(name.to_sym) - end - end - end + PARTIALS = { + "_partial.json.jbuilder" => "json.content content", + "_post.json.jbuilder" => POST_PARTIAL, + "racers/_racer.json.jbuilder" => RACER_PARTIAL, + "_collection.json.jbuilder" => COLLECTION_PARTIAL, - def assert_collection_rendered(result, context = nil) - result = result.fetch(context) if context + # Ensure we find only Jbuilder partials from within Jbuilder templates. + "_post.html.erb" => "Hello world!" + } - assert_equal 10, result.length - assert_equal Array, result.class - assert_equal "post body 5", result[4]["body"] - assert_equal "Heinemeier Hansson", result[2]["author"]["last_name"] - assert_equal "Pavel", result[5]["author"]["first_name"] - end + AUTHORS = [ "David Heinemeier Hansson", "Pavel Pravosud" ].cycle + POSTS = (1..10).collect { |i| Post.new(i, "Post ##{i}", AUTHORS.next) } - test "rendering" do - result = jbuild(<<-JBUILDER) - json.content "hello" - JBUILDER + setup { Rails.cache.clear } + test "basic template" do + result = render('json.content "hello"') assert_equal "hello", result["content"] end - test "key_format! with parameter" do - result = jbuild(<<-JBUILDER) - json.key_format! camelize: [:lower] - json.camel_style "for JS" - JBUILDER - - assert_equal ["camelStyle"], result.keys - end - - test "key_format! propagates to child elements" do - result = jbuild(<<-JBUILDER) - json.key_format! :upcase - json.level1 "one" - json.level2 do - json.value "two" - end - JBUILDER - - assert_equal "one", result["LEVEL1"] - assert_equal "two", result["LEVEL2"]["VALUE"] + test "partial by name with top-level locals" do + result = render('json.partial! "partial", content: "hello"') + assert_equal "hello", result["content"] end - test "partial! renders partial" do - result = jbuild(<<-JBUILDER) - json.partial! "partial" - JBUILDER - + test "partial by name with nested locals" do + result = render('json.partial! "partial", locals: { content: "hello" }') assert_equal "hello", result["content"] end - test "partial! + locals via :locals option" do - result = jbuild(<<-JBUILDER) - json.partial! "partial", locals: { foo: "howdy" } - JBUILDER - - assert_equal "howdy", result["content"] + test "partial by options containing nested locals" do + result = render('json.partial! partial: "partial", locals: { content: "hello" }') + assert_equal "hello", result["content"] end - test "partial! + locals without :locals key" do - result = jbuild(<<-JBUILDER) - json.partial! "partial", foo: "goodbye" - JBUILDER - - assert_equal "goodbye", result["content"] + test "partial by options containing top-level locals" do + result = render('json.partial! partial: "partial", content: "hello"') + assert_equal "hello", result["content"] end - test "partial! renders collections" do - result = jbuild(<<-JBUILDER) - json.partial! "blog_post", collection: BLOG_POST_COLLECTION, as: :blog_post - JBUILDER - - assert_collection_rendered result + test "partial for Active Model" do + result = render('json.partial! @racer', racer: Racer.new(123, "Chris Harris")) + assert_equal 123, result["id"] + assert_equal "Chris Harris", result["name"] end - test "partial! renders collections when as argument is a string" do - result = jbuild(<<-JBUILDER) - json.partial! "blog_post", collection: BLOG_POST_COLLECTION, as: "blog_post" - JBUILDER - - assert_collection_rendered result + test "partial collection by name with symbol local" do + result = render('json.partial! "post", collection: @posts, 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! renders collections as collections" do - result = jbuild(<<-JBUILDER) - json.partial! "collection", collection: COLLECTION_COLLECTION, as: :collection - JBUILDER - - assert_equal 5, result.length + 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 + 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! renders as empty array for nil-collection" do - result = jbuild(<<-JBUILDER) - json.partial! "blog_post", collection: nil, as: :blog_post - JBUILDER - - assert_equal [], result + test "partial collection by options" do + result = render('json.partial! partial: "post", collection: @posts, 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! renders collection (alt. syntax)" do - result = jbuild(<<-JBUILDER) - json.partial! partial: "blog_post", collection: BLOG_POST_COLLECTION, as: :blog_post - JBUILDER - - assert_collection_rendered result + test "nil partial collection by name" do + assert_equal [], render('json.partial! "post", collection: @posts, as: :post', posts: nil) end - test "partial! renders as empty array for nil-collection (alt. syntax)" do - result = jbuild(<<-JBUILDER) - json.partial! partial: "blog_post", collection: nil, as: :blog_post - JBUILDER - - assert_equal [], result + test "nil partial collection by options" do + assert_equal [], render('json.partial! partial: "post", collection: @posts, as: :post', posts: nil) end - test "render array of partials" do - result = jbuild(<<-JBUILDER) - json.array! BLOG_POST_COLLECTION, partial: "blog_post", as: :blog_post - JBUILDER - - assert_collection_rendered result + test "array of partials" do + result = render('json.array! @posts, partial: "post", 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 "render array of partials as empty array with nil-collection" do - result = jbuild(<<-JBUILDER) - json.array! nil, partial: "blog_post", as: :blog_post - JBUILDER - - assert_equal [], result + test "empty array of partials from nil collection" do + assert_equal [], render('json.array! @posts, partial: "post", as: :post', posts: nil) end - test "render array of partials as a value" do - result = jbuild(<<-JBUILDER) - json.posts BLOG_POST_COLLECTION, partial: "blog_post", as: :blog_post - JBUILDER - - assert_collection_rendered result, "posts" + test "array of partials under key" do + result = render('json.posts @posts, partial: "post", as: :post', posts: POSTS) + assert_equal 10, result["posts"].count + assert_equal "Post #5", result["posts"][4]["body"] + assert_equal "Heinemeier Hansson", result["posts"][2]["author"]["last_name"] + assert_equal "Pavel", result["posts"][5]["author"]["first_name"] end - test "render as empty array if partials as a nil value" do - result = jbuild <<-JBUILDER - json.posts nil, partial: "blog_post", as: :blog_post - JBUILDER - + test "empty array of partials under key from nil collection" do + result = render('json.posts @posts, partial: "post", as: :post', posts: nil) assert_equal [], result["posts"] end - test "cache an empty block" do - undef_context_methods :fragment_name_with_digest, :cache_fragment_name - - jbuild <<-JBUILDER - json.cache! "nothing" do + test "object fragment caching" do + render(<<-JBUILDER) + json.cache! "cache-key" do + json.name "Hit" end JBUILDER - result = nil - - assert_nothing_raised do - result = jbuild(<<-JBUILDER) - json.foo "bar" - json.cache! "nothing" do - end - JBUILDER - end - - assert_equal "bar", result["foo"] + hit = render('json.cache! "cache-key" do; end') + assert_equal "Hit", hit["name"] end - test "fragment caching a JSON object" do - undef_context_methods :fragment_name_with_digest, :cache_fragment_name - - jbuild <<-JBUILDER - json.cache! "cachekey" do - json.name "Cache" + test "conditional object fragment caching" do + render(<<-JBUILDER) + json.cache_if! true, "cache-key" do + json.a "Hit" end - JBUILDER - result = jbuild(<<-JBUILDER) - json.cache! "cachekey" do - json.name "Miss" + json.cache_if! false, "cache-key" do + json.b "Hit" end JBUILDER - assert_equal "Cache", result["name"] - end - - test "conditionally fragment caching a JSON object" do - undef_context_methods :fragment_name_with_digest, :cache_fragment_name - - jbuild <<-JBUILDER - json.cache_if! true, "cachekey" do - json.test1 "Cache" + result = render(<<-JBUILDER) + json.cache_if! true, "cache-key" do + json.a "Miss" end - json.cache_if! false, "cachekey" do - json.test2 "Cache" - end - JBUILDER - result = jbuild(<<-JBUILDER) - json.cache_if! true, "cachekey" do - json.test1 "Miss" - end - json.cache_if! false, "cachekey" do - json.test2 "Miss" + json.cache_if! false, "cache-key" do + json.b "Miss" end JBUILDER - assert_equal "Cache", result["test1"] - assert_equal "Miss", result["test2"] + assert_equal "Hit", result["a"] + assert_equal "Miss", result["b"] end - test "fragment caching deserializes an array" do - undef_context_methods :fragment_name_with_digest, :cache_fragment_name + test "object fragment caching with expiry" do + travel_to "2018-05-12 11:29:00 -0400" - jbuild <<-JBUILDER - json.cache! "cachekey" do - json.array! %w[a b c] + render <<-JBUILDER + json.cache! "cache-key", expires_in: 1.minute do + json.name "Hit" end JBUILDER - result = jbuild(<<-JBUILDER) - json.cache! "cachekey" do - json.array! %w[1 2 3] + travel 30.seconds + + result = render(<<-JBUILDER) + json.cache! "cache-key", expires_in: 1.minute do + json.name "Miss" end JBUILDER - assert_equal %w[a b c], result - end - - test "fragment caching works with current cache digests" do - undef_context_methods :fragment_name_with_digest + assert_equal "Hit", result["name"] - @context.expects :cache_fragment_name - ActiveSupport::Cache.expects :expand_cache_key + travel 31.seconds - jbuild <<-JBUILDER - json.cache! "cachekey" do - json.name "Cache" + result = render(<<-JBUILDER) + json.cache! "cache-key", expires_in: 1.minute do + json.name "Miss" end JBUILDER - end - - test "fragment caching uses combined_fragment_cache_key" do - undef_context_methods :fragment_name_with_digest, :cache_fragment_name - @context.expects(:combined_fragment_cache_key).with("cachekey") + assert_equal "Miss", result["name"] + end - jbuild <<-JBUILDER - json.cache! "cachekey" do - json.name "Cache" + test "object root caching" do + render <<-JBUILDER + json.cache_root! "cache-key" do + json.name "Hit" end JBUILDER - end - test "fragment caching instrumentation" do - undef_context_methods :fragment_name_with_digest, :cache_fragment_name - - payloads = {} - ActiveSupport::Notifications.subscribe("read_fragment.action_controller") { |*args| payloads[:read_fragment] = args.last } - ActiveSupport::Notifications.subscribe("write_fragment.action_controller") { |*args| payloads[:write_fragment] = args.last } + assert_equal JSON.dump(name: "Hit"), Rails.cache.read("jbuilder/root/cache-key") - jbuild <<-JBUILDER - json.cache! "cachekey" do - json.name "Cache" + result = render(<<-JBUILDER) + json.cache_root! "cache-key" do + json.name "Miss" end JBUILDER - assert_equal "jbuilder/cachekey", payloads[:read_fragment][:key] - assert_equal "jbuilder/cachekey", payloads[:write_fragment][:key] + assert_equal "Hit", result["name"] end - test "current cache digest option accepts options" do - undef_context_methods :fragment_name_with_digest - - @context.expects(:cache_fragment_name).with("cachekey", skip_digest: true) - ActiveSupport::Cache.expects :expand_cache_key - - jbuild <<-JBUILDER - json.cache! "cachekey", skip_digest: true do - json.name "Cache" + test "array fragment caching" do + render <<-JBUILDER + json.cache! "cache-key" do + json.array! %w[ a b c ] end JBUILDER - end - - test "fragment caching accepts expires_in option" do - undef_context_methods :fragment_name_with_digest - - @context.expects(:cache_fragment_name).with("cachekey", {}) - jbuild <<-JBUILDER - json.cache! "cachekey", expires_in: 1.minute do - json.name "Cache" - end - JBUILDER + assert_equal %w[ a b c ], render('json.cache! "cache-key" do; end') end - test "caching root structure" do - undef_context_methods :fragment_name_with_digest, :cache_fragment_name - - cache_miss_result = jbuild <<-JBUILDER - json.cache_root! "cachekey" do - json.name "Miss" + test "array root caching" do + render <<-JBUILDER + json.cache_root! "cache-key" do + json.array! %w[ a b c ] end JBUILDER - cache_hit_result = jbuild <<-JBUILDER - json.cache_root! "cachekey" do - json.name "Hit" + assert_equal JSON.dump(%w[ a b c ]), Rails.cache.read("jbuilder/root/cache-key") + + assert_equal %w[ a b c ], render(<<-JBUILDER) + json.cache_root! "cache-key" do + json.array! %w[ d e f ] end JBUILDER - - assert_equal cache_miss_result, cache_hit_result end - test "failing to cache root after attributes have been defined" do + test "failing to cache root after JSON structures have been defined" do assert_raises ActionView::Template::Error, "cache_root! can't be used after JSON structures have been defined" do - jbuild <<-JBUILDER + render <<-JBUILDER json.name "Kaboom" - json.cache_root! "cachekey" do + json.cache_root! "cache-key" do json.name "Miss" end JBUILDER end end - test "does not perform caching when controller.perform_caching is false" do - controller.perform_caching = false + test "empty fragment caching" do + render 'json.cache! "nothing" do; end' - jbuild <<-JBUILDER - json.cache! "cachekey" do - json.name "Cache" - end - JBUILDER + result = nil + + assert_nothing_raised do + result = render(<<-JBUILDER) + json.foo "bar" + json.cache! "nothing" do; end + JBUILDER + end - assert_equal Rails.cache.inspect[/entries=(\d+)/, 1], "0" + assert_equal "bar", result["foo"] end - test "invokes templates via params via set!" do - @post = BLOG_POST_COLLECTION.first + test "cache instrumentation" do + payloads = {} + + ActiveSupport::Notifications.subscribe("read_fragment.action_controller") { |*args| payloads[:read] = args.last } + ActiveSupport::Notifications.subscribe("write_fragment.action_controller") { |*args| payloads[:write] = args.last } - result = jbuild(<<-JBUILDER) - json.post @post, partial: "blog_post", as: :blog_post + render <<-JBUILDER + json.cache! "cache-key" do + json.name "Cache" + end JBUILDER - assert_equal 1, result["post"]["id"] - assert_equal "post body 1", result["post"]["body"] - assert_equal "David", result["post"]["author"]["first_name"] + assert_equal "jbuilder/cache-key", payloads[:read][:key] + assert_equal "jbuilder/cache-key", payloads[:write][:key] end - test "invokes templates implicitly for ActiveModel objects" do - @racer = Racer.new(123, "Chris Harris") - - result = jbuild(<<-JBUILDER) - json.partial! @racer + test "camelized keys" do + result = render(<<-JBUILDER) + json.key_format! camelize: [:lower] + json.first_name "David" JBUILDER - assert_equal %w[id name], result.keys - assert_equal 123, result["id"] - assert_equal "Chris Harris", result["name"] + assert_equal "David", result["firstName"] end - test "renders partial via set! with same name as HTML partial" do - partials = { - "_blog_post.html.erb" => "Hello!", - "_blog_post.json.jbuilder" => BLOG_POST_PARTIAL - } + private + def render(*args) + JSON.load render_without_parsing(*args) + end - @post = BLOG_POST_COLLECTION.first + def render_without_parsing(source, assigns = {}) + view = build_view(fixtures: PARTIALS.merge("source.json.jbuilder" => source), assigns: assigns) + view.render(template: "source.json.jbuilder") + end - result = jbuild(<<-JBUILDER, partials: partials) - json.post @post, partial: "blog_post", as: :blog_post - JBUILDER + def build_view(options = {}) + resolver = ActionView::FixtureResolver.new(options.fetch(:fixtures)) + lookup_context = ActionView::LookupContext.new([ resolver ], {}, [""]) + controller = ActionView::TestCase::TestController.new - assert_not_nil result["post"] - assert_equal 1, result["post"]["id"] - end + # TODO: Use with_empty_template_cache unconditionally after dropping support for Rails <6.0. + view = if ActionView::Base.respond_to?(:with_empty_template_cache) + ActionView::Base.with_empty_template_cache.new(lookup_context, options.fetch(:assigns, {}), controller) + else + ActionView::Base.new(lookup_context, options.fetch(:assigns, {}), controller) + end + + def view.view_cache_dependencies; []; end + + view + end 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 2018-11-05 16:49:16.000000000 +0100 +++ new/test/jbuilder_test.rb 2019-05-14 19:38:31.000000000 +0200 @@ -75,7 +75,7 @@ end assert result.has_key?('content') - assert_equal nil, result['content'] + assert_nil result['content'] end test 'multiple keys' do @@ -713,4 +713,13 @@ end end end + + if RUBY_VERSION >= "2.2.10" + test "respects JSON encoding customizations" do + # Active Support overrides Time#as_json for custom formatting. + # Ensure we call #to_json on the final attributes instead of JSON.dump. + result = JSON.load(Jbuilder.encode { |json| json.time Time.parse("2018-05-13 11:51:00.485 -0400") }) + assert_equal "2018-05-13T11:51:00.485-04:00", result["time"] + end + end end 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 2018-11-05 16:49:16.000000000 +0100 +++ new/test/scaffold_api_controller_generator_test.rb 2019-05-14 19:38:31.000000000 +0200 @@ -6,7 +6,7 @@ class ScaffoldApiControllerGeneratorTest < Rails::Generators::TestCase tests Rails::Generators::ScaffoldControllerGenerator - arguments %w(Post title body:text --api) + arguments %w(Post title body:text images:attachments --api) destination File.expand_path('../tmp', __FILE__) setup :prepare_destination @@ -39,7 +39,11 @@ end assert_match %r{def post_params}, content - assert_match %r{params\.require\(:post\)\.permit\(:title, :body\)}, content + if 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 + end end end 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 2018-11-05 16:49:16.000000000 +0100 +++ new/test/scaffold_controller_generator_test.rb 2019-05-14 19:38:31.000000000 +0200 @@ -4,7 +4,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase tests Rails::Generators::ScaffoldControllerGenerator - arguments %w(Post title body:text) + arguments %w(Post title body:text images:attachments) destination File.expand_path('../tmp', __FILE__) setup :prepare_destination @@ -51,7 +51,11 @@ end assert_match %r{def post_params}, content - assert_match %r{params\.require\(:post\)\.permit\(:title, :body\)}, content + if 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 + end end end 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 2018-11-05 16:49:16.000000000 +0100 +++ new/test/test_helper.rb 2019-05-14 19:38:31.000000000 +0200 @@ -1,16 +1,34 @@ require "bundler/setup" + require "active_support" -require 'active_support/core_ext/array/access' +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" -if Rails::VERSION::STRING > "4.0" - require "active_support/testing/autorun" -else - require "test/unit" +require "active_support/testing/autorun" +require "mocha/setup" + +ActiveSupport.test_order = :random + +class << Rails + def cache + @cache ||= ActiveSupport::Cache::MemoryStore.new + end end +class Post < Struct.new(:id, :body, :author_name); end -if ActiveSupport.respond_to?(:test_order=) - ActiveSupport.test_order = :random +class Racer < Struct.new(:id, :name) + extend ActiveModel::Naming + include ActiveModel::Conversion 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
participants (1)
-
root