Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #2 from ssorallen/master

Check for User.id before accessing it
  • Loading branch information...
commit abb94eb27f3e13b45fd715f00d404bdccf3bc07f 2 parents cc3266c + 470b88c
Justin Jones authored
6  lib/trebuchet/strategy/percentage.rb
@@ -11,7 +11,11 @@ def offset
11 11
   end
12 12
 
13 13
   def launch_at?(user, request = nil)
14  
-    (user.id + offset) % 100 < percentage
  14
+    if user.id.nil?
  15
+      false
  16
+    else
  17
+      (user.id + offset) % 100 < percentage
  18
+    end
15 19
   end
16 20
 
17 21
 end
5  spec/percentage_strategy_spec.rb
@@ -6,6 +6,11 @@ def offset
6 6
     99 # only works if feature name is 'percentage'
7 7
   end
8 8
 
  9
+  it "should not launch to unsaved users, users with no IDs" do
  10
+    Trebuchet.aim('percentage', :percent, 5)
  11
+    should_not_launch('percentage', [nil])
  12
+  end
  13
+
9 14
   it "should only launch to a percentage of users" do
10 15
     Trebuchet.aim('percentage', :percent, 5)
11 16
     should_launch('percentage', [0, 1, 2, 3, 4, 100, 101, 102, 103, 104].map{|i| i - offset})

0 notes on commit abb94eb

Please sign in to comment.
Something went wrong with that request. Please try again.