File tree 2 files changed +72
-0
lines changed 2 files changed +72
-0
lines changed Original file line number Diff line number Diff line change 3
3
module ActionController
4
4
module Serialization
5
5
class ImplicitSerializerTest < ActionController ::TestCase
6
+ include ActiveSupport ::Testing ::Stream
6
7
class ImplicitSerializationTestController < ActionController ::Base
7
8
def render_using_implicit_serializer
8
9
@profile = Profile . new ( { name : 'Name 1' , description : 'Description 1' , comments : 'Comments 1' } )
@@ -327,6 +328,28 @@ def test_cache_expiration_on_update
327
328
assert_equal 'application/json' , @response . content_type
328
329
assert_equal expected . to_json , @response . body
329
330
end
331
+
332
+ def test_warn_overridding_use_adapter_as_falsy_on_controller_instance
333
+ controller = Class . new ( ImplicitSerializationTestController ) {
334
+ def use_adapter?
335
+ false
336
+ end
337
+ } . new
338
+ assert_match /adapter: false/ , ( capture ( :stderr ) {
339
+ controller . get_serializer ( @profile )
340
+ } )
341
+ end
342
+
343
+ def test_dont_warn_overridding_use_adapter_as_truthy_on_controller_instance
344
+ controller = Class . new ( ImplicitSerializationTestController ) {
345
+ def use_adapter?
346
+ true
347
+ end
348
+ } . new
349
+ assert_equal "" , ( capture ( :stderr ) {
350
+ controller . get_serializer ( @profile )
351
+ } )
352
+ end
330
353
end
331
354
end
332
355
end
Original file line number Diff line number Diff line change 12
12
13
13
require 'active_model_serializers'
14
14
15
+ # Use cleaner stream testing interface from Rails 5 if available
16
+ # see https://github.com/rails/rails/blob/29959eb59d/activesupport/lib/active_support/testing/stream.rb
17
+ begin
18
+ require "active_support/testing/stream"
19
+ rescue LoadError
20
+ module ActiveSupport
21
+ module Testing
22
+ module Stream #:nodoc:
23
+ private
24
+
25
+ def silence_stream ( stream )
26
+ old_stream = stream . dup
27
+ stream . reopen ( IO ::NULL )
28
+ stream . sync = true
29
+ yield
30
+ ensure
31
+ stream . reopen ( old_stream )
32
+ old_stream . close
33
+ end
34
+
35
+ def quietly
36
+ silence_stream ( STDOUT ) do
37
+ silence_stream ( STDERR ) do
38
+ yield
39
+ end
40
+ end
41
+ end
42
+
43
+ def capture ( stream )
44
+ stream = stream . to_s
45
+ captured_stream = Tempfile . new ( stream )
46
+ stream_io = eval ( "$#{ stream } " )
47
+ origin_stream = stream_io . dup
48
+ stream_io . reopen ( captured_stream )
49
+
50
+ yield
51
+
52
+ stream_io . rewind
53
+ return captured_stream . read
54
+ ensure
55
+ captured_stream . close
56
+ captured_stream . unlink
57
+ stream_io . reopen ( origin_stream )
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+
15
64
class Foo < Rails ::Application
16
65
if Rails ::VERSION ::MAJOR >= 4
17
66
config . eager_load = false
You can’t perform that action at this time.
0 commit comments