@@ -15,6 +15,9 @@ def self.parse(*args)
1515 end
1616end
1717
18+ class RegularResource < TestResource
19+ end
20+
1821class CustomConnectionResource < TestResource
1922 self . connection_class = NullConnection
2023 self . parser = NullParser
@@ -69,4 +72,40 @@ def test_can_specify_http_proxy
6972 assert_equal proxy . uri . to_s , 'http://proxy.example.com'
7073 end
7174
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
72111end
0 commit comments