joosy 1.2.0.alpha.41 → 1.2.0.alpha.51

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/Gruntfile.coffee +27 -7
  4. data/bin/joosy +1 -1
  5. data/bower.json +3 -2
  6. data/build/joosy/extensions/preloaders.js +189 -0
  7. data/build/joosy/extensions/resources-form.js +588 -0
  8. data/build/joosy/extensions/resources.js +673 -0
  9. data/build/joosy.js +2395 -0
  10. data/{src/joosy/generators → generators}/base.coffee +2 -2
  11. data/{src/joosy/generators → generators/command}/command.coffee +16 -3
  12. data/generators/command/help.coffee +38 -0
  13. data/{src/joosy/generators → generators}/layout.coffee +0 -0
  14. data/{src/joosy/generators → generators}/page.coffee +0 -0
  15. data/{src/joosy/generators → generators}/project/base.coffee +2 -4
  16. data/{src/joosy/generators → generators}/project/standalone.coffee +4 -3
  17. data/{src/joosy/generators → generators}/project.coffee +0 -0
  18. data/generators/templates/application/base/application.coffee +13 -0
  19. data/{templates → generators/templates}/application/base/helpers/application.coffee +0 -0
  20. data/{templates → generators/templates}/application/base/layouts/application.coffee +0 -0
  21. data/{templates → generators/templates}/application/base/pages/application.coffee +0 -0
  22. data/{templates → generators/templates}/application/base/pages/welcome/index.coffee +0 -0
  23. data/{templates → generators/templates}/application/base/routes.coffee +0 -0
  24. data/{templates → generators/templates}/application/base/templates/layouts/application.jst.hamlc +0 -0
  25. data/{templates → generators/templates}/application/base/templates/pages/welcome/index.jst.hamlc +0 -0
  26. data/{templates → generators/templates}/application/standalone/Gruntfile.coffee +1 -0
  27. data/{templates → generators/templates}/application/standalone/Procfile +0 -0
  28. data/{templates → generators/templates}/application/standalone/_gitignore +0 -0
  29. data/generators/templates/application/standalone/bower.json +17 -0
  30. data/{templates → generators/templates}/application/standalone/package.json +0 -0
  31. data/{templates → generators/templates}/application/standalone/source/haml/index.haml +0 -0
  32. data/{templates → generators/templates}/application/standalone/source/stylesheets/application.styl +0 -0
  33. data/{templates → generators/templates}/layout/basic.coffee +0 -0
  34. data/{templates → generators/templates}/layout/namespaced.coffee +0 -0
  35. data/{templates → generators/templates}/page/basic.coffee +0 -0
  36. data/{templates → generators/templates}/page/namespaced.coffee +0 -0
  37. data/{templates → generators/templates}/widget/basic.coffee +0 -0
  38. data/{templates → generators/templates}/widget/namespaced.coffee +0 -0
  39. data/{src/joosy/generators → generators}/widget.coffee +0 -0
  40. data/lib/joosy.rb +3 -3
  41. data/package.json +2 -3
  42. data/source/joosy/application.coffee +95 -0
  43. data/source/joosy/events/namespace.coffee +24 -0
  44. data/{src → source}/joosy/extensions/preloaders/caching.coffee +0 -0
  45. data/{src → source}/joosy/extensions/preloaders/index.coffee +0 -0
  46. data/{src → source}/joosy/extensions/preloaders/inline.coffee +0 -0
  47. data/{src → source}/joosy/extensions/resources/base.coffee +16 -8
  48. data/{src → source}/joosy/extensions/resources/collection.coffee +0 -0
  49. data/{src → source}/joosy/extensions/resources/index.coffee +0 -0
  50. data/{src → source}/joosy/extensions/resources/rest.coffee +0 -0
  51. data/{src → source}/joosy/extensions/resources/rest_collection.coffee +0 -0
  52. data/{src → source}/joosy/extensions/resources-form/form.coffee +18 -18
  53. data/{src → source}/joosy/extensions/resources-form/helpers/form.coffee +6 -6
  54. data/{src → source}/joosy/extensions/resources-form/index.coffee +0 -0
  55. data/source/joosy/helpers/routes.coffee +10 -0
  56. data/source/joosy/helpers/view.coffee +115 -0
  57. data/{src/joosy/core → source/joosy}/helpers/widgets.coffee +1 -1
  58. data/{src/joosy/core → source/joosy}/joosy.coffee +59 -19
  59. data/source/joosy/layout.coffee +73 -0
  60. data/{src/joosy/core → source/joosy}/module.coffee +7 -2
  61. data/{src/joosy/core/modules/container.coffee → source/joosy/modules/dom.coffee} +24 -17
  62. data/source/joosy/modules/events.coffee +156 -0
  63. data/source/joosy/modules/filters.coffee +67 -0
  64. data/{src/joosy/core → source/joosy}/modules/log.coffee +7 -3
  65. data/source/joosy/modules/page/scrolling.coffee +51 -0
  66. data/source/joosy/modules/page/title.coffee +18 -0
  67. data/{src/joosy/core → source/joosy}/modules/renderer.coffee +12 -13
  68. data/{src/joosy/core → source/joosy}/modules/time_manager.coffee +5 -1
  69. data/{src/joosy/core → source/joosy}/modules/widgets_manager.coffee +9 -5
  70. data/source/joosy/page.coffee +68 -0
  71. data/{src/joosy/core → source/joosy}/resources/watcher.coffee +5 -1
  72. data/source/joosy/router.coffee +305 -0
  73. data/{src/joosy/core → source/joosy}/templaters/jst.coffee +10 -7
  74. data/source/joosy/widget.coffee +385 -0
  75. data/source/joosy.coffee +1 -0
  76. data/{src/vendor → source}/metamorph.coffee +0 -0
  77. data/spec/helpers/matchers.coffee +8 -1
  78. data/spec/joosy/core/application_spec.coffee +121 -20
  79. data/spec/joosy/core/helpers/view_spec.coffee +3 -3
  80. data/spec/joosy/core/helpers/widgets_spec.coffee +3 -6
  81. data/spec/joosy/core/joosy_spec.coffee +0 -5
  82. data/spec/joosy/core/layout_spec.coffee +2 -28
  83. data/spec/joosy/core/modules/dom_spec.coffee +133 -0
  84. data/spec/joosy/core/modules/events_spec.coffee +16 -9
  85. data/spec/joosy/core/modules/filters_spec.coffee +232 -89
  86. data/spec/joosy/core/modules/log_spec.coffee +2 -2
  87. data/spec/joosy/core/modules/renderer_spec.coffee +8 -4
  88. data/spec/joosy/core/page_spec.coffee +2 -201
  89. data/spec/joosy/core/router_spec.coffee +295 -233
  90. data/spec/joosy/core/templaters/jst_spec.coffee +1 -1
  91. data/spec/joosy/core/widget_spec.coffee +373 -34
  92. data/spec/joosy/environments/amd_spec.coffee +38 -0
  93. data/spec/joosy/environments/global_spec.coffee +21 -0
  94. data/spec/joosy/extensions/form/form_spec.coffee +18 -18
  95. data/spec/joosy/extensions/form/helpers/forms_spec.coffee +1 -1
  96. data/spec/joosy/extensions/resources/base_spec.coffee +23 -11
  97. data/tasks/joosy.coffee +6 -9
  98. metadata +75 -69
  99. data/lib/extensions/preloaders.js +0 -193
  100. data/lib/extensions/resources-form.js +0 -592
  101. data/lib/extensions/resources.js +0 -675
  102. data/lib/joosy.js +0 -2199
  103. data/spec/joosy/core/modules/container_spec.coffee +0 -153
  104. data/spec/joosy/core/modules/widget_manager_spec.coffee +0 -96
  105. data/src/joosy/core/application.coffee +0 -59
  106. data/src/joosy/core/helpers/view.coffee +0 -52
  107. data/src/joosy/core/layout.coffee +0 -174
  108. data/src/joosy/core/modules/events.coffee +0 -188
  109. data/src/joosy/core/modules/filters.coffee +0 -42
  110. data/src/joosy/core/page.coffee +0 -383
  111. data/src/joosy/core/router.coffee +0 -313
  112. data/src/joosy/core/widget.coffee +0 -88
  113. data/src/joosy.coffee +0 -1
  114. data/templates/application/base/application.coffee +0 -9
  115. data/templates/application/standalone/bower.json +0 -7
