Skip to content

Commit 10b3156

Browse files
committed
fix(cbstorages): Upgrade cbstorages to 2.0.0
Upgrade internal cbstorages library to 2.0.0 BREAKING CHANGE: Drop support for ACF 11
1 parent 8a86eb9 commit 10b3156

File tree

6 files changed

+45
-44
lines changed

6 files changed

+45
-44
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ env:
66
matrix:
77
- ENGINE=adobe@2018
88
- ENGINE=adobe@2016
9-
- ENGINE=adobe@11
109
- ENGINE=lucee@5
1110
before_install:
1211
- curl -fsSl https://downloads.ortussolutions.com/debs/gpg | sudo apt-key add -

box.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
}
2626
],
2727
"dependencies":{
28-
"cbstorages":"^1.2.0"
28+
"cbstorages":"^2.0.0"
2929
},
3030
"devDependencies":{
31-
"testbox":"^2.3.0+00044"
31+
"testbox":"^3.0.0"
3232
},
3333
"installPaths":{
3434
"testbox":"testbox/",

models/AuthenticationService.cfc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ component singleton {
55
property name="sessionStorage" inject="SessionStorage@cbauth";
66
property name="requestStorage" inject="RequestStorage@cbauth";
77
property name="userServiceClass" inject="coldbox:setting:userServiceClass@cbauth";
8-
8+
99
variables.USER_ID_KEY = "cbauth__userId";
1010
variables.USER_KEY = "cbauth__user";
1111

1212
public void function logout() {
13-
sessionStorage.deleteVar( USER_ID_KEY );
14-
requestStorage.deleteVar( USER_KEY );
13+
sessionStorage.delete( USER_ID_KEY );
14+
requestStorage.delete( USER_KEY );
1515
}
1616

1717
public void function login( required user ) {
18-
sessionStorage.setVar( USER_ID_KEY, user.getId() );
19-
requestStorage.setVar( USER_KEY, user );
18+
sessionStorage.set( USER_ID_KEY, user.getId() );
19+
requestStorage.set( USER_KEY, user );
2020
}
2121

2222
public boolean function authenticate( required string username, required string password ) {
@@ -30,7 +30,7 @@ component singleton {
3030
if ( NOT getUserService().isValidCredentials( args.username, args.password ) ) {
3131
throw( "Incorrect Credentials Entered", "InvalidCredentials" );
3232
}
33-
33+
3434
var user = getUserService().retrieveUserByUsername( args.username );
3535

3636
interceptorService.processState( "postAuthentication", {
@@ -59,10 +59,10 @@ component singleton {
5959
public any function getUser() {
6060
if ( ! requestStorage.exists( USER_KEY ) ) {
6161
var userBean = getUserService().retrieveUserById( getUserId() );
62-
requestStorage.setVar( USER_KEY, userBean );
62+
requestStorage.set( USER_KEY, userBean );
6363
}
6464

65-
return requestStorage.getVar( USER_KEY );
65+
return requestStorage.get( USER_KEY );
6666
}
6767

6868
public any function user() {
@@ -74,7 +74,7 @@ component singleton {
7474
throw( "No user is currently logged in.", "NoUserLoggedIn" );
7575
}
7676

77-
return sessionStorage.getVar( USER_ID_KEY );
77+
return sessionStorage.get( USER_ID_KEY );
7878
}
7979

8080
private any function getUserService() {

server.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"app":{
3-
"cfengine":"adobe@11"
3+
"cfengine":"adobe@2016"
44
},
55
"web":{
66
"http":{

tests/Application.cfc

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

33
this.name = 'TestBoxTestingSuite' & hash(getCurrentTemplatePath());
4+
this.sessionManagement = true;
45

56
this.mappings['/tests'] = getDirectoryFromPath(getCurrentTemplatePath());
67
this.mappings['/root'] = REReplaceNoCase(this.mappings['/tests'], 'tests(\\|/)', '');;
78

8-
}
9+
}

tests/specs/AuthenticationSpec.cfc

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ component extends="testbox.system.BaseSpec" {
2323
structDelete( variables, "requestStorageMock" );
2424
structDelete( variables, "sessionStorageMock" );
2525
structDelete( variables, "userMock" );
26+
session = {};
2627
} );
2728

2829
describe( "instantiating the user service", function() {
@@ -105,9 +106,9 @@ component extends="testbox.system.BaseSpec" {
105106
describe( "getUser", function() {
106107
it( "returns the currently logged in user component", function() {
107108
requestStorageMock.$( "exists", false );
108-
requestStorageMock.$( "getVar", userMock );
109+
requestStorageMock.$( "get", userMock );
109110
sessionStorageMock.$( "exists", true );
110-
sessionStorageMock.$( "getVar", 1 );
111+
sessionStorageMock.$( "get", 1 );
111112
userServiceMock.$( "retrieveUserById" ).$args( 1 ).$results( userMock );
112113

113114
var actual = auth.getUser();
@@ -116,6 +117,7 @@ component extends="testbox.system.BaseSpec" {
116117
} );
117118

118119
it( "throws an exception when trying to get the user without being logged in", function() {
120+
requestStorageMock.$( "exists", false );
119121
sessionStorageMock.$( "exists", false );
120122

121123
expect( function() {
@@ -125,7 +127,7 @@ component extends="testbox.system.BaseSpec" {
125127

126128
it( "returns the user from the request if it exists", function() {
127129
requestStorageMock.$( "exists", true );
128-
requestStorageMock.$( "getVar", userMock );
130+
requestStorageMock.$( "get", userMock );
129131

130132
auth.getUser();
131133

@@ -134,17 +136,19 @@ component extends="testbox.system.BaseSpec" {
134136
expect( sessionStorageCallLog )
135137
.notToHaveKey( "exists", "[exists] should not be called on the SessionStorage" );
136138
expect( sessionStorageCallLog )
137-
.notToHaveKey( "getVar", "[getVar] should not be called on the SessionStorage" );
139+
.notToHaveKey( "get", "[get] should not be called on the SessionStorage" );
138140
} );
139141

140142
it( "caches the user from in request scope", function() {
143+
requestStorageMock.$( "exists", false );
141144
sessionStorageMock.$( "exists", true );
142-
sessionStorageMock.$( "getVar", 1 );
145+
sessionStorageMock.$( "get", 1 );
146+
requestStorageMock.$( "get", 1 );
143147
userServiceMock.$( "retrieveUserById" ).$args( 1 ).$results( userMock );
144148

145149
auth.getUser();
146150

147-
expect( requestStorageMock.$once( "setVar" ) ).toBeTrue();
151+
expect( requestStorageMock.$once( "set" ) ).toBeTrue();
148152
requestStorageMock.$( "exists", true );
149153

150154
auth.getUser();
@@ -153,17 +157,17 @@ component extends="testbox.system.BaseSpec" {
153157

154158
expect( sessionStorageCallLog.exists )
155159
.toHaveLength( 1, "[exists] should only have been called once." );
156-
expect( sessionStorageCallLog.getVar )
157-
.toHaveLength( 1, "[getVar] should only have been called once." );
160+
expect( sessionStorageCallLog.get )
161+
.toHaveLength( 1, "[get] should only have been called once." );
158162
} );
159163
} );
160164

161165
describe( "user", function() {
162166
it( "is an alias for getUser", function() {
163167
requestStorageMock.$( "exists", false );
164-
requestStorageMock.$( "getVar", userMock );
168+
requestStorageMock.$( "get", userMock );
165169
sessionStorageMock.$( "exists", true );
166-
sessionStorageMock.$( "getVar", 1 );
170+
sessionStorageMock.$( "get", 1 );
167171
userServiceMock.$( "retrieveUserById" ).$args( 1 ).$results( userMock );
168172

169173
expect( auth.getUser() ).toBe( auth.user() );
@@ -174,28 +178,28 @@ component extends="testbox.system.BaseSpec" {
174178
describe( "logging in", function() {
175179
it( "stores a user id in the session storage", function() {
176180
auth.login( userMock );
177-
expect( sessionStorageMock.$once( "setVar" ) ).toBeTrue();
178-
expect( sessionStorageMock.$callLog().setVar[1][2] ) // first time called, second argument
179-
.toBe( userId, "User id of #userId# should have been passed to `setVar`." );
181+
expect( sessionStorageMock.$once( "set" ) ).toBeTrue();
182+
expect( sessionStorageMock.$callLog().set[1][2] ) // first time called, second argument
183+
.toBe( userId, "User id of #userId# should have been passed to `set`." );
180184
} );
181185

182186
it( "sets the logged in user object in the request scope to save on multiple db requests", function() {
183187
auth.login( userMock );
184-
expect( requestStorageMock.$once( "setVar" ) ).toBeTrue();
185-
expect( requestStorageMock.$callLog().setVar[1][2] ) // first time called, second argument
186-
.toBe( userMock, "User object should have been passed to `setVar`." );
188+
expect( requestStorageMock.$once( "set" ) ).toBeTrue();
189+
expect( requestStorageMock.$callLog().set[1][2] ) // first time called, second argument
190+
.toBe( userMock, "User object should have been passed to `set`." );
187191
} );
188192
} );
189193

190194
describe( "logging out", function() {
191195
it( "logs a user out, regardless of if there was any user logged in", function() {
192-
sessionStorageMock.$( "deleteVar", true );
193-
requestStorageMock.$( "deleteVar", true );
196+
sessionStorageMock.$( "delete", true );
197+
requestStorageMock.$( "delete", true );
194198

195199
auth.logout();
196200

197-
expect( sessionStorageMock.$once( "deleteVar" ) ).toBeTrue();
198-
expect( requestStorageMock.$once( "deleteVar" ) ).toBeTrue();
201+
expect( sessionStorageMock.$once( "delete" ) ).toBeTrue();
202+
expect( requestStorageMock.$once( "delete" ) ).toBeTrue();
199203
} );
200204
} );
201205

@@ -292,9 +296,9 @@ component extends="testbox.system.BaseSpec" {
292296

293297
auth.authenticate( validUsername, correctPassword );
294298

295-
expect( sessionStorageMock.$once( "setVar" ) ).toBeTrue();
296-
expect( sessionStorageMock.$callLog().setVar[1][2] ) // first time called, second argument
297-
.toBe( userId, "User id of #userId# should have been passed to `setVar`." );
299+
expect( sessionStorageMock.$once( "set" ) ).toBeTrue();
300+
expect( sessionStorageMock.$callLog().set[1][2] ) // first time called, second argument
301+
.toBe( userId, "User id of #userId# should have been passed to `set`." );
298302
} );
299303
} );
300304
} );
@@ -316,16 +320,13 @@ component extends="testbox.system.BaseSpec" {
316320
}
317321

318322
function setUpSessionStorage() {
319-
variables.sessionStorageMock = getMockBox()
320-
.createMock( "modules.cbstorages.models.SessionStorage" );
321-
sessionStorageMock.init();
322-
sessionStorageMock.$( "setVar" );
323+
variables.sessionStorageMock = getMockBox().createStub();
324+
sessionStorageMock.$( "set" );
323325
}
324326

325327
function setUpRequestStorage() {
326-
variables.requestStorageMock = getMockBox().createMock( "modules.cbstorages.models.RequestStorage" );
327-
requestStorageMock.init();
328-
requestStorageMock.$( "setVar" );
328+
variables.requestStorageMock = getMockBox().createStub();
329+
requestStorageMock.$( "set" );
329330
}
330331

331332
function setUpUserService() {

0 commit comments

Comments
 (0)