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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d949cb2167336c8e5b026626493bb07843dab242
4
- data.tar.gz: 1c0a6e23cb4441794732665e5fa2ef73a63eae0d
3
+ metadata.gz: c4b4939ae1d814cadb9d44ab80a4489d59b4c8a5
4
+ data.tar.gz: ae232631e1f37a815ae5e46cb45c88706c803da8
5
5
  SHA512:
6
- metadata.gz: bd78d3b8d0fa94ead3c7a77c7769593f2202ec46d18f3a2d3ba875f35a72040bd0e519bfd6e67b60fea465fbef8ffaf8966d964e02538eb8479c52011a5c24a1
7
- data.tar.gz: dc257849862f9619da61c740ab9596026b1e2d9cdf0b3b8aa7eee7ab23eef1912fc00ec49eb6c6a3cd888161104929ff851ddbabb1358d655dc947003f6222cc
6
+ metadata.gz: b0e4fb3d778a25514a6b82f6bdca2519690fe85719a902ec95c72ae5f7016f796e7567ca847cc369752077525d47f38344edff9f97d03a3a9dbe47b195c88d39
7
+ data.tar.gz: 24e1713528b9d0bfaa2d90c32f1432440c58acb7e6619c75d1956d23c041ef66672162dc97888af8f7558cd17024f33234102a285001a3188ba97bf39e6fd5ef
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ 2.6.1
4
+ -----
5
+
6
+ * [Optimize root caches with cache_root!][https://github.com/rails/jbuilder/pull/370]
7
+
3
8
  2.6.0
4
9
  -----
5
10
 
@@ -39,7 +39,8 @@ Ensure that you can build the project and run tests.
39
39
 
40
40
  ```
41
41
  bundle install
42
- bundle exec rake test
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 `bundle exec rake test` completes without errors.
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
- Go to https://github.com/contributor/jbuilder and select your feature branch. Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
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 on there!
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
- massaging giant hash structures. This is particularly helpful when the
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
 
@@ -6,8 +6,8 @@ gem "rake"
6
6
  gem "mocha", :require => false
7
7
  gem "appraisal"
8
8
  gem "pry"
9
- gem "railties", ">= 5.0.0.beta2", "< 5.1"
10
- gem "actionpack", ">= 5.0.0.beta2", "< 5.1"
11
- gem "activemodel", ">= 5.0.0.beta2", "< 5.1"
9
+ gem "railties", "~> 5.0.0"
10
+ gem "actionpack", "~> 5.0.0"
11
+ gem "activemodel", "~> 5.0.0"
12
12
 
13
13
  gemspec :path => "../"
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'jbuilder'
3
- s.version = '2.6.0'
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
 
@@ -11,8 +11,8 @@ class Jbuilder
11
11
  args.each do |name|
12
12
  @format[name] = []
13
13
  end
14
- options.each do |name, paramaters|
15
- @format[name] = paramaters
14
+ options.each do |name, parameters|
15
+ @format[name] = parameters
16
16
  end
17
17
  end
18
18
 
@@ -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 /json.array! @posts, partial: 'posts\/post', as: :post/, content
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 /json.partial! \"posts\/post\", post: @post/, content
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 /json\.extract! post, :id, :title, :body/, content
33
- assert_match /json\.url post_url\(post, format: :json\)/, content
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 /@posts = Post\.all/, m
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 /@post = Post\.new\(post_params\)/, m
27
- assert_match /@post\.save/, m
28
- assert_match /render :show, status: :created, location: @post/, m
29
- assert_match /render json: @post\.errors, status: :unprocessable_entity/, 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
30
  end
31
31
 
32
32
  assert_instance_method :update, content do |m|
33
- assert_match /render :show, status: :ok, location: @post/, m
34
- assert_match /render json: @post.errors, status: :unprocessable_entity/, 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
35
  end
36
36
 
37
37
  assert_instance_method :destroy, content do |m|
38
- assert_match /@post\.destroy/, m
38
+ assert_match %r{@post\.destroy}, m
39
39
  end
40
40
 
41
- assert_match(/def post_params/, content)
42
- assert_match(/params\.require\(:post\)\.permit\(:title, :body\)/, content)
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(/def post_params/, content)
51
- assert_match(/params\.fetch\(:post, {}\)/, content)
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 /@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,29 @@ 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
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(/def post_params/, content)
63
- assert_match(/params\.fetch\(:post, {}\)/, content)
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.0
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-07-20 00:00:00.000000000 Z
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.4
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