Permalink
Browse files

Merge pull request #2 from ssorallen/master

Check for User.id before accessing it
  • Loading branch information...
devpuppy committed May 4, 2012
2 parents cc3266c + 470b88c commit abb94eb27f3e13b45fd715f00d404bdccf3bc07f
Showing with 10 additions and 1 deletion.
  1. +5 −1 lib/trebuchet/strategy/percentage.rb
  2. +5 −0 spec/percentage_strategy_spec.rb
@@ -11,7 +11,11 @@ def offset
end
def launch_at?(user, request = nil)
- (user.id + offset) % 100 < percentage
+ if user.id.nil?
+ false
+ else
+ (user.id + offset) % 100 < percentage
+ end
end
end
@@ -6,6 +6,11 @@ def offset
99 # only works if feature name is 'percentage'
end
+ it "should not launch to unsaved users, users with no IDs" do
+ Trebuchet.aim('percentage', :percent, 5)
+ should_not_launch('percentage', [nil])
+ end
+
it "should only launch to a percentage of users" do
Trebuchet.aim('percentage', :percent, 5)
should_launch('percentage', [0, 1, 2, 3, 4, 100, 101, 102, 103, 104].map{|i| i - offset})

0 comments on commit abb94eb

Please sign in to comment.