@@ -0,0 +1,133 @@
1
+ describe "Joosy.Modules.DOM", ->
2
+
3
+ beforeEach ->
4
+ @$ground.seed()
5
+ container = @$ground.find('#application')
6
+
7
+ class @DOM extends Joosy.Module
8
+ @include Joosy.Modules.DOM
9
+
10
+ @mapElements
11
+ posts: '.post'
12
+ content:
13
+ post1: '#post1'
14
+ post2: '#post2'
15
+ footer: '.footer'
16
+
17
+ @mapEvents
18
+ 'test': 'onDOMTest'
19
+
20
+ $container: container
21
+
22
+ describe "elements assigner", ->
23
+
24
+ beforeEach ->
25
+ @dom = new @DOM
26
+ @dom.__assignElements()
27
+
28
+ it "declares", ->
29
+ class A extends @DOM
30
+ @mapElements
31
+ first: 'first'
32
+ second: 'second'
33
+
34
+ class B extends A
35
+ @mapElements
36
+ first: 'overrided'
37
+ third: 'third'
38
+
39
+ expect((new B).__elements).toEqual Object.extended
40
+ posts: '.post'
41
+ content:
42
+ post1: '#post1'
43
+ post2: '#post2'
44
+ first: 'overrided'
45
+ second: 'second'
46
+ third: 'third'
47
+ footer: '.footer'
48
+
49
+ expect((new @DOM).__elements).toEqual Object.extended
50
+ posts: '.post'
51
+ footer: '.footer'
52
+ content:
53
+ post1: '#post1'
54
+ post2: '#post2'
55
+
56
+ describe "selector resolvance", ->
57
+
58
+ it "works for plane selectors", ->
59
+ expect(@dom.__extractSelector '$footer').toEqual '.footer'
60
+
61
+ it "works for deep selectors", ->
62
+ expect(@dom.__extractSelector '$content.$post1').toEqual '#post1'
63
+
64
+ it "works for plane extended selectors", ->
65
+ expect(@dom.__extractSelector '$footer tr').toEqual '.footer tr'
66
+
67
+ it "works for deep extended selectors", ->
68
+ expect(@dom.__extractSelector '$footer $content.$post1').toEqual '.footer #post1'
69
+
70
+ it "assigns", ->
71
+ target = @dom.$footer().get 0
72
+ expect(target).toBeTruthy()
73
+ expect(target).toBe $('.footer', @dom.$container).get 0
74
+ expect(target).toBe @dom.$('.footer').get 0
75
+
76
+ it "assigns nesteds", ->
77
+ expect(@dom.$content.$post1().get 0).toBe $('#post1').get 0
78
+
79
+ it "filters assignation", ->
80
+ target = @dom.$posts('#post1').get 0
81
+ expect(target).toBeTruthy()
82
+ expect(target).toBe $('#post1', @dom.$container).get 0
83
+
84
+ it "respects container boundaries", ->
85
+ @$ground.prepend('<div class="footer" />') # out of container
86
+
87
+ target = @dom.$footer().get 0
88
+ expect(target).toBeTruthy()
89
+ expect(target).toBe $('.footer', @dom.$container).get 0
90
+ expect(target).toBe @dom.$('.footer').get 0
91
+
92
+ describe "events delegator", ->
93
+
94
+ it "declares", ->
95
+ class A extends @DOM
96
+ @mapEvents
97
+ 'test .post': 'callback2'
98
+ 'custom' : 'method'
99
+
100
+ class B extends A
101
+ @mapEvents
102
+ 'test $footer': 'onFooterTest'
103
+ 'custom' : 'overrided'
104
+
105
+ expect((new B).__events).toEqual Object.extended
106
+ 'test': 'onDOMTest'
107
+ 'test .post': 'callback2'
108
+ 'test $footer': 'onFooterTest'
109
+ 'custom' : 'overrided'
110
+
111
+ expect((new @DOM).__events).toEqual Object.extended
112
+ 'test': 'onDOMTest'
113
+
114
+ it "delegates", ->
115
+ callbacks = 1.upto(3).map -> sinon.spy()
116
+
117
+ @DOM.mapEvents
118
+ 'test .post': callbacks[2]
119
+ 'test $footer': 'onFooterTest'
120
+ @DOM::onDOMTest = callbacks[0]
121
+ @DOM::onFooterTest = callbacks[1]
122
+
123
+ dom = new @DOM
124
+ dom.__assignElements()
125
+ dom.__delegateEvents()
126
+
127
+ dom.$container.trigger 'test'
128
+ $('.footer', dom.$container).trigger 'test'
129
+ $('.post', dom.$container).trigger 'test'
130
+
131
+ expect(callbacks[0].callCount).toEqual 5
132
+ expect(callbacks[1].callCount).toEqual 1
133
+ expect(callbacks[2].callCount).toEqual 3
@@ -40,11 +40,6 @@ describe "Joosy.Modules.Events", ->
40
40
 
