a_b 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +18 -0
- data/README.markdown +4 -0
- data/Rakefile +74 -0
- data/config.ru +3 -0
- data/config/database.example.yml +6 -0
- data/config/externals.yml +6 -0
- data/config/mail.example.yml +32 -0
- data/db/migrate/001_a_b_tests.rb +14 -0
- data/db/migrate/002_a_b_variants.rb +19 -0
- data/db/migrate/003_a_b_users.rb +25 -0
- data/db/migrate/004_a_b_tokens.rb +12 -0
- data/features/example.feature +10 -0
- data/features/support/env.rb +35 -0
- data/features/support/rspec.rb +11 -0
- data/features/support/webrat.rb +3 -0
- data/gemspec.rb +41 -0
- data/lib/a_b.rb +31 -0
- data/lib/a_b/boot.rb +30 -0
- data/lib/a_b/controller/api.rb +32 -0
- data/lib/a_b/controller/application.rb +6 -0
- data/lib/a_b/controller/index.rb +16 -0
- data/lib/a_b/controller/sessions.rb +28 -0
- data/lib/a_b/controller/tests.rb +37 -0
- data/lib/a_b/controller/variants.rb +14 -0
- data/lib/a_b/helper/api.rb +8 -0
- data/lib/a_b/helper/application.rb +56 -0
- data/lib/a_b/helper/index.rb +12 -0
- data/lib/a_b/model/a_b_test.rb +65 -0
- data/lib/a_b/model/a_b_variant.rb +131 -0
- data/lib/a_b/model/token.rb +22 -0
- data/lib/a_b/model/user.rb +5 -0
- data/lib/a_b/model/user_session.rb +4 -0
- data/lib/a_b/view/index.haml +129 -0
- data/lib/a_b/view/index.sass +55 -0
- data/lib/a_b/view/layout.haml +15 -0
- data/lib/a_b/view/layout.sass +34 -0
- data/lib/a_b/view/log_in.haml +15 -0
- data/lib/a_b/view/log_in.sass +11 -0
- data/public/css/blueprint/ie.css +35 -0
- data/public/css/blueprint/print.css +29 -0
- data/public/css/blueprint/screen.css +257 -0
- data/public/js/index.js +126 -0
- data/public/js/jquery.js +19 -0
- data/public/js/visit.js +59 -0
- data/script/console +2 -0
- data/script/env.rb +30 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +16 -0
- data/vendor/authlogic/CHANGELOG.rdoc +345 -0
- data/vendor/authlogic/LICENSE +20 -0
- data/vendor/authlogic/README.rdoc +246 -0
- data/vendor/authlogic/Rakefile +42 -0
- data/vendor/authlogic/VERSION.yml +5 -0
- data/vendor/authlogic/authlogic.gemspec +217 -0
- data/vendor/authlogic/generators/session/session_generator.rb +9 -0
- data/vendor/authlogic/generators/session/templates/session.rb +2 -0
- data/vendor/authlogic/init.rb +1 -0
- data/vendor/authlogic/lib/authlogic.rb +57 -0
- data/vendor/authlogic/lib/authlogic/acts_as_authentic/base.rb +107 -0
- data/vendor/authlogic/lib/authlogic/acts_as_authentic/email.rb +110 -0
- data/vendor/authlogic/lib/authlogic/acts_as_authentic/logged_in_status.rb +60 -0
- data/vendor/authlogic/lib/authlogic/acts_as_authentic/login.rb +141 -0
- data/vendor/authlogic/lib/authlogic/acts_as_authentic/magic_columns.rb +24 -0
- data/vendor/authlogic/lib/authlogic/acts_as_authentic/password.rb +344 -0
- data/vendor/authlogic/lib/authlogic/acts_as_authentic/perishable_token.rb +105 -0
- data/vendor/authlogic/lib/authlogic/acts_as_authentic/persistence_token.rb +68 -0
- data/vendor/authlogic/lib/authlogic/acts_as_authentic/restful_authentication.rb +61 -0
- data/vendor/authlogic/lib/authlogic/acts_as_authentic/session_maintenance.rb +139 -0
- data/vendor/authlogic/lib/authlogic/acts_as_authentic/single_access_token.rb +65 -0
- data/vendor/authlogic/lib/authlogic/acts_as_authentic/validations_scope.rb +32 -0
- data/vendor/authlogic/lib/authlogic/authenticates_many/association.rb +42 -0
- data/vendor/authlogic/lib/authlogic/authenticates_many/base.rb +55 -0
- data/vendor/authlogic/lib/authlogic/controller_adapters/abstract_adapter.rb +67 -0
- data/vendor/authlogic/lib/authlogic/controller_adapters/merb_adapter.rb +30 -0
- data/vendor/authlogic/lib/authlogic/controller_adapters/rails_adapter.rb +48 -0
- data/vendor/authlogic/lib/authlogic/controller_adapters/sinatra_adapter.rb +61 -0
- data/vendor/authlogic/lib/authlogic/crypto_providers/aes256.rb +43 -0
- data/vendor/authlogic/lib/authlogic/crypto_providers/bcrypt.rb +90 -0
- data/vendor/authlogic/lib/authlogic/crypto_providers/md5.rb +34 -0
- data/vendor/authlogic/lib/authlogic/crypto_providers/sha1.rb +35 -0
- data/vendor/authlogic/lib/authlogic/crypto_providers/sha256.rb +50 -0
- data/vendor/authlogic/lib/authlogic/crypto_providers/sha512.rb +50 -0
- data/vendor/authlogic/lib/authlogic/crypto_providers/wordpress.rb +43 -0
- data/vendor/authlogic/lib/authlogic/i18n.rb +83 -0
- data/vendor/authlogic/lib/authlogic/i18n/translator.rb +15 -0
- data/vendor/authlogic/lib/authlogic/random.rb +33 -0
- data/vendor/authlogic/lib/authlogic/regex.rb +25 -0
- data/vendor/authlogic/lib/authlogic/session/activation.rb +58 -0
- data/vendor/authlogic/lib/authlogic/session/active_record_trickery.rb +61 -0
- data/vendor/authlogic/lib/authlogic/session/base.rb +37 -0
- data/vendor/authlogic/lib/authlogic/session/brute_force_protection.rb +96 -0
- data/vendor/authlogic/lib/authlogic/session/callbacks.rb +88 -0
- data/vendor/authlogic/lib/authlogic/session/cookies.rb +130 -0
- data/vendor/authlogic/lib/authlogic/session/existence.rb +93 -0
- data/vendor/authlogic/lib/authlogic/session/foundation.rb +63 -0
- data/vendor/authlogic/lib/authlogic/session/http_auth.rb +58 -0
- data/vendor/authlogic/lib/authlogic/session/id.rb +41 -0
- data/vendor/authlogic/lib/authlogic/session/klass.rb +78 -0
- data/vendor/authlogic/lib/authlogic/session/magic_columns.rb +95 -0
- data/vendor/authlogic/lib/authlogic/session/magic_states.rb +59 -0
- data/vendor/authlogic/lib/authlogic/session/params.rb +101 -0
- data/vendor/authlogic/lib/authlogic/session/password.rb +240 -0
- data/vendor/authlogic/lib/authlogic/session/perishable_token.rb +18 -0
- data/vendor/authlogic/lib/authlogic/session/persistence.rb +70 -0
- data/vendor/authlogic/lib/authlogic/session/priority_record.rb +34 -0
- data/vendor/authlogic/lib/authlogic/session/scopes.rb +101 -0
- data/vendor/authlogic/lib/authlogic/session/session.rb +62 -0
- data/vendor/authlogic/lib/authlogic/session/timeout.rb +82 -0
- data/vendor/authlogic/lib/authlogic/session/unauthorized_record.rb +50 -0
- data/vendor/authlogic/lib/authlogic/session/validation.rb +82 -0
- data/vendor/authlogic/lib/authlogic/test_case.rb +120 -0
- data/vendor/authlogic/lib/authlogic/test_case/mock_controller.rb +45 -0
- data/vendor/authlogic/lib/authlogic/test_case/mock_cookie_jar.rb +14 -0
- data/vendor/authlogic/lib/authlogic/test_case/mock_logger.rb +10 -0
- data/vendor/authlogic/lib/authlogic/test_case/mock_request.rb +19 -0
- data/vendor/authlogic/lib/authlogic/test_case/rails_request_adapter.rb +30 -0
- data/vendor/authlogic/rails/init.rb +1 -0
- data/vendor/authlogic/shoulda_macros/authlogic.rb +69 -0
- data/vendor/authlogic/test/acts_as_authentic_test/base_test.rb +18 -0
- data/vendor/authlogic/test/acts_as_authentic_test/email_test.rb +97 -0
- data/vendor/authlogic/test/acts_as_authentic_test/logged_in_status_test.rb +36 -0
- data/vendor/authlogic/test/acts_as_authentic_test/login_test.rb +109 -0
- data/vendor/authlogic/test/acts_as_authentic_test/magic_columns_test.rb +27 -0
- data/vendor/authlogic/test/acts_as_authentic_test/password_test.rb +236 -0
- data/vendor/authlogic/test/acts_as_authentic_test/perishable_token_test.rb +90 -0
- data/vendor/authlogic/test/acts_as_authentic_test/persistence_token_test.rb +55 -0
- data/vendor/authlogic/test/acts_as_authentic_test/restful_authentication_test.rb +40 -0
- data/vendor/authlogic/test/acts_as_authentic_test/session_maintenance_test.rb +84 -0
- data/vendor/authlogic/test/acts_as_authentic_test/single_access_test.rb +44 -0
- data/vendor/authlogic/test/authenticates_many_test.rb +16 -0
- data/vendor/authlogic/test/crypto_provider_test/aes256_test.rb +14 -0
- data/vendor/authlogic/test/crypto_provider_test/bcrypt_test.rb +14 -0
- data/vendor/authlogic/test/crypto_provider_test/sha1_test.rb +23 -0
- data/vendor/authlogic/test/crypto_provider_test/sha256_test.rb +14 -0
- data/vendor/authlogic/test/crypto_provider_test/sha512_test.rb +14 -0
- data/vendor/authlogic/test/fixtures/companies.yml +5 -0
- data/vendor/authlogic/test/fixtures/employees.yml +17 -0
- data/vendor/authlogic/test/fixtures/projects.yml +3 -0
- data/vendor/authlogic/test/fixtures/users.yml +24 -0
- data/vendor/authlogic/test/i18n_test.rb +33 -0
- data/vendor/authlogic/test/libs/affiliate.rb +7 -0
- data/vendor/authlogic/test/libs/company.rb +6 -0
- data/vendor/authlogic/test/libs/employee.rb +7 -0
- data/vendor/authlogic/test/libs/employee_session.rb +2 -0
- data/vendor/authlogic/test/libs/ldaper.rb +3 -0
- data/vendor/authlogic/test/libs/ordered_hash.rb +9 -0
- data/vendor/authlogic/test/libs/project.rb +3 -0
- data/vendor/authlogic/test/libs/user.rb +5 -0
- data/vendor/authlogic/test/libs/user_session.rb +6 -0
- data/vendor/authlogic/test/random_test.rb +49 -0
- data/vendor/authlogic/test/session_test/activation_test.rb +43 -0
- data/vendor/authlogic/test/session_test/active_record_trickery_test.rb +36 -0
- data/vendor/authlogic/test/session_test/brute_force_protection_test.rb +101 -0
- data/vendor/authlogic/test/session_test/callbacks_test.rb +6 -0
- data/vendor/authlogic/test/session_test/cookies_test.rb +112 -0
- data/vendor/authlogic/test/session_test/credentials_test.rb +0 -0
- data/vendor/authlogic/test/session_test/existence_test.rb +64 -0
- data/vendor/authlogic/test/session_test/http_auth_test.rb +28 -0
- data/vendor/authlogic/test/session_test/id_test.rb +17 -0
- data/vendor/authlogic/test/session_test/klass_test.rb +40 -0
- data/vendor/authlogic/test/session_test/magic_columns_test.rb +62 -0
- data/vendor/authlogic/test/session_test/magic_states_test.rb +60 -0
- data/vendor/authlogic/test/session_test/params_test.rb +53 -0
- data/vendor/authlogic/test/session_test/password_test.rb +106 -0
- data/vendor/authlogic/test/session_test/perishability_test.rb +15 -0
- data/vendor/authlogic/test/session_test/persistence_test.rb +21 -0
- data/vendor/authlogic/test/session_test/scopes_test.rb +60 -0
- data/vendor/authlogic/test/session_test/session_test.rb +59 -0
- data/vendor/authlogic/test/session_test/timeout_test.rb +52 -0
- data/vendor/authlogic/test/session_test/unauthorized_record_test.rb +13 -0
- data/vendor/authlogic/test/session_test/validation_test.rb +23 -0
- data/vendor/authlogic/test/test_helper.rb +182 -0
- metadata +325 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2009 Winton Welsh
|
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.markdown
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
gems = [
|
4
|
+
[ 'cucumber', '=0.4.3' ],
|
5
|
+
[ 'rspec', '=1.2.9' ],
|
6
|
+
[ 'active_wrapper', '=0.2.1' ]
|
7
|
+
]
|
8
|
+
|
9
|
+
gems.each do |name, version|
|
10
|
+
if File.exists?(path = "#{File.dirname(__FILE__)}/vendor/#{name}/lib")
|
11
|
+
$:.unshift path
|
12
|
+
else
|
13
|
+
gem name, version
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'rake'
|
18
|
+
require 'active_wrapper/tasks'
|
19
|
+
require 'cucumber/rake/task'
|
20
|
+
require 'rake/gempackagetask'
|
21
|
+
require 'spec/rake/spectask'
|
22
|
+
require 'gemspec'
|
23
|
+
|
24
|
+
ActiveWrapper::Tasks.new(
|
25
|
+
:base => File.dirname(__FILE__),
|
26
|
+
:env => ENV['ENV']
|
27
|
+
)
|
28
|
+
|
29
|
+
desc "Generate gemspec"
|
30
|
+
task :gemspec do
|
31
|
+
File.open("#{Dir.pwd}/#{GEM_NAME}.gemspec", 'w') do |f|
|
32
|
+
f.write(GEM_SPEC.to_ruby)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Install gem"
|
37
|
+
task :install do
|
38
|
+
Rake::Task['gem'].invoke
|
39
|
+
`sudo gem uninstall #{GEM_NAME} -x`
|
40
|
+
`sudo gem install pkg/#{GEM_NAME}*.gem`
|
41
|
+
`rm -Rf pkg`
|
42
|
+
end
|
43
|
+
|
44
|
+
desc "Package gem"
|
45
|
+
Rake::GemPackageTask.new(GEM_SPEC) do |pkg|
|
46
|
+
pkg.gem_spec = GEM_SPEC
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "Rename project"
|
50
|
+
task :rename do
|
51
|
+
name = ENV['NAME'] || File.basename(Dir.pwd)
|
52
|
+
begin
|
53
|
+
dir = Dir['**/gem_template*']
|
54
|
+
from = dir.pop
|
55
|
+
if from
|
56
|
+
rb = from.include?('.rb')
|
57
|
+
to = File.dirname(from) + "/#{name}#{'.rb' if rb}"
|
58
|
+
FileUtils.mv(from, to)
|
59
|
+
end
|
60
|
+
end while dir.length > 0
|
61
|
+
Dir["**/*"].each do |path|
|
62
|
+
next if path.include?('Rakefile')
|
63
|
+
if File.file?(path)
|
64
|
+
`sed -i "" 's/gem_template/#{name}/g' #{path}`
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
desc "Run specs"
|
70
|
+
Spec::Rake::SpecTask.new do |t|
|
71
|
+
t.rcov = true
|
72
|
+
t.spec_opts = ["--format", "specdoc", "--colour"]
|
73
|
+
t.spec_files = FileList["spec/**/*_spec.rb"]
|
74
|
+
end
|
data/config.ru
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
development:
|
2
|
+
imap:
|
3
|
+
password: password
|
4
|
+
port: 993
|
5
|
+
server: imap.gmail.com
|
6
|
+
ssl: true
|
7
|
+
use_login: true
|
8
|
+
username: test@sumapp.com
|
9
|
+
smtp:
|
10
|
+
address: smtp.gmail.com
|
11
|
+
authentication: :plain
|
12
|
+
domain: sumapp.com
|
13
|
+
password:
|
14
|
+
port: 587
|
15
|
+
enable_starttls_auto: true
|
16
|
+
user_name: test@sumapp.com
|
17
|
+
production:
|
18
|
+
imap:
|
19
|
+
password: password
|
20
|
+
port: 993
|
21
|
+
server: imap.gmail.com
|
22
|
+
ssl: true
|
23
|
+
use_login: true
|
24
|
+
username: sum@sumapp.com
|
25
|
+
smtp:
|
26
|
+
address: smtp.gmail.com
|
27
|
+
authentication: :plain
|
28
|
+
domain: sumapp.com
|
29
|
+
password:
|
30
|
+
port: 587
|
31
|
+
enable_starttls_auto: true
|
32
|
+
user_name: sum@sumapp.com
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class ABVariants < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :a_b_variants do |t|
|
4
|
+
t.string :name
|
5
|
+
t.boolean :control, :default => false
|
6
|
+
t.integer :conversions, :default => 0
|
7
|
+
t.integer :visitors, :default => 0
|
8
|
+
t.integer :a_b_test_id
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
add_index :a_b_variants, :a_b_test_id
|
12
|
+
add_index :a_b_variants, :control
|
13
|
+
add_index :a_b_variants, :name
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.down
|
17
|
+
drop_table :a_b_variants
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class ABUsers < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :a_b_users do |t|
|
4
|
+
t.string :login, :null => false # optional, you can use email instead, or both
|
5
|
+
t.string :crypted_password, :null => false # optional, see below
|
6
|
+
t.string :password_salt, :null => false # optional, but highly recommended
|
7
|
+
t.string :persistence_token, :null => false # required
|
8
|
+
t.string :single_access_token, :null => false # optional, see Authlogic::Session::Params
|
9
|
+
t.string :perishable_token, :null => false # optional, see Authlogic::Session::Perishability
|
10
|
+
|
11
|
+
# Magic columns, all optional, see Authlogic::Session::MagicColumns
|
12
|
+
t.integer :login_count, :null => false, :default => 0
|
13
|
+
t.integer :failed_login_count, :null => false, :default => 0
|
14
|
+
t.datetime :last_request_at
|
15
|
+
t.datetime :current_login_at
|
16
|
+
t.datetime :last_login_at
|
17
|
+
t.string :current_login_ip
|
18
|
+
t.string :last_login_ip
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.down
|
23
|
+
drop_table :users
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
$testing = true
|
2
|
+
$root = File.expand_path(File.dirname(__FILE__) + "/../../")
|
3
|
+
$:.unshift "#{$root}/lib"
|
4
|
+
|
5
|
+
require 'a_b'
|
6
|
+
|
7
|
+
gems = [
|
8
|
+
[ 'rack-test', '=0.5.1' ],
|
9
|
+
[ 'rspec', '=1.2.9' ],
|
10
|
+
[ 'webrat', '=0.5.3' ]
|
11
|
+
]
|
12
|
+
|
13
|
+
gems.each do |name, version|
|
14
|
+
if File.exists?(path = "#{File.dirname(__FILE__)}/../../vendor/#{name}/lib")
|
15
|
+
$:.unshift path
|
16
|
+
else
|
17
|
+
gem name, version
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rack/test'
|
22
|
+
require 'spec/mocks'
|
23
|
+
require 'test/unit'
|
24
|
+
require 'webrat'
|
25
|
+
|
26
|
+
World do
|
27
|
+
def app
|
28
|
+
Application
|
29
|
+
end
|
30
|
+
|
31
|
+
include Rack::Test::Methods
|
32
|
+
include Test::Unit::Assertions
|
33
|
+
include Webrat::Matchers
|
34
|
+
include Webrat::Methods
|
35
|
+
end
|
data/gemspec.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
GEM_NAME = 'a_b'
|
2
|
+
GEM_FILES = FileList['**/*'] - FileList[
|
3
|
+
'*.gem',
|
4
|
+
'*.log',
|
5
|
+
'config/database.yml',
|
6
|
+
'config/deploy.rb',
|
7
|
+
'config/mail.yml',
|
8
|
+
'coverage',
|
9
|
+
'coverage/**/*',
|
10
|
+
'log',
|
11
|
+
'log/**/*',
|
12
|
+
'pkg',
|
13
|
+
'pkg/**/*',
|
14
|
+
'tmp',
|
15
|
+
'tmp/**/*'
|
16
|
+
]
|
17
|
+
GEM_SPEC = Gem::Specification.new do |s|
|
18
|
+
# == CONFIGURE ==
|
19
|
+
s.author = "Winton Welsh"
|
20
|
+
s.email = "mail@wintoni.us"
|
21
|
+
s.homepage = "http://github.com/winton/#{GEM_NAME}"
|
22
|
+
s.summary = "A/B test data aggregator as a Sinatra web service"
|
23
|
+
# == CONFIGURE ==
|
24
|
+
s.add_dependency('active_wrapper', '=0.2.1')
|
25
|
+
s.add_dependency('cucumber', '=0.4.3')
|
26
|
+
s.add_dependency('haml', '=2.2.13')
|
27
|
+
s.add_dependency('rack', '=1.0.1')
|
28
|
+
s.add_dependency('rack-flash', '=0.1.1')
|
29
|
+
s.add_dependency('rack-test', '=0.5.1')
|
30
|
+
s.add_dependency('rspec', '=1.2.9')
|
31
|
+
s.add_dependency('shotgun', '=0.4')
|
32
|
+
s.add_dependency('sinatra', '=0.9.4')
|
33
|
+
s.add_dependency('webrat', '=0.5.3')
|
34
|
+
s.extra_rdoc_files = [ "README.markdown" ]
|
35
|
+
s.files = GEM_FILES.to_a
|
36
|
+
s.has_rdoc = false
|
37
|
+
s.name = GEM_NAME
|
38
|
+
s.platform = Gem::Platform::RUBY
|
39
|
+
s.require_path = "lib"
|
40
|
+
s.version = "0.1.0"
|
41
|
+
end
|
data/lib/a_b.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
gems = [
|
4
|
+
[ 'haml', '=2.2.13' ],
|
5
|
+
[ 'sinatra', '=0.9.4' ],
|
6
|
+
[ 'active_wrapper', '=0.2.1' ],
|
7
|
+
[ 'rack-flash', '=0.1.1' ],
|
8
|
+
[ 'authlogic', '=2.1.3' ]
|
9
|
+
]
|
10
|
+
|
11
|
+
gems.each do |name, version|
|
12
|
+
if File.exists?(path = "#{File.dirname(__FILE__)}/../vendor/#{name}/lib")
|
13
|
+
$:.unshift path
|
14
|
+
else
|
15
|
+
gem name, version
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'haml'
|
20
|
+
require 'sass'
|
21
|
+
require 'sinatra/base'
|
22
|
+
require 'active_wrapper'
|
23
|
+
require 'rack-flash'
|
24
|
+
require 'authlogic'
|
25
|
+
|
26
|
+
class Application < Sinatra::Base
|
27
|
+
end
|
28
|
+
|
29
|
+
Dir["#{File.dirname(__FILE__)}/a_b/**/*.rb"].each do |path|
|
30
|
+
require path
|
31
|
+
end
|
data/lib/a_b/boot.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
Application.class_eval do
|
2
|
+
|
3
|
+
# Sinatra
|
4
|
+
enable :raise_errors
|
5
|
+
enable :sessions
|
6
|
+
set :environment, $testing ? :test : environment
|
7
|
+
set :root, File.expand_path("#{File.dirname(__FILE__)}/../../")
|
8
|
+
set :public, "#{root}/public"
|
9
|
+
set :logging, true
|
10
|
+
set :static, true
|
11
|
+
set :views, "#{root}/lib/a_b/view"
|
12
|
+
|
13
|
+
# Database, logging, and email
|
14
|
+
$db, $log, $mail = ActiveWrapper.setup(
|
15
|
+
:base => root,
|
16
|
+
:env => environment,
|
17
|
+
:stdout => environment != :test
|
18
|
+
)
|
19
|
+
$db.establish_connection
|
20
|
+
if $mail.config
|
21
|
+
ActionMailer::Base.raise_delivery_errors = true
|
22
|
+
end
|
23
|
+
|
24
|
+
# Rack flash
|
25
|
+
use Rack::Flash, :accessorize => %w(error notice success)
|
26
|
+
|
27
|
+
# Generate token
|
28
|
+
require File.dirname(__FILE__) + '/model/token'
|
29
|
+
Token.generate!
|
30
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
Application.class_eval do
|
2
|
+
|
3
|
+
get '/boot.json' do
|
4
|
+
content_type :json
|
5
|
+
restrict
|
6
|
+
{
|
7
|
+
:user_token => Token.cached,
|
8
|
+
:tests => ABTest.find(:all)
|
9
|
+
}.to_json(
|
10
|
+
:include => :variants,
|
11
|
+
:only => [ :user_token, :tests, :variants, :name, :visitors ]
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
get '/convert.js' do
|
16
|
+
return nil unless valid_token?
|
17
|
+
if variant = ABVariant.find_by_name(params[:variant])
|
18
|
+
variant.increment!(:conversions)
|
19
|
+
end
|
20
|
+
'true'
|
21
|
+
end
|
22
|
+
|
23
|
+
get '/visit.js' do
|
24
|
+
return nil unless valid_token?
|
25
|
+
if params[:variants] && variants = ABVariant.find_all_by_name(params[:variants])
|
26
|
+
variants.each do |variant|
|
27
|
+
variant.increment!(:visitors)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
redirect '/js/visit.js'
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Application.class_eval do
|
2
|
+
|
3
|
+
get '/' do
|
4
|
+
restrict
|
5
|
+
@css = @js = %w(index)
|
6
|
+
@error = flash[:error]
|
7
|
+
@success = flash[:success]
|
8
|
+
@tests = ABTest.find :all, :order => 'updated_at desc'
|
9
|
+
haml :index, :layout => :layout
|
10
|
+
end
|
11
|
+
|
12
|
+
get '/css/index.css' do
|
13
|
+
headers 'Content-Type' => 'text/css; charset=utf-8'
|
14
|
+
sass :index
|
15
|
+
end
|
16
|
+
end
|