Skip to content

Commit

Permalink
Fixing problem reading searching for cookie value in the same request…
Browse files Browse the repository at this point in the history
… that sets it.
  • Loading branch information
rdh committed Jan 20, 2014
1 parent d5c95d8 commit dd82707
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Create or add to `config/initializers/split_cat.rb`:

end

### Implement Hypotheses
### Implement Hypotheses Views

Create partials for each hypothesis. e.g. `button_a.html.erb` and `button_b.html.erb`

Expand All @@ -87,6 +87,13 @@ When rendering the partial, scope it with the experiment:

This will cause the partial to use the hypothesis assigned for the user/token.

### Implement Hypothesis Logic

You can get a raw hypothesis symbol for logic-based experiments:

hypothesis = split_cat_hypothesis( name, token )
do_something if hypothesis == :a

### Record Goals

Call `split_cat_goal` to record a goal achieved by a user:
Expand Down
13 changes: 7 additions & 6 deletions lib/split_cat/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,21 @@ def split_cat_scope( root, name, token, hypothesis = nil )
# #set_split_cat_cookie

def set_split_cat_cookie( options = {} )
@split_cat_token = cookies[ :split_cat_token ]

# Create a Subject for the cookie token, if it doesn't exist

if cookies[ :split_cat_token ] && cookies[ :split_cat_token ][ :value ] &&
!Subject.where( :token => cookies[ :split_cat_token ][ :value ] ).first
split_cat_token( cookies[ :split_cat_token ] )
if @split_cat_token && !Subject.where( :token => @split_cat_token ).first
split_cat_token( @split_cat_token )
end

if options[ :force ] || !cookies[ :split_cat_token ]
if options[ :force ] || !@split_cat_token
expires = SplitCat.config.cookie_expiration.from_now
cookies[ :split_cat_token ] = { :value => split_cat_token, :expires => expires }
@split_cat_token = split_cat_token
cookies[ :split_cat_token ] = { :value => @split_cat_token, :expires => expires }
end

@split_cat_token = cookies[ :split_cat_token ]
return @split_cat_token
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/split_cat/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module SplitCat
VERSION = '0.0.7'
VERSION = '0.0.8'
end
1 change: 1 addition & 0 deletions spec/lib/split_cat/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ module SplitCat

it 'assigns a cookie when passed the :force option' do
token = set_split_cat_cookie
@cookies[ :split_cat_token ] = token # Hack to prevent lookup including expires value
set_split_cat_cookie.should eql( token )
set_split_cat_cookie( :force => true ).should_not eql( token )
end
Expand Down

0 comments on commit dd82707

Please sign in to comment.