Module: TestTrack

Defined in:
lib/test_track.rb,
app/jobs/test_track/application_job.rb,
app/models/test_track/analytics_event.rb,
lib/test_track/server_error_middleware.rb,
app/jobs/test_track/assignment_event_job.rb,
app/jobs/test_track/identifier_creation_job.rb,
lib/generators/test_track/migration_generator.rb,
lib/test_track/delayed_job/job_session_plugin.rb,
lib/test_track/unrecoverable_connectivity_error.rb

Defined Under Namespace

Modules: Analytics, ApplicationHelper, Controller, DelayedJob, Generators, Identity, MisconfigurationNotifier, RemoteModel, RequiredOptions Classes: AbConfiguration, AnalyticsEvent, ApplicationIdentity, ApplicationJob, Assignment, AssignmentEventJob, ConfigUpdater, FakeServer, IdentifierCreationJob, IdentitySessionLocator, JobSession, LazyVisitorByIdentity, NotifyAssignmentJob, OfflineSession, ServerErrorMiddleware, SplitRegistry, ThreadedVisitorNotifier, UnrecoverableConnectivityError, UnsyncedAssignmentsNotifier, VariantCalculator, VaryDsl, Visitor, VisitorDsl, WebSession, WebSessionVisitorRepository

Constant Summary collapse

SERVER_ERRORS =
[Faraday::ConnectionFailed, Faraday::TimeoutError, Her::Errors::RemoteServerError].freeze
BUILD_TIMESTAMP_FILE_PATH =
'testtrack/build_timestamp'.freeze
BUILD_TIMESTAMP_REGEX =
/\A\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d(.\d+)?([+-][0-2]\d:[0-5]\d|Z)\z/

Class Method Summary collapse

Class Method Details

._build_timestampObject



136
137
138
# File 'lib/test_track.rb', line 136

def _build_timestamp
  File.read(BUILD_TIMESTAMP_FILE_PATH).chomp.presence if File.exist?(BUILD_TIMESTAMP_FILE_PATH)
end

._uncredentialed_private_urlObject



127
128
129
130
131
132
133
134
# File 'lib/test_track.rb', line 127

def _uncredentialed_private_url
  return nil unless private_url

  full_uri = URI.parse(private_url)
  full_uri.user = nil
  full_uri.password = nil
  full_uri.to_s
end

.analyticsObject



26
27
28
# File 'lib/test_track.rb', line 26

def analytics
  analytics_wrapper(analytics_instance || mixpanel)
end

.analytics=(*_) ⇒ Object



30
31
32
# File 'lib/test_track.rb', line 30

def analytics=(*_)
  raise "`TestTrack.analytics=` is not longer supported. Please use `TestTrack.analytics_class_name=` instead."
end

.analytics_class_name=(client_class_name) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/test_track.rb', line 34

def analytics_class_name=(client_class_name)
  begin
    client_class = client_class_name.constantize
    client_class.respond_to?(:instance) || client_class.new
  rescue StandardError
    raise "analytics_class_name #{client_class_name} must be a class that can be instantiated without arguments"
  end
  @analytics_class_name = client_class_name
end

.app_ab(split_name, context:) ⇒ Object



144
145
146
# File 'lib/test_track.rb', line 144

def app_ab(split_name, context:)
  app.test_track_ab(split_name, context: context)
end

.build_timestampObject Also known as: set_build_timestamp!

rubocop:disable Metrics/MethodLength



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/test_track.rb', line 58

def build_timestamp # rubocop:disable Metrics/MethodLength
  @build_timestamp ||= begin
    timestamp = _build_timestamp

    if Rails.env.test? || Rails.env.development?
      Time.zone.now.iso8601
    elsif timestamp.present?
      unless BUILD_TIMESTAMP_REGEX.match?(timestamp)
        raise "./testtrack/build_timestamp is not a valid ISO 8601 timestamp, got '#{timestamp}'"
      end

      timestamp
    else
      raise 'TestTrack failed to load the required build timestamp. ' \
        'Ensure `test_track:generate_build_timestamp` task is run in `assets:precompile` and the build timestamp file is present.'
    end
  end
end

.enabled?Boolean

Returns:

  • (Boolean)


140
141
142
# File 'lib/test_track.rb', line 140

def enabled?
  enabled_override.nil? ? !Rails.env.test? : enabled_override
end

.misconfiguration_notifierObject



44
45
46
# File 'lib/test_track.rb', line 44

def misconfiguration_notifier
  TestTrack::MisconfigurationNotifier::Wrapper.new(misconfiguration_notifier_instance || default_notifier)
end

.misconfiguration_notifier_class_name=(notifier_class_name) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/test_track.rb', line 48

def misconfiguration_notifier_class_name=(notifier_class_name)
  begin
    notifier_class = notifier_class_name.constantize
    notifier_class.respond_to?(:instance) || notifier_class.new
  rescue StandardError
    raise "misconfiguration_notifier_class_name #{notifier_class_name} must be a class that can be instantiated without arguments"
  end
  @misconfiguration_notifier_class_name = notifier_class_name
end

.private_urlObject



123
124
125
# File 'lib/test_track.rb', line 123

def private_url
  ENV['TEST_TRACK_API_URL']
end

.public_urlObject



119
120
121
# File 'lib/test_track.rb', line 119

def public_url
  ENV['TEST_TRACK_PUBLIC_API_URL'] || _uncredentialed_private_url
end

.update_config {|ConfigUpdater.new| ... } ⇒ Object

Yields:



115
116
117
# File 'lib/test_track.rb', line 115

def update_config
  yield(ConfigUpdater.new)
end