jbuilder 2.13.0 → 2.15.1

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.
@@ -2,81 +2,81 @@ 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
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
+ if Gem::Version.new(Rack::RELEASE) < Gem::Version.new("3.1")
29
28
  assert_match %r{render json: @post\.errors, status: :unprocessable_entity}, m
29
+ else
30
+ assert_match %r{render json: @post\.errors, status: :unprocessable_content}, m
30
31
  end
32
+ end
31
33
 
32
- assert_instance_method :update, content do |m|
33
- assert_match %r{render :show, status: :ok, location: @post}, m
34
+ assert_instance_method :update, content do |m|
35
+ assert_match %r{render :show, status: :ok, location: @post}, m
36
+ if Gem::Version.new(Rack::RELEASE) < Gem::Version.new("3.1")
34
37
  assert_match %r{render json: @post.errors, status: :unprocessable_entity}, m
35
- end
36
-
37
- assert_instance_method :destroy, content do |m|
38
- assert_match %r{@post\.destroy}, m
39
- end
40
-
41
- assert_match %r{def set_post}, content
42
- if Rails::VERSION::MAJOR >= 8
43
- assert_match %r{params\.expect\(:id\)}, content
44
38
  else
45
- assert_match %r{params\[:id\]}, content
39
+ assert_match %r{render json: @post.errors, status: :unprocessable_content}, m
46
40
  end
41
+ end
47
42
 
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
43
+ assert_instance_method :destroy, content do |m|
44
+ assert_match %r{@post\.destroy}, m
56
45
  end
57
- end
58
46
 
59
- test "don't use require and permit if there are no attributes" do
60
- run_generator %w(Post --api)
47
+ assert_match %r{def set_post}, content
48
+ if Rails::VERSION::MAJOR >= 8
49
+ assert_match %r{params\.expect\(:id\)}, content
50
+ else
51
+ assert_match %r{params\[:id\]}, content
52
+ end
61
53
 
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
54
+ assert_match %r{def post_params}, content
55
+ if Rails::VERSION::MAJOR >= 8
56
+ assert_match %r{params\.expect\(post: \[ :title, :body, images: \[\] \]\)}, content
57
+ else
58
+ assert_match %r{params\.require\(:post\)\.permit\(:title, :body, images: \[\]\)}, content
65
59
  end
66
60
  end
61
+ end
67
62
 
63
+ test "don't use require and permit if there are no attributes" do
64
+ run_generator %w(Post --api --skip-routes)
68
65
 
69
- if Rails::VERSION::MAJOR >= 6
70
- test 'handles virtual attributes' do
71
- run_generator ["Message", "content:rich_text", "video:attachment", "photos:attachments"]
66
+ assert_file 'app/controllers/posts_controller.rb' do |content|
67
+ assert_match %r{def post_params}, content
68
+ assert_match %r{params\.fetch\(:post, \{\}\)}, content
69
+ end
70
+ end
72
71
 
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
72
+ test 'handles virtual attributes' do
73
+ run_generator %w(Message content:rich_text video:attachment photos:attachments --skip-routes)
74
+
75
+ assert_file 'app/controllers/messages_controller.rb' do |content|
76
+ if Rails::VERSION::MAJOR >= 8
77
+ assert_match %r{params\.expect\(message: \[ :content, :video, photos: \[\] \]\)}, content
78
+ else
79
+ assert_match %r{params\.require\(:message\)\.permit\(:content, :video, photos: \[\]\)}, content
80
80
  end
81
81
  end
82
82
  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
 
@@ -33,20 +33,30 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
33
33
  assert_match %r{@post\.save}, m
34
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
- assert_match %r{format\.html \{ render :new, status: :unprocessable_entity \}}, m
37
- assert_match %r{format\.json \{ render json: @post\.errors, status: :unprocessable_entity \}}, m
36
+ if Gem::Version.new(Rack::RELEASE) < Gem::Version.new("3.1")
37
+ assert_match %r{format\.html \{ render :new, status: :unprocessable_entity \}}, m
38
+ assert_match %r{format\.json \{ render json: @post\.errors, status: :unprocessable_entity \}}, m
39
+ else
40
+ assert_match %r{format\.html \{ render :new, status: :unprocessable_content \}}, m
41
+ assert_match %r{format\.json \{ render json: @post\.errors, status: :unprocessable_content \}}, m
42
+ end
38
43
  end
39
44
 
40
45
  assert_instance_method :update, content do |m|
41
- assert_match %r{format\.html \{ redirect_to @post, notice: "Post was successfully updated\." \}}, m
46
+ assert_match %r{format\.html \{ redirect_to @post, notice: "Post was successfully updated\.", status: :see_other \}}, m
42
47
  assert_match %r{format\.json \{ render :show, status: :ok, location: @post \}}, m
43
- assert_match %r{format\.html \{ render :edit, status: :unprocessable_entity \}}, m
44
- assert_match %r{format\.json \{ render json: @post.errors, status: :unprocessable_entity \}}, m
48
+ if Gem::Version.new(Rack::RELEASE) < Gem::Version.new("3.1")
49
+ assert_match %r{format\.html \{ render :edit, status: :unprocessable_entity \}}, m
50
+ assert_match %r{format\.json \{ render json: @post.errors, status: :unprocessable_entity \}}, m
51
+ else
52
+ assert_match %r{format\.html \{ render :edit, status: :unprocessable_content \}}, m
53
+ assert_match %r{format\.json \{ render json: @post.errors, status: :unprocessable_content \}}, m
54
+ end
45
55
  end
