@@ -15,6 +15,9 @@ def self.parse(*args)
15
15
end
16
16
end
17
17
18
+ class RegularResource < TestResource
19
+ end
20
+
18
21
class CustomConnectionResource < TestResource
19
22
self . connection_class = NullConnection
20
23
self . parser = NullParser
@@ -69,4 +72,40 @@ def test_can_specify_http_proxy
69
72
assert_equal proxy . uri . to_s , 'http://proxy.example.com'
70
73
end
71
74
75
+ def test_gzipping_without_server_support
76
+ stub_request ( :get , "http://example.com/regular_resources" )
77
+ . with ( headers : { 'Accept-Encoding' => 'gzip,deflate' } )
78
+ . to_return (
79
+ status : 200 ,
80
+ body : { data : [ { id : "1" , type : "regular_resources" , attributes : { foo : "bar" } } ] } . to_json ,
81
+ headers : { content_type : "application/vnd.api+json" }
82
+ )
83
+
84
+ resources = RegularResource . all
85
+ assert_equal 1 , resources . length
86
+ resource = resources . first
87
+ assert_equal "bar" , resource . foo
88
+ end
89
+
90
+ def test_gzipping_with_server_support
91
+ io = StringIO . new
92
+ gz = Zlib ::GzipWriter . new ( io )
93
+ gz . write ( { data : [ { id : "1" , type : "regular_resources" , attributes : { foo : "bar" } } ] } . to_json )
94
+ gz . close
95
+ body = io . string
96
+ body . force_encoding ( 'BINARY' ) if body . respond_to? ( :force_encoding )
97
+
98
+ stub_request ( :get , "http://example.com/regular_resources" )
99
+ . with ( headers : { 'Accept-Encoding' => 'gzip,deflate' } )
100
+ . to_return (
101
+ status : 200 ,
102
+ body : body ,
103
+ headers : { content_type : "application/vnd.api+json" , content_encoding : 'gzip' }
104
+ )
105
+
106
+ resources = RegularResource . all
107
+ assert_equal 1 , resources . length
108
+ resource = resources . first
109
+ assert_equal "bar" , resource . foo
110
+ end
72
111
end
0 commit comments