jbuilder 2.12.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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/devcontainer.json +25 -0
  3. data/.github/workflows/ruby.yml +14 -50
  4. data/Appraisals +14 -32
  5. data/CONTRIBUTING.md +1 -7
  6. data/Gemfile +2 -0
  7. data/README.md +38 -19
  8. data/Rakefile +2 -0
  9. data/bin/release +14 -0
  10. data/bin/test +6 -0
  11. data/gemfiles/rails_7_0.gemfile +1 -0
  12. data/gemfiles/{rails_6_1.gemfile → rails_7_2.gemfile} +1 -1
  13. data/gemfiles/{rails_6_0.gemfile → rails_8_0.gemfile} +1 -1
  14. data/jbuilder.gemspec +8 -4
  15. data/lib/generators/rails/jbuilder_generator.rb +2 -0
  16. data/lib/generators/rails/scaffold_controller_generator.rb +2 -0
  17. data/lib/generators/rails/templates/api_controller.rb +6 -0
  18. data/lib/generators/rails/templates/controller.rb +9 -3
  19. data/lib/jbuilder/blank.rb +2 -0
  20. data/lib/jbuilder/collection_renderer.rb +19 -77
  21. data/lib/jbuilder/errors.rb +3 -1
  22. data/lib/jbuilder/jbuilder.rb +3 -1
  23. data/lib/jbuilder/jbuilder_dependency_tracker.rb +2 -0
  24. data/lib/jbuilder/jbuilder_template.rb +36 -50
  25. data/lib/jbuilder/key_formatter.rb +19 -21
  26. data/lib/jbuilder/railtie.rb +15 -17
  27. data/lib/jbuilder/version.rb +5 -0
  28. data/lib/jbuilder.rb +38 -37
  29. data/test/jbuilder_generator_test.rb +6 -8
  30. data/test/jbuilder_template_test.rb +97 -77
  31. data/test/jbuilder_test.rb +7 -9
  32. data/test/scaffold_api_controller_generator_test.rb +52 -47
  33. data/test/scaffold_controller_generator_test.rb +34 -27
  34. data/test/test_helper.rb +1 -1
  35. metadata +16 -19
  36. data/gemfiles/rails_5_0.gemfile +0 -11
  37. data/gemfiles/rails_5_1.gemfile +0 -11
  38. data/gemfiles/rails_5_2.gemfile +0 -11
@@ -49,6 +49,17 @@ class JbuilderTemplateTest < ActiveSupport::TestCase
49
49
  assert_equal "hello", result["content"]
50
50
  end
51
51
 
52
+ test "partial by name with hash value omission (punning) as last statement [3.1+]" do
53
+ major, minor, _ = RUBY_VERSION.split(".").map(&:to_i)
54
+ return unless (major == 3 && minor >= 1) || major > 3
55
+
56
+ result = render(<<-JBUILDER)
57
+ content = "hello"
58
+ json.partial! "partial", content:
59
+ JBUILDER
60
+ assert_equal "hello", result["content"]
61
+ end
62
+
52
63
  test "partial by options containing nested locals" do
53
64
  result = render('json.partial! partial: "partial", locals: { content: "hello" }')
54
65
  assert_equal "hello", result["content"]
@@ -98,10 +109,12 @@ class JbuilderTemplateTest < ActiveSupport::TestCase
98
109
  end
99
110
 
100
111
  test "nil partial collection by name" do
112
+ Jbuilder::CollectionRenderer.expects(:new).never
101
113
  assert_equal [], render('json.partial! "post", collection: @posts, as: :post', posts: nil)
102
114
  end
103
115
 
104
116
  test "nil partial collection by options" do
117
+ Jbuilder::CollectionRenderer.expects(:new).never
105
118
  assert_equal [], render('json.partial! partial: "post", collection: @posts, as: :post', posts: nil)
106
119
  end
107
120
 
@@ -113,7 +126,13 @@ class JbuilderTemplateTest < ActiveSupport::TestCase
113
126
  assert_equal "Pavel", result[5]["author"]["first_name"]
114
127
  end
115
128
 
129
+ test "empty array of partials from empty collection" do
130
+ Jbuilder::CollectionRenderer.expects(:new).never
131
+ assert_equal [], render('json.array! @posts, partial: "post", as: :post', posts: [])
132
+ end
133
+
116
134
  test "empty array of partials from nil collection" do
135
+ Jbuilder::CollectionRenderer.expects(:new).never
117
136
  assert_equal [], render('json.array! @posts, partial: "post", as: :post', posts: nil)
118
137
  end
119
138
 
