jbuilder 2.7.0 → 2.13.0
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 +5 -5
- data/.github/workflows/ruby.yml +49 -0
- data/.gitignore +3 -0
- data/Appraisals +10 -14
- data/CONTRIBUTING.md +5 -13
- data/Gemfile +0 -1
- data/MIT-LICENSE +1 -1
- data/README.md +103 -19
- data/Rakefile +1 -1
- data/bin/release +14 -0
- data/bin/test +6 -0
- data/gemfiles/{rails_4_2.gemfile → rails_7_0.gemfile} +1 -4
- data/gemfiles/{rails_5_0.gemfile → rails_7_1.gemfile} +1 -4
- data/gemfiles/{rails_5_1.gemfile → rails_head.gemfile} +1 -4
- data/jbuilder.gemspec +20 -4
- data/lib/generators/rails/jbuilder_generator.rb +16 -2
- data/lib/generators/rails/scaffold_controller_generator.rb +6 -0
- data/lib/generators/rails/templates/api_controller.rb +10 -4
- data/lib/generators/rails/templates/controller.rb +21 -19
- data/lib/generators/rails/templates/index.json.jbuilder +1 -1
- data/lib/generators/rails/templates/partial.json.jbuilder +15 -1
- data/lib/generators/rails/templates/show.json.jbuilder +1 -1
- data/lib/jbuilder/collection_renderer.rb +116 -0
- data/lib/jbuilder/jbuilder.rb +1 -7
- data/lib/jbuilder/jbuilder_dependency_tracker.rb +73 -0
- data/lib/jbuilder/jbuilder_template.rb +80 -22
- data/lib/jbuilder/railtie.rb +3 -3
- data/lib/jbuilder/version.rb +3 -0
- data/lib/jbuilder.rb +71 -30
- data/test/jbuilder_dependency_tracker_test.rb +3 -4
- data/test/jbuilder_generator_test.rb +37 -5
- data/test/jbuilder_template_test.rb +300 -324
- data/test/jbuilder_test.rb +229 -4
- data/test/scaffold_api_controller_generator_test.rb +31 -3
- data/test/scaffold_controller_generator_test.rb +54 -8
- data/test/test_helper.rb +41 -8
- metadata +28 -21
- data/.travis.yml +0 -66
- data/CHANGELOG.md +0 -249
- data/lib/jbuilder/dependency_tracker.rb +0 -61
data/test/jbuilder_test.rb
CHANGED
@@ -49,7 +49,7 @@ end
|
|
49
49
|
|
50
50
|
|
51
51
|
class JbuilderTest < ActiveSupport::TestCase
|
52
|
-
|
52
|
+
teardown do
|
53
53
|
Jbuilder.send :class_variable_set, '@@key_formatter', nil
|
54
54
|
end
|
55
55
|
|
@@ -75,7 +75,7 @@ class JbuilderTest < ActiveSupport::TestCase
|
|
75
75
|
end
|
76
76
|
|
77
77
|
assert result.has_key?('content')
|
78
|
-
|
78
|
+
assert_nil result['content']
|
79
79
|
end
|
80
80
|
|
81
81
|
test 'multiple keys' do
|
@@ -99,7 +99,7 @@ class JbuilderTest < ActiveSupport::TestCase
|
|
99
99
|
assert_equal 32, result['age']
|
100
100
|
end
|
101
101
|
|
102
|
-
test 'extracting from object using call style
|
102
|
+
test 'extracting from object using call style' do
|
103
103
|
person = Struct.new(:name, :age).new('David', 32)
|
104
104
|
|
105
105
|
result = jbuild do |json|
|
@@ -159,6 +159,25 @@ class JbuilderTest < ActiveSupport::TestCase
|
|
159
159
|
assert_equal 32, result['author']['age']
|
160
160
|
end
|
161
161
|
|
162
|
+
test 'nested blocks are additive' do
|
163
|
+
result = jbuild do |json|
|
164
|
+
json.author do
|
165
|
+
json.name do
|
166
|
+
json.first 'David'
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
json.author do
|
171
|
+
json.name do
|
172
|
+
json.last 'Heinemeier Hansson'
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
assert_equal 'David', result['author']['name']['first']
|
178
|
+
assert_equal 'Heinemeier Hansson', result['author']['name']['last']
|
179
|
+
end
|
180
|
+
|
162
181
|
test 'support merge! method' do
|
163
182
|
result = jbuild do |json|
|
164
183
|
json.merge! 'foo' => 'bar'
|
@@ -177,6 +196,18 @@ class JbuilderTest < ActiveSupport::TestCase
|
|
177
196
|
assert_equal 'Pavel', result['author']['name']
|
178
197
|
end
|
179
198
|
|
199
|
+
test 'support merge! method with Jbuilder instance' do
|
200
|
+
obj = jbuild do |json|
|
201
|
+
json.foo 'bar'
|
202
|
+
end
|
203
|
+
|
204
|
+
result = jbuild do |json|
|
205
|
+
json.merge! obj
|
206
|
+
end
|
207
|
+
|
208
|
+
assert_equal 'bar', result['foo']
|
209
|
+
end
|
210
|
+
|
180
211
|
test 'blocks are additive via extract syntax' do
|
181
212
|
person = Person.new('Pavel', 27)
|
182
213
|
|
@@ -281,7 +312,7 @@ class JbuilderTest < ActiveSupport::TestCase
|
|
281
312
|
assert_equal 'world', result['comments'].second['content']
|
282
313
|
end
|
283
314
|
|
284
|
-
test 'nesting multiple
|
315
|
+
test 'nesting multiple children from a non-Enumerable that responds to #map with inline loop' do
|
285
316
|
comments = NonEnumerable.new([ Comment.new('hello', 1), Comment.new('world', 2) ])
|
286
317
|
|
287
318
|
result = jbuild do |json|
|
@@ -535,6 +566,36 @@ class JbuilderTest < ActiveSupport::TestCase
|
|
535
566
|
assert_equal 'one', result['level1']
|
536
567
|
end
|
537
568
|
|
569
|
+
test 'key_format! can be changed in child elements' do
|
570
|
+
result = jbuild do |json|
|
571
|
+
json.key_format! camelize: :lower
|
572
|
+
|
573
|
+
json.level_one do
|
574
|
+
json.key_format! :upcase
|
575
|
+
json.value 'two'
|
576
|
+
end
|
577
|
+
end
|
578
|
+
|
579
|
+
assert_equal ['levelOne'], result.keys
|
580
|
+
assert_equal ['VALUE'], result['levelOne'].keys
|
581
|
+
end
|
582
|
+
|
583
|
+
test 'key_format! can be changed in array!' do
|
584
|
+
result = jbuild do |json|
|
585
|
+
json.key_format! camelize: :lower
|
586
|
+
|
587
|
+
json.level_one do
|
588
|
+
json.array! [{value: 'two'}] do |object|
|
589
|
+
json.key_format! :upcase
|
590
|
+
json.value object[:value]
|
591
|
+
end
|
592
|
+
end
|
593
|
+
end
|
594
|
+
|
595
|
+
assert_equal ['levelOne'], result.keys
|
596
|
+
assert_equal ['VALUE'], result['levelOne'][0].keys
|
597
|
+
end
|
598
|
+
|
538
599
|
test 'key_format! with no parameter' do
|
539
600
|
result = jbuild do |json|
|
540
601
|
json.key_format! :upcase
|
@@ -562,6 +623,161 @@ class JbuilderTest < ActiveSupport::TestCase
|
|
562
623
|
assert_equal ['oats and friends'], result.keys
|
563
624
|
end
|
564
625
|
|
626
|
+
test 'key_format! is not applied deeply by default' do
|
627
|
+
names = { first_name: 'camel', last_name: 'case' }
|
628
|
+
result = jbuild do |json|
|
629
|
+
json.key_format! camelize: :lower
|
630
|
+
json.set! :all_names, names
|
631
|
+
end
|
632
|
+
|
633
|
+
assert_equal %i[first_name last_name], result['allNames'].keys
|
634
|
+
end
|
635
|
+
|
636
|
+
test 'applying key_format! deeply can be enabled per scope' do
|
637
|
+
names = { first_name: 'camel', last_name: 'case' }
|
638
|
+
result = jbuild do |json|
|
639
|
+
json.key_format! camelize: :lower
|
640
|
+
json.scope do
|
641
|
+
json.deep_format_keys!
|
642
|
+
json.set! :all_names, names
|
643
|
+
end
|
644
|
+
json.set! :all_names, names
|
645
|
+
end
|
646
|
+
|
647
|
+
assert_equal %w[firstName lastName], result['scope']['allNames'].keys
|
648
|
+
assert_equal %i[first_name last_name], result['allNames'].keys
|
649
|
+
end
|
650
|
+
|
651
|
+
test 'applying key_format! deeply can be disabled per scope' do
|
652
|
+
names = { first_name: 'camel', last_name: 'case' }
|
653
|
+
result = jbuild do |json|
|
654
|
+
json.key_format! camelize: :lower
|
655
|
+
json.deep_format_keys!
|
656
|
+
json.set! :all_names, names
|
657
|
+
json.scope do
|
658
|
+
json.deep_format_keys! false
|
659
|
+
json.set! :all_names, names
|
660
|
+
end
|
661
|
+
end
|
662
|
+
|
663
|
+
assert_equal %w[firstName lastName], result['allNames'].keys
|
664
|
+
assert_equal %i[first_name last_name], result['scope']['allNames'].keys
|
665
|
+
end
|
666
|
+
|
667
|
+
test 'applying key_format! deeply can be enabled globally' do
|
668
|
+
names = { first_name: 'camel', last_name: 'case' }
|
669
|
+
|
670
|
+
Jbuilder.deep_format_keys true
|
671
|
+
result = jbuild do |json|
|
672
|
+
json.key_format! camelize: :lower
|
673
|
+
json.set! :all_names, names
|
674
|
+
end
|
675
|
+
|
676
|
+
assert_equal %w[firstName lastName], result['allNames'].keys
|
677
|
+
Jbuilder.send(:class_variable_set, '@@deep_format_keys', false)
|
678
|
+
end
|
679
|
+
|
680
|
+
test 'deep key_format! with merge!' do
|
681
|
+
hash = { camel_style: 'for JS' }
|
682
|
+
result = jbuild do |json|
|
683
|
+
json.key_format! camelize: :lower
|
684
|
+
json.deep_format_keys!
|
685
|
+
json.merge! hash
|
686
|
+
end
|
687
|
+
|
688
|
+
assert_equal ['camelStyle'], result.keys
|
689
|
+
end
|
690
|
+
|
691
|
+
test 'deep key_format! with merge! deep' do
|
692
|
+
hash = { camel_style: { sub_attr: 'for JS' } }
|
693
|
+
result = jbuild do |json|
|
694
|
+
json.key_format! camelize: :lower
|
695
|
+
json.deep_format_keys!
|
696
|
+
json.merge! hash
|
697
|
+
end
|
698
|
+
|
699
|
+
assert_equal ['subAttr'], result['camelStyle'].keys
|
700
|
+
end
|
701
|
+
|
702
|
+
test 'deep key_format! with set! array of hashes' do
|
703
|
+
names = [{ first_name: 'camel', last_name: 'case' }]
|
704
|
+
result = jbuild do |json|
|
705
|
+
json.key_format! camelize: :lower
|
706
|
+
json.deep_format_keys!
|
707
|
+
json.set! :names, names
|
708
|
+
end
|
709
|
+
|
710
|
+
assert_equal %w[firstName lastName], result['names'][0].keys
|
711
|
+
end
|
712
|
+
|
713
|
+
test 'deep key_format! with set! extracting hash from object' do
|
714
|
+
comment = Struct.new(:author).new({ first_name: 'camel', last_name: 'case' })
|
715
|
+
result = jbuild do |json|
|
716
|
+
json.key_format! camelize: :lower
|
717
|
+
json.deep_format_keys!
|
718
|
+
json.set! :comment, comment, :author
|
719
|
+
end
|
720
|
+
|
721
|
+
assert_equal %w[firstName lastName], result['comment']['author'].keys
|
722
|
+
end
|
723
|
+
|
724
|
+
test 'deep key_format! with array! of hashes' do
|
725
|
+
names = [{ first_name: 'camel', last_name: 'case' }]
|
726
|
+
result = jbuild do |json|
|
727
|
+
json.key_format! camelize: :lower
|
728
|
+
json.deep_format_keys!
|
729
|
+
json.array! names
|
730
|
+
end
|
731
|
+
|
732
|
+
assert_equal %w[firstName lastName], result[0].keys
|
733
|
+
end
|
734
|
+
|
735
|
+
test 'deep key_format! with merge! array of hashes' do
|
736
|
+
names = [{ first_name: 'camel', last_name: 'case' }]
|
737
|
+
new_names = [{ first_name: 'snake', last_name: 'case' }]
|
738
|
+
result = jbuild do |json|
|
739
|
+
json.key_format! camelize: :lower
|
740
|
+
json.deep_format_keys!
|
741
|
+
json.array! names
|
742
|
+
json.merge! new_names
|
743
|
+
end
|
744
|
+
|
745
|
+
assert_equal %w[firstName lastName], result[1].keys
|
746
|
+
end
|
747
|
+
|
748
|
+
test 'deep key_format! is applied to hash extracted from object' do
|
749
|
+
comment = Struct.new(:author).new({ first_name: 'camel', last_name: 'case' })
|
750
|
+
result = jbuild do |json|
|
751
|
+
json.key_format! camelize: :lower
|
752
|
+
json.deep_format_keys!
|
753
|
+
json.extract! comment, :author
|
754
|
+
end
|
755
|
+
|
756
|
+
assert_equal %w[firstName lastName], result['author'].keys
|
757
|
+
end
|
758
|
+
|
759
|
+
test 'deep key_format! is applied to hash extracted from hash' do
|
760
|
+
comment = {author: { first_name: 'camel', last_name: 'case' }}
|
761
|
+
result = jbuild do |json|
|
762
|
+
json.key_format! camelize: :lower
|
763
|
+
json.deep_format_keys!
|
764
|
+
json.extract! comment, :author
|
765
|
+
end
|
766
|
+
|
767
|
+
assert_equal %w[firstName lastName], result['author'].keys
|
768
|
+
end
|
769
|
+
|
770
|
+
test 'deep key_format! is applied to hash extracted directly from array' do
|
771
|
+
comments = [Struct.new(:author).new({ first_name: 'camel', last_name: 'case' })]
|
772
|
+
result = jbuild do |json|
|
773
|
+
json.key_format! camelize: :lower
|
774
|
+
json.deep_format_keys!
|
775
|
+
json.array! comments, :author
|
776
|
+
end
|
777
|
+
|
778
|
+
assert_equal %w[firstName lastName], result[0]['author'].keys
|
779
|
+
end
|
780
|
+
|
565
781
|
test 'default key_format!' do
|
566
782
|
Jbuilder.key_format camelize: :lower
|
567
783
|
result = jbuild{ |json| json.camel_style 'for JS' }
|
@@ -713,4 +929,13 @@ class JbuilderTest < ActiveSupport::TestCase
|
|
713
929
|
end
|
714
930
|
end
|
715
931
|
end
|
932
|
+
|
933
|
+
if RUBY_VERSION >= "2.2.10"
|
934
|
+
test "respects JSON encoding customizations" do
|
935
|
+
# Active Support overrides Time#as_json for custom formatting.
|
936
|
+
# Ensure we call #to_json on the final attributes instead of JSON.dump.
|
937
|
+
result = JSON.load(Jbuilder.encode { |json| json.time Time.parse("2018-05-13 11:51:00.485 -0400") })
|
938
|
+
assert_equal "2018-05-13T11:51:00.485-04:00", result["time"]
|
939
|
+
end
|
940
|
+
end
|
716
941
|
end
|
@@ -6,7 +6,7 @@ if Rails::VERSION::MAJOR > 4
|
|
6
6
|
|
7
7
|
class ScaffoldApiControllerGeneratorTest < Rails::Generators::TestCase
|
8
8
|
tests Rails::Generators::ScaffoldControllerGenerator
|
9
|
-
arguments %w(Post title body:text --api)
|
9
|
+
arguments %w(Post title body:text images:attachments --api)
|
10
10
|
destination File.expand_path('../tmp', __FILE__)
|
11
11
|
setup :prepare_destination
|
12
12
|
|
@@ -38,12 +38,25 @@ if Rails::VERSION::MAJOR > 4
|
|
38
38
|
assert_match %r{@post\.destroy}, m
|
39
39
|
end
|
40
40
|
|
41
|
+
assert_match %r{def set_post}, content
|
42
|
+
if Rails::VERSION::MAJOR >= 8
|
43
|
+
assert_match %r{params\.expect\(:id\)}, content
|
44
|
+
else
|
45
|
+
assert_match %r{params\[:id\]}, content
|
46
|
+
end
|
47
|
+
|
41
48
|
assert_match %r{def post_params}, content
|
42
|
-
|
49
|
+
if Rails::VERSION::MAJOR >= 8
|
50
|
+
assert_match %r{params\.expect\(post: \[ :title, :body, images: \[\] \]\)}, content
|
51
|
+
elsif Rails::VERSION::MAJOR >= 6
|
52
|
+
assert_match %r{params\.require\(:post\)\.permit\(:title, :body, images: \[\]\)}, content
|
53
|
+
else
|
54
|
+
assert_match %r{params\.require\(:post\)\.permit\(:title, :body, :images\)}, content
|
55
|
+
end
|
43
56
|
end
|
44
57
|
end
|
45
58
|
|
46
|
-
test '
|
59
|
+
test "don't use require and permit if there are no attributes" do
|
47
60
|
run_generator %w(Post --api)
|
48
61
|
|
49
62
|
assert_file 'app/controllers/posts_controller.rb' do |content|
|
@@ -51,5 +64,20 @@ if Rails::VERSION::MAJOR > 4
|
|
51
64
|
assert_match %r{params\.fetch\(:post, \{\}\)}, content
|
52
65
|
end
|
53
66
|
end
|
67
|
+
|
68
|
+
|
69
|
+
if Rails::VERSION::MAJOR >= 6
|
70
|
+
test 'handles virtual attributes' do
|
71
|
+
run_generator ["Message", "content:rich_text", "video:attachment", "photos:attachments"]
|
72
|
+
|
73
|
+
assert_file 'app/controllers/messages_controller.rb' do |content|
|
74
|
+
if Rails::VERSION::MAJOR >= 8
|
75
|
+
assert_match %r{params\.expect\(message: \[ :content, :video, photos: \[\] \]\)}, content
|
76
|
+
else
|
77
|
+
assert_match %r{params\.require\(:message\)\.permit\(:content, :video, photos: \[\]\)}, content
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
54
82
|
end
|
55
83
|
end
|
@@ -4,7 +4,7 @@ require 'generators/rails/scaffold_controller_generator'
|
|
4
4
|
|
5
5
|
class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
|
6
6
|
tests Rails::Generators::ScaffoldControllerGenerator
|
7
|
-
arguments %w(Post title body:text)
|
7
|
+
arguments %w(Post title body:text images:attachments)
|
8
8
|
destination File.expand_path('../tmp', __FILE__)
|
9
9
|
setup :prepare_destination
|
10
10
|
|
@@ -31,31 +31,63 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
|
|
31
31
|
assert_instance_method :create, content do |m|
|
32
32
|
assert_match %r{@post = Post\.new\(post_params\)}, m
|
33
33
|
assert_match %r{@post\.save}, m
|
34
|
-
assert_match %r{format\.html \{ redirect_to @post, notice:
|
34
|
+
assert_match %r{format\.html \{ redirect_to @post, notice: "Post was successfully created\." \}}, m
|
35
35
|
assert_match %r{format\.json \{ render :show, status: :created, location: @post \}}, m
|
36
|
-
assert_match %r{format\.html \{ render :new \}}, m
|
36
|
+
assert_match %r{format\.html \{ render :new, status: :unprocessable_entity \}}, m
|
37
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 %r{format\.html \{ redirect_to @post, notice:
|
41
|
+
assert_match %r{format\.html \{ redirect_to @post, notice: "Post was successfully updated\." \}}, m
|
42
42
|
assert_match %r{format\.json \{ render :show, status: :ok, location: @post \}}, m
|
43
|
-
assert_match %r{format\.html \{ render :edit \}}, m
|
43
|
+
assert_match %r{format\.html \{ render :edit, status: :unprocessable_entity \}}, m
|
44
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
48
|
assert_match %r{@post\.destroy}, m
|
49
|
-
assert_match %r{format\.html \{ redirect_to
|
49
|
+
assert_match %r{format\.html \{ redirect_to posts_path, status: :see_other, notice: "Post was successfully destroyed\." \}}, m
|
50
50
|
assert_match %r{format\.json \{ head :no_content \}}, m
|
51
51
|
end
|
52
52
|
|
53
|
+
assert_match %r{def set_post}, content
|
54
|
+
if Rails::VERSION::MAJOR >= 8
|
55
|
+
assert_match %r{params\.expect\(:id\)}, content
|
56
|
+
else
|
57
|
+
assert_match %r{params\[:id\]}, content
|
58
|
+
end
|
59
|
+
|
53
60
|
assert_match %r{def post_params}, content
|
54
|
-
|
61
|
+
if Rails::VERSION::MAJOR >= 8
|
62
|
+
assert_match %r{params\.expect\(post: \[ :title, :body, images: \[\] \]\)}, content
|
63
|
+
elsif Rails::VERSION::MAJOR >= 6
|
64
|
+
assert_match %r{params\.require\(:post\)\.permit\(:title, :body, images: \[\]\)}, content
|
65
|
+
else
|
66
|
+
assert_match %r{params\.require\(:post\)\.permit\(:title, :body, :images\)}, content
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
if Rails::VERSION::MAJOR >= 6
|
72
|
+
test 'controller with namespace' do
|
73
|
+
run_generator %w(Admin::Post --model-name=Post)
|
74
|
+
assert_file 'app/controllers/admin/posts_controller.rb' do |content|
|
75
|
+
assert_instance_method :create, content do |m|
|
76
|
+
assert_match %r{format\.html \{ redirect_to \[:admin, @post\], notice: "Post was successfully created\." \}}, m
|
77
|
+
end
|
78
|
+
|
79
|
+
assert_instance_method :update, content do |m|
|
80
|
+
assert_match %r{format\.html \{ redirect_to \[:admin, @post\], notice: "Post was successfully updated\." \}}, m
|
81
|
+
end
|
82
|
+
|
83
|
+
assert_instance_method :destroy, content do |m|
|
84
|
+
assert_match %r{format\.html \{ redirect_to admin_posts_path, status: :see_other, notice: "Post was successfully destroyed\." \}}, m
|
85
|
+
end
|
86
|
+
end
|
55
87
|
end
|
56
88
|
end
|
57
89
|
|
58
|
-
test '
|
90
|
+
test "don't use require and permit if there are no attributes" do
|
59
91
|
run_generator %w(Post)
|
60
92
|
|
61
93
|
assert_file 'app/controllers/posts_controller.rb' do |content|
|
@@ -63,4 +95,18 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
|
|
63
95
|
assert_match %r{params\.fetch\(:post, \{\}\)}, content
|
64
96
|
end
|
65
97
|
end
|
98
|
+
|
99
|
+
if Rails::VERSION::MAJOR >= 6
|
100
|
+
test 'handles virtual attributes' do
|
101
|
+
run_generator %w(Message content:rich_text video:attachment photos:attachments)
|
102
|
+
|
103
|
+
assert_file 'app/controllers/messages_controller.rb' do |content|
|
104
|
+
if Rails::VERSION::MAJOR >= 8
|
105
|
+
assert_match %r{params\.expect\(message: \[ :content, :video, photos: \[\] \]\)}, content
|
106
|
+
else
|
107
|
+
assert_match %r{params\.require\(:message\)\.permit\(:content, :video, photos: \[\]\)}, content
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
66
112
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,14 +1,47 @@
|
|
1
1
|
require "bundler/setup"
|
2
|
-
require "active_support"
|
3
|
-
require "rails/version"
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
require "rails"
|
4
|
+
|
5
|
+
require "jbuilder"
|
6
|
+
|
7
|
+
require "active_support/core_ext/array/access"
|
8
|
+
require "active_support/cache/memory_store"
|
9
|
+
require "active_support/json"
|
10
|
+
require "active_model"
|
11
|
+
require 'action_controller/railtie'
|
12
|
+
require 'action_view/railtie'
|
13
|
+
|
14
|
+
require "active_support/testing/autorun"
|
15
|
+
require "mocha/minitest"
|
16
|
+
|
17
|
+
ActiveSupport.test_order = :random
|
18
|
+
|
19
|
+
ENV["RAILS_ENV"] ||= "test"
|
20
|
+
|
21
|
+
class << Rails
|
22
|
+
def cache
|
23
|
+
@cache ||= ActiveSupport::Cache::MemoryStore.new
|
24
|
+
end
|
9
25
|
end
|
10
26
|
|
27
|
+
Jbuilder::CollectionRenderer.collection_cache = Rails.cache
|
28
|
+
|
29
|
+
class Post < Struct.new(:id, :body, :author_name)
|
30
|
+
def cache_key
|
31
|
+
"post-#{id}"
|
32
|
+
end
|
33
|
+
end
|
11
34
|
|
12
|
-
|
13
|
-
|
35
|
+
class Racer < Struct.new(:id, :name)
|
36
|
+
extend ActiveModel::Naming
|
37
|
+
include ActiveModel::Conversion
|
14
38
|
end
|
39
|
+
|
40
|
+
# Instantiate an Application in order to trigger the initializers
|
41
|
+
Class.new(Rails::Application) do
|
42
|
+
config.secret_key_base = 'secret'
|
43
|
+
config.eager_load = false
|
44
|
+
end.initialize!
|
45
|
+
|
46
|
+
# Touch AV::Base in order to trigger :action_view on_load hook before running the tests
|
47
|
+
ActionView::Base.inspect
|
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: 2.
|
4
|
+
version: 2.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,46 +16,47 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 5.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 5.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: actionview
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 5.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
-
description:
|
40
|
+
version: 5.0.0
|
41
|
+
description:
|
42
42
|
email: david@basecamp.com
|
43
43
|
executables: []
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files: []
|
46
46
|
files:
|
47
|
+
- ".github/workflows/ruby.yml"
|
47
48
|
- ".gitignore"
|
48
|
-
- ".travis.yml"
|
49
49
|
- Appraisals
|
50
|
-
- CHANGELOG.md
|
51
50
|
- CONTRIBUTING.md
|
52
51
|
- Gemfile
|
53
52
|
- MIT-LICENSE
|
54
53
|
- README.md
|
55
54
|
- Rakefile
|
56
|
-
-
|
57
|
-
-
|
58
|
-
- gemfiles/
|
55
|
+
- bin/release
|
56
|
+
- bin/test
|
57
|
+
- gemfiles/rails_7_0.gemfile
|
58
|
+
- gemfiles/rails_7_1.gemfile
|
59
|
+
- gemfiles/rails_head.gemfile
|
59
60
|
- jbuilder.gemspec
|
60
61
|
- lib/generators/rails/jbuilder_generator.rb
|
61
62
|
- lib/generators/rails/scaffold_controller_generator.rb
|
@@ -66,12 +67,14 @@ files:
|
|
66
67
|
- lib/generators/rails/templates/show.json.jbuilder
|
67
68
|
- lib/jbuilder.rb
|
68
69
|
- lib/jbuilder/blank.rb
|
69
|
-
- lib/jbuilder/
|
70
|
+
- lib/jbuilder/collection_renderer.rb
|
70
71
|
- lib/jbuilder/errors.rb
|
71
72
|
- lib/jbuilder/jbuilder.rb
|
73
|
+
- lib/jbuilder/jbuilder_dependency_tracker.rb
|
72
74
|
- lib/jbuilder/jbuilder_template.rb
|
73
75
|
- lib/jbuilder/key_formatter.rb
|
74
76
|
- lib/jbuilder/railtie.rb
|
77
|
+
- lib/jbuilder/version.rb
|
75
78
|
- test/jbuilder_dependency_tracker_test.rb
|
76
79
|
- test/jbuilder_generator_test.rb
|
77
80
|
- test/jbuilder_template_test.rb
|
@@ -82,8 +85,13 @@ files:
|
|
82
85
|
homepage: https://github.com/rails/jbuilder
|
83
86
|
licenses:
|
84
87
|
- MIT
|
85
|
-
metadata:
|
86
|
-
|
88
|
+
metadata:
|
89
|
+
bug_tracker_uri: https://github.com/rails/jbuilder/issues
|
90
|
+
changelog_uri: https://github.com/rails/jbuilder/releases/tag/v2.13.0
|
91
|
+
mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
|
92
|
+
source_code_uri: https://github.com/rails/jbuilder/tree/v2.13.0
|
93
|
+
rubygems_mfa_required: 'true'
|
94
|
+
post_install_message:
|
87
95
|
rdoc_options: []
|
88
96
|
require_paths:
|
89
97
|
- lib
|
@@ -91,16 +99,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
99
|
requirements:
|
92
100
|
- - ">="
|
93
101
|
- !ruby/object:Gem::Version
|
94
|
-
version:
|
102
|
+
version: 2.2.2
|
95
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
104
|
requirements:
|
97
105
|
- - ">="
|
98
106
|
- !ruby/object:Gem::Version
|
99
107
|
version: '0'
|
100
108
|
requirements: []
|
101
|
-
|
102
|
-
|
103
|
-
signing_key:
|
109
|
+
rubygems_version: 3.5.16
|
110
|
+
signing_key:
|
104
111
|
specification_version: 4
|
105
112
|
summary: Create JSON structures via a Builder-style DSL
|
106
113
|
test_files:
|
data/.travis.yml
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
|
3
|
-
sudo: false
|
4
|
-
cache: bundler
|
5
|
-
|
6
|
-
rvm:
|
7
|
-
- 1.9
|
8
|
-
- 2.0
|
9
|
-
- 2.1
|
10
|
-
- 2.2.5
|
11
|
-
- 2.3.1
|
12
|
-
- 2.4.0
|
13
|
-
- ruby-head
|
14
|
-
- jruby-19mode
|
15
|
-
- rbx
|
16
|
-
|
17
|
-
gemfile:
|
18
|
-
- gemfiles/rails_3_0.gemfile
|
19
|
-
- gemfiles/rails_3_1.gemfile
|
20
|
-
- gemfiles/rails_3_2.gemfile
|
21
|
-
- gemfiles/rails_4_0.gemfile
|
22
|
-
- gemfiles/rails_4_1.gemfile
|
23
|
-
- gemfiles/rails_4_2.gemfile
|
24
|
-
- gemfiles/rails_5_0.gemfile
|
25
|
-
- gemfiles/rails_5_1.gemfile
|
26
|
-
|
27
|
-
matrix:
|
28
|
-
allow_failures:
|
29
|
-
- rvm: jruby-19mode
|
30
|
-
- rvm: rbx
|
31
|
-
- rvm: ruby-head
|
32
|
-
fast_finish: true
|
33
|
-
exclude:
|
34
|
-
- rvm: 1.9
|
35
|
-
gemfile: gemfiles/rails_5_0.gemfile
|
36
|
-
- rvm: 1.9
|
37
|
-
gemfile: gemfiles/rails_5_1.gemfile
|
38
|
-
- rvm: 2.0
|
39
|
-
gemfile: gemfiles/rails_5_0.gemfile
|
40
|
-
- rvm: 2.0
|
41
|
-
gemfile: gemfiles/rails_5_1.gemfile
|
42
|
-
- rvm: 2.1
|
43
|
-
gemfile: gemfiles/rails_5_0.gemfile
|
44
|
-
- rvm: 2.1
|
45
|
-
gemfile: gemfiles/rails_5_1.gemfile
|
46
|
-
- rvm: jruby-19mode
|
47
|
-
gemfile: gemfiles/rails_5_0.gemfile
|
48
|
-
- rvm: jruby-19mode
|
49
|
-
gemfile: gemfiles/rails_5_1.gemfile
|
50
|
-
- rvm: rbx
|
51
|
-
gemfile: gemfiles/rails_5_0.gemfile
|
52
|
-
- rvm: rbx
|
53
|
-
gemfile: gemfiles/rails_5_1.gemfile
|
54
|
-
- rvm: 2.4.0
|
55
|
-
gemfile: gemfiles/rails_3_0.gemfile
|
56
|
-
- rvm: 2.4.0
|
57
|
-
gemfile: gemfiles/rails_3_1.gemfile
|
58
|
-
- rvm: 2.4.0
|
59
|
-
gemfile: gemfiles/rails_3_2.gemfile
|
60
|
-
- rvm: 2.4.0
|
61
|
-
gemfile: gemfiles/rails_4_0.gemfile
|
62
|
-
- rvm: 2.4.0
|
63
|
-
gemfile: gemfiles/rails_4_1.gemfile
|
64
|
-
|
65
|
-
notifications:
|
66
|
-
email: false
|