adhearsion 0.7.6 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/.version +1 -1
  2. data/CHANGELOG +43 -25
  3. data/Rakefile +0 -5
  4. data/TODO +51 -2
  5. data/ahn +2 -1
  6. data/apps/default/Rakefile +16 -7
  7. data/apps/default/config/adhearsion.yml +22 -1
  8. data/apps/default/config/helpers/manager_proxy.yml +1 -0
  9. data/apps/default/config/helpers/micromenus/images/arrow-off.gif +0 -0
  10. data/apps/default/config/helpers/micromenus/images/arrow-on.gif +0 -0
  11. data/apps/default/config/helpers/micromenus/images/error.gif +0 -0
  12. data/apps/default/config/helpers/micromenus/images/folder-off.gif +0 -0
  13. data/apps/default/config/helpers/micromenus/images/folder-on.gif +0 -0
  14. data/apps/default/config/helpers/micromenus/images/folder.png +0 -0
  15. data/apps/default/config/helpers/micromenus/images/ggbridge.jpg +0 -0
  16. data/apps/default/config/helpers/micromenus/images/green.png +0 -0
  17. data/apps/default/config/helpers/micromenus/images/microbrowser.bg.gif +0 -0
  18. data/apps/default/config/helpers/micromenus/images/red.png +0 -0
  19. data/apps/default/config/helpers/micromenus/images/url-off.gif +0 -0
  20. data/apps/default/config/helpers/micromenus/images/url-on.gif +0 -0
  21. data/apps/default/config/helpers/micromenus/images/yellow.png +0 -0
  22. data/apps/default/config/helpers/micromenus/javascripts/animation.js +1341 -0
  23. data/apps/default/config/helpers/micromenus/javascripts/carousel.js +1238 -0
  24. data/apps/default/config/helpers/micromenus/javascripts/columnav.js +306 -0
  25. data/apps/default/config/helpers/micromenus/javascripts/connection.js +965 -0
  26. data/apps/default/config/helpers/micromenus/javascripts/container.js +4727 -0
  27. data/apps/default/config/helpers/micromenus/javascripts/container_core.js +2915 -0
  28. data/apps/default/config/helpers/micromenus/javascripts/dom.js +892 -0
  29. data/apps/default/config/helpers/micromenus/javascripts/dragdrop.js +2921 -907
  30. data/apps/default/config/helpers/micromenus/javascripts/event.js +1771 -0
  31. data/apps/default/config/helpers/micromenus/javascripts/yahoo.js +433 -0
  32. data/apps/default/config/helpers/micromenus/stylesheets/carousel.css +78 -0
  33. data/apps/default/config/helpers/micromenus/stylesheets/columnav.css +135 -0
  34. data/apps/default/config/helpers/micromenus/stylesheets/microbrowsers.css +42 -0
  35. data/apps/default/config/helpers/multi_messenger.yml +5 -1
  36. data/apps/default/config/migration.rb +10 -0
  37. data/apps/default/extensions.rb +1 -1
  38. data/apps/default/helpers/factorial.alien.c +3 -3
  39. data/apps/default/helpers/lookup.rb +2 -1
  40. data/apps/default/helpers/manager_proxy.rb +67 -15
  41. data/apps/default/helpers/micromenus.rb +173 -31
  42. data/apps/default/helpers/multi_messenger.rb +20 -3
  43. data/lib/adhearsion.rb +218 -88
  44. data/lib/constants.rb +1 -0
  45. data/lib/core_extensions.rb +15 -9
  46. data/lib/phone_number.rb +85 -0
  47. data/lib/rami.rb +3 -2
  48. data/lib/servlet_container.rb +47 -24
  49. data/lib/sexy_migrations.rb +70 -0
  50. data/test/asterisk_module_test.rb +9 -9
  51. data/test/specs/numerical_string_spec.rb +53 -0
  52. metadata +31 -11
  53. data/apps/default/config/helpers/micromenus/javascripts/builder.js +0 -131
  54. data/apps/default/config/helpers/micromenus/javascripts/controls.js +0 -834
  55. data/apps/default/config/helpers/micromenus/javascripts/effects.js +0 -956
  56. data/apps/default/config/helpers/micromenus/javascripts/prototype.js +0 -2319
  57. data/apps/default/config/helpers/micromenus/javascripts/scriptaculous.js +0 -51
  58. data/apps/default/config/helpers/micromenus/javascripts/slider.js +0 -278
  59. data/apps/default/config/helpers/micromenus/javascripts/unittest.js +0 -557
  60. data/apps/default/config/helpers/micromenus/stylesheets/firefox.css +0 -10
  61. data/apps/default/config/helpers/micromenus/stylesheets/firefox.xul.css +0 -44
