jbuilder 2.13.0 → 2.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -784,12 +784,12 @@ class JbuilderTest < ActiveSupport::TestCase
784
784
  assert_equal ['camelStyle'], result.keys
785
785
  end
786
786
 
787
- test 'do not use default key formatter directly' do
787
+ test 'use default key formatter when configured' do
788
788
  Jbuilder.key_format
789
789
  jbuild{ |json| json.key 'value' }
790
790
  formatter = Jbuilder.send(:class_variable_get, '@@key_formatter')
791
791
  cache = formatter.instance_variable_get('@cache')
792
- assert_empty cache
792
+ assert_includes cache, :key
793
793
  end
794
794
 
795
795
  test 'ignore_nil! without a parameter' do
@@ -930,12 +930,10 @@ class JbuilderTest < ActiveSupport::TestCase
930
930
  end
931
931
  end
932
932
 
933
- if RUBY_VERSION >= "2.2.10"
934
- test "respects JSON encoding customizations" do
935
- # Active Support overrides Time#as_json for custom formatting.
936
- # Ensure we call #to_json on the final attributes instead of JSON.dump.
937
- result = JSON.load(Jbuilder.encode { |json| json.time Time.parse("2018-05-13 11:51:00.485 -0400") })
938
- assert_equal "2018-05-13T11:51:00.485-04:00", result["time"]
939
- end
933
+ test "respects JSON encoding customizations" do
934
+ # Active Support overrides Time#as_json for custom formatting.
935
+ # Ensure we call #to_json on the final attributes instead of JSON.dump.
936
+ result = JSON.load(Jbuilder.encode { |json| json.time Time.parse("2018-05-13 11:51:00.485 -0400") })
937
+ assert_equal "2018-05-13T11:51:00.485-04:00", result["time"]
940
938
  end
941
939
  end
@@ -2,81 +2,73 @@ require 'test_helper'
2
2
  require 'rails/generators/test_case'
3
3
  require 'generators/rails/scaffold_controller_generator'
4
4
 
5
- if Rails::VERSION::MAJOR > 4
5
+ class ScaffoldApiControllerGeneratorTest < Rails::Generators::TestCase
6
+ tests Rails::Generators::ScaffoldControllerGenerator
7
+ arguments %w(Post title body:text images:attachments --api --skip-routes)
8
+ destination File.expand_path('../tmp', __FILE__)
9
+ setup :prepare_destination
6
10
 
7
- class ScaffoldApiControllerGeneratorTest < Rails::Generators::TestCase
8
- tests Rails::Generators::ScaffoldControllerGenerator
9
- arguments %w(Post title body:text images:attachments --api)
10
- destination File.expand_path('../tmp', __FILE__)
11
- setup :prepare_destination
11
+ test 'controller content' do
12
+ run_generator
12
13
 
13
- test 'controller content' do
14
- run_generator
15
-
16
- assert_file 'app/controllers/posts_controller.rb' do |content|
17
- assert_instance_method :index, content do |m|
18
- assert_match %r{@posts = Post\.all}, m
19
- end
14
+ assert_file 'app/controllers/posts_controller.rb' do |content|
15
+ assert_instance_method :index, content do |m|
16
+ assert_match %r{@posts = Post\.all}, m
17
+ end
20
18
 
21
- assert_instance_method :show, content do |m|
22
- assert m.blank?
23
- end
19
+ assert_instance_method :show, content do |m|
20
+ assert m.blank?
21
+ end
24
22
 
25
- assert_instance_method :create, content do |m|
26
- assert_match %r{@post = Post\.new\(post_params\)}, m
27
- assert_match %r{@post\.save}, m
28
- assert_match %r{render :show, status: :created, location: @post}, m
29
- assert_match %r{render json: @post\.errors, status: :unprocessable_entity}, m
30
- end
23
+ assert_instance_method :create, content do |m|
24
+ assert_match %r{@post = Post\.new\(post_params\)}, m
25
+ assert_match %r{@post\.save}, m
26
+ assert_match %r{render :show, status: :created, location: @post}, m
27
+ assert_match %r{render json: @post\.errors, status: :unprocessable_entity}, m
28
+ end
31
29
 
