local_time 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,50 @@
1
+ fs = require 'fs'
2
+ print = (s) -> fs.write "/dev/stderr", s, 'w'
3
+
4
+ page = new WebPage()
5
+ page.onConsoleMessage = (msg) -> console.error msg
6
+
7
+ timeoutId = null
8
+ deferTimeout = ->
9
+ clearTimeout timeoutId if timeoutId
10
+ timeoutId = setTimeout ->
11
+ console.error "Timeout"
12
+ phantom.exit 1
13
+ , 3000
14
+
15
+ console.log "Local time: #{new Date}"
16
+
17
+ page.open phantom.args[0], ->
18
+ deferTimeout()
19
+
20
+ setInterval ->
21
+ tests = page.evaluate ->
22
+ tests = document.getElementById('qunit-tests').children
23
+ for test in tests when test.className isnt 'running' and not test.recorded
24
+ test.recorded = true
25
+ if test.className is 'pass'
26
+ '.'
27
+ else if test.className is 'fail'
28
+ 'F'
29
+
30
+ for test in tests when test
31
+ deferTimeout()
32
+ print test
33
+
34
+ result = page.evaluate ->
35
+ result = document.getElementById('qunit-testresult')
36
+ tests = document.getElementById('qunit-tests').children
37
+
38
+ if result.innerText.match /completed/
39
+ console.error ""
40
+
41
+ for test in tests when test.className is 'fail'
42
+ console.error test.innerText
43
+
44
+ console.error result.innerText
45
+ return parseInt result.getElementsByClassName('failed')[0].innerText
46
+
47
+ return
48
+
49
+ phantom.exit result if result?
50
+ , 100
@@ -0,0 +1,385 @@
1
+ /**
2
+ * Sinon.JS 1.7.1, 2013/05/07
3
+ *
4
+ * @author Christian Johansen (christian@cjohansen.no)
5
+ * @author Contributors: https://github.com/cjohansen/Sinon.JS/blob/master/AUTHORS
6
+ *
7
+ * (The BSD License)
8
+ *
9
+ * Copyright (c) 2010-2013, Christian Johansen, christian@cjohansen.no
10
+ * All rights reserved.
11
+ *
12
+ * Redistribution and use in source and binary forms, with or without modification,
13
+ * are permitted provided that the following conditions are met:
14
+ *
15
+ * * Redistributions of source code must retain the above copyright notice,
16
+ * this list of conditions and the following disclaimer.
17
+ * * Redistributions in binary form must reproduce the above copyright notice,
18
+ * this list of conditions and the following disclaimer in the documentation
19
+ * and/or other materials provided with the distribution.
20
+ * * Neither the name of Christian Johansen nor the names of his contributors
21
+ * may be used to endorse or promote products derived from this software
22
+ * without specific prior written permission.
23
+ *
24
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+ */
35
+
36
+ /*jslint eqeqeq: false, plusplus: false, evil: true, onevar: false, browser: true, forin: false*/
37
+ /*global module, require, window*/
38
+ /**
39
+ * Fake timer API
40
+ * setTimeout
41
+ * setInterval
42
+ * clearTimeout
43
+ * clearInterval
44
+ * tick
45
+ * reset
46
+ * Date
47
+ *
48
+ * Inspired by jsUnitMockTimeOut from JsUnit
49
+ *
50
+ * @author Christian Johansen (christian@cjohansen.no)
51
+ * @license BSD
52
+ *
53
+ * Copyright (c) 2010-2013 Christian Johansen
54
+ */
55
+
56
+ if (typeof sinon == "undefined") {
57
+ var sinon = {};
58
+ }
59
+
60
+ (function (global) {
61
+ var id = 1;
62
+
63
+ function addTimer(args, recurring) {
64
+ if (args.length === 0) {
65
+ throw new Error("Function requires at least 1 parameter");
66
+ }
67
+
68
+ var toId = id++;
69
+ var delay = args[1] || 0;
70
+
71
+ if (!this.timeouts) {
72
+ this.timeouts = {};
73
+ }
74
+
75
+ this.timeouts[toId] = {
76
+ id: toId,
77
+ func: args[0],
78
+ callAt: this.now + delay,
79
+ invokeArgs: Array.prototype.slice.call(args, 2)
80
+ };
81
+
82
+ if (recurring === true) {
83
+ this.timeouts[toId].interval = delay;
84
+ }
85
+
86
+ return toId;
87
+ }
88
+
89
+ function parseTime(str) {
90
+ if (!str) {
91
+ return 0;
92
+ }
93
+
94
+ var strings = str.split(":");
95
+ var l = strings.length, i = l;
96
+ var ms = 0, parsed;
97
+
98
+ if (l > 3 || !/^(\d\d:){0,2}\d\d?$/.test(str)) {
99
+ throw new Error("tick only understands numbers and 'h:m:s'");
100
+ }
101
+
102
+ while (i--) {
103
+ parsed = parseInt(strings[i], 10);
104
+
105
+ if (parsed >= 60) {
106
+ throw new Error("Invalid time " + str);
107
+ }
108
+
109
+ ms += parsed * Math.pow(60, (l - i - 1));
110
+ }
111
+
112
+ return ms * 1000;
113
+ }
114
+
115
+ function createObject(object) {
116
+ var newObject;
117
+
118
+ if (Object.create) {
119
+ newObject = Object.create(object);
120
+ } else {
121
+ var F = function () {};
122
+ F.prototype = object;
123
+ newObject = new F();
124
+ }
125
+
126
+ newObject.Date.clock = newObject;
127
+ return newObject;
128
+ }
129
+
130
+ sinon.clock = {
131
+ now: 0,
132
+
133
+ create: function create(now) {
134
+ var clock = createObject(this);
135
+
136
+ if (typeof now == "number") {
137
+ clock.now = now;
138
+ }
139
+
140
+ if (!!now && typeof now == "object") {
141
+ throw new TypeError("now should be milliseconds since UNIX epoch");
142
+ }
143
+
144
+ return clock;
145
+ },
146
+
147
+ setTimeout: function setTimeout(callback, timeout) {
148
+ return addTimer.call(this, arguments, false);
149
+ },
150
+
151
+ clearTimeout: function clearTimeout(timerId) {
152
+ if (!this.timeouts) {
153
+ this.timeouts = [];
154
+ }
155
+
156
+ if (timerId in this.timeouts) {
157
+ delete this.timeouts[timerId];
158
+ }
159
+ },
160
+
161
+ setInterval: function setInterval(callback, timeout) {
162
+ return addTimer.call(this, arguments, true);
163
+ },
164
+
165
+ clearInterval: function clearInterval(timerId) {
166
+ this.clearTimeout(timerId);
167
+ },
168
+
169
+ tick: function tick(ms) {
170
+ ms = typeof ms == "number" ? ms : parseTime(ms);
171
+ var tickFrom = this.now, tickTo = this.now + ms, previous = this.now;
172
+ var timer = this.firstTimerInRange(tickFrom, tickTo);
173
+
174
+ var firstException;
175
+ while (timer && tickFrom <= tickTo) {
176
+ if (this.timeouts[timer.id]) {
177
+ tickFrom = this.now = timer.callAt;
178
+ try {
179
+ this.callTimer(timer);
180
+ } catch (e) {
181
+ firstException = firstException || e;
182
+ }
183
+ }
184
+
185
+ timer = this.firstTimerInRange(previous, tickTo);
186
+ previous = tickFrom;
187
+ }
188
+
189
+ this.now = tickTo;
190
+
191
+ if (firstException) {
192
+ throw firstException;
193
+ }
194
+
195
+ return this.now;
196
+ },
197
+
198
+ firstTimerInRange: function (from, to) {
199
+ var timer, smallest, originalTimer;
200
+
201
+ for (var id in this.timeouts) {
202
+ if (this.timeouts.hasOwnProperty(id)) {
203
+ if (this.timeouts[id].callAt < from || this.timeouts[id].callAt > to) {
204
+ continue;
205
+ }
206
+
207
+ if (!smallest || this.timeouts[id].callAt < smallest) {
208
+ originalTimer = this.timeouts[id];
209
+ smallest = this.timeouts[id].callAt;
210
+
211
+ timer = {
212
+ func: this.timeouts[id].func,
213
+ callAt: this.timeouts[id].callAt,
214
+ interval: this.timeouts[id].interval,
215
+ id: this.timeouts[id].id,
216
+ invokeArgs: this.timeouts[id].invokeArgs
217
+ };
218
+ }
219
+ }
220
+ }
221
+
222
+ return timer || null;
223
+ },
224
+
225
+ callTimer: function (timer) {
226
+ if (typeof timer.interval == "number") {
227
+ this.timeouts[timer.id].callAt += timer.interval;
228
+ } else {
229
+ delete this.timeouts[timer.id];
230
+ }
231
+
232
+ try {
233
+ if (typeof timer.func == "function") {
234
+ timer.func.apply(null, timer.invokeArgs);
235
+ } else {
236
+ eval(timer.func);
237
+ }
238
+ } catch (e) {
239
+ var exception = e;
240
+ }
241
+
242
+ if (!this.timeouts[timer.id]) {
243
+ if (exception) {
244
+ throw exception;
245
+ }
246
+ return;
247
+ }
248
+
249
+ if (exception) {
250
+ throw exception;
251
+ }
252
+ },
253
+
254
+ reset: function reset() {
255
+ this.timeouts = {};
256
+ },
257
+
258
+ Date: (function () {
259
+ var NativeDate = Date;
260
+
261
+ function ClockDate(year, month, date, hour, minute, second, ms) {
262
+ // Defensive and verbose to avoid potential harm in passing
263
+ // explicit undefined when user does not pass argument
264
+ switch (arguments.length) {
265
+ case 0:
266
+ return new NativeDate(ClockDate.clock.now);
267
+ case 1:
268
+ return new NativeDate(year);
269
+ case 2:
270
+ return new NativeDate(year, month);
271
+ case 3:
272
+ return new NativeDate(year, month, date);
273
+ case 4:
274
+ return new NativeDate(year, month, date, hour);
275
+ case 5:
276
+ return new NativeDate(year, month, date, hour, minute);
277
+ case 6:
278
+ return new NativeDate(year, month, date, hour, minute, second);
279
+ default:
280
+ return new NativeDate(year, month, date, hour, minute, second, ms);
281
+ }
282
+ }
283
+
284
+ return mirrorDateProperties(ClockDate, NativeDate);
285
+ }())
286
+ };
287
+
288
+ function mirrorDateProperties(target, source) {
289
+ if (source.now) {
290
+ target.now = function now() {
291
+ return target.clock.now;
292
+ };
293
+ } else {
294
+ delete target.now;
295
+ }
296
+
297
+ if (source.toSource) {
298
+ target.toSource = function toSource() {
299
+ return source.toSource();
300
+ };
301
+ } else {
302
+ delete target.toSource;
303
+ }
304
+
305
+ target.toString = function toString() {
306
+ return source.toString();
307
+ };
308
+
309
+ target.prototype = source.prototype;
310
+ target.parse = source.parse;
311
+ target.UTC = source.UTC;
312
+ target.prototype.toUTCString = source.prototype.toUTCString;
313
+ return target;
314
+ }
315
+
316
+ var methods = ["Date", "setTimeout", "setInterval",
317
+ "clearTimeout", "clearInterval"];
318
+
319
+ function restore() {
320
+ var method;
321
+
322
+ for (var i = 0, l = this.methods.length; i < l; i++) {
323
+ method = this.methods[i];
324
+ if (global[method].hadOwnProperty) {
325
+ global[method] = this["_" + method];
326
+ } else {
327
+ delete global[method];
328
+ }
329
+ }
330
+
331
+ // Prevent multiple executions which will completely remove these props
332
+ this.methods = [];
333
+ }
334
+
335
+ function stubGlobal(method, clock) {
336
+ clock[method].hadOwnProperty = Object.prototype.hasOwnProperty.call(global, method);
337
+ clock["_" + method] = global[method];
338
+
339
+ if (method == "Date") {
340
+ var date = mirrorDateProperties(clock[method], global[method]);
341
+ global[method] = date;
342
+ } else {
343
+ global[method] = function () {
344
+ return clock[method].apply(clock, arguments);
345
+ };
346
+
347
+ for (var prop in clock[method]) {
348
+ if (clock[method].hasOwnProperty(prop)) {
349
+ global[method][prop] = clock[method][prop];
350
+ }
351
+ }
352
+ }
353
+
354
+ global[method].clock = clock;
355
+ }
356
+
357
+ sinon.useFakeTimers = function useFakeTimers(now) {
358
+ var clock = sinon.clock.create(now);
359
+ clock.restore = restore;
360
+ clock.methods = Array.prototype.slice.call(arguments,
361
+ typeof now == "number" ? 1 : 0);
362
+
363
+ if (clock.methods.length === 0) {
364
+ clock.methods = methods;
365
+ }
366
+
367
+ for (var i = 0, l = clock.methods.length; i < l; i++) {
368
+ stubGlobal(clock.methods[i], clock);
369
+ }
370
+
371
+ return clock;
372
+ };
373
+ }(typeof global != "undefined" && typeof global !== "function" ? global : this));
374
+
375
+ sinon.timers = {
376
+ setTimeout: setTimeout,
377
+ clearTimeout: clearTimeout,
378
+ setInterval: setInterval,
379
+ clearInterval: clearInterval,
380
+ Date: Date
381
+ };
382
+
383
+ if (typeof module == "object" && typeof require == "function") {
384
+ module.exports = sinon;
385
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: local_time
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javan Makhmali
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-09 00:00:00.000000000 Z
12
+ date: 2014-04-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: coffee-rails
@@ -40,7 +40,7 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  description:
43
- email: javan@37signals.com
43
+ email: javan@basecamp.com
44
44
  executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
@@ -51,14 +51,20 @@ files:
51
51
  - MIT-LICENSE
52
52
  - README.md
53
53
  - test/helpers/local_time_helper_test.rb
54
- - test/javascripts/config.ru
55
- - test/javascripts/index.html
56
- - test/javascripts/index.js.coffee
57
- - test/javascripts/unit/local_time_test.js.coffee
58
- - test/javascripts/unit/page_events_test.js.coffee
59
- - test/javascripts/unit/public_api_test.js.coffee
60
- - test/javascripts/unit/strftime_test.js.coffee
61
- - test/javascripts/unit/time_ago_test.js.coffee
54
+ - test/javascripts/local_time/index.js.coffee
55
+ - test/javascripts/local_time/local_time_test.js.coffee
56
+ - test/javascripts/local_time/page_events_test.js.coffee
57
+ - test/javascripts/local_time/public_api_test.js.coffee
58
+ - test/javascripts/local_time/relative_date_test.js.coffee
59
+ - test/javascripts/local_time/strftime_test.js.coffee
60
+ - test/javascripts/local_time/time_ago_test.js.coffee
61
+ - test/javascripts/runner/config.ru
62
+ - test/javascripts/runner/index.html
63
+ - test/javascripts/vendor/moment.js
64
+ - test/javascripts/vendor/qunit.css
65
+ - test/javascripts/vendor/qunit.js
66
+ - test/javascripts/vendor/run-qunit.coffee
67
+ - test/javascripts/vendor/sinon-timers.js
62
68
  homepage:
63
69
  licenses:
64
70
  - MIT
@@ -82,14 +88,20 @@ rubyforge_project:
82
88
  rubygems_version: 2.1.11
83
89
  signing_key:
84
90
  specification_version: 4
85
- summary: Rails engine for client-side local time
91
+ summary: Rails engine for cache-friendly, client-side local time
86
92
  test_files:
87
93
  - test/helpers/local_time_helper_test.rb
88
- - test/javascripts/config.ru
89
- - test/javascripts/index.html
90
- - test/javascripts/index.js.coffee
91
- - test/javascripts/unit/local_time_test.js.coffee
92
- - test/javascripts/unit/page_events_test.js.coffee
93
- - test/javascripts/unit/public_api_test.js.coffee
94
- - test/javascripts/unit/strftime_test.js.coffee
95
- - test/javascripts/unit/time_ago_test.js.coffee
94
+ - test/javascripts/local_time/index.js.coffee
95
+ - test/javascripts/local_time/local_time_test.js.coffee
96
+ - test/javascripts/local_time/page_events_test.js.coffee
97
+ - test/javascripts/local_time/public_api_test.js.coffee
98
+ - test/javascripts/local_time/relative_date_test.js.coffee
99
+ - test/javascripts/local_time/strftime_test.js.coffee
100
+ - test/javascripts/local_time/time_ago_test.js.coffee
101
+ - test/javascripts/runner/config.ru
102
+ - test/javascripts/runner/index.html
103
+ - test/javascripts/vendor/moment.js
104
+ - test/javascripts/vendor/qunit.css
105
+ - test/javascripts/vendor/qunit.js
106
+ - test/javascripts/vendor/run-qunit.coffee
107
+ - test/javascripts/vendor/sinon-timers.js