@@ -126,10 +145,17 @@ class JbuilderTemplateTest < ActiveSupport::TestCase
126
145
  end
127
146
 
128
147
  test "empty array of partials under key from nil collection" do
148
+ Jbuilder::CollectionRenderer.expects(:new).never
129
149
  result = render('json.posts @posts, partial: "post", as: :post', posts: nil)
130
150
  assert_equal [], result["posts"]
131
151
  end
132
152
 
153
+ test "empty array of partials under key from an empy collection" do
154
+ Jbuilder::CollectionRenderer.expects(:new).never
155
+ result = render('json.posts @posts, partial: "post", as: :post', posts: [])
156
+ assert_equal [], result["posts"]
157
+ end
158
+
133
159
  test "object fragment caching" do
134
160
  render(<<-JBUILDER)
135
161
  json.cache! "cache-key" do
@@ -291,98 +317,97 @@ class JbuilderTemplateTest < ActiveSupport::TestCase
291
317
  assert_equal "David", result["firstName"]
292
318
  end
293
319
 
294
- if JbuilderTemplate::CollectionRenderer.supported?
295
- test "returns an empty array for an empty collection" do
296
- result = render('json.array! @posts, partial: "post", as: :post, cached: true', posts: [])
320
+ test "returns an empty array for an empty collection" do
321
+ Jbuilder::CollectionRenderer.expects(:new).never
322
+ result = render('json.array! @posts, partial: "post", as: :post, cached: true', posts: [])
297
323
 
298
- # Do not use #assert_empty as it is important to ensure that the type of the JSON result is an array.
299
- assert_equal [], result
300
- end
324
+ # Do not use #assert_empty as it is important to ensure that the type of the JSON result is an array.
325
+ assert_equal [], result
326
+ end
301
327
 
302
- test "works with an enumerable object" do
303
- enumerable_class = Class.new do
304
- include Enumerable
328
+ test "works with an enumerable object" do
329
+ enumerable_class = Class.new do
330
+ include Enumerable
305
331
 
306
- def each(&block)
307
- [].each(&block)
308
- end
332
+ def each(&block)
333
+ [].each(&block)
309
334
  end
335
+ end
310
336
 
311
- result = render('json.array! @posts, partial: "post", as: :post, cached: true', posts: enumerable_class.new)
337
+ result = render('json.array! @posts, partial: "post", as: :post, cached: true', posts: enumerable_class.new)
312
338
 
313
- # Do not use #assert_empty as it is important to ensure that the type of the JSON result is an array.
314
- assert_equal [], result
315
- end
339
+ # Do not use #assert_empty as it is important to ensure that the type of the JSON result is an array.
340
+ assert_equal [], result
341
+ end
342
+
343
+ test "supports the cached: true option" do
344
+ result = render('json.array! @posts, partial: "post", as: :post, cached: true', posts: POSTS)
316
345
 