32
- assert_instance_method :update, content do |m|
33
- assert_match %r{render :show, status: :ok, location: @post}, m
34
- assert_match %r{render json: @post.errors, status: :unprocessable_entity}, m
35
- end
30
+ assert_instance_method :update, content do |m|
31
+ assert_match %r{render :show, status: :ok, location: @post}, m
32
+ assert_match %r{render json: @post.errors, status: :unprocessable_entity}, m
33
+ end
36
34
 
37
- assert_instance_method :destroy, content do |m|
38
- assert_match %r{@post\.destroy}, m
39
- end
35
+ assert_instance_method :destroy, content do |m|
36
+ assert_match %r{@post\.destroy}, m
37
+ end
40
38
 
41
- assert_match %r{def set_post}, content
42
- if Rails::VERSION::MAJOR >= 8
43
- assert_match %r{params\.expect\(:id\)}, content
44
- else
45
- assert_match %r{params\[:id\]}, content
46
- end
39
+ assert_match %r{def set_post}, content
40
+ if Rails::VERSION::MAJOR >= 8
41
+ assert_match %r{params\.expect\(:id\)}, content
42
+ else
43
+ assert_match %r{params\[:id\]}, content
44
+ end
47
45
 
48
- assert_match %r{def post_params}, content
49
- if Rails::VERSION::MAJOR >= 8
50
- assert_match %r{params\.expect\(post: \[ :title, :body, images: \[\] \]\)}, content
51
- elsif Rails::VERSION::MAJOR >= 6
52
- assert_match %r{params\.require\(:post\)\.permit\(:title, :body, images: \[\]\)}, content
53
- else
54
- assert_match %r{params\.require\(:post\)\.permit\(:title, :body, :images\)}, content
55
- end
46
+ assert_match %r{def post_params}, content
47
+ if Rails::VERSION::MAJOR >= 8
48
+ assert_match %r{params\.expect\(post: \[ :title, :body, images: \[\] \]\)}, content
49
+ else
50
+ assert_match %r{params\.require\(:post\)\.permit\(:title, :body, images: \[\]\)}, content
56
51
  end
57
52
  end
53
+ end
58
54
 
59
- test "don't use require and permit if there are no attributes" do
60
- run_generator %w(Post --api)
55
+ test "don't use require and permit if there are no attributes" do
56
+ run_generator %w(Post --api --skip-routes)
61
57
 
62
- assert_file 'app/controllers/posts_controller.rb' do |content|
63
- assert_match %r{def post_params}, content
64
- assert_match %r{params\.fetch\(:post, \{\}\)}, content
65
- end
58
+ assert_file 'app/controllers/posts_controller.rb' do |content|
59
+ assert_match %r{def post_params}, content
60
+ assert_match %r{params\.fetch\(:post, \{\}\)}, content
66
61
  end
62
+ end
67
63
 
64
+ test 'handles virtual attributes' do
65
+ run_generator %w(Message content:rich_text video:attachment photos:attachments --skip-routes)
68
66
 
69
- if Rails::VERSION::MAJOR >= 6
70
- test 'handles virtual attributes' do
71
- run_generator ["Message", "content:rich_text", "video:attachment", "photos:attachments"]
72
-
73
- assert_file 'app/controllers/messages_controller.rb' do |content|
74
- if Rails::VERSION::MAJOR >= 8
75
- assert_match %r{params\.expect\(message: \[ :content, :video, photos: \[\] \]\)}, content
76
- else
77
- assert_match %r{params\.require\(:message\)\.permit\(:content, :video, photos: \[\]\)}, content
78
- end
79
- end
67
+ assert_file 'app/controllers/messages_controller.rb' do |content|
68
+ if Rails::VERSION::MAJOR >= 8
69
+ assert_match %r{params\.expect\(message: \[ :content, :video, photos: \[\] \]\)}, content
70
+ else
71
+ assert_match %r{params\.require\(:message\)\.permit\(:content, :video, photos: \[\]\)}, content
80
72
  end
81
73
  end
82
74
  end
@@ -4,7 +4,7 @@ require 'generators/rails/scaffold_controller_generator'
4
4
 
5
5
  class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
6
6
  tests Rails::Generators::ScaffoldControllerGenerator