46
56
 
47
57
  assert_instance_method :destroy, content do |m|
48
58
  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
59
+ assert_match %r{format\.html \{ redirect_to posts_path, notice: "Post was successfully destroyed\.", status: :see_other \}}, m
50
60
  assert_match %r{format\.json \{ head :no_content \}}, m
51
61
  end
52
62
 
@@ -60,35 +70,31 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
60
70
  assert_match %r{def post_params}, content
61
71
  if Rails::VERSION::MAJOR >= 8
62
72
  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
73
  else
66
- assert_match %r{params\.require\(:post\)\.permit\(:title, :body, :images\)}, content
74
+ assert_match %r{params\.require\(:post\)\.permit\(:title, :body, images: \[\]\)}, content
67
75
  end
68
76
  end
69
77
  end
70
78
 
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
79
+ test 'controller with namespace' do
80
+ run_generator %w(Admin::Post --model-name=Post --skip-routes)
81
+ assert_file 'app/controllers/admin/posts_controller.rb' do |content|
82
+ assert_instance_method :create, content do |m|
83
+ assert_match %r{format\.html \{ redirect_to \[:admin, @post\], notice: "Post was successfully created\." \}}, m
84
+ end
78
85
 
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
86
+ assert_instance_method :update, content do |m|
87
+ assert_match %r{format\.html \{ redirect_to \[:admin, @post\], notice: "Post was successfully updated\.", status: :see_other \}}, m
88
+ end
82
89
 
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
90
+ assert_instance_method :destroy, content do |m|
91
+ assert_match %r{format\.html \{ redirect_to admin_posts_path, notice: "Post was successfully destroyed\.", status: :see_other \}}, m
86
92
  end
87
93
  end
88
94
  end
89
95
 
90
96
  test "don't use require and permit if there are no attributes" do
91
- run_generator %w(Post)
97
+ run_generator %w(Post --skip-routes)
92
98
 
93
99
  assert_file 'app/controllers/posts_controller.rb' do |content|
94
100
  assert_match %r{def post_params}, content
@@ -96,16 +102,14 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
96
102
  end
97
103
  end
98
104
 
99
- if Rails::VERSION::MAJOR >= 6
100
- test 'handles virtual attributes' do
101
- run_generator %w(Message content:rich_text video:attachment photos:attachments)
105
+ test 'handles virtual attributes' do
106
+ run_generator %w(Message content:rich_text video:attachment photos:attachments --skip-routes)
102
107
 
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
108
+ assert_file 'app/controllers/messages_controller.rb' do |content|
109
+ if Rails::VERSION::MAJOR >= 8
110
+ assert_match %r{params\.expect\(message: \[ :content, :video, photos: \[\] \]\)}, content
111
+ else
112
+ assert_match %r{params\.require\(:message\)\.permit\(:content, :video, photos: \[\]\)}, content
109
113
  end
110
114
  end
111
115
  end
data/test/test_helper.rb CHANGED
@@ -19,14 +19,14 @@ 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
26
26
 
27
27
  Jbuilder::CollectionRenderer.collection_cache = Rails.cache
28
28
 
29
- class Post < Struct.new(:id, :body, :author_name)
29
+ class Post < Struct.new(:id, :title, :body, :author_name)
30
30
  def cache_key
31
31
  "post-#{id}"
32
32
  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.15.1
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,35 @@ 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-lock.json"
46
+ - ".devcontainer/devcontainer.json"
47
47
  - ".github/workflows/ruby.yml"
48
48
  - ".gitignore"
49
49
  - Appraisals
@@ -56,6 +56,9 @@ files:
56
56
  - bin/test
57
57
  - gemfiles/rails_7_0.gemfile
58
58
  - gemfiles/rails_7_1.gemfile
59
+ - gemfiles/rails_7_2.gemfile
60
+ - gemfiles/rails_8_0.gemfile
61
+ - gemfiles/rails_8_1.gemfile
59
62
  - gemfiles/rails_head.gemfile
60
63
  - jbuilder.gemspec
61
64
  - lib/generators/rails/jbuilder_generator.rb
@@ -87,11 +90,10 @@ licenses:
87
90
  - MIT
88
91
  metadata:
89
92
  bug_tracker_uri: https://github.com/rails/jbuilder/issues
90
- changelog_uri: https://github.com/rails/jbuilder/releases/tag/v2.13.0
93
+ changelog_uri: https://github.com/rails/jbuilder/releases/tag/v2.15.1
91
94
  mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
92
- source_code_uri: https://github.com/rails/jbuilder/tree/v2.13.0
95
+ source_code_uri: https://github.com/rails/jbuilder/tree/v2.15.1
93
96
  rubygems_mfa_required: 'true'
94
- post_install_message:
95
97
  rdoc_options: []
96
98
  require_paths:
97
99
  - lib
@@ -99,15 +101,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
101
  requirements:
100
102
  - - ">="
101
103
  - !ruby/object:Gem::Version
102
- version: 2.2.2
104
+ version: 3.0.0
103
105
  required_rubygems_version: !ruby/object:Gem::Requirement
104
106
  requirements:
105
107
  - - ">="
106
108
  - !ruby/object:Gem::Version
107
109
  version: '0'
108
110
  requirements: []
109
- rubygems_version: 3.5.16
110
- signing_key:
111
+ rubygems_version: 4.0.10
111
112
  specification_version: 4
112
113
  summary: Create JSON structures via a Builder-style DSL
113
114
  test_files: