banana_split 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2010 Dennis Plougmann Buus and Rasmus Rønn Nielsen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,42 @@
1
+ == Banana Split
2
+
3
+ Banana Split is a simple lightweight split testing utility for Rails. It makes it extremely easy to tests different designs on your users:
4
+
5
+ <%= ab_test :buy_form, :colorful => 'shop/colorful_buy_form', :simplistic => 'shop/simplistic_buy_form' %>
6
+
7
+ Here, Bananasplit will render the shop/colorful_buy_form partial 50% of the times, and shop/simplistic_buy_form the other 50%. On the immediate action after purchase do like so to complete the goal:
8
+
9
+ def receipt
10
+ ab_goal :buy_form
11
+ # whatever...
12
+ end
13
+
14
+ The ab_goal takes the value of the goal completion as a second argument - it defaults to 1.
15
+
16
+ == Other examples
17
+
18
+ <%= submit_tag ab_test(:sign_up_button_text, {
19
+ :standard => { :text => 'Create user' },
20
+ :funky => { :text => 'Come on in!' }
21
+ }) %>
22
+
23
+ <%= submit_tag ab_test(:welcome_message, {
24
+ :simple => { :partial => 'welcome/simple_welcome_message', :locals => { :statistics => @statistics },
25
+ :complex => { :partial => 'welcome/complex_welcome_message', :locals => { :statistics => @statistics }
26
+ }) %>
27
+
28
+ == Showing test results
29
+
30
+ Banana Split currently provides no ways of rendering the split test results but the included models makes it very easy to do so.
31
+
32
+ == Installation
33
+
34
+ Add banana_split to your Gemfile:
35
+
36
+ gem 'banana_split'
37
+
38
+ And run the installer:
39
+
40
+ rails generate banana_split
41
+
42
+ ... and you're ready to go :)
@@ -0,0 +1,21 @@
1
+ module BananaSplit
2
+ module Controller
3
+ def self.included(base)
4
+ base.class_eval do
5
+ helper_method :current_user_id
6
+ end
7
+ end
8
+
9
+ def ab_goal(test_name, value = 1)
10
+ test_run = AbTestRun.last :conditions => { :user_id => current_user_id }
11
+ if test_run && test_run.value == 0
12
+ test_run.update_attribute(:value, value)
13
+ end
14
+ end
15
+
16
+ def current_user_id
17
+ current_user.id
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ module BananaSplit
2
+ module VERSION
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 1
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,20 @@
1
+ module BananaSplit
2
+ module ViewHelpers
3
+
4
+ def ab_test(test_name, designs)
5
+ test = AbTest.find_or_create_by_name(:name => test_name.to_s)
6
+
7
+ design_name = designs.keys.sample
8
+ design_render_options = designs[design_name]
9
+ design = AbTestDesign.find_or_create_by_ab_test_id_and_name :ab_test_id => test.id, :name => design_name.to_s
10
+
11
+ test_run = test.runs.create({
12
+ :ab_test_design_id => design.id,
13
+ :user_id => current_user_id
14
+ })
15
+
16
+ design_render_options ? render(design_render_options) : nil
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ module BananaSplit
2
+ class << self
3
+
4
+ def enable
5
+ enable_view_helpers
6
+ enable_controller
7
+ end
8
+
9
+ def enable_view_helpers
10
+ require 'banana_split/view_helpers'
11
+ ActionView::Base.send :include, ViewHelpers
12
+ end
13
+
14
+ def enable_controller
15
+ require 'banana_split/controller'
16
+ ActionController::Base.send :include, Controller
17
+ end
18
+
19
+ end
20
+ end
21
+
22
+ BananaSplit.enable
@@ -0,0 +1,25 @@
1
+ module BananaSplit
2
+ module Generators
3
+ class BananaSplitGenerator < Rails::Generators::Base
4
+ include Rails::Generators::Migration
5
+
6
+ source_root File.expand_path("../templates", __FILE__)
7
+ namespace "banana_split"
8
+
9
+ def create_models
10
+ copy_file "models/ab_test.rb", "app/models/ab_test.rb"
11
+ copy_file "models/ab_test_design.rb", "app/models/ab_test_design.rb"
12
+ copy_file "models/ab_test_run.rb", "app/models/ab_test_run.rb"
13
+ end
14
+
15
+ def create_migration
16
+ migration_template "migrations/migration.rb", "db/migrate/create_banana_split_tables"
17
+ end
18
+
19
+ def self.next_migration_number(path)
20
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ class CreateBananaSplitTables < ActiveRecord::Migration
2
+ def self.up
3
+ create_table(:ab_tests) do |t|
4
+ t.string :name
5
+ end
6
+
7
+ create_table(:ab_test_designs) do |t|
8
+ t.references :ab_test
9
+ t.string :name
10
+ end
11
+
12
+ create_table(:ab_test_runs) do |t|
13
+ t.references :user
14
+ t.references :ab_test
15
+ t.references :ab_test_design
16
+ t.integer :value, :null => false, :default => 0
17
+ end
18
+ end
19
+
20
+ def self.down
21
+ drop_table :ab_tests
22
+ drop_table :ab_test_designs
23
+ drop_table :ab_test_runs
24
+ end
25
+ end
@@ -0,0 +1,4 @@
1
+ class AbTest < ActiveRecord::Base
2
+ has_many :designs, :class_name => 'AbTestDesign', :dependent => :destroy
3
+ has_many :runs, :class_name => 'AbTestRun', :dependent => :destroy
4
+ end
@@ -0,0 +1,3 @@
1
+ class AbTestDesign < ActiveRecord::Base
2
+ belongs_to :ab_test
3
+ end
@@ -0,0 +1,3 @@
1
+ class AbTestRun < ActiveRecord::Base
2
+ belongs_to :ab_test
3
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: banana_split
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Dennis Plougman Buus
13
+ - "Rasmus R\xC3\xB8nn Nielsen"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-28 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Description not written yet.
23
+ email: rasmusrnielsen@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/banana_split/controller.rb
32
+ - lib/banana_split/version.rb
33
+ - lib/banana_split/view_helpers.rb
34
+ - lib/banana_split.rb
35
+ - lib/generators/banana_split_generator.rb
36
+ - lib/generators/templates/migrations/migration.rb
37
+ - lib/generators/templates/models/ab_test.rb
38
+ - lib/generators/templates/models/ab_test_design.rb
39
+ - lib/generators/templates/models/ab_test_run.rb
40
+ - README.rdoc
41
+ - LICENSE
42
+ has_rdoc: true
43
+ homepage:
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ requirements: []
68
+
69
+ rubyforge_project:
70
+ rubygems_version: 1.3.7
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: AB testing for Rails
74
+ test_files: []
75
+