forked from activeadmin/activeadmin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matt Vague
authored and
Matt Vague
committed
Dec 8, 2011
1 parent
5ee02e5
commit 2fad9b1
Showing
10 changed files
with
3,456 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,4 +38,5 @@ group :test do | |
gem 'launchy' | ||
gem 'jslint_on_rails', '~> 1.0.6' | ||
gem 'guard-rspec' | ||
gem 'jasmine' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
beforeEach(function() { | ||
window.inject = $.jasmine.inject; | ||
}); |
108 changes: 108 additions & 0 deletions
108
spec/javascripts/helpers/vendor/jasmine-fixture-0.0.5.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* jasmine-fixture Makes injecting HTML snippets into the DOM easy & clean! | ||
* site: https://github.com/searls/jasmine-fixture */ | ||
(function($){ | ||
var originalJasmineFixture = window.jasmineFixture, | ||
defaultConfiguration = { | ||
el:'div', | ||
cssClass:'', | ||
id:'', | ||
text: '', | ||
html: '', | ||
defaultAttribute: 'class', | ||
attrs: {} | ||
}; | ||
|
||
window.jasmineFixture = function($) { | ||
var isReady = false, | ||
rootId = 'specContainer', | ||
defaults = $.extend({},defaultConfiguration); | ||
|
||
$.jasmine = { | ||
inject: function(arg,context) { | ||
if(isReady !== true) init(); | ||
var parent = context ? context : $('#'+rootId), | ||
$toInject; | ||
if(itLooksLikeHtml(arg)) { | ||
$toInject = $(arg); | ||
} else { | ||
var config = $.extend({},defaults,arg,{ userString: arg }); | ||
$toInject = $('<'+config.el+'></'+config.el+'>'); | ||
applyAttributes($toInject,config); | ||
injectContents($toInject,config); | ||
} | ||
return $toInject.appendTo(parent); | ||
}, | ||
configure: function(config) { | ||
$.extend(defaults,config); | ||
}, | ||
restoreDefaults: function(){ | ||
defaults = $.extend({},defaultConfiguration); | ||
}, | ||
noConflict: function() { | ||
window.jasmineFixture = originalJasmineFixture; | ||
return this; | ||
} | ||
}; | ||
|
||
$.fn.inject = function(html){ | ||
return $.jasmine.inject(html,$(this)); | ||
}; | ||
|
||
var applyAttributes = function($html,config) { | ||
var attrs = $.extend({},{ | ||
id: config.id, | ||
'class': config['class'] || config.cssClass | ||
}, config.attrs); | ||
if(isString(config.userString)) { | ||
attrs[config.defaultAttribute] = config.userString; | ||
} | ||
for(var key in attrs) { | ||
if(attrs[key]) { | ||
$html.attr(key,attrs[key]); | ||
} | ||
} | ||
}; | ||
|
||
var injectContents = function($el,config){ | ||
if(config.text && config.html) { | ||
throw "Error: because they conflict, you may only configure inject() to set `html` or `text`, not both! \n\nHTML was: "+config.html+" \n\n Text was: "+config.text | ||
} else if(config.text) { | ||
$el.text(config.text); | ||
} else if(config.html) { | ||
$el.html(config.html); | ||
} | ||
} | ||
|
||
var itLooksLikeHtml = function(arg) { | ||
return isString(arg) && arg.indexOf('<') !== -1 | ||
}; | ||
|
||
var isString = function(arg) { | ||
return arg && arg.constructor === String; | ||
}; | ||
|
||
var init = function() { | ||
$('body').append('<div id="'+rootId+'"></div>'); | ||
isReady = true; | ||
}; | ||
|
||
var tidyUp = function() { | ||
$('#'+rootId).remove(); | ||
isReady = false; | ||
}; | ||
|
||
$(function(jQuery){ | ||
init(); | ||
}); | ||
afterEach(function(){ | ||
tidyUp(); | ||
}); | ||
|
||
return $.jasmine; | ||
}; | ||
|
||
if(jQuery) { | ||
var jasmineFixture = window.jasmineFixture(jQuery); | ||
window.inject = window.inject || jasmineFixture.inject; | ||
} | ||
})(jQuery); |
Oops, something went wrong.