41
41
  expect(@callback.callCount).toEqual 0
42
42
 
43
- it "recognizes invalid arguments", ->
44
- expect(=> @eventer.wait '', @callback).toThrow()
45
- expect(=> @eventer.wait ' ', @callback).toThrow()
46
- expect(=> @eventer.wait [], @callback).toThrow()
47
-
48
43
  describe "binder", ->
49
44
 
50
45
  it "fires", ->
@@ -75,10 +70,22 @@ describe "Joosy.Modules.Events", ->
75
70
 
76
71
  expect(@callback.callCount).toEqual 0
77
72
 
78
- it "recognizes invalid arguments", ->
79
- expect(=> @eventer.bind '', @callback).toThrow()
80
- expect(=> @eventer.bind ' ', @callback).toThrow()
81
- expect(=> @eventer.bind [], @callback).toThrow()
73
+ describe 'remember', ->
74
+
75
+ it 'binds', ->
76
+ @eventer.trigger name: 'e1', remember: true
77
+ @eventer.bind 'e1 e2', @callback
78
+ @eventer.trigger 'e1', @callback
79
+ @eventer.trigger 'e2', @callback
80
+
81
+ expect(@callback.callCount).toEqual 1
82
+
83
+ it 'waits', ->
84
+ @eventer.trigger name: 'e1', remember: true
85
+ @eventer.wait 'e1 e2', @callback
86
+ @eventer.trigger 'e2', @callback
87
+
88
+ expect(@callback.callCount).toEqual 1
82
89
 
