Skip to content

Commit 08dc986

Browse files
committed
Some refactoring and fixes for ACF.
1 parent 77a28ee commit 08dc986

File tree

5 files changed

+23
-14
lines changed

5 files changed

+23
-14
lines changed

models/HyperRequest.cfc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ component accessors="true" {
8484
throw( type = "NoUrlException" );
8585
}
8686

87-
var res = new Hyper.models.HyperResponse( this );
88-
res.populateFromCFHTTP( makeCFHTTPRequest() );
87+
var res = new Hyper.models.HyperResponse( this, makeCFHTTPRequest() );
8988

9089
if ( res.isRedirect() ) {
9190
if ( shouldFollowRedirect() ) {
@@ -119,7 +118,7 @@ component accessors="true" {
119118
private function makeCFHTTPRequest() {
120119
local.res = "";
121120
cfhttp(
122-
result = "local.res"
121+
result = "local.res",
123122
url = getUrl(),
124123
method = getMethod(),
125124
redirect = false

models/HyperResponse.cfc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
component accessors="true" setters="false" {
1+
component accessors="true" {
22

3-
property name="statusCode" default="200";
4-
property name="data" default="";
5-
property name="request";
3+
property name="statusCode" default="200" setter="false";
4+
property name="data" default="" setter="false";
5+
property name="request" setter="false";
6+
property name="charset" setter="false";
7+
property name="timestamp" setter="false";
68

7-
function init( req ) {
9+
function init( req, cfhttpResponse, timestamp = now() ) {
810
variables.request = req;
11+
populateFromCFHTTP( cfhttpResponse );
12+
variables.timestamp = arguments.timestamp;
913
return this;
1014
}
1115

@@ -16,7 +20,8 @@ component accessors="true" setters="false" {
1620
return deserializeJSON( getData() );
1721
}
1822

19-
function populateFromCFHTTP( res ) {
23+
private function populateFromCFHTTP( res ) {
24+
variables.charset = res.charset;
2025
variables.statusCode = res.responseheader.status_code;
2126
res.responseheader.each( function( name, value ) {
2227
variables.headers[ lcase( name ) ] = value;

tests/specs/integration/BuilderPassThroughSpec.cfc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ component extends="tests.resources.ModuleIntegrationSpec" appMapping="/app" {
1515
it( "passes through all other methods to the HyperRequest", function() {
1616
var res = hyper.setUrl( "https://jsonplaceholder.typicode.com/posts/1" ).get();
1717
expect( res ).toBeInstanceOf(
18-
"HyperResponse",
18+
"Hyper.models.HyperResponse",
1919
"A HyperResponse object should have been returned."
2020
);
2121
var data = res.json();

tests/specs/integration/GetSpec.cfc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ component extends="tests.resources.ModuleIntegrationSpec" appMapping="/app" {
1515
it( "can make a GET request", function() {
1616
var res = hyper.get( "https://jsonplaceholder.typicode.com/posts/1" );
1717
expect( res ).toBeInstanceOf(
18-
"HyperResponse",
18+
"Hyper.models.HyperResponse",
1919
"A HyperResponse object should have been returned."
2020
);
2121
var data = res.json();
@@ -33,7 +33,7 @@ component extends="tests.resources.ModuleIntegrationSpec" appMapping="/app" {
3333
it( "has access to the original HyperRequest in the HyperResponse", function() {
3434
var res = hyper.get( "https://jsonplaceholder.typicode.com/posts/1" );
3535
expect( res ).toBeInstanceOf(
36-
"HyperResponse",
36+
"Hyper.models.HyperResponse",
3737
"A HyperResponse object should have been returned."
3838
);
3939
var req = res.getRequest();

tests/specs/unit/HyperResponseSpec.cfc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ component extends="testbox.system.BaseSpec" {
33
function run() {
44
describe( "HyperResponse", function() {
55
it( "throws an exception when requesting json data but the data is not json", function() {
6-
var res = new Hyper.models.HyperResponse( createStub() );
7-
res.setData( "definitely not json" );
6+
var res = new Hyper.models.HyperResponse( createStub(), {
7+
"charset" = "UTF-8",
8+
"responseheader" = {
9+
"status_code" = "200"
10+
},
11+
"filecontent" = "definitely not json"
12+
} );
813
expect( function() {
914
var json = res.json();
1015
} ).toThrow( "DeserializeJsonException" );

0 commit comments

Comments
 (0)