lib/field_test/helpers.rb in field_test-0.3.0 vs lib/field_test/helpers.rb in field_test-0.3.1

- old
+ new

@@ -1,14 +1,16 @@ module FieldTest module Helpers - def field_test(experiment, options = {}) + def field_test(experiment, **options) exp = FieldTest::Experiment.find(experiment) - participants = FieldTest::Participant.standardize(field_test_participant, options) + participants = FieldTest::Participant.standardize(options[:participant] || field_test_participant) if try(:request) - if !options[:variant] && params[:field_test] && params[:field_test][experiment] + options = options.dup + + if !options[:variant] && params[:field_test] && params[:field_test][experiment] && exp.variants.include?(params[:field_test][experiment]) params_variant = params[:field_test][experiment] end if FieldTest.exclude_bots? options[:exclude] = Browser.new(request.user_agent).bot? @@ -23,20 +25,20 @@ # don't update variant when passed via params @field_test_cache[experiment] ||= params_variant || exp.variant(participants, options) end - def field_test_converted(experiment, options = {}) + def field_test_converted(experiment, **options) exp = FieldTest::Experiment.find(experiment) - participants = FieldTest::Participant.standardize(field_test_participant, options) + participants = FieldTest::Participant.standardize(options[:participant] || field_test_participant) exp.convert(participants, goal: options[:goal]) end # TODO fetch in single query - def field_test_experiments(options = {}) - participants = FieldTest::Participant.standardize(field_test_participant, options) + def field_test_experiments(**options) + participants = FieldTest::Participant.standardize(options[:participant] || field_test_participant) experiments = {} participants.each do |participant| FieldTest::Membership.where(participant.where_values).each do |membership| experiments[membership.experiment] ||= membership.variant end