83
90
  it "allows simultaneous usage", ->
84
91
  3.times (i) => @eventer.bind "event#{i}", @callback
@@ -1,91 +1,234 @@
1
1
  describe "Joosy.Modules.Filters", ->
2
2
 
3
- beforeEach ->
4
- class @Filters extends Joosy.Module
5
- @include Joosy.Modules.Filters
6
-
7
- @filters = new @Filters
8
-
9
- it "inherits filters by copying them", ->
10
- class A extends @Filters
11
- @beforeLoad 'filter1'
12
- @afterLoad 'filter2'
13
- @afterUnload 'filter3'
14
-
15
- class B extends A
16
- @beforeLoad 'filter4'
17
- @afterLoad 'filter5'
18
- @afterUnload 'filter6'
19
-
20
- target = new B
21
- expect(target.__beforeLoads).toEqual ['filter1', 'filter4']
22
- expect(target.__afterLoads).toEqual ['filter2', 'filter5']
23
- expect(target.__afterUnloads).toEqual ['filter3', 'filter6']
24
-
25
- target = new A
26
- expect(target.__beforeLoads).toEqual ['filter1']
27
- expect(target.__afterLoads).toEqual ['filter2']
28
- expect(target.__afterUnloads).toEqual ['filter3']
29
-
30
- target = new @Filters
31
- expect(target.__beforeLoads).toBeUndefined()
32
- expect(target.__afterLoads).toBeUndefined()
33
- expect(target.__afterUnloads).toBeUndefined()
34
-
35
- it "runs callbacks", ->
36
- callbacks = 0.upto(2).map -> sinon.spy()
37
- @Filters.beforeLoad callbacks[0]
38
- @Filters.afterLoad callbacks[1]
39
- @Filters.afterUnload callbacks[2]
40
-
41
- @filters.__runBeforeLoads 1, 2
42
- @filters.__runAfterLoads 1, 2
43
- @filters.__runAfterUnloads 1, 2
44
-
45
- for i in 0.upto(2)
46
- expect(callbacks[i].callCount).toEqual 1
47
- expect(callbacks[i].alwaysCalledWithExactly 1, 2).toBeTruthy()
48
-
49
- describe "chaining", ->
50
-
51
- it "evaluates", ->
52
- callbacks = 0.upto(1).map =>
53
- callback = sinon.stub()
54
- @Filters.beforeLoad callback
55
- callback
56
-
57
- callbacks[0].returns true
58
- callbacks[1].returns true
59
-
60
- expect(@filters.__runBeforeLoads()).toBeTruthy()
61
-
62
- expect(callbacks[0].callCount).toEqual 1
63
- expect(callbacks[1].callCount).toEqual 1
64
-
65
- it "breaks on false", ->
66
- callbacks = 0.upto(2).map =>
67
- callback = sinon.stub()
68
- @Filters.beforeLoad callback
69
- callback
70
-
71
- callbacks[0].returns true
72
- callbacks[1].returns false
73
-
74
- expect(@filters.__runBeforeLoads()).toBeFalsy()
75
-
76
- expect(callbacks[0].callCount).toEqual 1
77
- expect(callbacks[1].callCount).toEqual 1
78
- expect(callbacks[2].callCount).toEqual 0
79
-
80
- it "accepts method names as callbacks", ->
81
- @filters['callback' + i] = sinon.spy() for i in 0.upto(2)
82
-
83
- @Filters.beforeLoad 'callback0'
84
- @Filters.afterLoad 'callback1'
85
- @Filters.afterUnload 'callback2'
86
-
87
- @filters.__runBeforeLoads()
88
- @filters.__runAfterLoads()
89
- @filters.__runAfterUnloads()
90
-
91
- expect(@filters['callback' + i].callCount).toEqual 1 for i in 0.upto(2)
3
+ describe 'plain', ->
4
+
5
+ beforeEach ->
6
+ class @Filters extends Joosy.Module
7
+ @include Joosy.Modules.Filters
8
+ @registerPlainFilters 'beforeLoad', 'afterLoad', 'afterUnload'
9
+
10
+ @filters = new @Filters
11
+
12
+ it "inherits filters by copying them", ->
13
+ class A extends @Filters
14
+ @beforeLoad 'filter1'
15
+ @afterLoad 'filter2'
16
+ @afterUnload 'filter3'
17
+
18
+ class B extends A
19
+ @beforeLoad 'filter4'
20
+ @afterLoad 'filter5'
21
+ @afterUnload 'filter6'
22
+
23
+ target = new B
24
+ expect(target.__beforeLoads).toEqual ['filter1', 'filter4']
25
+ expect(target.__afterLoads).toEqual ['filter2', 'filter5']
26
+ expect(target.__afterUnloads).toEqual ['filter3', 'filter6']
27
+
28
+ target = new A
29
+ expect(target.__beforeLoads).toEqual ['filter1']
30
+ expect(target.__afterLoads).toEqual ['filter2']
31
+ expect(target.__afterUnloads).toEqual ['filter3']
32
+
33
+ target = new @Filters
34
+ expect(target.__beforeLoads).toBeUndefined()
35
+ expect(target.__afterLoads).toBeUndefined()
36
+ expect(target.__afterUnloads).toBeUndefined()
37
+
38
+ it "runs callbacks", ->
39
+ callbacks = 0.upto(2).map -> sinon.spy()
40
+ @Filters.beforeLoad callbacks[0]
41
+ @Filters.afterLoad callbacks[1]
42
+ @Filters.afterUnload callbacks[2]
43
+
44
+ @filters.__runBeforeLoads 1, 2
45
+ @filters.__runAfterLoads 1, 2
46
+ @filters.__runAfterUnloads 1, 2
47
+
48
+ for i in 0.upto(2)
49
+ expect(callbacks[i].callCount).toEqual 1
50
+ expect(callbacks[i].alwaysCalledWithExactly 1, 2).toBeTruthy()
51
+
52
+ describe "chaining", ->
53
+
54
+ it "evaluates", ->
55
+ callbacks = 0.upto(1).map =>
56
+ callback = sinon.stub()
57
+ @Filters.beforeLoad callback
58
+ callback
59
+
60
+ callbacks[0].returns true
61
+ callbacks[1].returns true
62
+
63
+ expect(@filters.__runBeforeLoads()).toBeTruthy()
64
+
65
+ expect(callbacks[0].callCount).toEqual 1
66
+ expect(callbacks[1].callCount).toEqual 1
67
+
68
+ it "breaks on false", ->
69
+ callbacks = 0.upto(2).map =>
70
+ callback = sinon.stub()
71
+ @Filters.beforeLoad callback
72
+ callback
73
+
74
+ callbacks[0].returns true
75
+ callbacks[1].returns false
76
+
77
+ expect(@filters.__runBeforeLoads()).toBeFalsy()
78
+
79
+ expect(callbacks[0].callCount).toEqual 1
80
+ expect(callbacks[1].callCount).toEqual 1
81
+ expect(callbacks[2].callCount).toEqual 0
82
+
83
+ it "accepts method names as callbacks", ->
84
+ @filters['callback' + i] = sinon.spy() for i in 0.upto(2)
85
+
86
+ @Filters.beforeLoad 'callback0'
87
+ @Filters.afterLoad 'callback1'
88
+ @Filters.afterUnload 'callback2'
89
+
90
+ @filters.__runBeforeLoads()
91
+ @filters.__runAfterLoads()
92
+ @filters.__runAfterUnloads()
93
+
94
+ expect(@filters['callback' + i].callCount).toEqual 1 for i in 0.upto(2)
95
+
96
+ describe 'sequenced', ->
97
+
98
+ beforeEach ->
99
+ class @Filters extends Joosy.Module
100
+ @include Joosy.Modules.Filters
101
+ @registerSequencedFilters 'beforeLoad', 'afterLoad', 'afterUnload'
102
+
103
+ @filters = new @Filters
104
+
105
+ it "inherits filters by copying them", ->
106
+ class A extends @Filters
107
+ @beforeLoad 'filter1'
108
+ @afterLoad 'filter2'
109
+ @afterUnload 'filter3'
110
+
111
+ class B extends A
112
+ @beforeLoad 'filter4'
113
+ @afterLoad 'filter5'
114
+ @afterUnload 'filter6'
115
+
116
+ target = new B
117
+ expect(target.__beforeLoads).toEqual ['filter1', 'filter4']
118
+ expect(target.__afterLoads).toEqual ['filter2', 'filter5']
119
+ expect(target.__afterUnloads).toEqual ['filter3', 'filter6']
120
+
121
+ target = new A
122
+ expect(target.__beforeLoads).toEqual ['filter1']
123
+ expect(target.__afterLoads).toEqual ['filter2']
124
+ expect(target.__afterUnloads).toEqual ['filter3']
125
+
126
+ target = new @Filters
127
+ expect(target.__beforeLoads).toBeUndefined()
128
+ expect(target.__afterLoads).toBeUndefined()
129
+ expect(target.__afterUnloads).toBeUndefined()
130
+
131
+ it "runs with no callbacks", ->
132
+ spy = sinon.spy()
133
+
134
+ @filters.__runBeforeLoads [], =>
135
+ @filters.__runAfterLoads ['test'], =>
136
+ @filters.__runAfterUnloads ['test'], =>
137
+ spy()
138
+
139
+ expect(spy.callCount).toEqual 1
140
+
141
+ it "runs single callbacks", ->
142
+ spy = sinon.spy()
143
+ context = @filters
144
+
145
+ @Filters.beforeLoad (complete) ->
146
+ expect(@).toEqual context
147
+ spy(); complete()
148
+ @Filters.afterLoad (argument, complete) ->
149
+ expect(@).toEqual context
150
+ spy(argument); complete()
151
+ @Filters.afterUnload (argument1, argument2, complete) ->
152
+ expect(@).toEqual context
153
+ spy(argument1, argument2); complete()
154
+
155
+ @filters.__runBeforeLoads [], =>
156
+ expect(spy.callCount).toEqual 1
157
+
158
+ @filters.__runAfterLoads ['test'], =>
159
+ expect(spy.callCount).toEqual 2
160
+ expect(spy.args[1][0]).toEqual 'test'
161
+
162
+ @filters.__runAfterUnloads ['test', 'test2'], =>
163
+ expect(spy.callCount).toEqual 3
164
+ expect(spy.args[2][0]).toEqual 'test'
165
+ expect(spy.args[2][1]).toEqual 'test2'
166
+
167
+ it "runs multiple callbacks", ->
168
+ spies = 0.upto(2).map -> sinon.spy()
169
+ context = @filters
170
+
171
+ @Filters.beforeLoad (argument, complete) ->
172
+ expect(argument).toEqual 'test'
173
+ expect(@).toEqual context
174
+ spies[0]()
175
+ complete()
176
+
177
+ @Filters.beforeLoad (argument, complete) ->
178
+ expect(argument).toEqual 'test'
179
+ expect(@).toEqual context
180
+ spies[1]()
181
+ complete()
182
+
183
+ @Filters.beforeLoad (argument, complete) ->
184
+ expect(argument).toEqual 'test'
185
+ expect(@).toEqual context
186
+ spies[2]()
187
+ complete()
188
+
189
+ @filters.__runBeforeLoads ['test'], ->
190
+ expect(spies).toBeSequenced()
191
+
192
+ # describe "chaining", ->
193
+
194
+ # it "evaluates", ->
195
+ # callbacks = 0.upto(1).map =>
196
+ # callback = sinon.stub()
197
+ # @Filters.beforeLoad callback
198
+ # callback
199
+
200
+ # callbacks[0].returns true
201
+ # callbacks[1].returns true
202
+
203
+ # expect(@filters.__runBeforeLoads()).toBeTruthy()
204
+
205
+ # expect(callbacks[0].callCount).toEqual 1
206
+ # expect(callbacks[1].callCount).toEqual 1
207
+
208
+ # it "breaks on false", ->
209
+ # callbacks = 0.upto(2).map =>
210
+ # callback = sinon.stub()
211
+ # @Filters.beforeLoad callback
212
+ # callback
213
+
214
+ # callbacks[0].returns true
215
+ # callbacks[1].returns false
216
+
217
+ # expect(@filters.__runBeforeLoads()).toBeFalsy()
218
+
219
+ # expect(callbacks[0].callCount).toEqual 1
220
+ # expect(callbacks[1].callCount).toEqual 1
221
+ # expect(callbacks[2].callCount).toEqual 0
222
+
223
+ # it "accepts method names as callbacks", ->
224
+ # @filters['callback' + i] = sinon.spy() for i in 0.upto(2)
225
+
226
+ # @Filters.beforeLoad 'callback0'
227
+ # @Filters.afterLoad 'callback1'
228
+ # @Filters.afterUnload 'callback2'
229
+
230
+ # @filters.__runBeforeLoads()
231
+ # @filters.__runAfterLoads()
232
+ # @filters.__runAfterUnloads()
233
+
234
+ # expect(@filters['callback' + i].callCount).toEqual 1 for i in 0.upto(2)
@@ -15,9 +15,9 @@ describe "Joosy.Modules.Log", ->
15
15
  expect(@stub.callCount).toEqual 1
