Skip to content

Commit

Permalink
Specs passing
Browse files Browse the repository at this point in the history
  • Loading branch information
winton committed Aug 23, 2010
1 parent 63f5f2b commit 2c48ab7
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 140 deletions.
4 changes: 2 additions & 2 deletions config/a_b.yml
@@ -1,5 +1,5 @@
development:
url: http://127.0.0.1:9393
url: http://winton-ubuntu.local:9395
site: test
categories:
- name: Category
tests:
Expand Down
8 changes: 4 additions & 4 deletions lib/a_b.rb
Expand Up @@ -8,13 +8,13 @@

require 'version'

require 'boot/a_b_plugin'
require 'boot/delayed_job'

require 'boot/application'
require 'boot/sinatra'
require 'boot/active_wrapper'
require 'boot/a_b_plugin'
require 'boot/delayed_job'
require 'boot/lilypad'
require 'boot/controller'
require 'boot/helper'
require 'boot/model'
require 'boot/model'
require 'boot/job'
3 changes: 1 addition & 2 deletions lib/a_b/boot/a_b_plugin.rb
@@ -1,3 +1,2 @@
$:.unshift File.expand_path('../../../../vendor/a_b_plugin/lib', __FILE__)

$:.unshift File.expand_path(File.dirname(__FILE__) + '/../../../vendor/a_b_plugin/lib')
require 'a_b_plugin'
8 changes: 4 additions & 4 deletions lib/a_b/boot/console.rb
Expand Up @@ -4,10 +4,10 @@

$:.unshift File.dirname(__FILE__) + '/../'

require 'boot/a_b_plugin'
require 'boot/delayed_job'

require 'boot/application'
require 'boot/sinatra'
require 'boot/active_wrapper'
require 'boot/model'
require 'boot/a_b_plugin'
require 'boot/delayed_job'
require 'boot/model'
require 'boot/job'
1 change: 0 additions & 1 deletion lib/a_b/boot/delayed_job.rb
@@ -1,3 +1,2 @@
$:.unshift File.expand_path('../../../../vendor/delayed_job/lib', __FILE__)

require 'delayed_job'
9 changes: 8 additions & 1 deletion lib/a_b/controller/spec.rb
Expand Up @@ -6,8 +6,15 @@
end

get '/spec' do
@user = User.find_or_create_by_identifier('test')
@site = Site.find_by_name('test').destroy rescue
@site = Site.create(:name => 'test', :user_id => @user.id)

Env.create(:name => 'development', :user_id => @user.id, :site_id => @site.id)

Variant.delete(2)
Variant.connection.insert("INSERT INTO variants (id, name) VALUES (2, 'test')")
Variant.connection.insert("INSERT INTO variants (id, name, site_id, user_id) VALUES (2, 'test', #{@site.id}, #{@user.id})")

haml :spec, :layout => false
end
end
Expand Down
61 changes: 30 additions & 31 deletions public/js/a_b.js
Expand Up @@ -49,40 +49,39 @@ window.A_B = new function() {
this.get = cookie;
this.set = cookie;

function cookie(name, value) {
if (!name) return null;
function cookie(key, value, options) {

options = options || {};

if (!key)
return null;

if (typeof value != 'undefined') {

if (value === null)
document.cookie = [
name, '=', '; expires=-1; path=/'
].join('');
else
document.cookie = [
name, '=', encodeURIComponent(value), '; path=/'
].join('');
} else {
var cookie_value = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = trim(cookies[i]);
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookie_value = decodeURIComponent(
cookie.substring(name.length + 1)
);
break;
}
}
options.expires = -1;

if (typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setDate(t.getDate() + days);
}
return cookie_value;
}
return null;
}

function trim(text) {
return (text || "")
.replace(/^(\s|\u00A0)+|(\s|\u00A0)+$/g, "");
}

document.cookie = [
key + '=' + encodeURIComponent(value),
'path=' + (options.path ? options.path : '/'),
options.domain ? 'domain=' + options.domain : '',
options.expires ? 'expires=' + options.expires.toUTCString() : '',
options.secure ? 'secure' : ''
].join('; ');

} else
options = value || options;

var result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)')
.exec(document.cookie);

return result ? decodeURIComponent(result[1]) : null;
};
};

Datastore = function() {
Expand Down
126 changes: 31 additions & 95 deletions public/js/jquery.cookie.js
@@ -1,97 +1,33 @@
/**
* Cookie plugin
*
* Copyright (c) 2006 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/

/**
* Create a cookie with the given name and value and other optional parameters.
*
* @example $.cookie('the_cookie', 'the_value');
* @desc Set the value of a cookie.
* @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
* @desc Create a cookie with all available options.
* @example $.cookie('the_cookie', 'the_value');
* @desc Create a session cookie.
* @example $.cookie('the_cookie', null);
* @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
* used when the cookie was set.
*
* @param String name The name of the cookie.
* @param String value The value of the cookie.
* @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
* @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
* If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
* If set to null or omitted, the cookie will be a session cookie and will not be retained
* when the the browser exits.
* @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
* @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
* @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
* require a secure protocol (like HTTPS).
* @type undefined
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/klaus.hartl@stilbuero.de
*/

/**
* Get the value of a cookie with the given name.
*
* @example $.cookie('the_cookie');
* @desc Get the value of a cookie.
*
* @param String name The name of the cookie.
* @return The value of the cookie.
* @type String
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/klaus.hartl@stilbuero.de
*/
jQuery.cookie = function(name, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
// CAUTION: Needed to parenthesize options.path and options.domain
// in the following expressions, otherwise they evaluate to undefined
// in the packed version for some reason...
var path = options.path ? '; path=' + (options.path) : '; path=/';
var domain = options.domain ? '; domain=' + (options.domain) : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
} else { // only name given, get cookie
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
jQuery.cookie = function(key, value, options) {

options = options || {};

if (!key)
return null;

if (typeof value != 'undefined') {

if (value === null)
options.expires = -1;

if (typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setDate(t.getDate() + days);
}

document.cookie = [
key + '=' + encodeURIComponent(value),
'path=' + (options.path ? options.path : '/'),
options.domain ? 'domain=' + options.domain : '',
options.expires ? 'expires=' + options.expires.toUTCString() : '',
options.secure ? 'secure' : ''
].join('; ');

} else
options = value || options;

var result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)')
.exec(document.cookie);

return result ? decodeURIComponent(result[1]) : null;
};

0 comments on commit 2c48ab7

Please sign in to comment.