7
- arguments %w(Post title body:text images:attachments)
7
+ arguments %w(Post title body:text images:attachments --skip-routes)
8
8
  destination File.expand_path('../tmp', __FILE__)
9
9
  setup :prepare_destination
10
10
 
@@ -38,7 +38,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
38
38
  end
39
39
 
40
40
  assert_instance_method :update, content do |m|
41
- assert_match %r{format\.html \{ redirect_to @post, notice: "Post was successfully updated\." \}}, m
41
+ assert_match %r{format\.html \{ redirect_to @post, notice: "Post was successfully updated\.", status: :see_other \}}, m
42
42
  assert_match %r{format\.json \{ render :show, status: :ok, location: @post \}}, m
43
43
  assert_match %r{format\.html \{ render :edit, status: :unprocessable_entity \}}, m
44
44
  assert_match %r{format\.json \{ render json: @post.errors, status: :unprocessable_entity \}}, m
@@ -46,7 +46,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
46
46
 
47
47
  assert_instance_method :destroy, content do |m|
48
48
  assert_match %r{@post\.destroy}, m
49
- assert_match %r{format\.html \{ redirect_to posts_path, status: :see_other, notice: "Post was successfully destroyed\." \}}, m
49
+ assert_match %r{format\.html \{ redirect_to posts_path, notice: "Post was successfully destroyed\.", status: :see_other \}}, m
50
50
  assert_match %r{format\.json \{ head :no_content \}}, m
51
51
  end
52
52
 
@@ -60,35 +60,31 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
60
60
  assert_match %r{def post_params}, content
61
61
  if Rails::VERSION::MAJOR >= 8
62
62
  assert_match %r{params\.expect\(post: \[ :title, :body, images: \[\] \]\)}, content
63
- elsif Rails::VERSION::MAJOR >= 6
64
- assert_match %r{params\.require\(:post\)\.permit\(:title, :body, images: \[\]\)}, content
65
63
  else
66
- assert_match %r{params\.require\(:post\)\.permit\(:title, :body, :images\)}, content
64
+ assert_match %r{params\.require\(:post\)\.permit\(:title, :body, images: \[\]\)}, content
67
65
  end
68
66
  end
69
67
  end
70
68
 
71
- if Rails::VERSION::MAJOR >= 6
72
- test 'controller with namespace' do
73
- run_generator %w(Admin::Post --model-name=Post)
74
- assert_file 'app/controllers/admin/posts_controller.rb' do |content|
75
- assert_instance_method :create, content do |m|
76
- assert_match %r{format\.html \{ redirect_to \[:admin, @post\], notice: "Post was successfully created\." \}}, m
77
- end
78
-
79
- assert_instance_method :update, content do |m|
80
- assert_match %r{format\.html \{ redirect_to \[:admin, @post\], notice: "Post was successfully updated\." \}}, m
81
- end
82
-
83
- assert_instance_method :destroy, content do |m|
84
- assert_match %r{format\.html \{ redirect_to admin_posts_path, status: :see_other, notice: "Post was successfully destroyed\." \}}, m
85
- end
69
+ test 'controller with namespace' do
70
+ run_generator %w(Admin::Post --model-name=Post --skip-routes)
71
+ assert_file 'app/controllers/admin/posts_controller.rb' do |content|
72
+ assert_instance_method :create, content do |m|
73
+ assert_match %r{format\.html \{ redirect_to \[:admin, @post\], notice: "Post was successfully created\." \}}, m
74
+ end
75
+
76
+ assert_instance_method :update, content do |m|
77
+ assert_match %r{format\.html \{ redirect_to \[:admin, @post\], notice: "Post was successfully updated\.", status: :see_other \}}, m
78
+ end
79
+
80
+ assert_instance_method :destroy, content do |m|
81
+ assert_match %r{format\.html \{ redirect_to admin_posts_path, notice: "Post was successfully destroyed\.", status: :see_other \}}, m
86
82
  end
87
83
  end
88
84
  end
89
85
 
90
86
  test "don't use require and permit if there are no attributes" do
91
- run_generator %w(Post)
87
+ run_generator %w(Post --skip-routes)
92
88
 
93
89
  assert_file 'app/controllers/posts_controller.rb' do |content|
