jbuilder 2.1.2 → 2.1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 076e206930dcf4260390206ed366028320a9b897
4
- data.tar.gz: ad02cd2d181c768614d5eb87feedc326ebb9646e
3
+ metadata.gz: 8d5b664cede402d0f7c028a234e22a7bf1114274
4
+ data.tar.gz: d4e163e75dea9c02ecb14ce79f7dafda0b5f32f3
5
5
  SHA512:
6
- metadata.gz: 8430c22ceacd53c3b3b26fc762e4e6051cd865b1542d0b38091953a5d2371890ea392a51e675a1d8d0c1fb4bbaa171fecd1d37d95c1448f6bd065a03b98f8875
7
- data.tar.gz: 968917e192f36be06d5adf63803bd0a26443f474b29b71716c111cf29df08a283a47044eaef684091ecbd363c36cdf88ac14b5d8d17c4a40e1d3340ecb3a51f1
6
+ metadata.gz: 88378366476f8fbaf94eecdc4e31be5bf000d605c9797c4c0a9b53ae3be63dc0f5c119e5cd349f42d1fa9459b69de9730d5dad2a2d7fd89e38cefe3808884cf7
7
+ data.tar.gz: 13134bb6ea6ff1df39592cfef8a3575f94e185864ebf629af38b8cd19911bdb9f6804eeaf87d5d2a256c1d482cec49cf93aa7b77094f2124a798f7fa959af048
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  require "bundler/setup"
2
+ require "bundler/gem_tasks"
2
3
  require "rake/testtask"
3
4
 
4
5
  if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'jbuilder'
3
- s.version = '2.1.2'
3
+ s.version = '2.1.3'
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'
@@ -27,7 +27,7 @@ class JbuilderTemplate < Jbuilder
27
27
  options[:collection] = locals[:collection] if locals.key?(:collection)
28
28
  end
29
29
 
30
- _handle_partial_options options
30
+ _render_partial_with_options options
31
31
  end
32
32
 
33
33
  def array!(collection = [], *attributes, &block)
@@ -75,17 +75,19 @@ class JbuilderTemplate < Jbuilder
75
75
 
76
76
  protected
77
77
 
78
- def _handle_partial_options(options)
78
+ def _render_partial_with_options(options)
79
79
  options.reverse_merge! locals: {}
80
80
  options.reverse_merge! ::JbuilderTemplate.template_lookup_options
81
81
  as = options[:as]
82
82
 
83
83
  if as && options.key?(:collection)
84
- collection = options.delete(:collection) || []
85
- array!(collection) do |member|
86
- options[:locals].merge! as => member
87
- options[:locals].merge! collection: collection
88
- _render_partial options
84
+ collection = options.delete(:collection)
85
+ locals = options.delete(:locals)
86
+ array! collection do |member|
87
+ member_locals = locals.clone
88
+ member_locals.merge! collection: collection
89
+ member_locals.merge! as => member
90
+ _render_partial options.merge(locals: member_locals)
89
91
  end
90
92
  else
91
93
  _render_partial options
@@ -15,9 +15,15 @@ BLOG_POST_PARTIAL = <<-JBUILDER
15
15
  end
16
16
  JBUILDER
17
17
 
18
+ COLLECTION_PARTIAL = <<-JBUILDER
19
+ json.extract! collection, :id, :name
20
+ JBUILDER
21
+
18
22
  BlogPost = Struct.new(:id, :body, :author_name)
23
+ Collection = Struct.new(:id, :name)
19
24
  blog_authors = [ 'David Heinemeier Hansson', 'Pavel Pravosud' ].cycle
20
25
  BLOG_POST_COLLECTION = 10.times.map{ |i| BlogPost.new(i+1, "post body #{i+1}", blog_authors.next) }
26
+ COLLECTION_COLLECTION = 5.times.map{ |i| Collection.new(i+1, "collection #{i+1}") }
21
27
 
22
28
  module Rails
23
29
  def self.cache
@@ -34,7 +40,8 @@ class JbuilderTemplateTest < ActionView::TestCase
34
40
  def partials
35
41
  {
36
42
  '_partial.json.jbuilder' => 'json.content "hello"',
37
- '_blog_post.json.jbuilder' => BLOG_POST_PARTIAL
43
+ '_blog_post.json.jbuilder' => BLOG_POST_PARTIAL,
44
+ '_collection.json.jbuilder' => COLLECTION_PARTIAL
38
45
  }
39
46
  end
40
47
 
@@ -47,7 +54,7 @@ class JbuilderTemplateTest < ActionView::TestCase
47
54
  def undef_context_methods(*names)
48
55
  self.class_eval do
49
56
  names.each do |name|
50
- undef_method name.to_sym if self.method_defined?(name.to_sym)
57
+ undef_method name.to_sym if method_defined?(name.to_sym)
51
58
  end
52
59
  end
53
60
  end
@@ -110,6 +117,12 @@ class JbuilderTemplateTest < ActionView::TestCase
110
117
  assert_collection_rendered json
111
118
  end
112
119
 
120
+ test 'partial! renders collections as collections' do
121
+ json = render_jbuilder <<-JBUILDER
122
+ json.partial! 'collection', collection: COLLECTION_COLLECTION, as: :collection
123
+ JBUILDER
124
+ end
125
+
113
126
  test 'partial! renders as empty array for nil-collection' do
114
127
  json = render_jbuilder <<-JBUILDER
115
128
  json.partial! 'blog_post', :collection => nil, :as => :blog_post
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.1.2
4
+ version: 2.1.3
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: 2014-07-07 00:00:00.000000000 Z
12
+ date: 2014-07-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport