Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
Fix for issue #11, a visitor with a non-valid combination is now kick…
Browse files Browse the repository at this point in the history
…ed to the next new valid one.
  • Loading branch information
markmandel committed Nov 4, 2011
1 parent d32143c commit 4b74b34
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 12 deletions.
11 changes: 7 additions & 4 deletions squabble/Squabble.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,21 @@
access="public" returntype="void" output="false">
<cfargument name="testName" hint="the name of the test." type="string" required="Yes">
<cfscript>
//Question: would this section be easier to read as a single if with OR statement, or as it is?

//skip disabled
if(isTestDisabled(arguments.testname))
{
return;
}

//make it easier for testing, as deleting a cookie just makes it an empty string, rather than removing the key.
if(getVisitor().hasCombination(arguments.testName))
{
return;
if(arrayContains(listTestCombinations(arguments.testName), getCurrentCombination(arguments.testName)))
{
return;
}

//if the test has been disabled, or if someone has messed with thier cookie, give them something new.
getVisitor().clearCombination(arguments.testName);
}

//if it's a crawler, then dump it.
Expand Down
21 changes: 20 additions & 1 deletion squabble/Visitor.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@
</cfscript>
</cffunction>

<cffunction name="clearCombination" hint="clear out the combination for a given test" access="public" returntype="void" output="false">
<cfargument name="testname" hint="the name of the test to get the variations for." type="string" required="Yes">

<cfif hasCombination(arguments.testname)>
<cfscript>
var cookieKey = createTestCombinationCookieKey(arguments.testname);
var requestKey = getRequestScopeKey(arguments.testname);

structDelete(request, requestKey);
</cfscript>
</cfif>
<cfcookie name="#cookieKey#" value="" expires="183">
</cffunction>

<!------------------------------------------- PACKAGE ------------------------------------------->

<!------------------------------------------- PRIVATE ------------------------------------------->
Expand All @@ -93,7 +107,7 @@
<cfargument name="testname" hint="the name of the test to deserialise" type="string" required="Yes">
<cfscript>
//store all our bits in a request scope variable.
var key = "squabble-" & arguments.testName;
var key = getRequestScopeKey(arguments.testName);
if(!StructKeyExists(request, key))
{
request[key] = deserializeJSON(cookie[createTestCombinationCookieKey(arguments.testName)]);
Expand All @@ -103,6 +117,11 @@
</cfscript>
</cffunction>

<cffunction name="getRequestScopeKey" hint="create the request scope key for storing deserialised combos" access="private" returntype="string" output="false">
<cfargument name="testname" hint="the name of the test to deserialise" type="string" required="Yes">
<cfreturn "squabble-" & arguments.testName />
</cffunction>

<cffunction name="getPreviewCombination" hint="returns a preview combination" access="public" returntype="struct" output="false">
<cfscript>
var combination = {};
Expand Down
35 changes: 35 additions & 0 deletions unittests/service/ServiceTest.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,41 @@
</cfscript>
</cffunction>

<cffunction name="testResetDisabledCombination" hint="test that a combination that has already been set, gets reset after it gets disabled"
access="public" returntype="void" output="false">
<cfscript>
clearSquabbleCookies();
service.registerTest("foo", testConfig);

//make sure it's not on control
service.runTest("foo");
clearSquabbleCookies();
service.runTest("foo");
clearSquabbleCookies();
service.runTest("foo");

var combos = service.listTestCombinations("foo");
combos = duplicate(combos);

debug(service.getCurrentCombination("foo"));

var combo = {barsection="test5", foosection="control"};

assertEquals(combo, service.getCurrentCombination("foo"));

service.removeCombination("foo", combo);

var reget = service.listTestCombinations("foo");

//make sure remove works
assertNotEquals(reget, combos);

service.runTest("foo");

assertNotEquals(combo, service.getCurrentCombination("foo"));
</cfscript>
</cffunction>

<!------------------------------------------- PACKAGE ------------------------------------------->

<!------------------------------------------- PRIVATE ------------------------------------------->
Expand Down
8 changes: 1 addition & 7 deletions unittests/tags/TagsTest.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,7 @@
<cffunction name="noSectionTest" hint="test tag functionality for a user whose cookie is missing a test section" access="public" returntype="void" output="false">
<cftransaction>
<cfscript>
//mock out the response we want
var visitor = mock(service.getVisitor());

visitor.isEnabled().returns(true);
visitor.hasCombination("foo").returns(true);
visitor.getCombination().returns({ barSection = "test4" });
service.setVisitor(visitor);
service.getVisitor().setCombination("foo", createUUID(),{ barSection = "test4" });

service.registerTest("foo", testConfig);
service.runTest("foo");
Expand Down

0 comments on commit 4b74b34

Please sign in to comment.