joosy 0.1.0.RC3 → 0.1.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. data/.gitignore +0 -2
  2. data/Gemfile +2 -13
  3. data/Gemfile.lock +62 -80
  4. data/Guardfile +15 -21
  5. data/MIT-LICENSE +2 -2
  6. data/README.rdoc +3 -0
  7. data/app/helpers/joosy/sprockets_helper.rb +11 -23
  8. data/joosy.gemspec +3 -3
  9. data/lib/joosy/forms.rb +12 -2
  10. data/lib/joosy/rails/engine.rb +1 -9
  11. data/lib/joosy/rails/version.rb +2 -2
  12. data/lib/joosy-rails.rb +5 -0
  13. data/lib/rails/generators/joosy/application_generator.rb +3 -13
  14. data/lib/rails/generators/joosy/joosy_base.rb +2 -2
  15. data/lib/rails/generators/joosy/layout_generator.rb +1 -8
  16. data/lib/rails/generators/joosy/page_generator.rb +6 -21
  17. data/lib/rails/generators/joosy/preloader_generator.rb +7 -14
  18. data/lib/rails/generators/joosy/templates/app/layouts/application.js.coffee +0 -1
  19. data/lib/rails/generators/joosy/templates/app/layouts/template.js.coffee +1 -1
  20. data/lib/rails/generators/joosy/templates/app/pages/application.js.coffee +1 -1
  21. data/lib/rails/generators/joosy/templates/app/pages/template.js.coffee +3 -3
  22. data/lib/rails/generators/joosy/templates/app/routes.js.coffee +1 -7
  23. data/lib/rails/generators/joosy/templates/app/widgets/template.js.coffee +2 -2
  24. data/lib/rails/generators/joosy/templates/app.js.coffee +0 -3
  25. data/lib/rails/generators/joosy/templates/app_preloader.js.coffee.erb +12 -9
  26. data/lib/rails/generators/joosy/templates/preload.html.erb +6 -5
  27. data/lib/rails/generators/joosy/templates/preload.html.haml +5 -3
  28. data/lib/rails/generators/joosy/templates/preload.html.slim +21 -0
  29. data/lib/rails/generators/joosy/widget_generator.rb +1 -8
  30. data/spec/javascripts/helpers/spec_helper.js.coffee +0 -20
  31. data/spec/javascripts/joosy/core/modules/container_spec.js.coffee +27 -24
  32. data/spec/javascripts/joosy/core/modules/events_spec.js.coffee +18 -42
  33. data/spec/javascripts/joosy/core/modules/filters_spec.js.coffee +27 -27
  34. data/spec/javascripts/joosy/core/modules/log_spec.js.coffee +3 -3
  35. data/spec/javascripts/joosy/core/modules/module_spec.js.coffee +15 -6
  36. data/spec/javascripts/joosy/core/modules/time_manager_spec.js.coffee +7 -12
  37. data/spec/javascripts/joosy/core/modules/widget_manager_spec.js.coffee +17 -31
  38. data/tmp/javascripts/.gitignore +1 -0
  39. data/tmp/spec/javascripts/helpers/.gitignore +1 -0
  40. data/vendor/assets/javascripts/base64.js +135 -0
  41. data/vendor/assets/javascripts/joosy/core/application.js.coffee +26 -0
  42. data/vendor/assets/javascripts/joosy/core/form.js.coffee +87 -0
  43. data/vendor/assets/javascripts/joosy/core/joosy.js.coffee +62 -0
  44. data/vendor/assets/javascripts/joosy/core/layout.js.coffee +38 -0
  45. data/vendor/assets/javascripts/joosy/core/modules/container.js.coffee +51 -0
  46. data/vendor/assets/javascripts/joosy/core/modules/events.js.coffee +17 -0
  47. data/vendor/assets/javascripts/joosy/core/modules/filters.js.coffee +39 -0
  48. data/vendor/assets/javascripts/joosy/core/modules/log.js.coffee +12 -0
  49. data/vendor/assets/javascripts/joosy/core/modules/module.js.coffee +28 -0
  50. data/vendor/assets/javascripts/joosy/core/modules/time_manager.js.coffee +23 -0
  51. data/vendor/assets/javascripts/joosy/core/modules/widgets_manager.js.coffee +45 -0
  52. data/vendor/assets/javascripts/joosy/core/page.js.coffee +136 -0
  53. data/vendor/assets/javascripts/joosy/core/resource/rest.js.coffee +69 -0
  54. data/vendor/assets/javascripts/joosy/core/resource/rest_collection.js.coffee +42 -0
  55. data/vendor/assets/javascripts/joosy/core/router.js.coffee +75 -0
  56. data/vendor/assets/javascripts/joosy/core/widget.js.coffee +35 -0
  57. data/vendor/assets/javascripts/joosy/preloader/development.js.coffee +27 -0
  58. data/vendor/assets/javascripts/joosy/preloader/production.js.coffee +84 -0
  59. data/{app → vendor}/assets/javascripts/joosy.js.coffee +0 -0
  60. data/vendor/assets/javascripts/jquery.form.js +963 -978
  61. data/vendor/assets/javascripts/sugar.js +1 -1
  62. metadata +48 -77
  63. data/.codoopts +0 -5
  64. data/README.md +0 -95
  65. data/app/assets/javascripts/joosy/core/application.js.coffee +0 -50
  66. data/app/assets/javascripts/joosy/core/form.js.coffee +0 -304
  67. data/app/assets/javascripts/joosy/core/helpers/view.js.coffee +0 -30
  68. data/app/assets/javascripts/joosy/core/joosy.js.coffee +0 -129
  69. data/app/assets/javascripts/joosy/core/layout.js.coffee +0 -162
  70. data/app/assets/javascripts/joosy/core/modules/container.js.coffee +0 -104
  71. data/app/assets/javascripts/joosy/core/modules/events.js.coffee +0 -123
  72. data/app/assets/javascripts/joosy/core/modules/filters.js.coffee +0 -67
  73. data/app/assets/javascripts/joosy/core/modules/log.js.coffee +0 -36
  74. data/app/assets/javascripts/joosy/core/modules/module.js.coffee +0 -105
  75. data/app/assets/javascripts/joosy/core/modules/renderer.js.coffee +0 -195
  76. data/app/assets/javascripts/joosy/core/modules/time_manager.js.coffee +0 -46
  77. data/app/assets/javascripts/joosy/core/modules/widgets_manager.js.coffee +0 -84
  78. data/app/assets/javascripts/joosy/core/page.js.coffee +0 -375
  79. data/app/assets/javascripts/joosy/core/preloader.js.coffee +0 -13
  80. data/app/assets/javascripts/joosy/core/resource/collection.js.coffee +0 -174
  81. data/app/assets/javascripts/joosy/core/resource/generic.js.coffee +0 -254
  82. data/app/assets/javascripts/joosy/core/resource/rest.js.coffee +0 -197
  83. data/app/assets/javascripts/joosy/core/resource/rest_collection.js.coffee +0 -125
  84. data/app/assets/javascripts/joosy/core/router.js.coffee +0 -163
  85. data/app/assets/javascripts/joosy/core/templaters/rails_jst.js.coffee +0 -36
  86. data/app/assets/javascripts/joosy/core/widget.js.coffee +0 -80
  87. data/app/assets/javascripts/joosy/preloaders/caching.js.coffee +0 -169
  88. data/app/assets/javascripts/joosy/preloaders/inline.js.coffee +0 -56
  89. data/lib/joosy.rb +0 -9
  90. data/lib/rails/generators/joosy/resource_generator.rb +0 -29
  91. data/lib/rails/generators/joosy/templates/app/helpers/application.js.coffee +0 -4
  92. data/lib/rails/generators/joosy/templates/app/pages/welcome/index.js.coffee +0 -22
  93. data/lib/rails/generators/joosy/templates/app/resources/template.js.coffee +0 -2
  94. data/lib/rails/generators/joosy/templates/app/templates/layouts/application.jst.hamlc +0 -2
  95. data/lib/rails/generators/joosy/templates/app/templates/pages/welcome/index.jst.hamlc +0 -7
  96. data/spec/javascripts/joosy/core/application_spec.js.coffee +0 -40
  97. data/spec/javascripts/joosy/core/form_spec.js.coffee +0 -184
  98. data/spec/javascripts/joosy/core/joosy_spec.js.coffee +0 -72
  99. data/spec/javascripts/joosy/core/layout_spec.js.coffee +0 -50
  100. data/spec/javascripts/joosy/core/modules/renderer_spec.js.coffee +0 -185
  101. data/spec/javascripts/joosy/core/page_spec.js.coffee +0 -178
  102. data/spec/javascripts/joosy/core/resource/collection_spec.js.coffee +0 -84
  103. data/spec/javascripts/joosy/core/resource/generic_spec.js.coffee +0 -118
  104. data/spec/javascripts/joosy/core/resource/rest_collection_spec.js.coffee +0 -58
  105. data/spec/javascripts/joosy/core/resource/rest_spec.js.coffee +0 -129
  106. data/spec/javascripts/joosy/core/router_spec.js.coffee +0 -123
  107. data/spec/javascripts/joosy/core/templaters/rails_jst_spec.js.coffee +0 -25
  108. data/spec/javascripts/joosy/core/widget_spec.js.coffee +0 -40
  109. data/spec/javascripts/joosy/preloaders/caching_spec.js.coffee +0 -36
  110. data/spec/javascripts/joosy/preloaders/inline_spec.js.coffee +0 -16
  111. data/spec/javascripts/support/assets/coolface.jpg +0 -0
  112. data/spec/javascripts/support/assets/okay.jpg +0 -0
  113. data/spec/javascripts/support/assets/test.js +0 -1
  114. data/spec/javascripts/support/sinon-ie-1.3.1.js +0 -82
  115. data/vendor/assets/javascripts/metamorph.js +0 -409