16
16
 
17
17
  it "should log debug messages into console", ->
18
- Joosy.Application.config.debug = true
18
+ Joosy.debug(true)
19
19
  @logger.debug 'debug message'
20
- Joosy.Application.config.debug = false
20
+ Joosy.debug(false)
21
21
  @logger.debug 'unseen debug message'
22
22
 
23
23
  expect(@stub.callCount).toEqual 1
@@ -26,13 +26,17 @@ describe "Joosy.Modules.Renderer", ->
26
26
  it "accepts lambda", ->
27
27
  expect(@renderer.render @template, foo: 'bar').toEqual 'result'
28
28
 
29
+ it "expects templater definition", ->
30
+ expect(=> @renderer.render 'template', foo: 'bar').toThrow()
31
+
29
32
  it "accepts template", ->
30
- target = sinon.stub Joosy.Application.templater, 'buildView'
31
- target.returns @template
33
+ Joosy.templater
34
+ buildView: ->
35
+ -> 'result'
32
36
 
33
- expect(@renderer.render @template, foo: 'bar').toEqual 'result'
37
+ expect(@renderer.render 'template', foo: 'bar').toEqual 'result'
34
38
 
35
- Joosy.Application.templater.buildView.restore()
39
+ Joosy.templater false
36
40
 
37
41
  describe "dynamic rendering", ->
38
42
  beforeEach ->