317
- test "supports the cached: true option" do
318
- result = render('json.array! @posts, partial: "post", as: :post, cached: true', posts: POSTS)
319
-
320
- assert_equal 10, result.count
321
- assert_equal "Post #5", result[4]["body"]
322
- assert_equal "Heinemeier Hansson", result[2]["author"]["last_name"]
323
- assert_equal "Pavel", result[5]["author"]["first_name"]
324
-
325
- expected = {
326
- "id" => 1,
327
- "body" => "Post #1",
328
- "author" => {
329
- "first_name" => "David",
330
- "last_name" => "Heinemeier Hansson"
331
- }
346
+ assert_equal 10, result.count
347
+ assert_equal "Post #5", result[4]["body"]
348
+ assert_equal "Heinemeier Hansson", result[2]["author"]["last_name"]
349
+ assert_equal "Pavel", result[5]["author"]["first_name"]
350
+
351
+ expected = {
352
+ "id" => 1,
353
+ "body" => "Post #1",
354
+ "author" => {
355
+ "first_name" => "David",
356
+ "last_name" => "Heinemeier Hansson"
332
357
  }
358
+ }
333
359
 
334
- assert_equal expected, Rails.cache.read("post-1")
360
+ assert_equal expected, Rails.cache.read("post-1")
335
361
 
336
- result = render('json.array! @posts, partial: "post", as: :post, cached: true', posts: POSTS)
362
+ result = render('json.array! @posts, partial: "post", as: :post, cached: true', posts: POSTS)
337
363
 
338
- assert_equal 10, result.count
339
- assert_equal "Post #5", result[4]["body"]
340
- assert_equal "Heinemeier Hansson", result[2]["author"]["last_name"]
341
- assert_equal "Pavel", result[5]["author"]["first_name"]
342
- end
364
+ assert_equal 10, result.count
365
+ assert_equal "Post #5", result[4]["body"]
366
+ assert_equal "Heinemeier Hansson", result[2]["author"]["last_name"]
367
+ assert_equal "Pavel", result[5]["author"]["first_name"]
368
+ end
343
369
 
344
- test "supports the cached: ->() {} option" do
345
- result = render('json.array! @posts, partial: "post", as: :post, cached: ->(post) { [post, "foo"] }', posts: POSTS)
346
-
347
- assert_equal 10, result.count
348
- assert_equal "Post #5", result[4]["body"]
349
- assert_equal "Heinemeier Hansson", result[2]["author"]["last_name"]
350
- assert_equal "Pavel", result[5]["author"]["first_name"]
351
-
352
- expected = {
353
- "id" => 1,
354
- "body" => "Post #1",
355
- "author" => {
356
- "first_name" => "David",
357
- "last_name" => "Heinemeier Hansson"
358
- }
359
- }
370
+ test "supports the cached: ->() {} option" do
371
+ result = render('json.array! @posts, partial: "post", as: :post, cached: ->(post) { [post, "foo"] }', posts: POSTS)
360
372
 
361
- assert_equal expected, Rails.cache.read("post-1/foo")
373
+ assert_equal 10, result.count
374
+ assert_equal "Post #5", result[4]["body"]
375
+ assert_equal "Heinemeier Hansson", result[2]["author"]["last_name"]
376
+ assert_equal "Pavel", result[5]["author"]["first_name"]
362
377
 
363
- result = render('json.array! @posts, partial: "post", as: :post, cached: ->(post) { [post, "foo"] }', posts: POSTS)
378
+ expected = {
379
+ "id" => 1,
380
+ "body" => "Post #1",
381
+ "author" => {
382
+ "first_name" => "David",
383
+ "last_name" => "Heinemeier Hansson"
384
+ }
385
+ }
364
386
 
365
- assert_equal 10, result.count
366
- assert_equal "Post #5", result[4]["body"]
367
- assert_equal "Heinemeier Hansson", result[2]["author"]["last_name"]
368
- assert_equal "Pavel", result[5]["author"]["first_name"]
369
- end
387
+ assert_equal expected, Rails.cache.read("post-1/foo")
370
388
 
371
- test "raises an error on a render call with the :layout option" do
372
- error = assert_raises NotImplementedError do
373
- render('json.array! @posts, partial: "post", as: :post, layout: "layout"', posts: POSTS)
374
- end
389
+ result = render('json.array! @posts, partial: "post", as: :post, cached: ->(post) { [post, "foo"] }', posts: POSTS)
375
390
 
376
- assert_equal "The `:layout' option is not supported in collection rendering.", error.message
391
+ assert_equal 10, result.count
392
+ assert_equal "Post #5", result[4]["body"]
393
+ assert_equal "Heinemeier Hansson", result[2]["author"]["last_name"]
394
+ assert_equal "Pavel", result[5]["author"]["first_name"]
395
+ end
396
+
397
+ test "raises an error on a render call with the :layout option" do
398
+ error = assert_raises NotImplementedError do
399
+ render('json.array! @posts, partial: "post", as: :post, layout: "layout"', posts: POSTS)
377
400
  end
378
401
 
379
- test "raises an error on a render call with the :spacer_template option" do
380
- error = assert_raises NotImplementedError do
381
- render('json.array! @posts, partial: "post", as: :post, spacer_template: "template"', posts: POSTS)
382
- end
402
+ assert_equal "The `:layout' option is not supported in collection rendering.", error.message
403
+ end
383
404
 
384
- assert_equal "The `:spacer_template' option is not supported in collection rendering.", error.message
405
+ test "raises an error on a render call with the :spacer_template option" do
406
+ error = assert_raises NotImplementedError do
407
+ render('json.array! @posts, partial: "post", as: :post, spacer_template: "template"', posts: POSTS)
385
408
  end
409
+
410
+ assert_equal "The `:spacer_template' option is not supported in collection rendering.", error.message
386
411
  end
387
412
 
388
413
  private
@@ -400,12 +425,7 @@ class JbuilderTemplateTest < ActiveSupport::TestCase
400
425
  lookup_context = ActionView::LookupContext.new([ resolver ], {}, [""])
401
426
  controller = ActionView::TestCase::TestController.new
402
427
 
403
- # TODO: Use with_empty_template_cache unconditionally after dropping support for Rails <6.0.
404
- view = if ActionView::Base.respond_to?(:with_empty_template_cache)
405
- ActionView::Base.with_empty_template_cache.new(lookup_context, options.fetch(:assigns, {}), controller)
406
- else
407
- ActionView::Base.new(lookup_context, options.fetch(:assigns, {}), controller)
408
- end
428
+ view = ActionView::Base.with_empty_template_cache.new(lookup_context, options.fetch(:assigns, {}), controller)
409
429
 
410
430
  def view.view_cache_dependencies; []; end
411
431
  def view.combined_fragment_cache_key(key) [ key ] end
@@ -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,68 +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
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
15
18
 
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
19
+ assert_instance_method :show, content do |m|
20
+ assert m.blank?
21
+ end
20
22
 
21
- assert_instance_method :show, content do |m|
22
- assert m.blank?
23
- 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
24
29
 
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
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
31
34
 
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
35
+ assert_instance_method :destroy, content do |m|
36
+ assert_match %r{@post\.destroy}, m
37
+ end
36
38
 
37
- assert_instance_method :destroy, content do |m|
38
- assert_match %r{@post\.destroy}, m
39
- 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
40
45
 
41
- assert_match %r{def post_params}, content
42
- if Rails::VERSION::MAJOR >= 6
43
- assert_match %r{params\.require\(:post\)\.permit\(:title, :body, images: \[\]\)}, content
44
- else
45
- assert_match %r{params\.require\(:post\)\.permit\(:title, :body, :images\)}, content
46
- 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
47
51
  end
48
52
  end
53
+ end
49
54
 
50
- test "don't use require and permit if there are no attributes" do
51
- 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)
52
57
 