@@ -1,84 +0,0 @@
1
- describe "Joosy.Resource.Collection", ->
2
-
3
- class Test extends Joosy.Resource.Generic
4
- @entity 'test'
5
-
6
- data = '[{"id": 1, "name": "test1"}, {"id": 2, "name": "test2"}]'
7
-
8
- checkData = (collection) ->
9
- expect(collection.data.length).toEqual 2
10
- expect(collection.data[0].constructor == Test).toBeTruthy()
11
- expect(collection.data[0].e.name).toEqual 'test1'
12
-
13
- beforeEach ->
14
- @collection = new Joosy.Resource.Collection(Test)
15
-
16
- it "should initialize", ->
17
- expect(@collection.model).toEqual Test
18
- expect(@collection.data).toEqual []
19
-
20
- it "should modelize", ->
21
- result = @collection.modelize $.parseJSON(data)
22
- expect(result[0].constructor == Test).toBeTruthy()
23
- expect(result[0].e.name).toEqual 'test1'
24
-
25
- it "should reset", ->
26
- @collection.reset $.parseJSON(data)
27
- checkData @collection
28
-
29
- it "should trigger changes", ->
30
- @collection.bind 'changed', callback = sinon.spy()
31
- @collection.reset $.parseJSON(data)
32
- expect(callback.callCount).toEqual 1
33
-
34
- it "should not trigger changes", ->
35
- @collection.bind 'changed', callback = sinon.spy()
36
- @collection.reset $.parseJSON(data), false
37
- expect(callback.callCount).toEqual 0
38
-
39
- it "should properly handle the before filter", ->
40
- class RC extends Joosy.Resource.Collection
41
- @beforeLoad (data) ->
42
- data.each (entry, i) ->
43
- data[i].tested = true
44
- data
45
-
46
- collection = new RC(Test)
47
- collection.reset $.parseJSON(data)
48
-
49
- expect(collection.at(0)('tested')).toBeTruthy()
50
-
51
- it "should remove item from collection", ->
52
- @collection.reset $.parseJSON(data)
53
- @collection.bind 'changed', callback = sinon.spy()
54
- @collection.remove @collection.data[1]
55
- expect(@collection.data.length).toEqual 1
56
- @collection.remove 0
57
- expect(@collection.data.length).toEqual 0
58
- expect(callback.callCount).toEqual 2
59
-
60
- it "should silently remove item from collection", ->
61
- @collection.reset $.parseJSON(data)
62
- @collection.bind 'changed', callback = sinon.spy()
63
- @collection.remove @collection.data[1], false
64
- expect(@collection.data.length).toEqual 1
65
- @collection.remove 0, false
66
- expect(@collection.data.length).toEqual 0
67
- expect(callback.callCount).toEqual 0
68
-
69
- it "should add item from collection", ->
70
- @collection.reset $.parseJSON(data)
71
- @collection.bind 'changed', callback = sinon.spy()
72
- @collection.add new Test {'rocking': 'mocking'}
73
- expect(@collection.data.length).toEqual 3
74
- expect(@collection.at(2).e).toEqual {'rocking': 'mocking'}
75
- @collection.add new Test({'rocking': 'mocking'}), 1
76
- expect(@collection.data.length).toEqual 4
77
- expect(@collection.at(1).e).toEqual {'rocking': 'mocking'}
78
- expect(@collection.at(3).e).toEqual {'rocking': 'mocking'}
79
-
80
- it "should find items by id", ->
81
- @collection.reset $.parseJSON(data)
82
-
83
- expect(@collection.findById 1).toEqual @collection.data[0]
84
- expect(@collection.findById 2).toEqual @collection.data[1]
@@ -1,118 +0,0 @@
1
- describe "Joosy.Resource.Generic", ->
2
-
3
- beforeEach ->
4
- @resource = Joosy.Resource.Generic.create @data =
5
- foo: 'bar'
6
- bar: 'baz'
7
- very:
8
- deep:
9
- value: 'boo!'
10
-
11
-
12
- it "should remember where it belongs", ->
13
- resource = new Joosy.Resource.Generic foo: 'bar'
14
- expect(resource.e).toEqual foo: 'bar'
15
-
16
- it "should produce magic function", ->
17
- expect(Object.isFunction @resource).toBeTruthy()
18
- expect(@resource.e).toEqual @data
19
-
20
- it "should get values", ->
21
- expect(@resource 'foo').toEqual 'bar'
22
- expect(@resource 'very.deep').toEqual value: 'boo!'
23
- expect(@resource 'very.deep.value').toEqual 'boo!'
24
-
25
- it "should set values", ->
26
- expect(@resource 'foo').toEqual 'bar'
27
- @resource 'foo', 'baz'
28
- expect(@resource 'foo').toEqual 'baz'
29
-
30
- expect(@resource 'very.deep').toEqual value: 'boo!'
31
- @resource 'very.deep', 'banana!'
32
- expect(@resource 'very.deep').toEqual 'banana!'
33
-
34
- @resource 'another.deep.value', 'banana strikes back'
35
- expect(@resource 'another.deep').toEqual value: 'banana strikes back'
36
-
37
- it "should handle lambdas in @source properly", ->
38
- class Fluffy extends Joosy.Resource.Generic
39
- @source (rumbas) -> "#{rumbas}!"
40
-
41
- clone = Fluffy.at('rumbas')
42
-
43
- expect(-> clone.at 'kutuzka').toThrow(new Error 'clone> should be created directly (without `at\')')
44
- expect(clone.__source).toEqual 'rumbas!'
45
-
46
- expect(Joosy.Module.hasAncestor clone, Fluffy).toBeTruthy()
47
- # clone won't be instanceof Fluffy in IE
48
- #expect(clone.create({}) instanceof Fluffy).toBeTruthy()
49
-
50
- it "should trigger 'changed' right", ->
51
- callback = sinon.spy()
52
- @resource.bind 'changed', callback
53
- @resource 'foo', 'baz'
54
- @resource 'foo', 'baz2'
55
-
56
- expect(callback.callCount).toEqual(2)
57
-
58
- it "should properly handle the before filter", ->
59
- class R extends Joosy.Resource.Generic
60
- @beforeLoad (data) ->
61
- data ||= {}
62
- data.tested = true
63
- data
64
-
65
- resource = R.create()
66
-
67
- expect(resource 'tested').toBeTruthy()
68
-
69
- it "should map inlines", ->
70
- class RumbaMumba extends Joosy.Resource.Generic
71
- @entity 'rumba_mumba'
72
-
73
- class R extends Joosy.Resource.Generic
74
- @map 'rumbaMumbas', RumbaMumba
75
-
76
- resource = R.create
77
- rumbaMumbas: [
78
- {foo: 'bar'},
79
- {bar: 'baz'}
80
- ]
81
- expect(resource.rumbaMumbas instanceof Joosy.Resource.Collection).toBeTruthy()
82
- expect(resource.rumbaMumbas.at(0)('foo')).toEqual 'bar'
83
-
84
-
85
- it "should use magic collections", ->
86
- class window.RumbaMumbasCollection extends Joosy.Resource.Collection
87
-
88
- class RumbaMumba extends Joosy.Resource.Generic
89
- @entity 'rumba_mumba'
90
- class R extends Joosy.Resource.Generic
91
- @map 'rumbaMumbas', RumbaMumba
92
-
93
- resource = R.create
94
- rumbaMumbas: [
95
- {foo: 'bar'},
96
- {bar: 'baz'}
97
- ]
98
- expect(resource.rumbaMumbas instanceof RumbaMumbasCollection).toBeTruthy()
99
- expect(resource.rumbaMumbas.at(0)('foo')).toEqual 'bar'
100
-
101
- window.RumbaMumbasCollection = undefined
102
-
103
- it "should use manually set collections", ->
104
- class OloCollection extends Joosy.Resource.Collection
105
-
106
- class RumbaMumba extends Joosy.Resource.Generic
107
- @entity 'rumba_mumba'
108
- @collection OloCollection
109
- class R extends Joosy.Resource.Generic
110
- @map 'rumbaMumbas', RumbaMumba
111
-
112
- resource = R.create
113
- rumbaMumbas: [
114
- {foo: 'bar'},
115
- {bar: 'baz'}
116
- ]
117
- expect(resource.rumbaMumbas instanceof OloCollection).toBeTruthy()
118
- expect(resource.rumbaMumbas.at(0)('foo')).toEqual 'bar'
@@ -1,58 +0,0 @@
1
- describe "Joosy.Resource.RESTCollection", ->
2
-
3
- class Test extends Joosy.Resource.REST
4
- @entity 'test'
5
-
6
- data = '[{"id": 1, "name": "test1"}, {"id": 2, "name": "test2"}]'
7
-
8
- checkData = (collection) ->
9
- expect(collection.data.length).toEqual 2
10
- expect(collection.data[0].constructor == Test).toBeTruthy()
11
- expect(collection.data[0].e.name).toEqual 'test1'
12
-
13
- spoofData = (server) ->
14
- target = server.requests.last()
15
- expect(target.method).toEqual 'GET'
16
- expect(target.url).toMatch /^\/tests\/\?(page=\d+&)?_=\d+/
17
- target.respond 200, 'Content-Type': 'application/json', data
18
-
19
- beforeEach ->
20
- @server = sinon.fakeServer.create()
21
- @collection = new Joosy.Resource.RESTCollection(Test)
22
-
23
- afterEach ->
24
- @server.restore()
25
-
26
- it "should fetch", ->
27
- @collection.fetch()
28
- spoofData @server
29
- checkData @collection
30
-
31
- it "should paginate", ->
32
- @collection.fetch()
33
- spoofData @server
34
- checkData @collection
35
-
36
- @collection.page 2, callback=sinon.spy()
37
- spoofData @server
38
- expect(callback.callCount).toEqual 1
39
- expect(@collection.data.length).toEqual 2
40
- expect(@collection.data[0].constructor == Test).toBeTruthy()
41
- expect(@collection.data[0].e.name).toEqual 'test1'
42
-
43
- # Again from cache
44
- @collection.page 2, callback=sinon.spy()
45
- spoofData @server
46
- expect(callback.callCount).toEqual 1
47
- expect(@collection.data.length).toEqual 2
48
- expect(@collection.data[0].constructor == Test).toBeTruthy()
49
- expect(@collection.data[0].e.name).toEqual 'test1'
50
-
51
- it "should trigger changes", ->
52
- @collection.bind 'changed', callback = sinon.spy()
53
- @collection.fetch()
54
- spoofData @server
55
- expect(callback.callCount).toEqual 1
56
- @collection.page 2
57
- spoofData @server
58
- expect(callback.callCount).toEqual 2
@@ -1,129 +0,0 @@
1
- describe "Joosy.Resource.REST", ->
2
-
3
- beforeEach ->
4
- @server = sinon.fakeServer.create()
5
- class @Test extends Joosy.Resource.REST
6
- @entity 'test'
7
-
8
- afterEach ->
9
- @server.restore()
10
-
11
- it "should have default primary key", ->
12
- expect(@Test::__primaryKey).toEqual 'id'
13
-
14
- it "should have appropriate accessors", ->
15
- @Test.entity 'tada'
16
- expect(@Test::__entityName).toEqual 'tada'
17
- @Test.source 'uri'
18
- expect(@Test.__source).toEqual 'uri'
19
- expect(@Test.__buildSource()).toEqual 'uri/'
20
- @Test.primary 'uid'
21
- expect(@Test::__primaryKey).toEqual 'uid'
22
-
23
- it "should build source url based on entity name", ->
24
- options =
25
- extension: 'id'
26
- params:
27
- test: 1
28
- expect(@Test.__buildSource(options)).toEqual '/tests/id?test=1'
29
-
30
- it "should have overloaded constructor", ->
31
- resource = @Test.create 'someId'
32
- expect(resource.id).toEqual 'someId'
33
-
34
- data = {id: 'someId', field: 'value'}
35
-
36
- rooted = @Test.create {test: data}
37
- unrooted = @Test.create data
38
-
39
- expect(rooted.e).toEqual unrooted.e
40
- expect(rooted.id).toEqual 'someId'
41
- expect(rooted.e.id).toEqual 'someId'
42
- expect(rooted.e.field).toEqual 'value'
43
-
44
- it 'should find single object', ->
45
- @Test.beforeLoad beforeLoadCallback = sinon.spy (data) ->
46
- expect(data.id).toEqual 1
47
- expect(data.name).toEqual 'test1'
48
- Object.extended(data)
49
- @Test.find 1, callback = sinon.spy (target) ->
50
- expect(target.id).toEqual 1
51
- expect(target.e?.name).toEqual 'test1'
52
- target = @server.requests[0]
53
- expect(target.method).toEqual 'GET'
54
- expect(target.url).toMatch /^\/tests\/1\?_=\d+/
55
- target.respond 200, 'Content-Type': 'application/json',
56
- '{"test": {"id": 1, "name": "test1"}}'
57
- expect(callback.callCount).toEqual 1
58
- expect(beforeLoadCallback.callCount).toEqual 1
59
-
60
- it 'should find objects collection with params', ->
61
- callback = sinon.spy (collection) ->
62
- i = 1
63
- expect(collection instanceof Joosy.Resource.RESTCollection).toBeTruthy()
64
- collection.data.each (target) ->
65
- expect(target.id).toEqual i
66
- expect(target.e?.name).toEqual 'test' + i
67
- i += 1
68
- @Test.find null, callback
69
- target = @server.requests[0]
70
- expect(target.method).toEqual 'GET'
71
- expect(target.url).toMatch /^\/tests\/\?_=\d+/
72
- target.respond 200, 'Content-Type': 'application/json',
73
- '[{"id": 1, "name": "test1"}, {"id": 2, "name": "test2"}]'
74
- expect(callback.callCount).toEqual 1
75
-
76
- it 'should find all objects collection', ->
77
- callback = sinon.spy (collection) ->
78
- i = 1
79
- expect(collection instanceof Joosy.Resource.RESTCollection).toBeTruthy()
80
- collection.data.each (target) ->
81
- expect(target.id).toEqual i
82
- expect(target.e?.name).toEqual 'test' + i
83
- i += 1
84
- @Test.find callback
85
- target = @server.requests[0]
86
- expect(target.method).toEqual 'GET'
87
- expect(target.url).toMatch /^\/tests\/\?_=\d+/
88
- target.respond 200, 'Content-Type': 'application/json',
89
- '[{"id": 1, "name": "test1"}, {"id": 2, "name": "test2"}]'
90
- expect(callback.callCount).toEqual 1
91
-
92
- it 'should destroy single object', ->
93
- obj = @Test.create 1
94
- callback = sinon.spy (target) ->
95
- expect(target).toBe obj
96
- obj.destroy callback
97
- target = @server.requests[0]
98
- expect(target.method).toEqual 'DELETE'
99
- expect(target.url).toEqual '/tests/1'
100
- target.respond 200
101
- expect(callback.callCount).toEqual 1
102
-
103
- it "should identify identifiers", ->
104
- [0, 123, -5, '123abd', 'whatever'].each (variant) =>
105
- expect(@Test.__isId variant).toBeTruthy()
106
- [(->) , [], {}, null, undefined, true, false].each (variant) =>
107
- expect(@Test.__isId variant).toBeFalsy()
108
-
109
- it "should trigger 'changed' on fetch", ->
110
- resource = @Test.find 1, callback = sinon.spy (target) ->
111
- expect(target.id).toEqual 1
112
- expect(target.e?.name).toEqual 'test1'
113
- target = @server.requests[0]
114
- expect(target.method).toEqual 'GET'
115
- expect(target.url).toMatch /^\/tests\/1\?_=\d+/
116
- target.respond 200, 'Content-Type': 'application/json',
117
- '{"test": {"id": 1, "name": "test1"}}'
118
- expect(callback.callCount).toEqual 1
119
-
120
- resource.bind 'changed', callback = sinon.spy()
121
- resource.fetch()
122
-
123
- target = @server.requests[1]
124
- expect(target.method).toEqual 'GET'
125
- expect(target.url).toMatch /^\/tests\/1\?_=\d+/
126
- target.respond 200, 'Content-Type': 'application/json',
127
- '{"test": {"id": 1, "name": "test1"}}'
128
-
129
- expect(callback.callCount).toEqual 1
@@ -1,123 +0,0 @@
1
- describe "Joosy.Router", ->
2
-
3
- class TestPage extends Joosy.Page
4
-
5
- spies =
6
- root: sinon.spy()
7
- section: sinon.spy()
8
- wildcard: sinon.spy()
9
-
10
- map = Object.extended
11
- '/': spies.root
12
- '/page': TestPage
13
- '/section':
14
- '/page/:id': spies.section
15
- '/page2/:more': TestPage
16
- 404: spies.wildcard
17
-
18
- beforeEach ->
19
- Joosy.Router.reset()
20
-
21
- afterEach ->
22
- $(window).unbind 'hashchange'
23
-
24
- it "should map", ->
25
- Joosy.Router.map map
26
- expect(Joosy.Router.rawRoutes).toEqual map
27
-
28
- it "should initialize on setup", ->
29
- sinon.stub Joosy.Router, '__prepareRoutes'
30
- sinon.stub Joosy.Router, '__respondRoute'
31
-
32
- Joosy.Router.map map
33
- Joosy.Router.__setupRoutes()
34
- expect(Joosy.Router.__prepareRoutes.callCount).toEqual 1
35
- expect(Joosy.Router.__prepareRoutes.args[0][0]).toEqual map
36
- expect(Joosy.Router.__respondRoute.callCount).toEqual 1
37
- expect(Joosy.Router.__respondRoute.args[0][0]).toEqual location.hash
38
- Joosy.Router.__prepareRoutes.restore()
39
- Joosy.Router.__respondRoute.restore()
40
-
41
- it "should prepare route", ->
42
- route = Joosy.Router.__prepareRoute "/such/a/long/long/url/:with/:plenty/:of/:params", "123"
43
-
44
- expect(route).toEqual Object.extended
45
- '^/?such/a/long/long/url/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$':
46
- capture: ['with', 'plenty', 'of', 'params']
47
- action: "123"
48
-
49
- it "should cook routes", ->
50
- sinon.stub Joosy.Router, '__respondRoute'
51
-
52
- Joosy.Router.map map
53
- Joosy.Router.__setupRoutes()
54
-
55
- expect(Joosy.Router.routes).toEqual Object.extended
56
- '^/?/?$':
57
- capture: []
58
- action: spies.root
59
- '^/?page/?$':
60
- capture: []
61
- action: TestPage
62
- '^/?section/page/([^/]+)/?$':
63
- capture: ['id']
64
- action: spies.section
65
- '^/?section/page2/([^/]+)/?$':
66
- capture: ['more']
67
- action: TestPage
68
-
69
- Joosy.Router.__respondRoute.restore()
70
-
71
- it "should get route params", ->
72
- route = Joosy.Router.__prepareRoute "/such/a/long/long/url/:with/:plenty/:of/:params", "123"
73
- result = Joosy.Router.__paramsFromRouteMatch ['full regex match here', 1, 2, 3, 4], route.values().first()
74
-
75
- expect(result).toEqual Object.extended
76
- 'with': 1
77
- 'plenty': 2
78
- 'of': 3
79
- 'params': 4
80
-
81
- it "should build query params", ->
82
- result = Joosy.Router.__paramsFromQueryArray ["foo=bar", "bar=baz"]
83
-
84
- expect(result).toEqual Object.extended
85
- foo: 'bar'
86
- bar: 'baz'
87
-
88
- it "should respond routes", ->
89
- sinon.stub Joosy.Router, '__respondRoute'
90
- sinon.stub Joosy.Application, 'setCurrentPage'
91
-
92
- Joosy.Router.map map
93
- Joosy.Router.__setupRoutes()
94
-
95
- Joosy.Router.__respondRoute.restore()
96
-
97
- Joosy.Router.__respondRoute '/'
98
- expect(spies.root.callCount).toEqual 1
99
-
100
- Joosy.Router.__respondRoute '/page'
101
- expect(Joosy.Application.setCurrentPage.callCount).toEqual 1
102
- expect(Joosy.Application.setCurrentPage.args.last()).toEqual [TestPage, Object.extended()]
103
-
104
- Joosy.Router.__respondRoute '/section/page/1'
105
- expect(spies.section.callCount).toEqual 1
106
- expect(spies.section.args.last()).toEqual [Object.extended(id: '1')]
107
-
108
- Joosy.Router.__respondRoute '/section/page2/1&a=b'
109
- expect(Joosy.Application.setCurrentPage.callCount).toEqual 2
110
- expect(Joosy.Application.setCurrentPage.args.last()).toEqual [TestPage, Object.extended(more: '1', a: 'b')]
111
-
112
- Joosy.Router.__respondRoute '/thiswillneverbefound&a=b'
113
- expect(spies.wildcard.callCount).toEqual 1
114
- expect(spies.wildcard.args.last()).toEqual ['/thiswillneverbefound', Object.extended(a: 'b')]
115
-
116
- Joosy.Application.setCurrentPage.restore()
117
-
118
- it "should navigate", ->
119
- Joosy.Router.navigate 'test'
120
- expect(location.hash).toEqual '#!test'
121
- Joosy.Router.navigate ''
122
- expect(location.hash).toEqual '#!'
123
- location.hash = ''
@@ -1,25 +0,0 @@
1
- describe "Joosy.Templaters.RailsJST", ->
2
-
3
- beforeEach ->
4
- @templater = new Joosy.Templaters.RailsJST()
5
-
6
- class @Klass extends Joosy.Module
7
-
8
- Joosy.namespace 'British.Cities', ->
9
- class @Klass extends Joosy.Module
10
-
11
- it "should resolve templates correctly", ->
12
- expect(@templater.resolveTemplate(undefined, "/absolute", undefined)).
13
- toEqual "absolute"
14
-
15
- expect(@templater.resolveTemplate('widgets', 'fuga', {})).
16
- toEqual 'widgets/fuga'
17
-
18
- expect(@templater.resolveTemplate('widgets', 'fuga', new @Klass)).
19
- toEqual 'widgets/fuga'
20
-
21
- expect(@templater.resolveTemplate('widgets', 'fuga', new British.Cities.Klass)).
22
- toEqual 'widgets/british/cities/fuga'
23
-
24
- expect(@templater.resolveTemplate('widgets', 'hoge/fuga', new British.Cities.Klass)).
25
- toEqual 'widgets/british/cities/hoge/fuga'
@@ -1,40 +0,0 @@
1
- describe "Joosy.Widget", ->
2
-
3
- beforeEach ->
4
- class @TestWidget extends Joosy.Widget
5
- @box = new @TestWidget()
6
-
7
- it "should have appropriate accessors", ->
8
- test = ->
9
- @TestWidget.view test
10
- expect(@TestWidget::__renderer).toEqual test
11
- @TestWidget.view 'test'
12
- expect(@TestWidget::__renderer instanceof Function).toBeTruthy()
13
-
14
- it "should use Router", ->
15
- target = sinon.stub Joosy.Router, 'navigate'
16
- @box.navigate 'there'
17
- expect(target.callCount).toEqual 1
18
- expect(target.alwaysCalledWithExactly 'there').toBeTruthy()
19
- Joosy.Router.navigate.restore()
20
-
21
- it "should load itself", ->
22
- @box.data = {tested: true}
23
- spies = [sinon.spy()]
24
- @TestWidget.view spies[0]
25
- @parent = new Joosy.Layout()
26
- spies.push sinon.spy(@box, 'refreshElements')
27
- spies.push sinon.spy(@box, '__delegateEvents')
28
- spies.push sinon.spy(@box, '__runAfterLoads')
29
- target = @box.__load @parent, @ground
30
- expect(target).toBe @box
31
- expect(@box.__renderer.getCall(0).calledOn()).toBeFalsy()
32
- expect(@box.__renderer.getCall(0).args[0]).toEqual {tested: true}
33
- expect(spies).toBeSequenced()
34
-
35
- it "should unload itself", ->
36
- sinon.spy @box, '__runAfterUnloads'
37
- @box.__unload()
38
- target = @box.__runAfterUnloads
39
- expect(target.callCount).toEqual 1
40
- expect(target.getCall(0).calledOn()).toBeFalsy()
@@ -1,36 +0,0 @@
1
- describe "CachingPreloader", ->
2
-
3
- it "should load JS", ->
4
- window.variable_assigned_on_load = undefined
5
- localStorage.clear()
6
-
7
- callback = sinon.spy()
8
- server = sinon.fakeServer.create()
9
-
10
- load = ->
11
- CachingPreloader.load [['/spec/javascripts/support/assets/test.js']],
12
- complete: callback
13
-
14
- load()
15
-
16
- expect(server.requests.length).toEqual 1
17
- target = server.requests[0]
18
- expect(target.method).toEqual 'GET'
19
- expect(target.url).toMatch /^\/spec\/javascripts\/support\/assets\/test.js$/
20
- target.respond 200, 'Content-Type': 'application/javascript',
21
- "window.variable_assigned_on_load = 'yapyap';"
22
-
23
- expect(callback.callCount).toEqual 1
24
- expect(window.variable_assigned_on_load).toEqual 'yapyap'
25
- window.variable_assigned_on_load = undefined
26
-
27
- load()
28
-
29
- expect(server.requests.length).toEqual 1
30
- expect(callback.callCount).toEqual 2
31
- expect(window.variable_assigned_on_load).toEqual 'yapyap'
32
-
33
- server.restore()
34
-
35
- window.variable_assigned_on_load = undefined
36
- localStorage.clear()
@@ -1,16 +0,0 @@
1
- describe "InlinePreloader", ->
2
-
3
- it "should load JS", ->
4
- window.variable_assigned_on_load = undefined
5
- callback = sinon.spy()
6
-
7
- runs ->
8
- InlinePreloader.load [['/spec/javascripts/support/assets/test.js']],
9
- complete: callback
10
-
11
- waits 100
12
-
13
- runs ->
14
- expect(callback.callCount).toEqual 1
15
- expect(window.variable_assigned_on_load).toEqual 'yapyap'
16
- window.variable_assigned_on_load = undefined
@@ -1 +0,0 @@
1
- window.variable_assigned_on_load = 'yapyap';