@@ -1,51 +0,0 @@
1
- // script.aculo.us scriptaculous.js v1.6.5, Wed Nov 08 14:17:49 CET 2006
2
-
3
- // Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
4
- //
5
- // Permission is hereby granted, free of charge, to any person obtaining
6
- // a copy of this software and associated documentation files (the
7
- // "Software"), to deal in the Software without restriction, including
8
- // without limitation the rights to use, copy, modify, merge, publish,
9
- // distribute, sublicense, and/or sell copies of the Software, and to
10
- // permit persons to whom the Software is furnished to do so, subject to
11
- // the following conditions:
12
- //
13
- // The above copyright notice and this permission notice shall be
14
- // included in all copies or substantial portions of the Software.
15
- //
16
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
- //
24
- // For details, see the script.aculo.us web site: http://script.aculo.us/
25
-
26
- var Scriptaculous = {
27
- Version: '1.6.5',
28
- require: function(libraryName) {
29
- // inserting via DOM fails in Safari 2.0, so brute force approach
30
- document.write('<script type="text/javascript" src="'+libraryName+'"></script>');
31
- },
32
- load: function() {
33
- if((typeof Prototype=='undefined') ||
34
- (typeof Element == 'undefined') ||
35
- (typeof Element.Methods=='undefined') ||
36
- parseFloat(Prototype.Version.split(".")[0] + "." +
37
- Prototype.Version.split(".")[1]) < 1.5)
38
- throw("script.aculo.us requires the Prototype JavaScript framework >= 1.5.0");
39
-
40
- $A(document.getElementsByTagName("script")).findAll( function(s) {
41
- return (s.src && s.src.match(/scriptaculous\.js(\?.*)?$/))
42
- }).each( function(s) {
43
- var path = s.src.replace(/scriptaculous\.js(\?.*)?$/,'');
44
- var includes = s.src.match(/\?.*load=([a-z,]*)/);
45
- (includes ? includes[1] : 'builder,effects,dragdrop,controls,slider').split(',').each(
46
- function(include) { Scriptaculous.require(path+include+'.js') });
47
- });
48
- }
49
- }
50
-
51
- Scriptaculous.load();
@@ -1,278 +0,0 @@
1
- // script.aculo.us slider.js v1.6.5, Wed Nov 08 14:17:49 CET 2006
2
-
3
- // Copyright (c) 2005, 2006 Marty Haught, Thomas Fuchs
4
- //
5
- // script.aculo.us is freely distributable under the terms of an MIT-style license.
6
- // For details, see the script.aculo.us web site: http://script.aculo.us/
7
-
8
- if(!Control) var Control = {};
9
- Control.Slider = Class.create();
10
-
11
- // options:
12
- // axis: 'vertical', or 'horizontal' (default)
13
- //
14
- // callbacks:
15
- // onChange(value)
16
- // onSlide(value)
17
- Control.Slider.prototype = {
18
- initialize: function(handle, track, options) {
19
- var slider = this;
20
-
21
- if(handle instanceof Array) {
22
- this.handles = handle.collect( function(e) { return $(e) });
23
- } else {
24
- this.handles = [$(handle)];
25
- }
26
-
27
- this.track = $(track);
28
- this.options = options || {};
29
-
30
- this.axis = this.options.axis || 'horizontal';
31
- this.increment = this.options.increment || 1;
32
- this.step = parseInt(this.options.step || '1');
33
- this.range = this.options.range || $R(0,1);
34
-
35
- this.value = 0; // assure backwards compat
36
- this.values = this.handles.map( function() { return 0 });
37
- this.spans = this.options.spans ? this.options.spans.map(function(s){ return $(s) }) : false;
38
- this.options.startSpan = $(this.options.startSpan || null);
39
- this.options.endSpan = $(this.options.endSpan || null);
40
-
41
- this.restricted = this.options.restricted || false;
42
-
43
- this.maximum = this.options.maximum || this.range.end;
44
- this.minimum = this.options.minimum || this.range.start;
45
-
46
- // Will be used to align the handle onto the track, if necessary
47
- this.alignX = parseInt(this.options.alignX || '0');
48
- this.alignY = parseInt(this.options.alignY || '0');
49
-
50
- this.trackLength = this.maximumOffset() - this.minimumOffset();
51
-
52
- this.handleLength = this.isVertical() ?
53
- (this.handles[0].offsetHeight != 0 ?
54
- this.handles[0].offsetHeight : this.handles[0].style.height.replace(/px$/,"")) :
55
- (this.handles[0].offsetWidth != 0 ? this.handles[0].offsetWidth :
56
- this.handles[0].style.width.replace(/px$/,""));
57
-
58
- this.active = false;
59
- this.dragging = false;
60
- this.disabled = false;
61
-
62
- if(this.options.disabled) this.setDisabled();
63
-
64
- // Allowed values array
65
- this.allowedValues = this.options.values ? this.options.values.sortBy(Prototype.K) : false;
66
- if(this.allowedValues) {
67
- this.minimum = this.allowedValues.min();
68
- this.maximum = this.allowedValues.max();
69
- }
70
-
71
- this.eventMouseDown = this.startDrag.bindAsEventListener(this);
72
- this.eventMouseUp = this.endDrag.bindAsEventListener(this);
73
- this.eventMouseMove = this.update.bindAsEventListener(this);
74
-
75
- // Initialize handles in reverse (make sure first handle is active)
76
- this.handles.each( function(h,i) {
77
- i = slider.handles.length-1-i;
78
- slider.setValue(parseFloat(
79
- (slider.options.sliderValue instanceof Array ?
80
- slider.options.sliderValue[i] : slider.options.sliderValue) ||
81
- slider.range.start), i);
82
- Element.makePositioned(h); // fix IE
83
- Event.observe(h, "mousedown", slider.eventMouseDown);
84
- });
85
-
86
- Event.observe(this.track, "mousedown", this.eventMouseDown);
87
- Event.observe(document, "mouseup", this.eventMouseUp);
88
- Event.observe(document, "mousemove", this.eventMouseMove);
89
-
90
- this.initialized = true;
91
- },
92
- dispose: function() {
93
- var slider = this;
94
- Event.stopObserving(this.track, "mousedown", this.eventMouseDown);
95
- Event.stopObserving(document, "mouseup", this.eventMouseUp);
96
- Event.stopObserving(document, "mousemove", this.eventMouseMove);
97
- this.handles.each( function(h) {
98
- Event.stopObserving(h, "mousedown", slider.eventMouseDown);
99
- });
100
- },
101
- setDisabled: function(){
102
- this.disabled = true;
103
- },
104
- setEnabled: function(){
105
- this.disabled = false;
106
- },
107
- getNearestValue: function(value){
108
- if(this.allowedValues){
109
- if(value >= this.allowedValues.max()) return(this.allowedValues.max());
110
- if(value <= this.allowedValues.min()) return(this.allowedValues.min());
111
-
112
- var offset = Math.abs(this.allowedValues[0] - value);
113
- var newValue = this.allowedValues[0];
114
- this.allowedValues.each( function(v) {
115
- var currentOffset = Math.abs(v - value);
116
- if(currentOffset <= offset){
117
- newValue = v;
118
- offset = currentOffset;
119
- }
120
- });
121
- return newValue;
122
- }
123
- if(value > this.range.end) return this.range.end;
124
- if(value < this.range.start) return this.range.start;
125
- return value;
126
- },
127
- setValue: function(sliderValue, handleIdx){
128
- if(!this.active) {
129
- this.activeHandleIdx = handleIdx || 0;
130
- this.activeHandle = this.handles[this.activeHandleIdx];
131
- this.updateStyles();
132
- }
133
- handleIdx = handleIdx || this.activeHandleIdx || 0;
134
- if(this.initialized && this.restricted) {
135
- if((handleIdx>0) && (sliderValue<this.values[handleIdx-1]))
136
- sliderValue = this.values[handleIdx-1];
137
- if((handleIdx < (this.handles.length-1)) && (sliderValue>this.values[handleIdx+1]))
138
- sliderValue = this.values[handleIdx+1];
139
- }
140
- sliderValue = this.getNearestValue(sliderValue);
141
- this.values[handleIdx] = sliderValue;
142
- this.value = this.values[0]; // assure backwards compat
143
-
144
- this.handles[handleIdx].style[this.isVertical() ? 'top' : 'left'] =
145
- this.translateToPx(sliderValue);
146
-
147
- this.drawSpans();
148
- if(!this.dragging || !this.event) this.updateFinished();
149
- },
150
- setValueBy: function(delta, handleIdx) {
151
- this.setValue(this.values[handleIdx || this.activeHandleIdx || 0] + delta,
152
- handleIdx || this.activeHandleIdx || 0);
153
- },
154
- translateToPx: function(value) {
155
- return Math.round(
156
- ((this.trackLength-this.handleLength)/(this.range.end-this.range.start)) *
157
- (value - this.range.start)) + "px";
158
- },
159
- translateToValue: function(offset) {
160
- return ((offset/(this.trackLength-this.handleLength) *
161
- (this.range.end-this.range.start)) + this.range.start);
162
- },
163
- getRange: function(range) {
164
- var v = this.values.sortBy(Prototype.K);
165
- range = range || 0;
166
- return $R(v[range],v[range+1]);
167
- },
168
- minimumOffset: function(){
169
- return(this.isVertical() ? this.alignY : this.alignX);
170
- },
171
- maximumOffset: function(){
172
- return(this.isVertical() ?
173
- (this.track.offsetHeight != 0 ? this.track.offsetHeight :
174
- this.track.style.height.replace(/px$/,"")) - this.alignY :
175
- (this.track.offsetWidth != 0 ? this.track.offsetWidth :
176
- this.track.style.width.replace(/px$/,"")) - this.alignY);
177
- },
178
- isVertical: function(){
179
- return (this.axis == 'vertical');
180
- },
181
- drawSpans: function() {
182
- var slider = this;
183
- if(this.spans)
184
- $R(0, this.spans.length-1).each(function(r) { slider.setSpan(slider.spans[r], slider.getRange(r)) });
185
- if(this.options.startSpan)
186
- this.setSpan(this.options.startSpan,
187
- $R(0, this.values.length>1 ? this.getRange(0).min() : this.value ));
188
- if(this.options.endSpan)
189
- this.setSpan(this.options.endSpan,
190
- $R(this.values.length>1 ? this.getRange(this.spans.length-1).max() : this.value, this.maximum));
191
- },
192
- setSpan: function(span, range) {
193
- if(this.isVertical()) {
194
- span.style.top = this.translateToPx(range.start);
195
- span.style.height = this.translateToPx(range.end - range.start + this.range.start);
196
- } else {
197
- span.style.left = this.translateToPx(range.start);
198
- span.style.width = this.translateToPx(range.end - range.start + this.range.start);
199
- }
200
- },
201
- updateStyles: function() {
202
- this.handles.each( function(h){ Element.removeClassName(h, 'selected') });
203
- Element.addClassName(this.activeHandle, 'selected');
204
- },
205
- startDrag: function(event) {
206
- if(Event.isLeftClick(event)) {
207
- if(!this.disabled){
208
- this.active = true;
209
-
210
- var handle = Event.element(event);
211
- var pointer = [Event.pointerX(event), Event.pointerY(event)];
212
- var track = handle;
213
- if(track==this.track) {
214
- var offsets = Position.cumulativeOffset(this.track);
215
- this.event = event;
216
- this.setValue(this.translateToValue(
217
- (this.isVertical() ? pointer[1]-offsets[1] : pointer[0]-offsets[0])-(this.handleLength/2)
218
- ));
219
- var offsets = Position.cumulativeOffset(this.activeHandle);
220
- this.offsetX = (pointer[0] - offsets[0]);
221
- this.offsetY = (pointer[1] - offsets[1]);
222
- } else {
223
- // find the handle (prevents issues with Safari)
224
- while((this.handles.indexOf(handle) == -1) && handle.parentNode)
225
- handle = handle.parentNode;
226
-
227
- if(this.handles.indexOf(handle)!=-1) {
228
- this.activeHandle = handle;
229
- this.activeHandleIdx = this.handles.indexOf(this.activeHandle);
230
- this.updateStyles();
231
-
232
- var offsets = Position.cumulativeOffset(this.activeHandle);
233
- this.offsetX = (pointer[0] - offsets[0]);
234
- this.offsetY = (pointer[1] - offsets[1]);
235
- }
236
- }
237
- }
238
- Event.stop(event);
239
- }
240
- },
241
- update: function(event) {
242
- if(this.active) {
243
- if(!this.dragging) this.dragging = true;
244
- this.draw(event);
245
- // fix AppleWebKit rendering
246
- if(navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0);
247
- Event.stop(event);
248
- }
249
- },
250
- draw: function(event) {
251
- var pointer = [Event.pointerX(event), Event.pointerY(event)];
252
- var offsets = Position.cumulativeOffset(this.track);
253
- pointer[0] -= this.offsetX + offsets[0];
254
- pointer[1] -= this.offsetY + offsets[1];
255
- this.event = event;
256
- this.setValue(this.translateToValue( this.isVertical() ? pointer[1] : pointer[0] ));
257
- if(this.initialized && this.options.onSlide)
258
- this.options.onSlide(this.values.length>1 ? this.values : this.value, this);
259
- },
260
- endDrag: function(event) {
261
- if(this.active && this.dragging) {
262
- this.finishDrag(event, true);
263
- Event.stop(event);
264
- }
265
- this.active = false;
266
- this.dragging = false;
267
- },
268
- finishDrag: function(event, success) {
269
- this.active = false;
270
- this.dragging = false;
271
- this.updateFinished();
272
- },
273
- updateFinished: function() {
274
- if(this.initialized && this.options.onChange)
275
- this.options.onChange(this.values.length>1 ? this.values : this.value, this);
276
- this.event = null;
277
- }
278
- }
@@ -1,557 +0,0 @@
1
- // script.aculo.us unittest.js v1.6.5, Wed Nov 08 14:17:49 CET 2006
2
-
3
- // Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
4
- // (c) 2005, 2006 Jon Tirsen (http://www.tirsen.com)
5
- // (c) 2005, 2006 Michael Schuerig (http://www.schuerig.de/michael/)
6
- //
7
- // script.aculo.us is freely distributable under the terms of an MIT-style license.
8
- // For details, see the script.aculo.us web site: http://script.aculo.us/
9
-
10
- // experimental, Firefox-only
11
- Event.simulateMouse = function(element, eventName) {
12
- var options = Object.extend({
13
- pointerX: 0,
14
- pointerY: 0,
15
- buttons: 0,
16
- ctrlKey: false,
17
- altKey: false,
18
- shiftKey: false,
19
- metaKey: false
20
- }, arguments[2] || {});
21
- var oEvent = document.createEvent("MouseEvents");
22
- oEvent.initMouseEvent(eventName, true, true, document.defaultView,
23
- options.buttons, options.pointerX, options.pointerY, options.pointerX, options.pointerY,
24
- options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, 0, $(element));
25
-
26
- if(this.mark) Element.remove(this.mark);
27
- this.mark = document.createElement('div');
28
- this.mark.appendChild(document.createTextNode(" "));
29
- document.body.appendChild(this.mark);
30
- this.mark.style.position = 'absolute';
31
- this.mark.style.top = options.pointerY + "px";
32
- this.mark.style.left = options.pointerX + "px";
33
- this.mark.style.width = "5px";
34
- this.mark.style.height = "5px;";
35
- this.mark.style.borderTop = "1px solid red;"
36
- this.mark.style.borderLeft = "1px solid red;"
37
-
38
- if(this.step)
39
- alert('['+new Date().getTime().toString()+'] '+eventName+'/'+Test.Unit.inspect(options));
40
-
41
- $(element).dispatchEvent(oEvent);
42
- };
43
-
44
- // Note: Due to a fix in Firefox 1.0.5/6 that probably fixed "too much", this doesn't work in 1.0.6 or DP2.
45
- // You need to downgrade to 1.0.4 for now to get this working
46
- // See https://bugzilla.mozilla.org/show_bug.cgi?id=289940 for the fix that fixed too much
47
- Event.simulateKey = function(element, eventName) {
48
- var options = Object.extend({
49
- ctrlKey: false,
50
- altKey: false,
51
- shiftKey: false,
52
- metaKey: false,
53
- keyCode: 0,
54
- charCode: 0
55
- }, arguments[2] || {});
56
-
57
- var oEvent = document.createEvent("KeyEvents");
58
- oEvent.initKeyEvent(eventName, true, true, window,
59
- options.ctrlKey, options.altKey, options.shiftKey, options.metaKey,
60
- options.keyCode, options.charCode );
61
- $(element).dispatchEvent(oEvent);
62
- };
63
-
64
- Event.simulateKeys = function(element, command) {
65
- for(var i=0; i<command.length; i++) {
66
- Event.simulateKey(element,'keypress',{charCode:command.charCodeAt(i)});
67
- }
68
- };
69
-
70
- var Test = {}
71
- Test.Unit = {};
72
-
73
- // security exception workaround
74
- Test.Unit.inspect = Object.inspect;
75
-
76
- Test.Unit.Logger = Class.create();
77
- Test.Unit.Logger.prototype = {
78
- initialize: function(log) {
79
- this.log = $(log);
80
- if (this.log) {
81
- this._createLogTable();
82
- }
83
- },
84
- start: function(testName) {
85
- if (!this.log) return;
86
- this.testName = testName;
87
- this.lastLogLine = document.createElement('tr');
88
- this.statusCell = document.createElement('td');
89
- this.nameCell = document.createElement('td');
90
- this.nameCell.className = "nameCell";
91
- this.nameCell.appendChild(document.createTextNode(testName));
92
- this.messageCell = document.createElement('td');
93
- this.lastLogLine.appendChild(this.statusCell);
94
- this.lastLogLine.appendChild(this.nameCell);
95
- this.lastLogLine.appendChild(this.messageCell);
96
- this.loglines.appendChild(this.lastLogLine);
97
- },
98
- finish: function(status, summary) {
99
- if (!this.log) return;
100
- this.lastLogLine.className = status;
101
- this.statusCell.innerHTML = status;
102
- this.messageCell.innerHTML = this._toHTML(summary);
103
- this.addLinksToResults();
104
- },
105
- message: function(message) {
106
- if (!this.log) return;
107
- this.messageCell.innerHTML = this._toHTML(message);
108
- },
109
- summary: function(summary) {
110
- if (!this.log) return;
111
- this.logsummary.innerHTML = this._toHTML(summary);
112
- },
113
- _createLogTable: function() {
114
- this.log.innerHTML =
115
- '<div id="logsummary"></div>' +
116
- '<table id="logtable">' +
117
- '<thead><tr><th>Status</th><th>Test</th><th>Message</th></tr></thead>' +
118
- '<tbody id="loglines"></tbody>' +
119
- '</table>';
120
- this.logsummary = $('logsummary')
121
- this.loglines = $('loglines');
122
- },
123
- _toHTML: function(txt) {
124
- return txt.escapeHTML().replace(/\n/g,"<br/>");
125
- },
126
- addLinksToResults: function(){
127
- $$("tr.failed .nameCell").each( function(td){ // todo: limit to children of this.log
128
- td.title = "Run only this test"
129
- Event.observe(td, 'click', function(){ window.location.search = "?tests=" + td.innerHTML;});
130
- });
131
- $$("tr.passed .nameCell").each( function(td){ // todo: limit to children of this.log
132
- td.title = "Run all tests"
133
- Event.observe(td, 'click', function(){ window.location.search = "";});
134
- });
135
- }
136
- }
137
-
138
- Test.Unit.Runner = Class.create();
139
- Test.Unit.Runner.prototype = {
140
- initialize: function(testcases) {
141
- this.options = Object.extend({
142
- testLog: 'testlog'
143
- }, arguments[1] || {});
144
- this.options.resultsURL = this.parseResultsURLQueryParameter();
145
- this.options.tests = this.parseTestsQueryParameter();
146
- if (this.options.testLog) {
147
- this.options.testLog = $(this.options.testLog) || null;
148
- }
149
- if(this.options.tests) {
150
- this.tests = [];
151
- for(var i = 0; i < this.options.tests.length; i++) {
152
- if(/^test/.test(this.options.tests[i])) {
153
- this.tests.push(new Test.Unit.Testcase(this.options.tests[i], testcases[this.options.tests[i]], testcases["setup"], testcases["teardown"]));
154
- }
155
- }
156
- } else {
157
- if (this.options.test) {
158
- this.tests = [new Test.Unit.Testcase(this.options.test, testcases[this.options.test], testcases["setup"], testcases["teardown"])];
159
- } else {
160
- this.tests = [];
161
- for(var testcase in testcases) {
162
- if(/^test/.test(testcase)) {
163
- this.tests.push(
164
- new Test.Unit.Testcase(
165
- this.options.context ? ' -> ' + this.options.titles[testcase] : testcase,
166
- testcases[testcase], testcases["setup"], testcases["teardown"]
167
- ));
168
- }
169
- }
170
- }
171
- }
172
- this.currentTest = 0;
173
- this.logger = new Test.Unit.Logger(this.options.testLog);
174
- setTimeout(this.runTests.bind(this), 1000);
175
- },
176
- parseResultsURLQueryParameter: function() {
177
- return window.location.search.parseQuery()["resultsURL"];
178
- },
179
- parseTestsQueryParameter: function(){
180
- if (window.location.search.parseQuery()["tests"]){
181
- return window.location.search.parseQuery()["tests"].split(',');
182
- };
183
- },
184
- // Returns:
185
- // "ERROR" if there was an error,
186
- // "FAILURE" if there was a failure, or
187
- // "SUCCESS" if there was neither
188
- getResult: function() {
189
- var hasFailure = false;
190
- for(var i=0;i<this.tests.length;i++) {
191
- if (this.tests[i].errors > 0) {
192
- return "ERROR";
193
- }
194
- if (this.tests[i].failures > 0) {
195
- hasFailure = true;
196
- }
197
- }
198
- if (hasFailure) {
199
- return "FAILURE";
200
- } else {
201
- return "SUCCESS";
202
- }
203
- },
204
- postResults: function() {
205
- if (this.options.resultsURL) {
206
- new Ajax.Request(this.options.resultsURL,
207
- { method: 'get', parameters: 'result=' + this.getResult(), asynchronous: false });
208
- }
209
- },
210
- runTests: function() {
211
- var test = this.tests[this.currentTest];
212
- if (!test) {
213
- // finished!
214
- this.postResults();
215
- this.logger.summary(this.summary());
216
- return;
217
- }
218
- if(!test.isWaiting) {
219
- this.logger.start(test.name);
220
- }
221
- test.run();
222
- if(test.isWaiting) {
223
- this.logger.message("Waiting for " + test.timeToWait + "ms");
224
- setTimeout(this.runTests.bind(this), test.timeToWait || 1000);
225
- } else {
226
- this.logger.finish(test.status(), test.summary());
227
- this.currentTest++;
228
- // tail recursive, hopefully the browser will skip the stackframe
229
- this.runTests();
230
- }
231
- },
232
- summary: function() {
233
- var assertions = 0;
234
- var failures = 0;
235
- var errors = 0;
236
- var messages = [];
237
- for(var i=0;i<this.tests.length;i++) {
238
- assertions += this.tests[i].assertions;
239
- failures += this.tests[i].failures;
240
- errors += this.tests[i].errors;
241
- }
242
- return (
243
- (this.options.context ? this.options.context + ': ': '') +
244
- this.tests.length + " tests, " +
245
- assertions + " assertions, " +
246
- failures + " failures, " +
247
- errors + " errors");
248
- }
249
- }
250
-
251
- Test.Unit.Assertions = Class.create();
252
- Test.Unit.Assertions.prototype = {
253
- initialize: function() {
254
- this.assertions = 0;
255
- this.failures = 0;
256
- this.errors = 0;
257
- this.messages = [];
258
- },
259
- summary: function() {
260
- return (
261
- this.assertions + " assertions, " +
262
- this.failures + " failures, " +
263
- this.errors + " errors" + "\n" +
264
- this.messages.join("\n"));
265
- },
266
- pass: function() {
267
- this.assertions++;
268
- },
269
- fail: function(message) {
270
- this.failures++;
271
- this.messages.push("Failure: " + message);
272
- },
273
- info: function(message) {
274
- this.messages.push("Info: " + message);
275
- },
276
- error: function(error) {
277
- this.errors++;
278
- this.messages.push(error.name + ": "+ error.message + "(" + Test.Unit.inspect(error) +")");
279
- },
280
- status: function() {
281
- if (this.failures > 0) return 'failed';
282
- if (this.errors > 0) return 'error';
283
- return 'passed';
284
- },
285
- assert: function(expression) {
286
- var message = arguments[1] || 'assert: got "' + Test.Unit.inspect(expression) + '"';
287
- try { expression ? this.pass() :
288
- this.fail(message); }
289
- catch(e) { this.error(e); }
290
- },
291
- assertEqual: function(expected, actual) {
292
- var message = arguments[2] || "assertEqual";
293
- try { (expected == actual) ? this.pass() :
294
- this.fail(message + ': expected "' + Test.Unit.inspect(expected) +
295
- '", actual "' + Test.Unit.inspect(actual) + '"'); }
296
- catch(e) { this.error(e); }
297
- },
298
- assertEnumEqual: function(expected, actual) {
299
- var message = arguments[2] || "assertEnumEqual";
300
- try { $A(expected).length == $A(actual).length &&
301
- expected.zip(actual).all(function(pair) { return pair[0] == pair[1] }) ?
302
- this.pass() : this.fail(message + ': expected ' + Test.Unit.inspect(expected) +
303
- ', actual ' + Test.Unit.inspect(actual)); }
304
- catch(e) { this.error(e); }
305
- },
306
- assertNotEqual: function(expected, actual) {
307
- var message = arguments[2] || "assertNotEqual";
308
- try { (expected != actual) ? this.pass() :
309
- this.fail(message + ': got "' + Test.Unit.inspect(actual) + '"'); }
310
- catch(e) { this.error(e); }
311
- },
312
- assertIdentical: function(expected, actual) {
313
- var message = arguments[2] || "assertIdentical";
314
- try { (expected === actual) ? this.pass() :
315
- this.fail(message + ': expected "' + Test.Unit.inspect(expected) +
316
- '", actual "' + Test.Unit.inspect(actual) + '"'); }
317
- catch(e) { this.error(e); }
318
- },
319
- assertNotIdentical: function(expected, actual) {
320
- var message = arguments[2] || "assertNotIdentical";
321
- try { !(expected === actual) ? this.pass() :
322
- this.fail(message + ': expected "' + Test.Unit.inspect(expected) +
323
- '", actual "' + Test.Unit.inspect(actual) + '"'); }
324
- catch(e) { this.error(e); }
325
- },
326
- assertNull: function(obj) {
327
- var message = arguments[1] || 'assertNull'
328
- try { (obj==null) ? this.pass() :
329
- this.fail(message + ': got "' + Test.Unit.inspect(obj) + '"'); }
330
- catch(e) { this.error(e); }
331
- },
332
- assertMatch: function(expected, actual) {
333
- var message = arguments[2] || 'assertMatch';
334
- var regex = new RegExp(expected);
335
- try { (regex.exec(actual)) ? this.pass() :
336
- this.fail(message + ' : regex: "' + Test.Unit.inspect(expected) + ' did not match: ' + Test.Unit.inspect(actual) + '"'); }
337
- catch(e) { this.error(e); }
338
- },
339
- assertHidden: function(element) {
340
- var message = arguments[1] || 'assertHidden';
341
- this.assertEqual("none", element.style.display, message);
342
- },
343
- assertNotNull: function(object) {
344
- var message = arguments[1] || 'assertNotNull';
345
- this.assert(object != null, message);
346
- },
347
- assertType: function(expected, actual) {
348
- var message = arguments[2] || 'assertType';
349
- try {
350
- (actual.constructor == expected) ? this.pass() :
351
- this.fail(message + ': expected "' + Test.Unit.inspect(expected) +
352
- '", actual "' + (actual.constructor) + '"'); }
353
- catch(e) { this.error(e); }
354
- },
355
- assertNotOfType: function(expected, actual) {
356
- var message = arguments[2] || 'assertNotOfType';
357
- try {
358
- (actual.constructor != expected) ? this.pass() :
359
- this.fail(message + ': expected "' + Test.Unit.inspect(expected) +
360
- '", actual "' + (actual.constructor) + '"'); }
361
- catch(e) { this.error(e); }
362
- },
363
- assertInstanceOf: function(expected, actual) {
364
- var message = arguments[2] || 'assertInstanceOf';
365
- try {
366
- (actual instanceof expected) ? this.pass() :
367
- this.fail(message + ": object was not an instance of the expected type"); }
368
- catch(e) { this.error(e); }
369
- },
370
- assertNotInstanceOf: function(expected, actual) {
371
- var message = arguments[2] || 'assertNotInstanceOf';
372
- try {
373
- !(actual instanceof expected) ? this.pass() :
374
- this.fail(message + ": object was an instance of the not expected type"); }
375
- catch(e) { this.error(e); }
376
- },
377
- assertRespondsTo: function(method, obj) {
378
- var message = arguments[2] || 'assertRespondsTo';
379
- try {
380
- (obj[method] && typeof obj[method] == 'function') ? this.pass() :
381
- this.fail(message + ": object doesn't respond to [" + method + "]"); }
382
- catch(e) { this.error(e); }
383
- },
384
- assertReturnsTrue: function(method, obj) {
385
- var message = arguments[2] || 'assertReturnsTrue';
386
- try {
387
- var m = obj[method];
388
- if(!m) m = obj['is'+method.charAt(0).toUpperCase()+method.slice(1)];
389
- m() ? this.pass() :
390
- this.fail(message + ": method returned false"); }
391
- catch(e) { this.error(e); }
392
- },
393
- assertReturnsFalse: function(method, obj) {
394
- var message = arguments[2] || 'assertReturnsFalse';
395
- try {
396
- var m = obj[method];
397
- if(!m) m = obj['is'+method.charAt(0).toUpperCase()+method.slice(1)];
398
- !m() ? this.pass() :
399
- this.fail(message + ": method returned true"); }
400
- catch(e) { this.error(e); }
401
- },
402
- assertRaise: function(exceptionName, method) {
403
- var message = arguments[2] || 'assertRaise';
404
- try {
405
- method();
406
- this.fail(message + ": exception expected but none was raised"); }
407
- catch(e) {
408
- (e.name==exceptionName) ? this.pass() : this.error(e);
409
- }
410
- },
411
- assertElementsMatch: function() {
412
- var expressions = $A(arguments), elements = $A(expressions.shift());
413
- if (elements.length != expressions.length) {
414
- this.fail('assertElementsMatch: size mismatch: ' + elements.length + ' elements, ' + expressions.length + ' expressions');
415
- return false;
416
- }
417
- elements.zip(expressions).all(function(pair, index) {
418
- var element = $(pair.first()), expression = pair.last();
419
- if (element.match(expression)) return true;
420
- this.fail('assertElementsMatch: (in index ' + index + ') expected ' + expression.inspect() + ' but got ' + element.inspect());
421
- }.bind(this)) && this.pass();
422
- },
423
- assertElementMatches: function(element, expression) {
424
- this.assertElementsMatch([element], expression);
425
- },
426
- benchmark: function(operation, iterations) {
427
- var startAt = new Date();
428
- (iterations || 1).times(operation);
429
- var timeTaken = ((new Date())-startAt);
430
- this.info((arguments[2] || 'Operation') + ' finished ' +
431
- iterations + ' iterations in ' + (timeTaken/1000)+'s' );
432
- return timeTaken;
433
- },
434
- _isVisible: function(element) {
435
- element = $(element);
436
- if(!element.parentNode) return true;
437
- this.assertNotNull(element);
438
- if(element.style && Element.getStyle(element, 'display') == 'none')
439
- return false;
440
-
441
- return this._isVisible(element.parentNode);
442
- },
443
- assertNotVisible: function(element) {
444
- this.assert(!this._isVisible(element), Test.Unit.inspect(element) + " was not hidden and didn't have a hidden parent either. " + ("" || arguments[1]));
445
- },
446
- assertVisible: function(element) {
447
- this.assert(this._isVisible(element), Test.Unit.inspect(element) + " was not visible. " + ("" || arguments[1]));
448
- },
449
- benchmark: function(operation, iterations) {
450
- var startAt = new Date();
451
- (iterations || 1).times(operation);
452
- var timeTaken = ((new Date())-startAt);
453
- this.info((arguments[2] || 'Operation') + ' finished ' +
454
- iterations + ' iterations in ' + (timeTaken/1000)+'s' );
455
- return timeTaken;
456
- }
457
- }
458
-
459
- Test.Unit.Testcase = Class.create();
460
- Object.extend(Object.extend(Test.Unit.Testcase.prototype, Test.Unit.Assertions.prototype), {
461
- initialize: function(name, test, setup, teardown) {
462
- Test.Unit.Assertions.prototype.initialize.bind(this)();
463
- this.name = name;
464
-
465
- if(typeof test == 'string') {
466
- test = test.gsub(/(\.should[^\(]+\()/,'#{0}this,');
467
- test = test.gsub(/(\.should[^\(]+)\(this,\)/,'#{1}(this)');
468
- this.test = function() {
469
- eval('with(this){'+test+'}');
470
- }
471
- } else {
472
- this.test = test || function() {};
473
- }
474
-
475
- this.setup = setup || function() {};
476
- this.teardown = teardown || function() {};
477
- this.isWaiting = false;
478
- this.timeToWait = 1000;
479
- },
480
- wait: function(time, nextPart) {
481
- this.isWaiting = true;
482
- this.test = nextPart;
483
- this.timeToWait = time;
484
- },
485
- run: function() {
486
- try {
487
- try {
488
- if (!this.isWaiting) this.setup.bind(this)();
489
- this.isWaiting = false;
490
- this.test.bind(this)();
491
- } finally {
492
- if(!this.isWaiting) {
493
- this.teardown.bind(this)();
494
- }
495
- }
496
- }
497
- catch(e) { this.error(e); }
498
- }
499
- });
500
-
501
- // *EXPERIMENTAL* BDD-style testing to please non-technical folk
502
- // This draws many ideas from RSpec http://rspec.rubyforge.org/
503
-
504
- Test.setupBDDExtensionMethods = function(){
505
- var METHODMAP = {
506
- shouldEqual: 'assertEqual',
507
- shouldNotEqual: 'assertNotEqual',
508
- shouldEqualEnum: 'assertEnumEqual',
509
- shouldBeA: 'assertType',
510
- shouldNotBeA: 'assertNotOfType',
511
- shouldBeAn: 'assertType',
512
- shouldNotBeAn: 'assertNotOfType',
513
- shouldBeNull: 'assertNull',
514
- shouldNotBeNull: 'assertNotNull',
515
-
516
- shouldBe: 'assertReturnsTrue',
517
- shouldNotBe: 'assertReturnsFalse',
518
- shouldRespondTo: 'assertRespondsTo'
519
- };
520
- Test.BDDMethods = {};
521
- for(m in METHODMAP) {
522
- Test.BDDMethods[m] = eval(
523
- 'function(){'+
524
- 'var args = $A(arguments);'+
525
- 'var scope = args.shift();'+
526
- 'scope.'+METHODMAP[m]+'.apply(scope,(args || []).concat([this])); }');
527
- }
528
- [Array.prototype, String.prototype, Number.prototype].each(
529
- function(p){ Object.extend(p, Test.BDDMethods) }
530
- );
531
- }
532
-
533
- Test.context = function(name, spec, log){
534
- Test.setupBDDExtensionMethods();
535
-
536
- var compiledSpec = {};
537
- var titles = {};
538
- for(specName in spec) {
539
- switch(specName){
540
- case "setup":
541
- case "teardown":
542
- compiledSpec[specName] = spec[specName];
543
- break;
544
- default:
545
- var testName = 'test'+specName.gsub(/\s+/,'-').camelize();
546
- var body = spec[specName].toString().split('\n').slice(1);
547
- if(/^\{/.test(body[0])) body = body.slice(1);
548
- body.pop();
549
- body = body.map(function(statement){
550
- return statement.strip()
551
- });
552
- compiledSpec[testName] = body.join('\n');
553
- titles[testName] = specName;
554
- }
555
- }
556
- new Test.Unit.Runner(compiledSpec, { titles: titles, testLog: log || 'testlog', context: name });
557
- };