lib/field_test/helpers.rb in field_test-0.1.0 vs lib/field_test/helpers.rb in field_test-0.1.1

- old
+ new

@@ -22,10 +22,22 @@ participants = field_test_participants(options) exp.convert(participants) end + 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| + experiments[membership.experiment] ||= membership.variant + end + end + experiments + end + def field_test_participants(options = {}) participants = [] if options[:participant] participants << options[:participant] @@ -46,9 +58,9 @@ participants << "cookie:#{token.gsub(/[^a-z0-9\-]/i, "")}" end end end - participants + FieldTest::Participant.standardize(participants) end end end