53
- assert_file 'app/controllers/posts_controller.rb' do |content|
54
- assert_match %r{def post_params}, content
55
- assert_match %r{params\.fetch\(:post, \{\}\)}, content
56
- 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
57
61
  end
62
+ end
58
63
 
64
+ test 'handles virtual attributes' do
65
+ run_generator %w(Message content:rich_text video:attachment photos:attachments --skip-routes)
59
66
 
60
- if Rails::VERSION::MAJOR >= 6
61
- test 'handles virtual attributes' do
62
- run_generator ["Message", "content:rich_text", "video:attachment", "photos:attachments"]
63
-
64
- assert_file 'app/controllers/messages_controller.rb' do |content|
65
- assert_match %r{params\.require\(:message\)\.permit\(:content, :video, photos: \[\]\)}, content
66
- 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
67
72
  end
68
73
  end
69
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
 
@@ -31,14 +31,14 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
31
31
  assert_instance_method :create, content do |m|
32
32
  assert_match %r{@post = Post\.new\(post_params\)}, m
33
33
  assert_match %r{@post\.save}, m
34
- assert_match %r{format\.html \{ redirect_to post_url\(@post\), notice: "Post was successfully created\." \}}, m
34
+ assert_match %r{format\.html \{ redirect_to @post, notice: "Post was successfully created\." \}}, m
35
35
  assert_match %r{format\.json \{ render :show, status: :created, location: @post \}}, m
36
36
  assert_match %r{format\.html \{ render :new, status: :unprocessable_entity \}}, m
37
37
  assert_match %r{format\.json \{ render json: @post\.errors, status: :unprocessable_entity \}}, m
38
38
  end
39
39
 
40
40
  assert_instance_method :update, content do |m|
