jbuilder 1.5.3 → 2.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -19
- data/jbuilder.gemspec +3 -1
- data/lib/generators/rails/jbuilder_generator.rb +0 -4
- data/lib/generators/rails/templates/controller.rb +1 -1
- data/lib/jbuilder.rb +13 -38
- data/lib/jbuilder/dependency_tracker.rb +50 -0
- data/lib/jbuilder/jbuilder_template.rb +10 -10
- data/test/jbuilder_dependency_tracker_test.rb +72 -0
- data/test/jbuilder_generator_test.rb +2 -2
- data/test/jbuilder_test.rb +3 -84
- data/test/scaffold_controller_generator_test.rb +1 -1
- metadata +10 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3abb8f97fbc68d58021fc1c5bc66fec71d338da7
|
4
|
+
data.tar.gz: 1f5eac2118e6f0762d41d7b6ce1ea559a10feca9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe7ee8dc65453809938c89bfd35f037ae6113e30f648eb66da2ab844bd9dc0574a9c79c381198ec667077dd648cb30946cf81d433085ff31de2d8acba45a00bd
|
7
|
+
data.tar.gz: bcbf4fa794515f477a809d33b18b9ac7e9df227f3fbe1f708bea2f1b1f90d340439f783ff96f1b40c413c9ec539703f267745183761d9c3d8e945f3288ae20ce
|
data/.travis.yml
CHANGED
@@ -1,15 +1,10 @@
|
|
1
1
|
language: ruby
|
2
2
|
|
3
3
|
rvm:
|
4
|
-
- 1.8.7
|
5
|
-
- 1.9.2
|
6
4
|
- 1.9.3
|
7
5
|
- 2.0.0
|
8
6
|
- ruby-head
|
9
|
-
- ree
|
10
|
-
- jruby-18mode
|
11
7
|
- jruby-19mode
|
12
|
-
- rbx-18mode
|
13
8
|
- rbx-19mode
|
14
9
|
|
15
10
|
gemfile:
|
@@ -17,22 +12,10 @@ gemfile:
|
|
17
12
|
- Gemfile
|
18
13
|
|
19
14
|
matrix:
|
20
|
-
exclude:
|
21
|
-
# Edge Rails is only compatible with 1.9.3+
|
22
|
-
- gemfile: Gemfile
|
23
|
-
rvm: 1.8.7
|
24
|
-
- gemfile: Gemfile
|
25
|
-
rvm: 1.9.2
|
26
|
-
- gemfile: Gemfile
|
27
|
-
rvm: ree
|
28
|
-
- gemfile: Gemfile
|
29
|
-
rvm: jruby-18mode
|
30
|
-
- gemfile: Gemfile
|
31
|
-
rvm: rbx-18mode
|
32
15
|
allow_failures:
|
33
16
|
- rvm: ruby-head
|
34
|
-
- rvm:
|
17
|
+
- rvm: jruby-19mode
|
35
18
|
- rvm: rbx-19mode
|
36
19
|
|
37
20
|
notifications:
|
38
|
-
email: false
|
21
|
+
email: false
|
data/jbuilder.gemspec
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'jbuilder'
|
3
|
-
s.version = '
|
3
|
+
s.version = '2.0.0.beta'
|
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'
|
7
7
|
s.license = 'MIT'
|
8
8
|
|
9
|
+
s.required_ruby_version = '>= 1.9.3'
|
10
|
+
|
9
11
|
s.add_dependency 'activesupport', '>= 3.0.0'
|
10
12
|
s.add_dependency 'multi_json', '>= 1.2.0'
|
11
13
|
|
@@ -48,7 +48,7 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
48
48
|
respond_to do |format|
|
49
49
|
if @<%= orm_instance.update("#{singular_table_name}_params") %>
|
50
50
|
format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %> }
|
51
|
-
format.json {
|
51
|
+
format.json { render action: 'show', status: :ok, location: <%= "@#{singular_table_name}" %> }
|
52
52
|
else
|
53
53
|
format.html { render action: 'edit' }
|
54
54
|
format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
|
data/lib/jbuilder.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
require 'active_support/ordered_hash'
|
2
1
|
require 'active_support/core_ext/array/access'
|
3
2
|
require 'active_support/core_ext/enumerable'
|
4
3
|
require 'active_support/core_ext/hash'
|
5
|
-
require 'active_support/cache'
|
6
4
|
require 'multi_json'
|
7
5
|
|
8
6
|
begin
|
@@ -22,7 +20,7 @@ class Jbuilder < JbuilderProxy
|
|
22
20
|
|
23
21
|
class KeyFormatter
|
24
22
|
def initialize(*args)
|
25
|
-
@format =
|
23
|
+
@format = {}
|
26
24
|
@cache = {}
|
27
25
|
|
28
26
|
options = args.extract_options!
|
@@ -58,10 +56,9 @@ class Jbuilder < JbuilderProxy
|
|
58
56
|
@@key_formatter = KeyFormatter.new
|
59
57
|
@@ignore_nil = false
|
60
58
|
|
61
|
-
def initialize(
|
62
|
-
@attributes =
|
59
|
+
def initialize(options = {}, &block)
|
60
|
+
@attributes = {}
|
63
61
|
|
64
|
-
options = args.extract_options!
|
65
62
|
@key_formatter = options.fetch(:key_formatter){ @@key_formatter.clone }
|
66
63
|
@ignore_nil = options.fetch(:ignore_nil, @@ignore_nil)
|
67
64
|
yield self if block
|
@@ -222,9 +219,7 @@ class Jbuilder < JbuilderProxy
|
|
222
219
|
#
|
223
220
|
# [1,2,3]
|
224
221
|
def array!(collection = [], *attributes, &block)
|
225
|
-
@attributes = if block
|
226
|
-
_two_arguments_map_collection(collection, &block)
|
227
|
-
elsif block
|
222
|
+
@attributes = if block
|
228
223
|
_map_collection(collection, &block)
|
229
224
|
elsif attributes.any?
|
230
225
|
_map_collection(collection) { |element| extract! element, *attributes }
|
@@ -280,25 +275,17 @@ class Jbuilder < JbuilderProxy
|
|
280
275
|
|
281
276
|
# Encodes the current builder as JSON.
|
282
277
|
def target!
|
283
|
-
::MultiJson.dump
|
278
|
+
::MultiJson.dump(@attributes)
|
284
279
|
end
|
285
280
|
|
286
281
|
private
|
287
282
|
|
288
|
-
def
|
283
|
+
def _extract_hash_values(object, *attributes)
|
289
284
|
attributes.each{ |key| _set_value key, object.fetch(key) }
|
290
285
|
end
|
291
286
|
|
292
287
|
def _extract_method_values(object, *attributes)
|
293
|
-
attributes.each
|
294
|
-
unless object.respond_to?(method_name)
|
295
|
-
message = "Private method #{method_name.inspect} was used to " +
|
296
|
-
'extract value. This will be an error in future versions of Jbuilder'
|
297
|
-
end
|
298
|
-
|
299
|
-
_set_value method_name, object.send(method_name)
|
300
|
-
::ActiveSupport::Deprecation.warn message if message
|
301
|
-
end
|
288
|
+
attributes.each{ |key| _set_value key, object.public_send(key) }
|
302
289
|
end
|
303
290
|
|
304
291
|
def _set_value(key, value)
|
@@ -318,7 +305,7 @@ class Jbuilder < JbuilderProxy
|
|
318
305
|
|
319
306
|
def _scope
|
320
307
|
parent_attributes, parent_formatter = @attributes, @key_formatter
|
321
|
-
@attributes =
|
308
|
+
@attributes = {}
|
322
309
|
yield
|
323
310
|
@attributes
|
324
311
|
ensure
|
@@ -334,26 +321,14 @@ class Jbuilder < JbuilderProxy
|
|
334
321
|
end
|
335
322
|
end
|
336
323
|
|
337
|
-
def _two_arguments_map_collection(collection, &block)
|
338
|
-
message = "Passing jbuilder object to block is " \
|
339
|
-
"deprecated and will be removed soon."
|
340
|
-
|
341
|
-
if block.respond_to?(:parameters)
|
342
|
-
arguments = block.parameters.map(&:last)
|
343
|
-
actual = "|#{arguments.drop(1) * ', '}|"
|
344
|
-
deprecated = "|#{arguments * ', '}|"
|
345
|
-
message += "\nUse #{actual} instead of #{deprecated} as block arguments"
|
346
|
-
end
|
347
|
-
|
348
|
-
::ActiveSupport::Deprecation.warn message, ::Kernel.caller(5)
|
349
|
-
|
350
|
-
_map_collection(collection){ |element| block[self, element] }
|
351
|
-
end
|
352
|
-
|
353
324
|
def _mapable_arguments?(value, *args)
|
354
325
|
value.respond_to?(:map)
|
355
326
|
end
|
356
327
|
end
|
357
328
|
|
358
329
|
require 'jbuilder/jbuilder_template' if defined?(ActionView::Template)
|
359
|
-
|
330
|
+
|
331
|
+
if defined?(Rails::VERSION::MAJOR) && Rails::VERSION::MAJOR == 4
|
332
|
+
require 'jbuilder/railtie'
|
333
|
+
require 'jbuilder/dependency_tracker'
|
334
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'jbuilder'
|
2
|
+
require 'action_view'
|
3
|
+
require 'action_view/dependency_tracker'
|
4
|
+
|
5
|
+
class Jbuilder
|
6
|
+
class DependencyTracker < ::ActionView::DependencyTracker::ERBTracker
|
7
|
+
# Matches:
|
8
|
+
# json.partial! "messages/message"
|
9
|
+
# json.partial!('messages/message')
|
10
|
+
#
|
11
|
+
DIRECT_RENDERS = /
|
12
|
+
\w+\.partial! # json.partial!
|
13
|
+
\(?\s* # optional parenthesis
|
14
|
+
(['"])([^""]+)\1 # quoted value
|
15
|
+
/x
|
16
|
+
|
17
|
+
# Matches:
|
18
|
+
# json.partial! partial: "comments/comment"
|
19
|
+
# json.comments @post.comments, partial: "comments/comment", as: :comment
|
20
|
+
# json.array! @posts, partial: "posts/post", as: :post
|
21
|
+
# = render partial: "account"
|
22
|
+
#
|
23
|
+
INDIRECT_RENDERS = /
|
24
|
+
(?::partial\s*=>|partial:) # partial: or :partial =>
|
25
|
+
\s* # optional whitespace
|
26
|
+
(['"])([^'"]+)\1 # quoted value
|
27
|
+
/x
|
28
|
+
|
29
|
+
def dependencies
|
30
|
+
direct_dependencies + indirect_dependencies + explicit_dependencies
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def direct_dependencies
|
36
|
+
source.scan(DIRECT_RENDERS).map(&:second)
|
37
|
+
end
|
38
|
+
|
39
|
+
def indirect_dependencies
|
40
|
+
source.scan(INDIRECT_RENDERS).map(&:second)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
ActiveSupport.on_load :action_view do
|
47
|
+
ActiveSupport.on_load :after_initialize do
|
48
|
+
ActionView::DependencyTracker.register_tracker :jbuilder, Jbuilder::DependencyTracker
|
49
|
+
end
|
50
|
+
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
require 'jbuilder'
|
2
2
|
require 'action_dispatch/http/mime_type'
|
3
|
+
require 'active_support/cache'
|
3
4
|
|
4
5
|
class JbuilderTemplate < Jbuilder
|
5
6
|
class << self
|
6
7
|
attr_accessor :template_lookup_options
|
7
8
|
end
|
8
9
|
|
9
|
-
self.template_lookup_options = { :
|
10
|
+
self.template_lookup_options = { handlers: [:jbuilder] }
|
10
11
|
|
11
12
|
def initialize(context, *args, &block)
|
12
13
|
@context = context
|
@@ -20,14 +21,12 @@ class JbuilderTemplate < Jbuilder
|
|
20
21
|
options = name_or_options
|
21
22
|
else
|
22
23
|
# partial! 'name', foo: 'bar'
|
23
|
-
options = { :
|
24
|
+
options = { partial: name_or_options, locals: locals }
|
24
25
|
as = locals.delete(:as)
|
25
26
|
options[:as] = as if as.present?
|
26
27
|
options[:collection] = locals[:collection] if locals.key?(:collection)
|
27
28
|
end
|
28
29
|
|
29
|
-
options[:collection] ||= [] if options.key?(:collection)
|
30
|
-
|
31
30
|
_handle_partial_options options
|
32
31
|
end
|
33
32
|
|
@@ -35,7 +34,7 @@ class JbuilderTemplate < Jbuilder
|
|
35
34
|
options = attributes.extract_options!
|
36
35
|
|
37
36
|
if options.key?(:partial)
|
38
|
-
partial! options[:partial], options.merge(:
|
37
|
+
partial! options[:partial], options.merge(collection: collection)
|
39
38
|
else
|
40
39
|
super
|
41
40
|
end
|
@@ -63,14 +62,15 @@ class JbuilderTemplate < Jbuilder
|
|
63
62
|
|
64
63
|
protected
|
65
64
|
def _handle_partial_options(options)
|
66
|
-
options.reverse_merge! :
|
65
|
+
options.reverse_merge! locals: {}
|
67
66
|
options.reverse_merge! ::JbuilderTemplate.template_lookup_options
|
68
|
-
collection = options.delete(:collection)
|
69
67
|
as = options[:as]
|
70
68
|
|
71
|
-
if
|
69
|
+
if as && options.key?(:collection)
|
70
|
+
collection = options.delete(:collection) || []
|
72
71
|
array!(collection) do |member|
|
73
|
-
options[:locals].merge!
|
72
|
+
options[:locals].merge! as => member
|
73
|
+
options[:locals].merge! collection: collection
|
74
74
|
_render_partial options
|
75
75
|
end
|
76
76
|
else
|
@@ -79,7 +79,7 @@ class JbuilderTemplate < Jbuilder
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def _render_partial(options)
|
82
|
-
options[:locals].merge!
|
82
|
+
options[:locals].merge! json: self
|
83
83
|
@context.render options
|
84
84
|
end
|
85
85
|
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'active_support/test_case'
|
3
|
+
require 'jbuilder/dependency_tracker'
|
4
|
+
|
5
|
+
|
6
|
+
class FakeTemplate
|
7
|
+
attr_reader :source, :handler
|
8
|
+
def initialize(source, handler = :jbuilder)
|
9
|
+
@source, @handler = source, handler
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
class JbuilderDependencyTrackerTest < ActiveSupport::TestCase
|
15
|
+
def make_tracker(name, source)
|
16
|
+
template = FakeTemplate.new(source)
|
17
|
+
Jbuilder::DependencyTracker.new(name, template)
|
18
|
+
end
|
19
|
+
|
20
|
+
def track_dependencies(source)
|
21
|
+
make_tracker('jbuilder_template', source).dependencies
|
22
|
+
end
|
23
|
+
|
24
|
+
test 'detects dependency via direct partial! call' do
|
25
|
+
dependencies = track_dependencies <<-RUBY
|
26
|
+
json.partial! 'path/to/partial'
|
27
|
+
RUBY
|
28
|
+
|
29
|
+
assert_equal %w[path/to/partial], dependencies
|
30
|
+
end
|
31
|
+
|
32
|
+
test 'detects dependency via direct partial! call with parens' do
|
33
|
+
dependencies = track_dependencies <<-RUBY
|
34
|
+
json.partial!("path/to/partial")
|
35
|
+
RUBY
|
36
|
+
|
37
|
+
assert_equal %w[path/to/partial], dependencies
|
38
|
+
end
|
39
|
+
|
40
|
+
test 'detects partial with options (1.9 style)' do
|
41
|
+
dependencies = track_dependencies <<-RUBY
|
42
|
+
json.partial! hello: 'world', partial: 'path/to/partial', foo: :bar
|
43
|
+
RUBY
|
44
|
+
|
45
|
+
assert_equal %w[path/to/partial], dependencies
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'detects partial with options (1.8 style)' do
|
49
|
+
dependencies = track_dependencies <<-RUBY
|
50
|
+
json.partial! :hello => 'world', :partial => 'path/to/partial', :foo => :bar
|
51
|
+
RUBY
|
52
|
+
|
53
|
+
assert_equal %w[path/to/partial], dependencies
|
54
|
+
end
|
55
|
+
|
56
|
+
test 'detects partial in indirect collecton calls' do
|
57
|
+
dependencies = track_dependencies <<-RUBY
|
58
|
+
json.comments @post.comments, partial: 'comments/comment', as: :comment
|
59
|
+
RUBY
|
60
|
+
|
61
|
+
assert_equal %w[comments/comment], dependencies
|
62
|
+
end
|
63
|
+
|
64
|
+
test 'detects explicit depedency' do
|
65
|
+
dependencies = track_dependencies <<-RUBY
|
66
|
+
# Template Dependency: path/to/partial
|
67
|
+
json.foo 'bar'
|
68
|
+
RUBY
|
69
|
+
|
70
|
+
assert_equal %w[path/to/partial], dependencies
|
71
|
+
end
|
72
|
+
end
|
@@ -20,12 +20,12 @@ class JbuilderGeneratorTest < Rails::Generators::TestCase
|
|
20
20
|
|
21
21
|
assert_file 'app/views/posts/index.json.jbuilder' do |content|
|
22
22
|
assert_match /json\.array!\(@posts\) do \|post\|/, content
|
23
|
-
assert_match /json\.extract! post, :
|
23
|
+
assert_match /json\.extract! post, :title, :body/, content
|
24
24
|
assert_match /json\.url post_url\(post, format: :json\)/, content
|
25
25
|
end
|
26
26
|
|
27
27
|
assert_file 'app/views/posts/show.json.jbuilder' do |content|
|
28
|
-
assert_match /json\.extract! @post, :
|
28
|
+
assert_match /json\.extract! @post, :title, :body, :created_at, :updated_at/, content
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
data/test/jbuilder_test.rb
CHANGED
@@ -5,15 +5,6 @@ require 'jbuilder'
|
|
5
5
|
|
6
6
|
Comment = Struct.new(:content, :id)
|
7
7
|
|
8
|
-
unless JbuilderProxy.method_defined? :instance_eval
|
9
|
-
# Faking Object#instance_eval for 1.8 and some newer JRubies
|
10
|
-
class JbuilderProxy
|
11
|
-
def instance_eval(code)
|
12
|
-
eval code
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
8
|
class NonEnumerable
|
18
9
|
def initialize(collection)
|
19
10
|
@collection = collection
|
@@ -73,32 +64,11 @@ class JbuilderTest < ActiveSupport::TestCase
|
|
73
64
|
assert_equal 32, parsed['age']
|
74
65
|
end
|
75
66
|
|
76
|
-
test 'extracting from object using private method' do
|
77
|
-
person = Struct.new(:name) do
|
78
|
-
private
|
79
|
-
def age
|
80
|
-
32
|
81
|
-
end
|
82
|
-
end.new('David')
|
83
|
-
|
84
|
-
message = 'Private method :age was used to extract value. This will be' +
|
85
|
-
' an error in future versions of Jbuilder'
|
86
|
-
|
87
|
-
::ActiveSupport::Deprecation.expects(:warn).with(message)
|
88
|
-
json = Jbuilder.encode do |json|
|
89
|
-
json.extract! person, :name, :age
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
67
|
test 'extracting from object using call style for 1.9' do
|
94
68
|
person = Struct.new(:name, :age).new('David', 32)
|
95
69
|
|
96
70
|
json = Jbuilder.encode do |json|
|
97
|
-
|
98
|
-
instance_eval 'json.(person, :name, :age)'
|
99
|
-
else
|
100
|
-
instance_eval 'json.call(person, :name, :age)'
|
101
|
-
end
|
71
|
+
json.(person, :name, :age)
|
102
72
|
end
|
103
73
|
|
104
74
|
parsed = MultiJson.load(json)
|
@@ -241,23 +211,6 @@ class JbuilderTest < ActiveSupport::TestCase
|
|
241
211
|
assert_equal 'world', parsed['comments'].second['content']
|
242
212
|
end
|
243
213
|
|
244
|
-
test 'nesting multiple children from array with inline loop with old api' do
|
245
|
-
comments = [ Comment.new('hello', 1), Comment.new('world', 2) ]
|
246
|
-
|
247
|
-
json = Jbuilder.encode do |json|
|
248
|
-
::ActiveSupport::Deprecation.silence do
|
249
|
-
json.comments comments do |json, comment|
|
250
|
-
json.content comment.content
|
251
|
-
end
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
parsed = MultiJson.load(json)
|
256
|
-
assert_equal ['content'], parsed['comments'].first.keys
|
257
|
-
assert_equal 'hello', parsed['comments'].first['content']
|
258
|
-
assert_equal 'world', parsed['comments'].second['content']
|
259
|
-
end
|
260
|
-
|
261
214
|
test 'nesting multiple children from array with inline loop on root' do
|
262
215
|
comments = [ Comment.new('hello', 1), Comment.new('world', 2) ]
|
263
216
|
|
@@ -272,22 +225,6 @@ class JbuilderTest < ActiveSupport::TestCase
|
|
272
225
|
assert_equal 'world', parsed.second['content']
|
273
226
|
end
|
274
227
|
|
275
|
-
test 'nesting multiple children from array with inline loop on root with old api' do
|
276
|
-
comments = [ Comment.new('hello', 1), Comment.new('world', 2) ]
|
277
|
-
|
278
|
-
json = Jbuilder.encode do |json|
|
279
|
-
::ActiveSupport::Deprecation.silence do
|
280
|
-
json.call(comments) do |json, comment|
|
281
|
-
json.content comment.content
|
282
|
-
end
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
parsed = MultiJson.load(json)
|
287
|
-
assert_equal 'hello', parsed.first['content']
|
288
|
-
assert_equal 'world', parsed.second['content']
|
289
|
-
end
|
290
|
-
|
291
228
|
test 'array nested inside nested hash' do
|
292
229
|
json = Jbuilder.encode do |json|
|
293
230
|
json.author do
|
@@ -337,24 +274,6 @@ class JbuilderTest < ActiveSupport::TestCase
|
|
337
274
|
assert_not_equal 'hello', MultiJson.load(json)[0]['not_in_json']
|
338
275
|
end
|
339
276
|
|
340
|
-
test 'directly set an array nested in another array with old api' do
|
341
|
-
data = [ { :department => 'QA', :not_in_json => 'hello', :names => ['John', 'David'] } ]
|
342
|
-
json = Jbuilder.encode do |json|
|
343
|
-
::ActiveSupport::Deprecation.silence do
|
344
|
-
json.array! data do |json, object|
|
345
|
-
json.department object[:department]
|
346
|
-
json.names do
|
347
|
-
json.array! object[:names]
|
348
|
-
end
|
349
|
-
end
|
350
|
-
end
|
351
|
-
end
|
352
|
-
|
353
|
-
parsed = MultiJson.load(json)
|
354
|
-
assert_equal 'David', parsed.first['names'].last
|
355
|
-
assert_not_equal 'hello', parsed.first['not_in_json']
|
356
|
-
end
|
357
|
-
|
358
277
|
test 'nested jbuilder objects' do
|
359
278
|
to_nest = Jbuilder.new
|
360
279
|
to_nest.nested_value 'Nested Test'
|
@@ -484,8 +403,8 @@ class JbuilderTest < ActiveSupport::TestCase
|
|
484
403
|
|
485
404
|
test 'initialize via options hash' do
|
486
405
|
jbuilder = Jbuilder.new(:key_formatter => 1, :ignore_nil => 2)
|
487
|
-
assert_equal 1, jbuilder.instance_eval
|
488
|
-
assert_equal 2, jbuilder.instance_eval
|
406
|
+
assert_equal 1, jbuilder.instance_eval{ @key_formatter }
|
407
|
+
assert_equal 2, jbuilder.instance_eval{ @ignore_nil }
|
489
408
|
end
|
490
409
|
|
491
410
|
test 'key_format! with parameter' do
|
@@ -38,7 +38,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
|
|
38
38
|
|
39
39
|
assert_instance_method :update, content do |m|
|
40
40
|
assert_match /format\.html \{ redirect_to @post, notice: 'Post was successfully updated\.' \}/, m
|
41
|
-
assert_match /format\.json \{
|
41
|
+
assert_match /format\.json \{ render action: 'show', status: :ok, location: @post \}/, m
|
42
42
|
assert_match /format\.html \{ render action: 'edit' \}/, m
|
43
43
|
assert_match /format\.json \{ render json: @post.errors, status: :unprocessable_entity \}/, m
|
44
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jbuilder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -58,8 +58,10 @@ files:
|
|
58
58
|
- lib/generators/rails/templates/index.json.jbuilder
|
59
59
|
- lib/generators/rails/templates/show.json.jbuilder
|
60
60
|
- lib/jbuilder.rb
|
61
|
+
- lib/jbuilder/dependency_tracker.rb
|
61
62
|
- lib/jbuilder/jbuilder_template.rb
|
62
63
|
- lib/jbuilder/railtie.rb
|
64
|
+
- test/jbuilder_dependency_tracker_test.rb
|
63
65
|
- test/jbuilder_generator_test.rb
|
64
66
|
- test/jbuilder_template_test.rb
|
65
67
|
- test/jbuilder_test.rb
|
@@ -76,20 +78,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
78
|
requirements:
|
77
79
|
- - '>='
|
78
80
|
- !ruby/object:Gem::Version
|
79
|
-
version:
|
81
|
+
version: 1.9.3
|
80
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
83
|
requirements:
|
82
|
-
- - '
|
84
|
+
- - '>'
|
83
85
|
- !ruby/object:Gem::Version
|
84
|
-
version:
|
86
|
+
version: 1.3.1
|
85
87
|
requirements: []
|
86
88
|
rubyforge_project:
|
87
|
-
rubygems_version: 2.
|
89
|
+
rubygems_version: 2.1.5
|
88
90
|
signing_key:
|
89
91
|
specification_version: 4
|
90
92
|
summary: Create JSON structures via a Builder-style DSL
|
91
93
|
test_files:
|
94
|
+
- test/jbuilder_dependency_tracker_test.rb
|
92
95
|
- test/jbuilder_generator_test.rb
|
93
96
|
- test/jbuilder_template_test.rb
|
94
97
|
- test/jbuilder_test.rb
|
95
98
|
- test/scaffold_controller_generator_test.rb
|
99
|
+
has_rdoc:
|