jbuilder 2.2.16 → 2.6.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,55 @@
1
+ require 'test_helper'
2
+ require 'rails/generators/test_case'
3
+ require 'generators/rails/scaffold_controller_generator'
4
+
5
+ if Rails::VERSION::MAJOR > 4
6
+
7
+ class ScaffoldApiControllerGeneratorTest < Rails::Generators::TestCase
8
+ tests Rails::Generators::ScaffoldControllerGenerator
9
+ arguments %w(Post title body:text --api)
10
+ destination File.expand_path('../tmp', __FILE__)
11
+ setup :prepare_destination
12
+
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
20
+
21
+ assert_instance_method :show, content do |m|
22
+ assert m.blank?
23
+ end
24
+
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
31
+
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
36
+
37
+ assert_instance_method :destroy, content do |m|
38
+ assert_match %r{@post\.destroy}, m
39
+ end
40
+
41
+ assert_match %r{def post_params}, content
42
+ assert_match %r{params\.require\(:post\)\.permit\(:title, :body\)}, content
43
+ end
44
+ end
45
+
46
+ test 'dont use require and permit if there are no attributes' do
47
+ run_generator %w(Post --api)
48
+
49
+ assert_file 'app/controllers/posts_controller.rb' do |content|
50
+ assert_match %r{def post_params}, content
51
+ assert_match %r{params\.fetch\(:post, \{\}\)}, content
52
+ end
53
+ end
54
+ end
55
+ end
@@ -13,7 +13,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
13
13
 
14
14
  assert_file 'app/controllers/posts_controller.rb' do |content|
15
15
  assert_instance_method :index, content do |m|
16
- assert_match /@posts = Post\.all/, m
16
+ assert_match %r{@posts = Post\.all}, m
17
17
  end
18
18
 
19
19
  assert_instance_method :show, content do |m|
@@ -21,7 +21,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
21
21
  end
22
22
 
23
23
  assert_instance_method :new, content do |m|
24
- assert_match /@post = Post\.new/, m
24
+ assert_match %r{@post = Post\.new}, m
25
25
  end
26
26
 
27
27
  assert_instance_method :edit, content do |m|
@@ -29,29 +29,38 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
29
29
  end
30
30
 
31
31
  assert_instance_method :create, content do |m|
32
- assert_match /@post = Post\.new\(post_params\)/, m
33
- assert_match /@post\.save/, m
34
- assert_match /format\.html \{ redirect_to @post, notice: 'Post was successfully created\.' \}/, m
35
- assert_match /format\.json \{ render :show, status: :created, location: @post \}/, m
36
- assert_match /format\.html \{ render :new \}/, m
37
- assert_match /format\.json \{ render json: @post\.errors, status: :unprocessable_entity \}/, m
32
+ assert_match %r{@post = Post\.new\(post_params\)}, m
33
+ assert_match %r{@post\.save}, m
34
+ assert_match %r{format\.html \{ redirect_to @post, notice: 'Post was successfully created\.' \}}, m
35
+ assert_match %r{format\.json \{ render :show, status: :created, location: @post \}}, m
36
+ assert_match %r{format\.html \{ render :new \}}, m
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 /format\.html \{ redirect_to @post, notice: 'Post was successfully updated\.' \}/, m
42
- assert_match /format\.json \{ render :show, status: :ok, location: @post \}/, m
43
- assert_match /format\.html \{ render :edit \}/, m
44
- assert_match /format\.json \{ render json: @post.errors, status: :unprocessable_entity \}/, m
41
+ assert_match %r{format\.html \{ redirect_to @post, notice: 'Post was successfully updated\.' \}}, m
42
+ assert_match %r{format\.json \{ render :show, status: :ok, location: @post \}}, m
43
+ assert_match %r{format\.html \{ render :edit \}}, m
44
+ assert_match %r{format\.json \{ render json: @post.errors, status: :unprocessable_entity \}}, m
45
45
  end
46
46
 
47
47
  assert_instance_method :destroy, content do |m|
48
- assert_match /@post\.destroy/, m
49
- assert_match /format\.html \{ redirect_to posts_url, notice: 'Post was successfully destroyed\.' \}/, m
50
- assert_match /format\.json \{ head :no_content \}/, m
48
+ assert_match %r{@post\.destroy}, m
49
+ assert_match %r{format\.html \{ redirect_to posts_url, notice: 'Post was successfully destroyed\.' \}}, m
50
+ assert_match %r{format\.json \{ head :no_content \}}, m
51
51
  end
52
52
 