41
- assert_match %r{format\.html \{ redirect_to post_url\(@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,40 +46,45 @@ 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_url, 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
 
53
+ assert_match %r{def set_post}, content
54
+ if Rails::VERSION::MAJOR >= 8
55
+ assert_match %r{params\.expect\(:id\)}, content
56
+ else
57
+ assert_match %r{params\[:id\]}, content
58
+ end
59
+
53
60
  assert_match %r{def post_params}, content
54
- if Rails::VERSION::MAJOR >= 6
55
- assert_match %r{params\.require\(:post\)\.permit\(:title, :body, images: \[\]\)}, content
61
+ if Rails::VERSION::MAJOR >= 8
62
+ assert_match %r{params\.expect\(post: \[ :title, :body, images: \[\] \]\)}, content
56
63
  else
57
- assert_match %r{params\.require\(:post\)\.permit\(:title, :body, :images\)}, content
64
+ assert_match %r{params\.require\(:post\)\.permit\(:title, :body, images: \[\]\)}, content
58
65
  end
59
66
  end
60
67
  end
61
68
 
62
- if Rails::VERSION::MAJOR >= 6
63
- test 'controller with namespace' do
64
- run_generator %w(Admin::Post --model-name=Post)
65
- assert_file 'app/controllers/admin/posts_controller.rb' do |content|
66
- assert_instance_method :create, content do |m|
67
- assert_match %r{format\.html \{ redirect_to admin_post_url\(@post\), notice: "Post was successfully created\." \}}, m
68
- end
69
-
70
- assert_instance_method :update, content do |m|
71
- assert_match %r{format\.html \{ redirect_to admin_post_url\(@post\), notice: "Post was successfully updated\." \}}, m
72
- end
73
-
74
- assert_instance_method :destroy, content do |m|
75
- assert_match %r{format\.html \{ redirect_to admin_posts_url, notice: "Post was successfully destroyed\." \}}, m
76
- 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
77
82
  end
78
83
  end
79
84
  end
80
85
 
81
86
  test "don't use require and permit if there are no attributes" do
82
- run_generator %w(Post)
87
+ run_generator %w(Post --skip-routes)
83
88
 
84
89
  assert_file 'app/controllers/posts_controller.rb' do |content|
85
90
  assert_match %r{def post_params}, content
@@ -87,11 +92,13 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
87
92
  end
88
93
  end
89
94
 
90
- if Rails::VERSION::MAJOR >= 6
91
- test 'handles virtual attributes' do
92
- 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)
93
97
 
94
- assert_file 'app/controllers/messages_controller.rb' do |content|
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
95
102
  assert_match %r{params\.require\(:message\)\.permit\(:content, :video, photos: \[\]\)}, content
96
103
  end
97
104
  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.12.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-04-29 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
@@ -52,13 +51,12 @@ files:
52
51
  - MIT-LICENSE
53
52
  - README.md
54
53
  - Rakefile
55
- - gemfiles/rails_5_0.gemfile
56
- - gemfiles/rails_5_1.gemfile
57
- - gemfiles/rails_5_2.gemfile
58
- - gemfiles/rails_6_0.gemfile
59
- - gemfiles/rails_6_1.gemfile
54
+ - bin/release
55
+ - bin/test
60
56
  - gemfiles/rails_7_0.gemfile
61
57
  - gemfiles/rails_7_1.gemfile
58
+ - gemfiles/rails_7_2.gemfile
59
+ - gemfiles/rails_8_0.gemfile
62
60
  - gemfiles/rails_head.gemfile
63
61
  - jbuilder.gemspec
64
62
  - lib/generators/rails/jbuilder_generator.rb
@@ -77,6 +75,7 @@ files:
77
75
  - lib/jbuilder/jbuilder_template.rb
78
76
  - lib/jbuilder/key_formatter.rb
79
77
  - lib/jbuilder/railtie.rb
78
+ - lib/jbuilder/version.rb
80
79
  - test/jbuilder_dependency_tracker_test.rb
81
80
  - test/jbuilder_generator_test.rb
82
81
  - test/jbuilder_template_test.rb
@@ -89,11 +88,10 @@ licenses:
89
88
  - MIT
90
89
  metadata:
91
90
  bug_tracker_uri: https://github.com/rails/jbuilder/issues
92
- changelog_uri: https://github.com/rails/jbuilder/releases/tag/v2.12.0
91
+ changelog_uri: https://github.com/rails/jbuilder/releases/tag/v2.14.0
93
92
  mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
94
- source_code_uri: https://github.com/rails/jbuilder/tree/v2.12.0
93
+ source_code_uri: https://github.com/rails/jbuilder/tree/v2.14.0
95
94
  rubygems_mfa_required: 'true'
96
- post_install_message:
97
95
  rdoc_options: []
98
96
  require_paths:
99
97
  - lib
@@ -101,15 +99,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
99
  requirements:
102
100
  - - ">="
103
101
  - !ruby/object:Gem::Version
104
- version: 2.2.2
102
+ version: 3.0.0
105
103
  required_rubygems_version: !ruby/object:Gem::Requirement
106
104
  requirements:
107
105
  - - ">="
108
106
  - !ruby/object:Gem::Version
109
107
  version: '0'
110
108
  requirements: []
111
- rubygems_version: 3.5.9
112
- signing_key:
109
+ rubygems_version: 3.6.9
113
110
  specification_version: 4
114
111
  summary: Create JSON structures via a Builder-style DSL
115
112
  test_files:
@@ -1,11 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rake"
6
- gem "mocha", require: false
7
- gem "appraisal"
8
- gem "rails", "~> 5.0.0"
9
- gem "loofah", "< 2.21.0"
10
-
11
- gemspec path: "../"