jbuilder 2.6.0 → 2.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/CONTRIBUTING.md +5 -4
- data/README.md +1 -1
- data/gemfiles/rails_5_0.gemfile +3 -3
- data/jbuilder.gemspec +1 -1
- data/lib/jbuilder/jbuilder_template.rb +25 -0
- data/lib/jbuilder/key_formatter.rb +2 -2
- data/test/jbuilder_generator_test.rb +4 -4
- data/test/jbuilder_template_test.rb +29 -0
- data/test/scaffold_api_controller_generator_test.rb +12 -12
- data/test/scaffold_controller_generator_test.rb +19 -19
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4b4939ae1d814cadb9d44ab80a4489d59b4c8a5
|
4
|
+
data.tar.gz: ae232631e1f37a815ae5e46cb45c88706c803da8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0e4fb3d778a25514a6b82f6bdca2519690fe85719a902ec95c72ae5f7016f796e7567ca847cc369752077525d47f38344edff9f97d03a3a9dbe47b195c88d39
|
7
|
+
data.tar.gz: 24e1713528b9d0bfaa2d90c32f1432440c58acb7e6619c75d1956d23c041ef66672162dc97888af8f7558cd17024f33234102a285001a3188ba97bf39e6fd5ef
|
data/CHANGELOG.md
CHANGED
data/CONTRIBUTING.md
CHANGED
@@ -39,7 +39,8 @@ Ensure that you can build the project and run tests.
|
|
39
39
|
|
40
40
|
```
|
41
41
|
bundle install
|
42
|
-
|
42
|
+
appraisal install
|
43
|
+
appraisal rake test
|
43
44
|
```
|
44
45
|
|
45
46
|
#### Write Tests
|
@@ -52,7 +53,7 @@ We definitely appreciate pull requests that highlight or reproduce a problem, ev
|
|
52
53
|
|
53
54
|
Implement your feature or bug fix.
|
54
55
|
|
55
|
-
Make sure that `
|
56
|
+
Make sure that `appraisal rake test` completes without errors.
|
56
57
|
|
57
58
|
#### Write Documentation
|
58
59
|
|
@@ -82,7 +83,7 @@ git push origin my-feature-branch
|
|
82
83
|
|
83
84
|
#### Make a Pull Request
|
84
85
|
|
85
|
-
|
86
|
+
Visit your forked repo and click the 'New pull request' button. Select your feature branch, fill out the form, and click the 'Create pull request' button. Pull requests are usually reviewed within a few days.
|
86
87
|
|
87
88
|
#### Rebase
|
88
89
|
|
@@ -100,7 +101,7 @@ Go back to your pull request after a few minutes and see whether it passed muste
|
|
100
101
|
|
101
102
|
#### Be Patient
|
102
103
|
|
103
|
-
It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang
|
104
|
+
It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang in there!
|
104
105
|
|
105
106
|
#### Thank You
|
106
107
|
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Jbuilder
|
2
2
|
|
3
3
|
Jbuilder gives you a simple DSL for declaring JSON structures that beats
|
4
|
-
|
4
|
+
manipulating giant hash structures. This is particularly helpful when the
|
5
5
|
generation process is fraught with conditionals and loops. Here's a simple
|
6
6
|
example:
|
7
7
|
|
data/gemfiles/rails_5_0.gemfile
CHANGED
@@ -6,8 +6,8 @@ gem "rake"
|
|
6
6
|
gem "mocha", :require => false
|
7
7
|
gem "appraisal"
|
8
8
|
gem "pry"
|
9
|
-
gem "railties", "
|
10
|
-
gem "actionpack", "
|
11
|
-
gem "activemodel", "
|
9
|
+
gem "railties", "~> 5.0.0"
|
10
|
+
gem "actionpack", "~> 5.0.0"
|
11
|
+
gem "activemodel", "~> 5.0.0"
|
12
12
|
|
13
13
|
gemspec :path => "../"
|
data/jbuilder.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'jbuilder'
|
3
|
-
s.version = '2.6.
|
3
|
+
s.version = '2.6.1'
|
4
4
|
s.authors = ['David Heinemeier Hansson', 'Pavel Pravosud']
|
5
5
|
s.email = ['david@37signals.com', 'pavel@pravosud.com']
|
6
6
|
s.summary = 'Create JSON structures via a Builder-style DSL'
|
@@ -42,6 +42,27 @@ class JbuilderTemplate < Jbuilder
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
# Caches the json structure at the root using a string rather than the hash structure. This is considerably
|
46
|
+
# faster, but the drawback is that it only works, as the name hints, at the root. So you cannot
|
47
|
+
# use this approach to cache deeper inside the hierarchy, like in partials or such. Continue to use #cache! there.
|
48
|
+
#
|
49
|
+
# Example:
|
50
|
+
#
|
51
|
+
# json.cache_root! @person do
|
52
|
+
# json.extract! @person, :name, :age
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# # json.extra 'This will not work either, the root must be exclusive'
|
56
|
+
def cache_root!(key=nil, options={})
|
57
|
+
if @context.controller.perform_caching
|
58
|
+
raise "cache_root! can't be used after JSON structures have been defined" if @attributes.present?
|
59
|
+
|
60
|
+
@cached_root = _cache_fragment_for([ :root, key ], options) { yield; target! }
|
61
|
+
else
|
62
|
+
yield
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
45
66
|
# Conditionally caches the json depending in the condition given as first parameter. Has the same
|
46
67
|
# signature as the `cache` helper method in `ActionView::Helpers::CacheHelper` and so can be used in
|
47
68
|
# the same way.
|
@@ -55,6 +76,10 @@ class JbuilderTemplate < Jbuilder
|
|
55
76
|
condition ? cache!(*args, &::Proc.new) : yield
|
56
77
|
end
|
57
78
|
|
79
|
+
def target!
|
80
|
+
@cached_root || super
|
81
|
+
end
|
82
|
+
|
58
83
|
def array!(collection = [], *args)
|
59
84
|
options = args.first
|
60
85
|
|
@@ -21,16 +21,16 @@ 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
|
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
|
28
|
+
assert_match %r{json.partial! \"posts/post\", post: @post}, content
|
29
29
|
end
|
30
30
|
|
31
31
|
assert_file 'app/views/posts/_post.json.jbuilder' do |content|
|
32
|
-
assert_match
|
33
|
-
assert_match
|
32
|
+
assert_match %r{json\.extract! post, :id, :title, :body}, content
|
33
|
+
assert_match %r{json\.url post_url\(post, format: :json\)}, content
|
34
34
|
end
|
35
35
|
|
36
36
|
|
@@ -386,6 +386,35 @@ class JbuilderTemplateTest < ActionView::TestCase
|
|
386
386
|
JBUILDER
|
387
387
|
end
|
388
388
|
|
389
|
+
test "caching root structure" do
|
390
|
+
undef_context_methods :fragment_name_with_digest, :cache_fragment_name
|
391
|
+
|
392
|
+
cache_miss_result = jbuild <<-JBUILDER
|
393
|
+
json.cache_root! "cachekey" do
|
394
|
+
json.name "Miss"
|
395
|
+
end
|
396
|
+
JBUILDER
|
397
|
+
|
398
|
+
cache_hit_result = jbuild <<-JBUILDER
|
399
|
+
json.cache_root! "cachekey" do
|
400
|
+
json.name "Hit"
|
401
|
+
end
|
402
|
+
JBUILDER
|
403
|
+
|
404
|
+
assert_equal cache_miss_result, cache_hit_result
|
405
|
+
end
|
406
|
+
|
407
|
+
test "failing to cache root after attributes have been defined" do
|
408
|
+
assert_raises ActionView::Template::Error, "cache_root! can't be used after JSON structures have been defined" do
|
409
|
+
jbuild <<-JBUILDER
|
410
|
+
json.name "Kaboom"
|
411
|
+
json.cache_root! "cachekey" do
|
412
|
+
json.name "Miss"
|
413
|
+
end
|
414
|
+
JBUILDER
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
389
418
|
test "does not perform caching when controller.perform_caching is false" do
|
390
419
|
controller.perform_caching = false
|
391
420
|
|
@@ -15,7 +15,7 @@ if Rails::VERSION::MAJOR > 4
|
|
15
15
|
|
16
16
|
assert_file 'app/controllers/posts_controller.rb' do |content|
|
17
17
|
assert_instance_method :index, content do |m|
|
18
|
-
assert_match
|
18
|
+
assert_match %r{@posts = Post\.all}, m
|
19
19
|
end
|
20
20
|
|
21
21
|
assert_instance_method :show, content do |m|
|
@@ -23,23 +23,23 @@ if Rails::VERSION::MAJOR > 4
|
|
23
23
|
end
|
24
24
|
|
25
25
|
assert_instance_method :create, content do |m|
|
26
|
-
assert_match
|
27
|
-
assert_match
|
28
|
-
assert_match
|
29
|
-
assert_match
|
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
30
|
end
|
31
31
|
|
32
32
|
assert_instance_method :update, content do |m|
|
33
|
-
assert_match
|
34
|
-
assert_match
|
33
|
+
assert_match %r{render :show, status: :ok, location: @post}, m
|
34
|
+
assert_match %r{render json: @post.errors, status: :unprocessable_entity}, m
|
35
35
|
end
|
36
36
|
|
37
37
|
assert_instance_method :destroy, content do |m|
|
38
|
-
assert_match
|
38
|
+
assert_match %r{@post\.destroy}, m
|
39
39
|
end
|
40
40
|
|
41
|
-
assert_match
|
42
|
-
assert_match
|
41
|
+
assert_match %r{def post_params}, content
|
42
|
+
assert_match %r{params\.require\(:post\)\.permit\(:title, :body\)}, content
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -47,8 +47,8 @@ if Rails::VERSION::MAJOR > 4
|
|
47
47
|
run_generator %w(Post --api)
|
48
48
|
|
49
49
|
assert_file 'app/controllers/posts_controller.rb' do |content|
|
50
|
-
assert_match
|
51
|
-
assert_match
|
50
|
+
assert_match %r{def post_params}, content
|
51
|
+
assert_match %r{params\.fetch\(:post, \{\}\)}, content
|
52
52
|
end
|
53
53
|
end
|
54
54
|
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
|
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
|
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,29 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
|
|
29
29
|
end
|
30
30
|
|
31
31
|
assert_instance_method :create, content do |m|
|
32
|
-
assert_match
|
33
|
-
assert_match
|
34
|
-
assert_match
|
35
|
-
assert_match
|
36
|
-
assert_match
|
37
|
-
assert_match
|
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
|
42
|
-
assert_match
|
43
|
-
assert_match
|
44
|
-
assert_match
|
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
|
49
|
-
assert_match
|
50
|
-
assert_match
|
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
|
54
|
-
assert_match
|
53
|
+
assert_match %r{def post_params}, content
|
54
|
+
assert_match %r{params\.require\(:post\)\.permit\(:title, :body\)}, content
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -59,8 +59,8 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
|
|
59
59
|
run_generator %w(Post)
|
60
60
|
|
61
61
|
assert_file 'app/controllers/posts_controller.rb' do |content|
|
62
|
-
assert_match
|
63
|
-
assert_match
|
62
|
+
assert_match %r{def post_params}, content
|
63
|
+
assert_match %r{params\.fetch\(:post, \{\}\)}, content
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jbuilder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.6.
|
4
|
+
version: 2.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-11-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
112
|
version: '0'
|
113
113
|
requirements: []
|
114
114
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.6.
|
115
|
+
rubygems_version: 2.6.8
|
116
116
|
signing_key:
|
117
117
|
specification_version: 4
|
118
118
|
summary: Create JSON structures via a Builder-style DSL
|