Module: FieldTest::Controller

Extended by:
ActiveSupport::Concern
Includes:
Helpers
Defined in:
lib/field_test/controller.rb

Instance Method Summary collapse

Methods included from Helpers

#field_test, #field_test_converted, #field_test_experiments

Instance Method Details

#field_test_upgrade_memberships(options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/field_test/controller.rb', line 14

def field_test_upgrade_memberships(options = {})
  participants = FieldTest::Participant.standardize(options[:participant] || field_test_participant)
  preferred = participants.first
  Array(participants[1..-1]).each do |participant|
    # can do this in single query once legacy_participants is removed
    FieldTest::Membership.where(participant.where_values).each do |membership|
      membership.participant = preferred.participant if membership.respond_to?(:participant=)
      membership.participant_type = preferred.type if membership.respond_to?(:participant_type=)
      membership.participant_id = preferred.id if membership.respond_to?(:participant_id=)
      membership.save!
    end
  end
end