53
- assert_match(/def post_params/, content)
54
- assert_match(/params\.require\(:post\)\.permit\(:title, :body\)/, content)
53
+ assert_match %r{def post_params}, content
54
+ assert_match %r{params\.require\(:post\)\.permit\(:title, :body\)}, content
55
+ end
56
+ end
57
+
58
+ test 'dont use require and permit if there are no attributes' do
59
+ run_generator %w(Post)
60
+
61
+ assert_file 'app/controllers/posts_controller.rb' do |content|
62
+ assert_match %r{def post_params}, content
63
+ assert_match %r{params\.fetch\(:post, \{\}\)}, content
55
64
  end
56
65
  end
57
66
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jbuilder
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.16
4
+ version: 2.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
- - Pavel Pravosud
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-05-18 00:00:00.000000000 Z
11
+ date: 2017-05-10 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activesupport
@@ -18,9 +17,6 @@ dependencies:
18
17
  - - ">="
19
18
  - !ruby/object:Gem::Version
20
19
  version: 3.0.0
21
- - - "<"
22
- - !ruby/object:Gem::Version
23
- version: '5'
24
20
  type: :runtime
25
21
  prerelease: false
26
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -28,27 +24,23 @@ dependencies:
28
24
  - - ">="
29
25
  - !ruby/object:Gem::Version
30
26
  version: 3.0.0
31
- - - "<"
32
- - !ruby/object:Gem::Version
33
- version: '5'
34
27
  - !ruby/object:Gem::Dependency
35
28
  name: multi_json
36
29
  requirement: !ruby/object:Gem::Requirement
37
30
  requirements:
38
- - - "~>"
31
+ - - ">="
39
32
  - !ruby/object:Gem::Version
40
33
  version: '1.2'
41
34
  type: :runtime
42
35
  prerelease: false
43
36
  version_requirements: !ruby/object:Gem::Requirement
44
37
  requirements:
45
- - - "~>"
38
+ - - ">="
46
39
  - !ruby/object:Gem::Version
47
40
  version: '1.2'
48
41
  description:
49
42
  email:
50
43
  - david@37signals.com
51
- - pavel@pravosud.com
52
44
  executables: []
53
45
  extensions: []
54
46
  extra_rdoc_files: []
@@ -57,6 +49,7 @@ files:
57
49
  - ".travis.yml"
58
50
  - Appraisals
59
51
  - CHANGELOG.md
52
+ - CONTRIBUTING.md
60
53
  - Gemfile
61
54
  - MIT-LICENSE
62
55
  - README.md
@@ -67,11 +60,15 @@ files:
67
60
  - gemfiles/rails_4_0.gemfile
68
61
  - gemfiles/rails_4_1.gemfile
69
62
  - gemfiles/rails_4_2.gemfile
63
+ - gemfiles/rails_5_0.gemfile
64
+ - gemfiles/rails_5_1.gemfile
70
65
  - jbuilder.gemspec
71
66
  - lib/generators/rails/jbuilder_generator.rb
72
67
  - lib/generators/rails/scaffold_controller_generator.rb
68
+ - lib/generators/rails/templates/api_controller.rb
73
69
  - lib/generators/rails/templates/controller.rb
74
70
  - lib/generators/rails/templates/index.json.jbuilder
71
+ - lib/generators/rails/templates/partial.json.jbuilder
75
72
  - lib/generators/rails/templates/show.json.jbuilder
76
73
  - lib/jbuilder.rb
77
74
  - lib/jbuilder/blank.rb
@@ -85,6 +82,7 @@ files:
85
82
  - test/jbuilder_generator_test.rb
86
83
  - test/jbuilder_template_test.rb
87
84
  - test/jbuilder_test.rb
85
+ - test/scaffold_api_controller_generator_test.rb
88
86
  - test/scaffold_controller_generator_test.rb
89
87
  - test/test_helper.rb
90
88
  homepage: https://github.com/rails/jbuilder
@@ -107,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
105
  version: '0'
108
106
  requirements: []
109
107
  rubyforge_project:
110
- rubygems_version: 2.4.6
108
+ rubygems_version: 2.6.8
111
109
  signing_key:
112
110
  specification_version: 4
113
111
  summary: Create JSON structures via a Builder-style DSL
@@ -116,5 +114,6 @@ test_files:
116
114
  - test/jbuilder_generator_test.rb
117
115
  - test/jbuilder_template_test.rb
118
116
  - test/jbuilder_test.rb
117
+ - test/scaffold_api_controller_generator_test.rb
119
118
  - test/scaffold_controller_generator_test.rb
120
119
  - test/test_helper.rb