Class: RailsOnboarding::Admin::AbTestsController

Inherits:
BaseController show all
Defined in:
app/controllers/rails_onboarding/admin/ab_tests_controller.rb

Overview

Admin A/B tests controller View and toggle the A/B tests defined in RailsOnboarding.configuration.ab_tests, and inspect their results. Tests are config-defined (see RailsOnboarding::AbTestable), so there is no create/edit/destroy here - only viewing and enabling/disabling.

Constant Summary

Constants inherited from BaseController

BaseController::DEFAULT_PER_PAGE, BaseController::MAX_PER_PAGE

Instance Method Summary collapse

Instance Method Details

#exportObject



45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/rails_onboarding/admin/ab_tests_controller.rb', line 45

def export
  results = calculate_results(@test_name, @test_config)

  respond_to do |format|
    format.csv do
      send_data generate_csv_export(results),
        filename: "ab_test_#{@test_name}_results_#{Date.current}.csv",
        type: "text/csv"
    end
  end
end

#indexObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/rails_onboarding/admin/ab_tests_controller.rb', line 12

def index
  @ab_tests = ab_tests_collection
  @active_tests = @ab_tests.select { |t| t[:enabled] }
  @inactive_tests = @ab_tests.reject { |t| t[:enabled] }

  # The screen renders two lists off one collection, so paginate the
  # concatenation - active first, matching the order the sections appear in -
  # and split the current page back out. Paginating the two lists separately
  # would need two page parameters and two navs.
  #
  # @active_tests/@inactive_tests stay whole so the stat cards keep reporting
  # collection totals rather than per-page counts.
  @pagy, page_of_tests = paginate(@active_tests + @inactive_tests)
  @page_active_tests = page_of_tests.select { |t| t[:enabled] }
  @page_inactive_tests = page_of_tests.reject { |t| t[:enabled] }
end

#showObject



29
30
31
# File 'app/controllers/rails_onboarding/admin/ab_tests_controller.rb', line 29

def show
  @results = calculate_results(@test_name, @test_config)
end

#startObject



33
34
35
36
37
# File 'app/controllers/rails_onboarding/admin/ab_tests_controller.rb', line 33

def start
  set_enabled(true)
  flash[:notice] = "A/B test '#{@test_name}' started"
  redirect_to admin_ab_test_path(@test_name)
end

#stopObject



39
40
41
42
43
# File 'app/controllers/rails_onboarding/admin/ab_tests_controller.rb', line 39

def stop
  set_enabled(false)
  flash[:notice] = "A/B test '#{@test_name}' stopped"
  redirect_to admin_ab_test_path(@test_name)
end