94
90
  assert_match %r{def post_params}, content
@@ -96,16 +92,14 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
96
92
  end
97
93
  end
98
94
 
99
- if Rails::VERSION::MAJOR >= 6
100
- test 'handles virtual attributes' do
101
- run_generator %w(Message content:rich_text video:attachment photos:attachments)
95
+ test 'handles virtual attributes' do
96
+ run_generator %w(Message content:rich_text video:attachment photos:attachments --skip-routes)
102
97
 
103
- assert_file 'app/controllers/messages_controller.rb' do |content|
104
- if Rails::VERSION::MAJOR >= 8
105
- assert_match %r{params\.expect\(message: \[ :content, :video, photos: \[\] \]\)}, content
106
- else
107
- assert_match %r{params\.require\(:message\)\.permit\(:content, :video, photos: \[\]\)}, content
108
- end
98
+ assert_file 'app/controllers/messages_controller.rb' do |content|
99
+ if Rails::VERSION::MAJOR >= 8
100
+ assert_match %r{params\.expect\(message: \[ :content, :video, photos: \[\] \]\)}, content
101
+ else
102
+ assert_match %r{params\.require\(:message\)\.permit\(:content, :video, photos: \[\]\)}, content
109
103
  end
110
104
  end
111
105
  end
data/test/test_helper.rb CHANGED
@@ -19,7 +19,7 @@ ActiveSupport.test_order = :random
19
19
  ENV["RAILS_ENV"] ||= "test"
20
20
 
21
21
  class << Rails
22
- def cache
22
+ redefine_method :cache do
23
23
  @cache ||= ActiveSupport::Cache::MemoryStore.new
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jbuilder
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.13.0
4
+ version: 2.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-09-15 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activesupport
@@ -16,34 +15,34 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: 5.0.0
18
+ version: 7.0.0
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
- version: 5.0.0
25
+ version: 7.0.0
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: actionview
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - ">="
32
31
  - !ruby/object:Gem::Version
33
- version: 5.0.0
32
+ version: 7.0.0
34
33
  type: :runtime
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
37
  - - ">="
39
38
  - !ruby/object:Gem::Version
40
- version: 5.0.0
41
- description:
39
+ version: 7.0.0
42
40
  email: david@basecamp.com
43
41
  executables: []
44
42
  extensions: []
45
43
  extra_rdoc_files: []
46
44
  files:
45
+ - ".devcontainer/devcontainer.json"
47
46
  - ".github/workflows/ruby.yml"
48
47
  - ".gitignore"
49
48
  - Appraisals
@@ -56,6 +55,8 @@ files:
56
55
  - bin/test
57
56
  - gemfiles/rails_7_0.gemfile
58
57
  - gemfiles/rails_7_1.gemfile
58
+ - gemfiles/rails_7_2.gemfile
59
+ - gemfiles/rails_8_0.gemfile
59
60
  - gemfiles/rails_head.gemfile
60
61
  - jbuilder.gemspec
61
62
  - lib/generators/rails/jbuilder_generator.rb
@@ -87,11 +88,10 @@ licenses:
87
88
  - MIT
88
89
  metadata:
89
90
  bug_tracker_uri: https://github.com/rails/jbuilder/issues
90
- changelog_uri: https://github.com/rails/jbuilder/releases/tag/v2.13.0
91
+ changelog_uri: https://github.com/rails/jbuilder/releases/tag/v2.14.0
91
92
  mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
92
- source_code_uri: https://github.com/rails/jbuilder/tree/v2.13.0
93
+ source_code_uri: https://github.com/rails/jbuilder/tree/v2.14.0
93
94
  rubygems_mfa_required: 'true'
94
- post_install_message:
95
95
  rdoc_options: []
96
96
  require_paths:
97
97
  - lib
@@ -99,15 +99,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
- version: 2.2.2
102
+ version: 3.0.0
103
103
  required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  requirements:
105
105
  - - ">="
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
108
  requirements: []
109
- rubygems_version: 3.5.16
110
- signing_key:
109
+ rubygems_version: 3.6.9
111
110
  specification_version: 4
112
111
  summary: Create JSON structures via a Builder-style DSL
113
112
  test_files: