lib/field_test/helpers.rb in field_test-0.1.1 vs lib/field_test/helpers.rb in field_test-0.1.2
- old
+ new
@@ -7,10 +7,14 @@
if try(:request)
if params[:field_test] && params[:field_test][experiment]
options[:variant] ||= params[:field_test][experiment]
end
+
+ if FieldTest.exclude_bots?
+ options[:exclude] = Browser.new(request.user_agent).bot?
+ end
end
# cache results for request
@field_test_cache ||= {}
@field_test_cache[experiment] ||= exp.variant(participants, options)
@@ -27,11 +31,11 @@
def field_test_experiments(options = {})
participants = field_test_participants(options)
memberships = FieldTest::Membership.where(participant: participants).group_by(&:participant)
experiments = {}
participants.each do |participant|
- memberships[participant].each do |membership|
+ memberships[participant].to_a.each do |membership|
experiments[membership.experiment] ||= membership.variant
end
end
experiments
end
@@ -44,10 +48,11 @@
else
if respond_to?(:current_user, true) && current_user
participants << current_user
end
+ # controllers and views
if try(:request)
# use cookie
cookie_key = "field_test"
token = cookies[cookie_key]
if participants.empty? && !token
@@ -55,9 +60,15 @@
cookies[cookie_key] = {value: token, expires: 30.days.from_now}
end
if token
participants << "cookie:#{token.gsub(/[^a-z0-9\-]/i, "")}"
end
+ end
+
+ # mailers
+ to = try(:message).try(:to).try(:first)
+ if to
+ participants << to
end
end
FieldTest::Participant.standardize(participants)
end