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.
- checksums.yaml +4 -4
- data/.devcontainer/devcontainer.json +25 -0
- data/.github/workflows/ruby.yml +14 -7
- data/Appraisals +21 -12
- data/Gemfile +2 -0
- data/README.md +38 -19
- data/Rakefile +2 -0
- data/bin/test +1 -1
- data/gemfiles/rails_7_0.gemfile +1 -0
- data/gemfiles/rails_7_2.gemfile +10 -0
- data/gemfiles/rails_8_0.gemfile +10 -0
- data/jbuilder.gemspec +5 -3
- data/lib/generators/rails/jbuilder_generator.rb +2 -0
- data/lib/generators/rails/scaffold_controller_generator.rb +2 -0
- data/lib/generators/rails/templates/controller.rb +2 -2
- data/lib/jbuilder/blank.rb +2 -0
- data/lib/jbuilder/collection_renderer.rb +19 -77
- data/lib/jbuilder/errors.rb +3 -1
- data/lib/jbuilder/jbuilder.rb +3 -1
- data/lib/jbuilder/jbuilder_dependency_tracker.rb +2 -0
- data/lib/jbuilder/jbuilder_template.rb +29 -52
- data/lib/jbuilder/key_formatter.rb +19 -21
- data/lib/jbuilder/railtie.rb +15 -17
- data/lib/jbuilder/version.rb +4 -2
- data/lib/jbuilder.rb +38 -33
- data/test/jbuilder_generator_test.rb +6 -8
- data/test/jbuilder_template_test.rb +82 -78
- data/test/jbuilder_test.rb +7 -9
- data/test/scaffold_api_controller_generator_test.rb +52 -60
- data/test/scaffold_controller_generator_test.rb +25 -31
- data/test/test_helper.rb +1 -1
- metadata +13 -14
data/test/jbuilder_test.rb
CHANGED
@@ -784,12 +784,12 @@ class JbuilderTest < ActiveSupport::TestCase
|
|
784
784
|
assert_equal ['camelStyle'], result.keys
|
785
785
|
end
|
786
786
|
|
787
|
-
test '
|
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
|
-
|
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
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
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
|
-
|
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
|
-
|
8
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
19
|
+
assert_instance_method :show, content do |m|
|
20
|
+
assert m.blank?
|
21
|
+
end
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
35
|
+
assert_instance_method :destroy, content do |m|
|
36
|
+
assert_match %r{@post\.destroy}, m
|
37
|
+
end
|
40
38
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
60
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
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
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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,
|
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, :
|
64
|
+
assert_match %r{params\.require\(:post\)\.permit\(:title, :body, images: \[\]\)}, content
|
67
65
|
end
|
68
66
|
end
|
69
67
|
end
|
70
68
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
100
|
-
|
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
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
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
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.
|
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:
|
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:
|
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:
|
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:
|
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:
|
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.
|
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.
|
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:
|
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.
|
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:
|