Class: SplitTester::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/split_tester.rb

Class Method Summary collapse

Class Method Details

.active_test?(key) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
64
# File 'lib/split_tester.rb', line 61

def self.active_test?(key)
  return false unless LOADED
  SPLIT_TESTS.has_key?(key)
end

.custom_view_path(name) ⇒ Object



57
58
59
# File 'lib/split_tester.rb', line 57

def self.custom_view_path(name)
  name == "views" ? "app/views" : "test/split/#{name}/views"
end

.preprocessed_pathsetsObject



53
54
55
# File 'lib/split_tester.rb', line 53

def self.preprocessed_pathsets
  @@preprocessed_pathsets
end

.random_test_keyObject



70
71
72
# File 'lib/split_tester.rb', line 70

def self.random_test_key
  split_test_map.sample
end

.setupObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/split_tester.rb', line 21

def self.setup
  if LOADED
    # Add the split test language files to the load path
    I18n.load_path += Dir[Rails.root.join('test', 'split', '*', 'locale.{rb,yml}')]

    @@preprocessed_pathsets = begin
      self.test_keys.inject({}) do |pathsets, slug|
        path = custom_view_path(slug)
        pathsets[path] = ActionView::Base.process_view_paths(path).first
        pathsets
      end
    end

    @@split_test_map = begin
      tm = {} # test map
      SPLIT_TESTS.each { |k, v| tm[k] = v['size'].to_i }
      tm.keys.zip(tm.values).collect { |v,d| (0...d).collect { v }}.flatten
    end
  else
    @@split_test_map = []
    @@preprocessed_pathsets = []
  end
end

.split_test_mapObject



45
46
47
# File 'lib/split_tester.rb', line 45

def self.split_test_map
  @@split_test_map
end

.test_keysObject



49
50
51
# File 'lib/split_tester.rb', line 49

def self.test_keys
  @test_keys ||= SPLIT_TESTS.keys.reject { |k| k == 'BASELINE' }
end

.view_path(key) ⇒ Object



66
67
68
# File 'lib/split_tester.rb', line 66

def self.view_path(key)
  preprocessed_pathsets[custom_view_path(key)]
end