rack-noncache 0.0.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.pryrc +6 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +15 -0
  7. data/README.md +36 -52
  8. data/Rakefile +16 -1
  9. data/features/cache_control.feature +22 -0
  10. data/features/step_definitions/steps.rb +46 -0
  11. data/features/support/continous_integration.rb +47 -0
  12. data/features/support/coverage.rb +18 -0
  13. data/features/support/env.rb +9 -0
  14. data/features/support/helpers.rb +13 -0
  15. data/features/support/web_app/application.rb +70 -0
  16. data/features/support/web_app/config_blacklist.ru +13 -0
  17. data/features/support/web_app/config_whitelist.ru +13 -0
  18. data/features/support/web_app/public/app/collections/todos.js +17 -0
  19. data/features/support/web_app/public/app/config.js +18 -0
  20. data/features/support/web_app/public/app/main.js +21 -0
  21. data/features/support/web_app/public/app/models/todo.js +33 -0
  22. data/features/support/web_app/public/app/templates/todo-add.html +3 -0
  23. data/features/support/web_app/public/app/templates/todo-editor.html +1 -0
  24. data/features/support/web_app/public/app/templates/todo-item.html +2 -0
  25. data/features/support/web_app/public/app/templates/todo-list-empty.html +1 -0
  26. data/features/support/web_app/public/app/templates/todo-stats.html +4 -0
  27. data/features/support/web_app/public/app/views/stats.js +26 -0
  28. data/features/support/web_app/public/app/views/todo.js +55 -0
  29. data/features/support/web_app/public/app/views/todoadd.js +48 -0
  30. data/features/support/web_app/public/app/views/todoedit.js +70 -0
  31. data/features/support/web_app/public/app/views/todolist.js +69 -0
  32. data/features/support/web_app/public/assets/css/bootstrap.css +3990 -0
  33. data/features/support/web_app/public/assets/css/style.css +82 -0
  34. data/features/support/web_app/public/assets/js/libs/backbone.js +1428 -0
  35. data/features/support/web_app/public/assets/js/libs/jquery-1.7.2.js +9404 -0
  36. data/features/support/web_app/public/assets/js/libs/require.js +2053 -0
  37. data/features/support/web_app/public/assets/js/libs/underscore.js +1008 -0
  38. data/features/support/web_app/public/assets/js/plugins/text.js +288 -0
  39. data/features/support/web_app/public/test/SpecRunner.html +42 -0
  40. data/features/support/web_app/public/test/lib/jasmine-1.2.0.rc3/MIT.LICENSE +20 -0
  41. data/features/support/web_app/public/test/lib/jasmine-1.2.0.rc3/jasmine-html.js +616 -0
  42. data/features/support/web_app/public/test/lib/jasmine-1.2.0.rc3/jasmine.css +81 -0
  43. data/features/support/web_app/public/test/lib/jasmine-1.2.0.rc3/jasmine.js +2530 -0
  44. data/features/support/web_app/public/test/lib/jasmine-jquery.js +306 -0
  45. data/features/support/web_app/public/test/spec/models/todo.coffee +37 -0
  46. data/features/support/web_app/public/test/spec/models/todo.js +48 -0
  47. data/features/support/web_app/public/test/spec/spec_helper.coffee +20 -0
  48. data/features/support/web_app/public/test/spec/spec_helper.js +17 -0
  49. data/features/support/web_app/public/test/spec/views/stats.coffee +9 -0
  50. data/features/support/web_app/public/test/spec/views/stats.js +13 -0
  51. data/features/support/web_app/public/test/spec/views/todo.coffee +22 -0
  52. data/features/support/web_app/public/test/spec/views/todo.js +26 -0
  53. data/features/support/web_app/public/test/spec/views/todoadd.coffee +22 -0
  54. data/features/support/web_app/public/test/spec/views/todoadd.js +29 -0
  55. data/features/support/web_app/public/test/spec/views/todoedit.coffee +59 -0
  56. data/features/support/web_app/public/test/spec/views/todoedit.js +72 -0
  57. data/features/support/web_app/public/test/spec/views/todolist.coffee +28 -0
  58. data/features/support/web_app/public/test/spec/views/todolist.js +39 -0
  59. data/features/support/web_app/views/details.erb +14 -0
  60. data/features/support/web_app/views/index.erb +43 -0
  61. data/lib/rack/noncache.rb +5 -7
  62. data/lib/rack/noncache/engine.rb +10 -26
  63. data/lib/rack/noncache/filters.rb +75 -0
  64. data/lib/rack/noncache/version.rb +1 -1
  65. data/rack-noncache.gemspec +32 -10
  66. metadata +382 -7
