jbuilder 2.7.0 → 2.13.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 +5 -5
- data/.github/workflows/ruby.yml +49 -0
- data/.gitignore +3 -0
- data/Appraisals +10 -14
- data/CONTRIBUTING.md +5 -13
- data/Gemfile +0 -1
- data/MIT-LICENSE +1 -1
- data/README.md +103 -19
- data/Rakefile +1 -1
- data/bin/release +14 -0
- data/bin/test +6 -0
- data/gemfiles/{rails_4_2.gemfile → rails_7_0.gemfile} +1 -4
- data/gemfiles/{rails_5_0.gemfile → rails_7_1.gemfile} +1 -4
- data/gemfiles/{rails_5_1.gemfile → rails_head.gemfile} +1 -4
- data/jbuilder.gemspec +20 -4
- data/lib/generators/rails/jbuilder_generator.rb +16 -2
- data/lib/generators/rails/scaffold_controller_generator.rb +6 -0
- data/lib/generators/rails/templates/api_controller.rb +10 -4
- data/lib/generators/rails/templates/controller.rb +21 -19
- data/lib/generators/rails/templates/index.json.jbuilder +1 -1
- data/lib/generators/rails/templates/partial.json.jbuilder +15 -1
- data/lib/generators/rails/templates/show.json.jbuilder +1 -1
- data/lib/jbuilder/collection_renderer.rb +116 -0
- data/lib/jbuilder/jbuilder.rb +1 -7
- data/lib/jbuilder/jbuilder_dependency_tracker.rb +73 -0
- data/lib/jbuilder/jbuilder_template.rb +80 -22
- data/lib/jbuilder/railtie.rb +3 -3
- data/lib/jbuilder/version.rb +3 -0
- data/lib/jbuilder.rb +71 -30
- data/test/jbuilder_dependency_tracker_test.rb +3 -4
- data/test/jbuilder_generator_test.rb +37 -5
- data/test/jbuilder_template_test.rb +300 -324
- data/test/jbuilder_test.rb +229 -4
- data/test/scaffold_api_controller_generator_test.rb +31 -3
- data/test/scaffold_controller_generator_test.rb +54 -8
- data/test/test_helper.rb +41 -8
- metadata +28 -21
- data/.travis.yml +0 -66
- data/CHANGELOG.md +0 -249
- data/lib/jbuilder/dependency_tracker.rb +0 -61
@@ -21,18 +21,50 @@ class JbuilderGeneratorTest < Rails::Generators::TestCase
|
|
21
21
|
run_generator
|
22
22
|
|
23
23
|
assert_file 'app/views/posts/index.json.jbuilder' do |content|
|
24
|
-
assert_match %r{json
|
24
|
+
assert_match %r{json\.array! @posts, partial: "posts/post", as: :post}, content
|
25
25
|
end
|
26
26
|
|
27
27
|
assert_file 'app/views/posts/show.json.jbuilder' do |content|
|
28
|
-
assert_match %r{json
|
28
|
+
assert_match %r{json\.partial! "posts/post", post: @post}, content
|
29
29
|
end
|
30
|
-
|
31
|
-
assert_file 'app/views/posts/_post.json.jbuilder' do |content|
|
30
|
+
|
31
|
+
assert_file 'app/views/posts/_post.json.jbuilder' do |content|
|
32
32
|
assert_match %r{json\.extract! post, :id, :title, :body}, content
|
33
|
+
assert_match %r{:created_at, :updated_at}, content
|
33
34
|
assert_match %r{json\.url post_url\(post, format: :json\)}, content
|
34
35
|
end
|
35
|
-
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'timestamps are not generated in partial with --no-timestamps' do
|
39
|
+
run_generator %w(Post title body:text --no-timestamps)
|
40
|
+
|
41
|
+
assert_file 'app/views/posts/_post.json.jbuilder' do |content|
|
42
|
+
assert_match %r{json\.extract! post, :id, :title, :body$}, content
|
43
|
+
assert_no_match %r{:created_at, :updated_at}, content
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
test 'namespaced views are generated correctly for index' do
|
48
|
+
run_generator %w(Admin::Post --model-name=Post)
|
49
|
+
|
50
|
+
assert_file 'app/views/admin/posts/index.json.jbuilder' do |content|
|
51
|
+
assert_match %r{json\.array! @posts, partial: "admin/posts/post", as: :post}, content
|
52
|
+
end
|
36
53
|
|
54
|
+
assert_file 'app/views/admin/posts/show.json.jbuilder' do |content|
|
55
|
+
assert_match %r{json\.partial! "admin/posts/post", post: @post}, content
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
if Rails::VERSION::MAJOR >= 6
|
60
|
+
test 'handles virtual attributes' do
|
61
|
+
run_generator %w(Message content:rich_text video:attachment photos:attachments)
|
62
|
+
|
63
|
+
assert_file 'app/views/messages/_message.json.jbuilder' do |content|
|
64
|
+
assert_match %r{json\.content message\.content\.to_s}, content
|
65
|
+
assert_match %r{json\.video url_for\(message\.video\)}, content
|
66
|
+
assert_match %r{json\.photos do\n json\.array!\(message\.photos\) do \|photo\|\n json\.id photo\.id\n json\.url url_for\(photo\)\n end\nend}, content
|
67
|
+
end
|
68
|
+
end
|
37
69
|
end
|
38
70
|
end
|