jdl 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/test/view.js ADDED
@@ -0,0 +1,330 @@
1
+ $(document).ready(function() {
2
+
3
+ var view;
4
+
5
+ module("Backbone.View", {
6
+
7
+ setup: function() {
8
+ view = new Backbone.View({
9
+ id : 'test-view',
10
+ className : 'test-view',
11
+ other : 'non-special-option'
12
+ });
13
+ }
14
+
15
+ });
16
+
17
+ test("constructor", 3, function() {
18
+ equal(view.el.id, 'test-view');
19
+ equal(view.el.className, 'test-view');
20
+ equal(view.el.other, void 0);
21
+ });
22
+
23
+ test("jQuery", 1, function() {
24
+ var view = new Backbone.View;
25
+ view.setElement('<p><a><b>test</b></a></p>');
26
+ strictEqual(view.$('a b').html(), 'test');
27
+ });
28
+
29
+ test("initialize", 1, function() {
30
+ var View = Backbone.View.extend({
31
+ initialize: function() {
32
+ this.one = 1;
33
+ }
34
+ });
35
+
36
+ strictEqual(new View().one, 1);
37
+ });
38
+
39
+ test("delegateEvents", 6, function() {
40
+ var counter1 = 0, counter2 = 0;
41
+
42
+ var view = new Backbone.View({el: '<p><a id="test"></a></p>'});
43
+ view.increment = function(){ counter1++; };
44
+ view.$el.on('click', function(){ counter2++; });
45
+
46
+ var events = {'click #test': 'increment'};
47
+
48
+ view.delegateEvents(events);
49
+ view.$('#test').trigger('click');
50
+ equal(counter1, 1);
51
+ equal(counter2, 1);
52
+
53
+ view.$('#test').trigger('click');
54
+ equal(counter1, 2);
55
+ equal(counter2, 2);
56
+
57
+ view.delegateEvents(events);
58
+ view.$('#test').trigger('click');
59
+ equal(counter1, 3);
60
+ equal(counter2, 3);
61
+ });
62
+
63
+ test("delegateEvents allows functions for callbacks", 3, function() {
64
+ var view = new Backbone.View({el: '<p></p>'});
65
+ view.counter = 0;
66
+
67
+ var events = {
68
+ click: function() {
69
+ this.counter++;
70
+ }
71
+ };
72
+
73
+ view.delegateEvents(events);
74
+ view.$el.trigger('click');
75
+ equal(view.counter, 1);
76
+
77
+ view.$el.trigger('click');
78
+ equal(view.counter, 2);
79
+
80
+ view.delegateEvents(events);
81
+ view.$el.trigger('click');
82
+ equal(view.counter, 3);
83
+ });
84
+
85
+
86
+ test("delegateEvents ignore undefined methods", 0, function() {
87
+ var view = new Backbone.View({el: '<p></p>'});
88
+ view.delegateEvents({'click': 'undefinedMethod'});
89
+ view.$el.trigger('click');
90
+ });
91
+
92
+ test("undelegateEvents", 6, function() {
93
+ var counter1 = 0, counter2 = 0;
94
+
95
+ var view = new Backbone.View({el: '<p><a id="test"></a></p>'});
96
+ view.increment = function(){ counter1++; };
97
+ view.$el.on('click', function(){ counter2++; });
98
+
99
+ var events = {'click #test': 'increment'};
100
+
101
+ view.delegateEvents(events);
102
+ view.$('#test').trigger('click');
103
+ equal(counter1, 1);
104
+ equal(counter2, 1);
105
+
106
+ view.undelegateEvents();
107
+ view.$('#test').trigger('click');
108
+ equal(counter1, 1);
109
+ equal(counter2, 2);
110
+
111
+ view.delegateEvents(events);
112
+ view.$('#test').trigger('click');
113
+ equal(counter1, 2);
114
+ equal(counter2, 3);
115
+ });
116
+
117
+ test("_ensureElement with DOM node el", 1, function() {
118
+ var View = Backbone.View.extend({
119
+ el: document.body
120
+ });
121
+
122
+ equal(new View().el, document.body);
123
+ });
124
+
125
+ test("_ensureElement with string el", 3, function() {
126
+ var View = Backbone.View.extend({
127
+ el: "body"
128
+ });
129
+ strictEqual(new View().el, document.body);
130
+
131
+ View = Backbone.View.extend({
132
+ el: "#testElement > h1"
133
+ });
134
+ strictEqual(new View().el, $("#testElement > h1").get(0));
135
+
136
+ View = Backbone.View.extend({
137
+ el: "#nonexistent"
138
+ });
139
+ ok(!new View().el);
140
+ });
141
+
142
+ test("with className and id functions", 2, function() {
143
+ var View = Backbone.View.extend({
144
+ className: function() {
145
+ return 'className';
146
+ },
147
+ id: function() {
148
+ return 'id';
149
+ }
150
+ });
151
+
152
+ strictEqual(new View().el.className, 'className');
153
+ strictEqual(new View().el.id, 'id');
154
+ });
155
+
156
+ test("with attributes", 2, function() {
157
+ var View = Backbone.View.extend({
158
+ attributes: {
159
+ id: 'id',
160
+ 'class': 'class'
161
+ }
162
+ });
163
+
164
+ strictEqual(new View().el.className, 'class');
165
+ strictEqual(new View().el.id, 'id');
166
+ });
167
+
168
+ test("with attributes as a function", 1, function() {
169
+ var View = Backbone.View.extend({
170
+ attributes: function() {
171
+ return {'class': 'dynamic'};
172
+ }
173
+ });
174
+
175
+ strictEqual(new View().el.className, 'dynamic');
176
+ });
177
+
178
+ test("multiple views per element", 3, function() {
179
+ var count = 0;
180
+ var $el = $('<p></p>');
181
+
182
+ var View = Backbone.View.extend({
183
+ el: $el,
184
+ events: {
185
+ click: function() {
186
+ count++;
187
+ }
188
+ }
189
+ });
190
+
191
+ var view1 = new View;
192
+ $el.trigger("click");
193
+ equal(1, count);
194
+
195
+ var view2 = new View;
196
+ $el.trigger("click");
197
+ equal(3, count);
198
+
199
+ view1.delegateEvents();
200
+ $el.trigger("click");
201
+ equal(5, count);
202
+ });
203
+
204
+ test("custom events, with namespaces", 2, function() {
205
+ var count = 0;
206
+
207
+ var View = Backbone.View.extend({
208
+ el: $('body'),
209
+ events: function() {
210
+ return {"fake$event.namespaced": "run"};
211
+ },
212
+ run: function() {
213
+ count++;
214
+ }
215
+ });
216
+
217
+ var view = new View;
218
+ $('body').trigger('fake$event').trigger('fake$event');
219
+ equal(count, 2);
220
+
221
+ $('body').unbind('.namespaced');
222
+ $('body').trigger('fake$event');
223
+ equal(count, 2);
224
+ });
225
+
226
+ test("#1048 - setElement uses provided object.", 2, function() {
227
+ var $el = $('body');
228
+
229
+ var view = new Backbone.View({el: $el});
230
+ ok(view.$el === $el);
231
+
232
+ view.setElement($el = $($el));
233
+ ok(view.$el === $el);
234
+ });
235
+
236
+ test("#986 - Undelegate before changing element.", 1, function() {
237
+ var button1 = $('<button></button>');
238
+ var button2 = $('<button></button>');
239
+
240
+ var View = Backbone.View.extend({
241
+ events: {
242
+ click: function(e) {
243
+ ok(view.el === e.target);
244
+ }
245
+ }
246
+ });
247
+
248
+ var view = new View({el: button1});
249
+ view.setElement(button2);
250
+
251
+ button1.trigger('click');
252
+ button2.trigger('click');
253
+ });
254
+
255
+ test("#1172 - Clone attributes object", 2, function() {
256
+ var View = Backbone.View.extend({
257
+ attributes: {foo: 'bar'}
258
+ });
259
+
260
+ var view1 = new View({id: 'foo'});
261
+ strictEqual(view1.el.id, 'foo');
262
+
263
+ var view2 = new View();
264
+ ok(!view2.el.id);
265
+ });
266
+
267
+ test("#1228 - tagName can be provided as a function", 1, function() {
268
+ var View = Backbone.View.extend({
269
+ tagName: function() {
270
+ return 'p';
271
+ }
272
+ });
273
+
274
+ ok(new View().$el.is('p'));
275
+ });
276
+
277
+ test("views stopListening", 0, function() {
278
+ var View = Backbone.View.extend({
279
+ initialize: function() {
280
+ this.listenTo(this.model, 'all x', function(){ ok(false); }, this);
281
+ this.listenTo(this.collection, 'all x', function(){ ok(false); }, this);
282
+ }
283
+ });
284
+
285
+ var view = new View({
286
+ model: new Backbone.Model,
287
+ collection: new Backbone.Collection
288
+ });
289
+
290
+ view.stopListening();
291
+ view.model.trigger('x');
292
+ view.collection.trigger('x');
293
+ });
294
+
295
+ test("Provide function for el.", 1, function() {
296
+ var View = Backbone.View.extend({
297
+ el: function() {
298
+ return "<p><a></a></p>";
299
+ }
300
+ });
301
+
302
+ var view = new View;
303
+ ok(view.$el.is('p:has(a)'));
304
+ });
305
+
306
+ test("events passed in options", 2, function() {
307
+ var counter = 0;
308
+
309
+ var View = Backbone.View.extend({
310
+ el: '<p><a id="test"></a></p>',
311
+ increment: function() {
312
+ counter++;
313
+ }
314
+ });
315
+
316
+ var view = new View({events:{'click #test':'increment'}});
317
+ var view2 = new View({events:function(){
318
+ return {'click #test':'increment'};
319
+ }});
320
+
321
+ view.$('#test').trigger('click');
322
+ view2.$('#test').trigger('click');
323
+ equal(counter, 2);
324
+
325
+ view.$('#test').trigger('click');
326
+ view2.$('#test').trigger('click');
327
+ equal(counter, 4);
328
+ });
329
+
330
+ });
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jdl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - shiren1118
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: 根据指定目录,扫描内部扩展名为*的所有文件,并输出到jdl.js内
47
+ email:
48
+ - shiren1118@126.com
49
+ executables:
50
+ - jdl
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - bin/jdl
60
+ - jdl.gemspec
61
+ - lib/jdl.rb
62
+ - lib/jdl/version.rb
63
+ - test/collection.js
64
+ - test/environment.js
65
+ - test/events.js
66
+ - test/index.html
67
+ - test/model.coffee
68
+ - test/model.js
69
+ - test/noconflict.js
70
+ - test/router.js
71
+ - test/sync.js
72
+ - test/vendor/backbone.js
73
+ - test/vendor/jquery.js
74
+ - test/vendor/json2.js
75
+ - test/vendor/qunit.css
76
+ - test/vendor/qunit.js
77
+ - test/vendor/runner.js
78
+ - test/vendor/underscore.js
79
+ - test/view.js
80
+ homepage: ''
81
+ licenses:
82
+ - MIT
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ segments:
94
+ - 0
95
+ hash: 4035505812434293333
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ segments:
103
+ - 0
104
+ hash: 4035505812434293333
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 1.8.25
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: 根据指定目录,扫描内部扩展名为*的所有文件,并输出到jdl.js内,主要用于js测试
111
+ test_files:
112
+ - test/collection.js
113
+ - test/environment.js
114
+ - test/events.js
115
+ - test/index.html
116
+ - test/model.coffee
117
+ - test/model.js
118
+ - test/noconflict.js
119
+ - test/router.js
120
+ - test/sync.js
121
+ - test/vendor/backbone.js
122
+ - test/vendor/jquery.js
123
+ - test/vendor/json2.js
124
+ - test/vendor/qunit.css
125
+ - test/vendor/qunit.js
126
+ - test/vendor/runner.js
127
+ - test/vendor/underscore.js
128
+ - test/view.js