modularity-rails 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/{LICENSE → MIT-LICENSE} +0 -0
- data/README.md +16 -15
- data/Rakefile +3 -14
- data/{vendor → app}/assets/javascripts/modularity/data/ajax_loader.coffee +0 -0
- data/{vendor → app}/assets/javascripts/modularity/data/cache.coffee +5 -0
- data/{vendor → app}/assets/javascripts/modularity/data/indexed_cache.coffee +8 -2
- data/{vendor → app}/assets/javascripts/modularity/data/persistence_manager.coffee +11 -0
- data/{vendor → app}/assets/javascripts/modularity/mixins/clickable.coffee +2 -2
- data/{vendor → app}/assets/javascripts/modularity/mixins/closable.coffee +0 -0
- data/{vendor/assets/javascripts/modularity.js.coffee → app/assets/javascripts/modularity/modularity.coffee} +3 -0
- data/{vendor → app}/assets/javascripts/modularity/modules/autogrow_textarea.coffee +2 -1
- data/{vendor → app}/assets/javascripts/modularity/modules/button.coffee +0 -0
- data/{vendor → app}/assets/javascripts/modularity/tools/array_tools.coffee +1 -0
- data/{vendor → app}/assets/javascripts/modularity/tools/object_tools.coffee +0 -0
- data/config/initializers/konacha.rb +6 -0
- data/lib/modularity-rails.rb +0 -1
- data/lib/modularity-rails/engine.rb +1 -0
- data/lib/modularity-rails/version.rb +1 -1
- metadata +80 -100
- data/.evergreen +0 -6
- data/.gitignore +0 -20
- data/.travis.yml +0 -8
- data/Gemfile +0 -4
- data/Guardfile +0 -8
- data/demo/.gitignore +0 -15
- data/demo/Gemfile +0 -23
- data/demo/README.rdoc +0 -261
- data/demo/Rakefile +0 -7
- data/demo/app/assets/images/rails.png +0 -0
- data/demo/app/assets/javascripts/application.coffee +0 -2
- data/demo/app/assets/stylesheets/application.css +0 -13
- data/demo/app/controllers/application_controller.rb +0 -3
- data/demo/app/helpers/application_helper.rb +0 -2
- data/demo/app/mailers/.gitkeep +0 -0
- data/demo/app/models/.gitkeep +0 -0
- data/demo/app/views/layouts/application.html.erb +0 -14
- data/demo/config.ru +0 -4
- data/demo/config/application.rb +0 -59
- data/demo/config/boot.rb +0 -6
- data/demo/config/database.yml +0 -25
- data/demo/config/environment.rb +0 -5
- data/demo/config/environments/development.rb +0 -37
- data/demo/config/environments/production.rb +0 -67
- data/demo/config/environments/test.rb +0 -37
- data/demo/config/initializers/backtrace_silencers.rb +0 -7
- data/demo/config/initializers/inflections.rb +0 -15
- data/demo/config/initializers/konacha.rb +0 -5
- data/demo/config/initializers/mime_types.rb +0 -5
- data/demo/config/initializers/secret_token.rb +0 -7
- data/demo/config/initializers/session_store.rb +0 -8
- data/demo/config/initializers/wrap_parameters.rb +0 -14
- data/demo/config/locales/en.yml +0 -5
- data/demo/config/routes.rb +0 -58
- data/demo/db/seeds.rb +0 -7
- data/demo/lib/assets/.gitkeep +0 -0
- data/demo/lib/tasks/.gitkeep +0 -0
- data/demo/log/.gitkeep +0 -0
- data/demo/public/404.html +0 -26
- data/demo/public/422.html +0 -26
- data/demo/public/500.html +0 -25
- data/demo/public/favicon.ico +0 -0
- data/demo/public/index.html +0 -241
- data/demo/public/robots.txt +0 -5
- data/demo/script/rails +0 -6
- data/demo/spec/javascripts/data/ajax_loader_spec.coffee +0 -132
- data/demo/spec/javascripts/data/cache_spec.coffee +0 -103
- data/demo/spec/javascripts/data/indexed_cache_spec.coffee +0 -51
- data/demo/spec/javascripts/data/persistence_manager_spec.coffee +0 -283
- data/demo/spec/javascripts/konacha_config.coffee +0 -2
- data/demo/spec/javascripts/mixins/closable_spec.coffee +0 -98
- data/demo/spec/javascripts/modularity_spec.coffee +0 -329
- data/demo/spec/javascripts/modules/autogrow_textarea_spec.coffee +0 -43
- data/demo/spec/javascripts/modules/button_spec.coffee +0 -39
- data/demo/spec/javascripts/modules/counter_button_spec.coffee +0 -57
- data/demo/spec/javascripts/sinon-chai.js +0 -116
- data/demo/spec/javascripts/sinon.js +0 -3555
- data/demo/spec/javascripts/spec_helper.coffee +0 -10
- data/demo/spec/javascripts/templates/autogrow_textarea.jst.ejs +0 -2
- data/demo/spec/javascripts/templates/button.jst.ejs +0 -3
- data/demo/spec/javascripts/templates/closable.jst.ejs +0 -14
- data/demo/spec/javascripts/templates/modularity.jst.ejs +0 -6
- data/demo/spec/javascripts/tools/array_tools_spec.coffee +0 -12
- data/demo/spec/javascripts/tools/object_tools_spec.coffee +0 -46
- data/demo/vendor/assets/javascripts/.gitkeep +0 -0
- data/demo/vendor/assets/stylesheets/.gitkeep +0 -0
- data/demo/vendor/plugins/.gitkeep +0 -0
- data/modularity-rails.gemspec +0 -22
- data/run_tests +0 -6
- data/vendor/assets/javascripts/modularity/modules/counter_button.coffee +0 -17
@@ -1,98 +0,0 @@
|
|
1
|
-
#= require spec_helper
|
2
|
-
#= require modularity/mixins/closable
|
3
|
-
|
4
|
-
# A standard closable module.
|
5
|
-
class window.ClosableModule1 extends modularity.Module
|
6
|
-
@mixin modularity.closable
|
7
|
-
|
8
|
-
|
9
|
-
describe 'Closable', ->
|
10
|
-
|
11
|
-
spy_alert = null
|
12
|
-
beforeEach ->
|
13
|
-
template 'closable'
|
14
|
-
spy_alert = sinon.stub window, 'alert'
|
15
|
-
|
16
|
-
afterEach ->
|
17
|
-
spy_alert.restore()
|
18
|
-
|
19
|
-
describe 'constructor', ->
|
20
|
-
it 'shows an alert if there is no close button', ->
|
21
|
-
new ClosableModule1('#konacha #closable3')
|
22
|
-
window.alert.should.have.been.called
|
23
|
-
window.alert.args[0][0].should.match(/close button not found/i)
|
24
|
-
|
25
|
-
it 'shows no alert if there is a close button', ->
|
26
|
-
new ClosableModule1('#konacha #closable1')
|
27
|
-
window.alert.should.not.have.been.called
|
28
|
-
|
29
|
-
it 'finds the close button div automatically', ->
|
30
|
-
new ClosableModule1('#konacha #closable1')
|
31
|
-
$('#konacha #closable1 .CloseButton').click()
|
32
|
-
$('#konacha #closable1').should.have.length 0
|
33
|
-
|
34
|
-
|
35
|
-
describe 'when clicking the close button', ->
|
36
|
-
|
37
|
-
it "calls the closable_closing hook on the object if it exists", ->
|
38
|
-
|
39
|
-
# A closable module with the 'closing' hook.
|
40
|
-
class ClosableModule extends modularity.Module
|
41
|
-
@mixin modularity.closable
|
42
|
-
|
43
|
-
constructor: ->
|
44
|
-
super
|
45
|
-
@closing_hook_got_called = no
|
46
|
-
|
47
|
-
closable_closing: => @closing_hook_got_called = yes
|
48
|
-
|
49
|
-
module = new ClosableModule('#konacha #closable1')
|
50
|
-
$('#konacha #closable1 .CloseButton').click()
|
51
|
-
module.closing_hook_got_called.should.be.true
|
52
|
-
|
53
|
-
|
54
|
-
it "calls the closable_closed hook on the object if it exists", ->
|
55
|
-
|
56
|
-
# A closable module with the 'closed' hook.
|
57
|
-
class ClosableModule extends modularity.Module
|
58
|
-
@mixin modularity.closable
|
59
|
-
|
60
|
-
constructor: ->
|
61
|
-
super
|
62
|
-
@closed_hook_got_called = no
|
63
|
-
|
64
|
-
closable_closed: => @closed_hook_got_called = yes
|
65
|
-
|
66
|
-
module = new ClosableModule('#konacha #closable1')
|
67
|
-
$('#konacha #closable1 .CloseButton').click()
|
68
|
-
module.closed_hook_got_called.should.be.true
|
69
|
-
|
70
|
-
|
71
|
-
it "aborts the close operation if the closable_closing method returns false", ->
|
72
|
-
|
73
|
-
class ClosableModuleWithHookThatReturnsFalse extends modularity.Module
|
74
|
-
@mixin modularity.closable
|
75
|
-
closable_closing: -> false
|
76
|
-
|
77
|
-
module = new ClosableModuleWithHookThatReturnsFalse('#konacha #closable1')
|
78
|
-
module.bind_event('closed', (spy = sinon.spy()))
|
79
|
-
|
80
|
-
$('#konacha #closable1 .CloseButton').click()
|
81
|
-
|
82
|
-
spy.should.not.have.been.called
|
83
|
-
|
84
|
-
|
85
|
-
it 'removes the container', ->
|
86
|
-
new ClosableModule1('#konacha #closable1')
|
87
|
-
$('#konacha #closable1 .CloseButton').click()
|
88
|
-
|
89
|
-
$('#konacha #closable1').should.have.length 0
|
90
|
-
|
91
|
-
|
92
|
-
it "fires the 'closed' event", ->
|
93
|
-
closable_module = new ClosableModule1('#konacha #closable1')
|
94
|
-
closable_module.bind_event('closed', (spy = sinon.spy()))
|
95
|
-
|
96
|
-
$('#konacha #closable1 .CloseButton').click()
|
97
|
-
|
98
|
-
spy.should.have.been.calledOnce
|
@@ -1,329 +0,0 @@
|
|
1
|
-
#= require spec_helper
|
2
|
-
|
3
|
-
class window.TestModule extends modularity.Module
|
4
|
-
|
5
|
-
|
6
|
-
describe 'modularity', ->
|
7
|
-
|
8
|
-
alert_stub = null
|
9
|
-
beforeEach ->
|
10
|
-
template 'modularity'
|
11
|
-
alert_stub = sinon.stub window, 'alert'
|
12
|
-
|
13
|
-
afterEach ->
|
14
|
-
alert_stub.restore()
|
15
|
-
|
16
|
-
|
17
|
-
describe 'constructor', ->
|
18
|
-
|
19
|
-
it "is defined on the 'window' object", ->
|
20
|
-
modularity.Module.should.not.be.undefined
|
21
|
-
|
22
|
-
it 'shows an error if no container is given', ->
|
23
|
-
new TestModule()
|
24
|
-
window.alert.should.have.been.called
|
25
|
-
|
26
|
-
it 'tries to load the DOM if the given container is a string', ->
|
27
|
-
new TestModule('#konacha #module_container')
|
28
|
-
window.alert.should.not.have.been.called
|
29
|
-
|
30
|
-
it 'shows an error if the container is not a jQuery object', ->
|
31
|
-
new TestModule({})
|
32
|
-
window.alert.should.have.been.called
|
33
|
-
|
34
|
-
it 'shows an error if the container is an empty jQuery object', ->
|
35
|
-
new TestModule($('#konacha .zonk'))
|
36
|
-
window.alert.should.have.been.called
|
37
|
-
|
38
|
-
it 'shows an error if the container has more than one elements', ->
|
39
|
-
new TestModule($('#konacha .double'))
|
40
|
-
window.alert.should.have.been.called
|
41
|
-
|
42
|
-
it "allows to provide 'testing' in tests", ->
|
43
|
-
new TestModule('testing')
|
44
|
-
window.alert.should.not.have.been.called
|
45
|
-
|
46
|
-
|
47
|
-
describe 'assert', ->
|
48
|
-
|
49
|
-
it 'shows an alert with the given message if the given condition is false', ->
|
50
|
-
modularity.assert false, 'Message'
|
51
|
-
expect(window.alert.calledWith "Message").to.be.true
|
52
|
-
|
53
|
-
it 'fails when the condition is null', ->
|
54
|
-
modularity.assert null, 'Message'
|
55
|
-
expect(window.alert.calledWith "Message").to.be.true
|
56
|
-
|
57
|
-
it 'fails when the condition is undefined', ->
|
58
|
-
modularity.assert undefined, 'Message'
|
59
|
-
expect(window.alert.calledWith "Message").to.be.true
|
60
|
-
|
61
|
-
it 'fails when the condition is an empty array', ->
|
62
|
-
modularity.assert [], 'Message'
|
63
|
-
expect(window.alert.calledWith "Message").to.be.true
|
64
|
-
|
65
|
-
it 'fails when the condition is an empty string', ->
|
66
|
-
modularity.assert '', 'Message'
|
67
|
-
expect(window.alert.calledWith "Message").to.be.true
|
68
|
-
|
69
|
-
it 'passes when the condition is a string', ->
|
70
|
-
modularity.assert '123', 'Message'
|
71
|
-
window.alert.should.not.have.been.called
|
72
|
-
|
73
|
-
it "returns false if the condition doesn't pass", ->
|
74
|
-
modularity.assert(false).should.be.false
|
75
|
-
|
76
|
-
it "returns true if the condition passes", ->
|
77
|
-
modularity.assert('123').should.be.true
|
78
|
-
|
79
|
-
|
80
|
-
describe '@$ notation', ->
|
81
|
-
|
82
|
-
it 'returns a new jQuery object relative to container', ->
|
83
|
-
module = new TestModule $ '#module_container'
|
84
|
-
insideObject = module.$ '.inside_module,.outside_module'
|
85
|
-
insideObject.length.should.equal 1
|
86
|
-
insideObject.hasClass('inside_module').should.be.true
|
87
|
-
|
88
|
-
|
89
|
-
describe 'jQuery Integration', ->
|
90
|
-
|
91
|
-
it 'works', ->
|
92
|
-
$('#konacha #module_container').module(TestModule)
|
93
|
-
window.alert.should.not.have.been.called
|
94
|
-
|
95
|
-
it 'returns the created instance', ->
|
96
|
-
result = $('#konacha #module_container').module(modularity.Module)
|
97
|
-
result.should.exist
|
98
|
-
result.should.be.instanceOf modularity.Module
|
99
|
-
|
100
|
-
it 'returns an error if the given parameter is not a class', ->
|
101
|
-
$('#konacha').module()
|
102
|
-
window.alert.should.have.been.called
|
103
|
-
|
104
|
-
it 'returns an error if the jQuery object is empty.', ->
|
105
|
-
$('#konacha #zonk').module(modularity.Module)
|
106
|
-
window.alert.should.have.been.called
|
107
|
-
|
108
|
-
|
109
|
-
describe 'event handling', ->
|
110
|
-
|
111
|
-
module = null
|
112
|
-
mockContainer = null
|
113
|
-
|
114
|
-
beforeEach ->
|
115
|
-
mockContainer = $('#konacha #module_container')
|
116
|
-
module = new TestModule(mockContainer)
|
117
|
-
|
118
|
-
describe 'bind_event', ->
|
119
|
-
|
120
|
-
beforeEach ->
|
121
|
-
sinon.spy mockContainer, 'bind'
|
122
|
-
|
123
|
-
it 'binds the given custom jQuery event type and the given callback to the container', ->
|
124
|
-
myCallback = ->
|
125
|
-
module.bind_event 'myEventType', myCallback
|
126
|
-
mockContainer.bind.should.have.been.called
|
127
|
-
mockContainer.bind.args[0][0].should.equal 'myEventType'
|
128
|
-
mockContainer.bind.args[0][1].should.equal myCallback
|
129
|
-
window.alert.should.not.have.been.called
|
130
|
-
|
131
|
-
it "throws an error if no parameters are given", ->
|
132
|
-
module.bind_event()
|
133
|
-
window.alert.should.have.been.called
|
134
|
-
mockContainer.bind.should.not.have.been.called
|
135
|
-
|
136
|
-
it "throws an error if the given event type doesn't exist", ->
|
137
|
-
module.bind_event undefined, ->
|
138
|
-
window.alert.should.have.been.called
|
139
|
-
mockContainer.bind.should.not.have.been.called
|
140
|
-
|
141
|
-
it 'throws an error if the given event type is not a string', ->
|
142
|
-
module.bind_event {}, ->
|
143
|
-
window.alert.should.have.been.called
|
144
|
-
mockContainer.bind.should.not.have.been.called
|
145
|
-
|
146
|
-
it "throws an error if the given callback doesn't exist", ->
|
147
|
-
module.bind_event '123'
|
148
|
-
window.alert.should.have.been.called
|
149
|
-
mockContainer.bind.should.not.have.been.called
|
150
|
-
|
151
|
-
it 'throws an error if the given callback is not a function', ->
|
152
|
-
module.bind_event '123', {}
|
153
|
-
window.alert.should.have.been.called
|
154
|
-
mockContainer.bind.should.not.have.been.called
|
155
|
-
|
156
|
-
|
157
|
-
describe 'fire_event', ->
|
158
|
-
|
159
|
-
beforeEach ->
|
160
|
-
sinon.spy mockContainer, 'trigger'
|
161
|
-
|
162
|
-
it 'triggers a custom jQuery event with the given event type on the container object', ->
|
163
|
-
module.fire_event 'event type', 'event data'
|
164
|
-
mockContainer.trigger.should.have.been.called
|
165
|
-
mockContainer.trigger.args[0][0].should.equal 'event type'
|
166
|
-
mockContainer.trigger.args[0][1].should.equal 'event data'
|
167
|
-
|
168
|
-
describe 'when no payload is given', ->
|
169
|
-
it 'provides an empty object as payload', ->
|
170
|
-
module.fire_event 'event type'
|
171
|
-
mockContainer.trigger.should.have.been.called
|
172
|
-
mockContainer.trigger.args[0][1].should.eql({})
|
173
|
-
|
174
|
-
it "doesn't change the original payload variable", ->
|
175
|
-
data = undefined
|
176
|
-
module.fire_event 'event type', data
|
177
|
-
expect(data).to.be.undefined
|
178
|
-
|
179
|
-
it 'provides 0 as payload if 0 is given', ->
|
180
|
-
module.fire_event 'event type', 0
|
181
|
-
mockContainer.trigger.should.have.been.called
|
182
|
-
mockContainer.trigger.args[0][1].should.equal(0)
|
183
|
-
|
184
|
-
it 'throws an error if the given event type is not a string', ->
|
185
|
-
module.fire_event {}
|
186
|
-
mockContainer.trigger.should.not.have.been.called
|
187
|
-
window.alert.should.have.been.called
|
188
|
-
|
189
|
-
|
190
|
-
describe 'global events', ->
|
191
|
-
|
192
|
-
mockGlobalContainer = null
|
193
|
-
beforeEach ->
|
194
|
-
mockGlobalContainer = $('#test #module_container')
|
195
|
-
sinon.stub(modularity, 'global_event_container').returns(mockGlobalContainer)
|
196
|
-
|
197
|
-
afterEach ->
|
198
|
-
modularity.global_event_container.restore()
|
199
|
-
|
200
|
-
|
201
|
-
describe 'bind_global_event', ->
|
202
|
-
|
203
|
-
beforeEach ->
|
204
|
-
sinon.spy mockGlobalContainer, 'bind'
|
205
|
-
|
206
|
-
afterEach ->
|
207
|
-
mockGlobalContainer.bind.restore()
|
208
|
-
|
209
|
-
it 'binds the given event type and callback method to the global event container', ->
|
210
|
-
callback = ->
|
211
|
-
modularity.bind_global_event '123', callback
|
212
|
-
mockGlobalContainer.bind.should.have.been.called
|
213
|
-
mockGlobalContainer.bind.args[0][0].should.equal '123'
|
214
|
-
mockGlobalContainer.bind.args[0][1].should.equal callback
|
215
|
-
|
216
|
-
it "throws an error if no parameters are given", ->
|
217
|
-
modularity.bind_global_event()
|
218
|
-
window.alert.should.have.been.called
|
219
|
-
mockGlobalContainer.bind.should.not.have.been.called
|
220
|
-
|
221
|
-
it "throws an error if the given event type doesn't exist", ->
|
222
|
-
modularity.bind_global_event undefined, ->
|
223
|
-
window.alert.should.have.been.called
|
224
|
-
mockGlobalContainer.bind.should.not.have.been.called
|
225
|
-
|
226
|
-
it 'throws an error if the given event type is not a string', ->
|
227
|
-
modularity.bind_global_event {}, ->
|
228
|
-
window.alert.should.have.been.called
|
229
|
-
mockGlobalContainer.bind.should.not.have.been.called
|
230
|
-
|
231
|
-
it "throws an error if the given callback doesn't exist", ->
|
232
|
-
modularity.bind_global_event '123'
|
233
|
-
window.alert.should.have.been.called
|
234
|
-
mockGlobalContainer.bind.should.not.have.been.called
|
235
|
-
|
236
|
-
it 'throws an error if the given callback is not a function', ->
|
237
|
-
modularity.bind_global_event '123', {}
|
238
|
-
window.alert.should.have.been.called
|
239
|
-
mockGlobalContainer.bind.should.not.have.been.called
|
240
|
-
|
241
|
-
|
242
|
-
describe 'fire_global_event', ->
|
243
|
-
|
244
|
-
beforeEach ->
|
245
|
-
sinon.spy mockGlobalContainer, 'trigger'
|
246
|
-
|
247
|
-
afterEach ->
|
248
|
-
mockGlobalContainer.trigger.restore()
|
249
|
-
|
250
|
-
|
251
|
-
it 'triggers a custom jQuery event with the given event type on the global event container object', ->
|
252
|
-
modularity.fire_global_event 'event type', 'event data'
|
253
|
-
mockGlobalContainer.trigger.should.have.been.called
|
254
|
-
mockGlobalContainer.trigger.args[0][0].should.equal 'event type'
|
255
|
-
mockGlobalContainer.trigger.args[0][1].should.equal 'event data'
|
256
|
-
|
257
|
-
describe 'when no payload is given', ->
|
258
|
-
it 'provides an empty object as payload', ->
|
259
|
-
modularity.fire_global_event 'event type'
|
260
|
-
mockGlobalContainer.trigger.should.have.been.called
|
261
|
-
mockGlobalContainer.trigger.args[0][1].should.eql({})
|
262
|
-
|
263
|
-
it "doesn't change the original payload variable", ->
|
264
|
-
data = undefined
|
265
|
-
modularity.fire_global_event 'event type', data
|
266
|
-
expect(data).to.equal.undefined
|
267
|
-
|
268
|
-
it 'provides 0 as payload if 0 is given', ->
|
269
|
-
modularity.fire_global_event 'event type', 0
|
270
|
-
mockGlobalContainer.trigger.should.have.been.called
|
271
|
-
mockGlobalContainer.trigger.args[0][1].should.equal(0)
|
272
|
-
|
273
|
-
it 'throws an error if the given event type is not a string', ->
|
274
|
-
modularity.fire_global_event {}
|
275
|
-
mockGlobalContainer.trigger.should.not.have.been.called
|
276
|
-
window.alert.should.have.been.called
|
277
|
-
|
278
|
-
|
279
|
-
describe 'mixins', ->
|
280
|
-
|
281
|
-
myMixin = instance = recordedSelf = Test = null
|
282
|
-
myMixin =
|
283
|
-
constructor: -> recordedSelf = @
|
284
|
-
method1: ->
|
285
|
-
method2: ->
|
286
|
-
|
287
|
-
beforeEach ->
|
288
|
-
class Test extends modularity.Module
|
289
|
-
@mixin myMixin
|
290
|
-
|
291
|
-
|
292
|
-
it 'adds all methods from the mixin object to the class prototype', ->
|
293
|
-
instance = new Test('testing')
|
294
|
-
instance.method1.should.be.a("function")
|
295
|
-
|
296
|
-
|
297
|
-
it 'calls the proper mixin method when calling from the implementing module', ->
|
298
|
-
sinon.spy myMixin, 'method1'
|
299
|
-
sinon.spy myMixin, 'method2'
|
300
|
-
instance = new Test('testing')
|
301
|
-
instance.method1()
|
302
|
-
myMixin.method1.should.have.been.called
|
303
|
-
myMixin.method2.should.not.have.been.called
|
304
|
-
myMixin.method1.restore()
|
305
|
-
myMixin.method2.restore()
|
306
|
-
|
307
|
-
it 'calls the mixin with the proper paramaters', ->
|
308
|
-
sinon.spy myMixin, 'method1'
|
309
|
-
instance = new Test('testing')
|
310
|
-
instance.method1("arg1", "arg2")
|
311
|
-
expect(myMixin.method1.calledWith("arg1", "arg2")).to.be.true
|
312
|
-
myMixin.method1.restore()
|
313
|
-
|
314
|
-
|
315
|
-
it 'calls the constructor of the mixin', ->
|
316
|
-
sinon.spy myMixin, 'constructor'
|
317
|
-
instance = new Test('testing')
|
318
|
-
myMixin.constructor.should.have.been.called
|
319
|
-
|
320
|
-
|
321
|
-
it 'calls the constructor with the this object pointing to the instance', ->
|
322
|
-
instance = new Test('testing')
|
323
|
-
recordedSelf.should.equal instance
|
324
|
-
|
325
|
-
it "can handle mixins that don't define a constructor"
|
326
|
-
|
327
|
-
it "shows an error message if the given mixin is undefined"
|
328
|
-
|
329
|
-
it 'provides arguments to the @mixin method to the mixin constructor'
|
@@ -1,43 +0,0 @@
|
|
1
|
-
#= require spec_helper
|
2
|
-
#= require modularity/modules/autogrow_textarea
|
3
|
-
|
4
|
-
|
5
|
-
describe 'AutogrowTextArea', ->
|
6
|
-
|
7
|
-
autogrow = null
|
8
|
-
beforeEach ->
|
9
|
-
template 'autogrow_textarea'
|
10
|
-
autogrow = new modularity.AutogrowTextArea '#konacha #autogrow_area'
|
11
|
-
|
12
|
-
|
13
|
-
describe 'lines', ->
|
14
|
-
|
15
|
-
it 'works for empty lines', ->
|
16
|
-
modularity.AutogrowTextArea.lines(4, "\n\n\n").should == 3
|
17
|
-
|
18
|
-
it 'works for short lines', ->
|
19
|
-
modularity.AutogrowTextArea.lines(4, "1\n12\n123\n").should == 3
|
20
|
-
|
21
|
-
it 'works for a long line', ->
|
22
|
-
modularity.AutogrowTextArea.lines(4, "123456").should == 2
|
23
|
-
|
24
|
-
it 'works for several long lines', ->
|
25
|
-
modularity.AutogrowTextArea.lines(4, "123456\n123456").should == 4
|
26
|
-
|
27
|
-
|
28
|
-
describe 'grow()', ->
|
29
|
-
it 'sets the number of rows of the textarea according to the content area', ->
|
30
|
-
autogrow.textarea.value = "111\n222\n333\n444\n555"
|
31
|
-
autogrow.grow()
|
32
|
-
autogrow.textarea.rows.should.equal(5)
|
33
|
-
|
34
|
-
it 'sets the minimal number of rows if the content is less', ->
|
35
|
-
$(autogrow.textarea).val('one')
|
36
|
-
autogrow.grow()
|
37
|
-
autogrow.textarea.rows.should.equal 3
|
38
|
-
|
39
|
-
it 'can handle empty content', ->
|
40
|
-
$(autogrow.textarea).val('')
|
41
|
-
autogrow.grow()
|
42
|
-
autogrow.textarea.rows.should.equal 3
|
43
|
-
|