jbuilder 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Binary file
data/jbuilder.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'jbuilder'
3
- s.version = '0.4.2'
3
+ s.version = '0.4.3'
4
4
  s.author = 'David Heinemeier Hansson'
5
5
  s.email = 'david@37signals.com'
6
6
  s.summary = 'Create JSON structures via a Builder-style DSL'
data/lib/jbuilder.rb CHANGED
@@ -203,7 +203,7 @@ class Jbuilder < BlankSlate
203
203
 
204
204
  # json.comments(@post.comments, :content, :created_at)
205
205
  # { "comments": [ { "content": "hello", "created_at": "..." }, { "content": "world", "created_at": "..." } ] }
206
- when args.many? && args.first.is_a?(Enumerable)
206
+ when args.many? && args.first.respond_to?(:each)
207
207
  _inline_nesting method, args.first, args.from(1)
208
208
 
209
209
  # json.author @post.creator, :name, :email_address
@@ -270,6 +270,33 @@ class JbuilderTest < ActiveSupport::TestCase
270
270
  end
271
271
  end
272
272
 
273
+ test "query like object" do
274
+ class Person
275
+ attr_reader :name, :age
276
+
277
+ def initialize(name, age)
278
+ @name, @age = name, age
279
+ end
280
+ end
281
+ class RelationMock
282
+ def each(&block)
283
+ [Person.new("Bob", 30), Person.new("Frank", 50)].each(&block)
284
+ end
285
+ def empty?
286
+ false
287
+ end
288
+ end
289
+
290
+ result = Jbuilder.encode do |json|
291
+ json.relations RelationMock.new, :name, :age
292
+ end
293
+
294
+ parsed = JSON.parse(result)
295
+ assert_equal 2, parsed["relations"].length
296
+ assert_equal "Bob", parsed["relations"][0]["name"]
297
+ assert_equal 50, parsed["relations"][1]["age"]
298
+ end
299
+
273
300
  test "key_format! with parameter" do
274
301
  json = Jbuilder.new
275
302
  json.key_format! :camelize => [:lower]
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: 0.4.2
4
+ version: 0.4.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-08-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &2152793760 !ruby/object:Gem::Requirement
16
+ requirement: &2160638200 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152793760
24
+ version_requirements: *2160638200
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: blankslate
27
- requirement: &2152793020 !ruby/object:Gem::Requirement
27
+ requirement: &2160637580 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 2.1.2.4
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2152793020
35
+ version_requirements: *2160637580
36
36
  description:
37
37
  email: david@37signals.com
38
38
  executables: []
@@ -41,6 +41,7 @@ extra_rdoc_files: []
41
41
  files:
42
42
  - ./Gemfile
43
43
  - ./Gemfile.lock
44
+ - ./jbuilder-0.4.2.gem
44
45
  - ./jbuilder.gemspec
45
46
  - ./lib/jbuilder.rb
46
47
  - ./lib/jbuilder_template.rb