@@ -0,0 +1,306 @@
1
+ var readFixtures = function() {
2
+ return jasmine.getFixtures().proxyCallTo_('read', arguments);
3
+ };
4
+
5
+ var preloadFixtures = function() {
6
+ jasmine.getFixtures().proxyCallTo_('preload', arguments);
7
+ };
8
+
9
+ var loadFixtures = function() {
10
+ jasmine.getFixtures().proxyCallTo_('load', arguments);
11
+ };
12
+
13
+ var setFixtures = function(html) {
14
+ jasmine.getFixtures().set(html);
15
+ };
16
+
17
+ var sandbox = function(attributes) {
18
+ return jasmine.getFixtures().sandbox(attributes);
19
+ };
20
+
21
+ var spyOnEvent = function(selector, eventName) {
22
+ jasmine.JQuery.events.spyOn(selector, eventName);
23
+ };
24
+
25
+ jasmine.getFixtures = function() {
26
+ return jasmine.currentFixtures_ = jasmine.currentFixtures_ || new jasmine.Fixtures();
27
+ };
28
+
29
+ jasmine.Fixtures = function() {
30
+ this.containerId = 'jasmine-fixtures';
31
+ this.fixturesCache_ = {};
32
+ this.fixturesPath = 'spec/javascripts/fixtures';
33
+ };
34
+
35
+ jasmine.Fixtures.prototype.set = function(html) {
36
+ this.cleanUp();
37
+ this.createContainer_(html);
38
+ };
39
+
40
+ jasmine.Fixtures.prototype.preload = function() {
41
+ this.read.apply(this, arguments);
42
+ };
43
+
44
+ jasmine.Fixtures.prototype.load = function() {
45
+ this.cleanUp();
46
+ this.createContainer_(this.read.apply(this, arguments));
47
+ };
48
+
49
+ jasmine.Fixtures.prototype.read = function() {
50
+ var htmlChunks = [];
51
+
52
+ var fixtureUrls = arguments;
53
+ for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) {
54
+ htmlChunks.push(this.getFixtureHtml_(fixtureUrls[urlIndex]));
55
+ }
56
+
57
+ return htmlChunks.join('');
58
+ };
59
+
60
+ jasmine.Fixtures.prototype.clearCache = function() {
61
+ this.fixturesCache_ = {};
62
+ };
63
+
64
+ jasmine.Fixtures.prototype.cleanUp = function() {
65
+ jQuery('#' + this.containerId).remove();
66
+ };
67
+
68
+ jasmine.Fixtures.prototype.sandbox = function(attributes) {
69
+ var attributesToSet = attributes || {};
70
+ return jQuery('<div id="sandbox" />').attr(attributesToSet);
71
+ };
72
+
73
+ jasmine.Fixtures.prototype.createContainer_ = function(html) {
74
+ var container;
75
+ if(html instanceof jQuery) {
76
+ container = jQuery('<div id="' + this.containerId + '" />');
77
+ container.html(html);
78
+ } else {
79
+ container = '<div id="' + this.containerId + '">' + html + '</div>'
80
+ }
81
+ jQuery('body').append(container);
82
+ };
83
+
84
+ jasmine.Fixtures.prototype.getFixtureHtml_ = function(url) {
85
+ if (typeof this.fixturesCache_[url] == 'undefined') {
86
+ this.loadFixtureIntoCache_(url);
87
+ }
88
+ return this.fixturesCache_[url];
89
+ };
90
+
91
+ jasmine.Fixtures.prototype.loadFixtureIntoCache_ = function(relativeUrl) {
92
+ var url = this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl;
93
+ var request = new XMLHttpRequest();
94
+ request.open("GET", url + "?" + new Date().getTime(), false);
95
+ request.send(null);
96
+ this.fixturesCache_[relativeUrl] = request.responseText;
97
+ };
98
+
99
+ jasmine.Fixtures.prototype.proxyCallTo_ = function(methodName, passedArguments) {
100
+ return this[methodName].apply(this, passedArguments);
101
+ };
102
+
103
+
104
+ jasmine.JQuery = function() {};
105
+
106
+ jasmine.JQuery.browserTagCaseIndependentHtml = function(html) {
107
+ return jQuery('<div/>').append(html).html();
108
+ };
109
+
110
+ jasmine.JQuery.elementToString = function(element) {
111
+ return jQuery('<div />').append($(element).clone()).html();
112
+ };
113
+
114
+ jasmine.JQuery.matchersClass = {};
115
+
116
+ (function(namespace) {
117
+ var data = {
118
+ spiedEvents: {},
119
+ handlers: []
120
+ };
121
+
122
+ namespace.events = {
123
+ spyOn: function(selector, eventName) {
124
+ var handler = function(e) {
125
+ data.spiedEvents[[selector, eventName]] = e;
126
+ };
127
+ jQuery(selector).bind(eventName, handler);
128
+ data.handlers.push(handler);
129
+ },
130
+
131
+ wasTriggered: function(selector, eventName) {
132
+ return !!(data.spiedEvents[[selector, eventName]]);
133
+ },
134
+
135
+ wasPrevented: function(selector, eventName) {
136
+ return data.spiedEvents[[selector, eventName]].isDefaultPrevented();
137
+ },
138
+
139
+ cleanUp: function() {
140
+ data.spiedEvents = {};
141
+ data.handlers = [];
142
+ }
143
+ }
144
+ })(jasmine.JQuery);
145
+
146
+ (function(){
147
+ var jQueryMatchers = {
148
+ toHaveClass: function(className) {
149
+ return this.actual.hasClass(className);
150
+ },
151
+
152
+ toBeVisible: function() {
153
+ return this.actual.is(':visible');
154
+ },
155
+
156
+ toBeHidden: function() {
157
+ return this.actual.is(':hidden');
158
+ },
159
+
160
+ toBeSelected: function() {
161
+ return this.actual.is(':selected');
162
+ },
163
+
164
+ toBeChecked: function() {
165
+ return this.actual.is(':checked');
166
+ },
167
+
168
+ toBeEmpty: function() {
169
+ return this.actual.is(':empty');
170
+ },
171
+
172
+ toExist: function() {
173
+ return this.actual.size() > 0;
174
+ },
175
+
176
+ toHaveAttr: function(attributeName, expectedAttributeValue) {
177
+ return hasProperty(this.actual.attr(attributeName), expectedAttributeValue);
178
+ },
179
+
180
+ toHaveProp: function(propertyName, expectedPropertyValue) {
181
+ return hasProperty(this.actual.prop(propertyName), expectedPropertyValue);
182
+ },
183
+
184
+ toHaveId: function(id) {
185
+ return this.actual.attr('id') == id;
186
+ },
187
+
188
+ toHaveHtml: function(html) {
189
+ return this.actual.html() == jasmine.JQuery.browserTagCaseIndependentHtml(html);
190
+ },
191
+
192
+ toHaveText: function(text) {
193
+ var trimmedText = $.trim(this.actual.text());
194
+ if (text && jQuery.isFunction(text.test)) {
195
+ return text.test(trimmedText);
196
+ } else {
197
+ return trimmedText == text;
198
+ }
199
+ },
200
+
201
+ toHaveValue: function(value) {
202
+ return this.actual.val() == value;
203
+ },
204
+
205
+ toHaveData: function(key, expectedValue) {
206
+ return hasProperty(this.actual.data(key), expectedValue);
207
+ },
208
+
209
+ toBe: function(selector) {
210
+ return this.actual.is(selector);
211
+ },
212
+
213
+ toContain: function(selector) {
214
+ return this.actual.find(selector).size() > 0;
215
+ },
216
+
217
+ toBeDisabled: function(selector){
218
+ return this.actual.is(':disabled');
219
+ },
220
+
221
+ toBeFocused: function(selector) {
222
+ return this.actual.is(':focus');
223
+ },
224
+
225
+ // tests the existence of a specific event binding
226
+ toHandle: function(eventName) {
227
+ var events = this.actual.data("events");
228
+ return events && events[eventName].length > 0;
229
+ },
230
+
231
+ // tests the existence of a specific event binding + handler
232
+ toHandleWith: function(eventName, eventHandler) {
233
+ var stack = this.actual.data("events")[eventName];
234
+ var i;
235
+ for (i = 0; i < stack.length; i++) {
236
+ if (stack[i].handler == eventHandler) {
237
+ return true;
238
+ }
239
+ }
240
+ return false;
241
+ }
242
+ };
243
+
244
+ var hasProperty = function(actualValue, expectedValue) {
245
+ if (expectedValue === undefined) {
246
+ return actualValue !== undefined;
247
+ }
248
+ return actualValue == expectedValue;
249
+ };
250
+
251
+ var bindMatcher = function(methodName) {
252
+ var builtInMatcher = jasmine.Matchers.prototype[methodName];
253
+
254
+ jasmine.JQuery.matchersClass[methodName] = function() {
255
+ if (this.actual
256
+ && (this.actual instanceof jQuery
257
+ || jasmine.isDomNode(this.actual))) {
258
+ this.actual = $(this.actual);
259
+ var result = jQueryMatchers[methodName].apply(this, arguments);
260
+ this.actual = jasmine.JQuery.elementToString(this.actual);
261
+ return result;
262
+ }
263
+
264
+ if (builtInMatcher) {
265
+ return builtInMatcher.apply(this, arguments);
266
+ }
267
+
268
+ return false;
269
+ };
270
+ };
271
+
272
+ for(var methodName in jQueryMatchers) {
273
+ bindMatcher(methodName);
274
+ }
275
+ })();
276
+
277
+ beforeEach(function() {
278
+ this.addMatchers(jasmine.JQuery.matchersClass);
279
+ this.addMatchers({
280
+ toHaveBeenTriggeredOn: function(selector) {
281
+ this.message = function() {
282
+ return [
283
+ "Expected event " + this.actual + " to have been triggered on " + selector,
284
+ "Expected event " + this.actual + " not to have been triggered on " + selector
285
+ ];
286
+ };
287
+ return jasmine.JQuery.events.wasTriggered($(selector), this.actual);
288
+ }
289
+ });
290
+ this.addMatchers({
291
+ toHaveBeenPreventedOn: function(selector) {
292
+ this.message = function() {
293
+ return [
294
+ "Expected event " + this.actual + " to have been prevented on " + selector,
295
+ "Expected event " + this.actual + " not to have been prevented on " + selector
296
+ ];
297
+ };
298
+ return jasmine.JQuery.events.wasPrevented(selector, this.actual);
299
+ }
300
+ });
301
+ });
302
+
303
+ afterEach(function() {
304
+ jasmine.getFixtures().cleanUp();
305
+ jasmine.JQuery.events.cleanUp();
306
+ });
@@ -0,0 +1,37 @@
1
+ define ["models/todo", "collections/todos"], (Todo, TodoList) ->
2
+
3
+ describe "Todo", ->
4
+ beforeEach ->
5
+ @todo = new Todo
6
+ @todo.urlRoot = "/"
7
+
8
+ it "a done should be false be default", ->
9
+ expect(@todo.get("done")).toBeFalsy()
10
+
11
+ it "should return the text", ->
12
+ @todo.set "text", "hola"
13
+ expect(@todo.getText()).toEqual "hola"
14
+
15
+ it "should set and return the done state", ->
16
+ @todo.setText "ok"
17
+ @todo.done()
18
+ expect(@todo.isDone()).toBeTruthy()
19
+
20
+ it "should validate the text length", ->
21
+ expect(@todo.setText("")).toBeFalsy()
22
+ expect(@todo.setText("wat")).toBeTruthy()
23
+
24
+
25
+ describe "TodoList", ->
26
+ beforeEach ->
27
+ @collection = new TodoList
28
+ @collection.add({done: false, text: "uncompleted task"})
29
+ @collection.add({done: true, text: "done task"})
30
+
31
+ it "should return the remaining todos", ->
32
+ count = @collection.getRemaining().length
33
+ expect(count).toEqual(1)
34
+
35
+ it "should return the completed todos", ->
36
+ count = @collection.getCompleted().length
37
+ expect(count).toEqual(1)
@@ -0,0 +1,48 @@
1
+
2
+ define(["models/todo", "collections/todos"], function(Todo, TodoList) {
3
+ describe("Todo", function() {
4
+ beforeEach(function() {
5
+ this.todo = new Todo;
6
+ return this.todo.urlRoot = "/";
7
+ });
8
+ it("a done should be false be default", function() {
9
+ return expect(this.todo.get("done")).toBeFalsy();
10
+ });
11
+ it("should return the text", function() {
12
+ this.todo.set("text", "hola");
13
+ return expect(this.todo.getText()).toEqual("hola");
14
+ });
15
+ it("should set and return the done state", function() {
16
+ this.todo.setText("ok");
17
+ this.todo.done();
18
+ return expect(this.todo.isDone()).toBeTruthy();
19
+ });
20
+ return it("should validate the text length", function() {
21
+ expect(this.todo.setText("")).toBeFalsy();
22
+ return expect(this.todo.setText("wat")).toBeTruthy();
23
+ });
24
+ });
25
+ return describe("TodoList", function() {
26
+ beforeEach(function() {
27
+ this.collection = new TodoList;
28
+ this.collection.add({
29
+ done: false,
30
+ text: "uncompleted task"
31
+ });
32
+ return this.collection.add({
33
+ done: true,
34
+ text: "done task"
35
+ });
36
+ });
37
+ it("should return the remaining todos", function() {
38
+ var count;
39
+ count = this.collection.getRemaining().length;
40
+ return expect(count).toEqual(1);
41
+ });
42
+ return it("should return the completed todos", function() {
43
+ var count;
44
+ count = this.collection.getCompleted().length;
45
+ return expect(count).toEqual(1);
46
+ });
47
+ });
48
+ });
@@ -0,0 +1,20 @@
1
+ # Helper functions available to all specs in the this.scope.
2
+
3
+ define ["models/todo", "collections/todos", "views/todoedit"], (Todo, TodoList, TodoEditor) ->
4
+ beforeEach ->
5
+
6
+ # set fake url to not hit the DB with each test.
7
+ # TODO use sinon or stub out Backbone.sync() for better handling
8
+ @todoList = new TodoList
9
+ @todoList.url = "/"
10
+
11
+ @todo = new Todo(text: "new todo")
12
+ @todo.urlRoot = "/"
13
+
14
+ @editor = new TodoEditor
15
+
16
+ # Returns the default options for todos views.
17
+ @viewOptions =
18
+ model : @todo
19
+ collection : @todoList
20
+ editor : @editor
@@ -0,0 +1,17 @@
1
+
2
+ define(["models/todo", "collections/todos", "views/todoedit"], function(Todo, TodoList, TodoEditor) {
3
+ return beforeEach(function() {
4
+ this.todoList = new TodoList;
5
+ this.todoList.url = "/";
6
+ this.todo = new Todo({
7
+ text: "new todo"
8
+ });
9
+ this.todo.urlRoot = "/";
10
+ this.editor = new TodoEditor;
11
+ return this.viewOptions = {
12
+ model: this.todo,
13
+ collection: this.todoList,
14
+ editor: this.editor
15
+ };
16
+ });
17
+ });
@@ -0,0 +1,9 @@
1
+ define ["views/stats"], (TodoStatsView) ->
2
+ describe "TodoStatsView", ->
3
+ beforeEach ->
4
+ @view = new TodoStatsView(@viewOptions)
5
+
6
+ it "should render on the 'all' event", ->
7
+ spyOn(@view.$el, "html").andCallThrough()
8
+ @view.collection.trigger("all")
9
+ expect(@view.$el.html).toHaveBeenCalled()
@@ -0,0 +1,13 @@
1
+
2
+ define(["views/stats"], function(TodoStatsView) {
3
+ return describe("TodoStatsView", function() {
4
+ beforeEach(function() {
5
+ return this.view = new TodoStatsView(this.viewOptions);
6
+ });
7
+ return it("should render on the 'all' event", function() {
8
+ spyOn(this.view.$el, "html").andCallThrough();
9
+ this.view.collection.trigger("all");
10
+ return expect(this.view.$el.html).toHaveBeenCalled();
11
+ });
12
+ });
13
+ });