Skip to content

Commit ab034ca

Browse files
committed
Allow defaults to be set on the HyperBuilder that appear on each request
1 parent 9f21e88 commit ab034ca

4 files changed

Lines changed: 35 additions & 2 deletions

File tree

‎models/HyperBuilder.cfc‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
component {
22

3+
this.defaults = new Hyper.models.HyperRequest();
4+
5+
function new() {
6+
return duplicate( this.defaults );
7+
}
8+
39
function onMissingMethod( missingMethodName, missingMethodArguments ) {
4-
var req = new Hyper.models.HyperRequest();
5-
return invoke( req, missingMethodName, missingMethodArguments );
10+
return invoke( variables.new(), missingMethodName, missingMethodArguments );
611
}
712

813
}

‎models/HyperRequest.cfc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ component accessors="true" {
33
property name="url" default="";
44
property name="method" default="GET";
55
property name="maximumRedirects" default="*";
6+
property name="baseUrl" default="";
67
property name="body" default="";
78
property name="bodyFormat" default="json";
89
property name="referrer";
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
component extends="tests.resources.ModuleIntegrationSpec" appMapping="/app" {
2+
3+
function run() {
4+
describe( "Builder defaults", function() {
5+
beforeEach( function() {
6+
variables.hyper = getInstance( "HyperBuilder@Hyper" );
7+
} );
8+
9+
afterEach( function() {
10+
if ( variables.keyExists( "hyper" ) ) {
11+
variables.delete( "hyper" );
12+
}
13+
} );
14+
15+
it( "can be configured with defaults that get passed to every request", function() {
16+
hyper.defaults.setBaseUrl( "https://jsonplaceholder.typicode.com" );
17+
var req = hyper.new();
18+
expect( req.getBaseUrl() ).toBe( "https://jsonplaceholder.typicode.com" );
19+
} );
20+
} );
21+
}
22+
23+
}

‎tests/specs/unit/HyperBuilderSpec.cfc‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ component extends="testbox.system.BaseSpec" {
1212
}
1313
} );
1414

15+
it( "can create a new request", function() {
16+
expect( hyper.new() ).toBeInstanceOf( "Hyper.models.HyperRequest" );
17+
} );
18+
1519
it( "passes through all other methods to the HyperRequest", function() {
1620
var req = hyper.setUrl( "https://jsonplaceholder.typicode.com/posts/1" );
1721
expect( req ).toBeInstanceOf(

0 commit comments

Comments
 (0)