upjs-rails 0.12.5 → 0.13.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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.rdoc_options +23 -0
  3. data/CHANGELOG.md +20 -0
  4. data/design/up-validate.js.coffee +284 -0
  5. data/dist/up-bootstrap.js +4 -0
  6. data/dist/up-bootstrap.min.js +1 -1
  7. data/dist/up.js +547 -102
  8. data/dist/up.min.js +2 -2
  9. data/lib/assets/javascripts/up/browser.js.coffee +3 -2
  10. data/lib/assets/javascripts/up/flow.js.coffee +95 -17
  11. data/lib/assets/javascripts/up/form.js.coffee +327 -34
  12. data/lib/assets/javascripts/up/history.js.coffee +1 -1
  13. data/lib/assets/javascripts/up/layout.js.coffee +4 -4
  14. data/lib/assets/javascripts/up/link.js.coffee +5 -2
  15. data/lib/assets/javascripts/up/modal.js.coffee +1 -0
  16. data/lib/assets/javascripts/up/proxy.js.coffee +27 -12
  17. data/lib/assets/javascripts/up/syntax.js.coffee +39 -20
  18. data/lib/assets/javascripts/up/util.js.coffee +29 -12
  19. data/lib/assets/javascripts/up-bootstrap/form-ext.js.coffee +1 -0
  20. data/lib/upjs/rails/engine.rb +1 -1
  21. data/lib/upjs/rails/inspector.rb +63 -0
  22. data/lib/upjs/rails/inspector_accessor.rb +28 -0
  23. data/lib/upjs/rails/request_echo_headers.rb +7 -0
  24. data/lib/upjs/rails/request_method_cookie.rb +12 -4
  25. data/lib/upjs/rails/version.rb +5 -1
  26. data/lib/upjs-rails.rb +7 -5
  27. data/spec_app/.rspec +2 -0
  28. data/spec_app/Gemfile +0 -3
  29. data/spec_app/Gemfile.lock +43 -44
  30. data/spec_app/app/assets/stylesheets/application.css +1 -1
  31. data/spec_app/app/controllers/test_controller.rb +23 -0
  32. data/spec_app/config/routes.rb +2 -0
  33. data/spec_app/spec/controllers/test_controller_spec.rb +67 -0
  34. data/spec_app/spec/javascripts/helpers/append_fixture.js.coffee +8 -0
  35. data/spec_app/spec/javascripts/helpers/last_request.js.coffee +18 -0
  36. data/spec_app/spec/javascripts/helpers/reset_path.js.coffee +1 -0
  37. data/spec_app/spec/javascripts/up/flow_spec.js.coffee +93 -43
  38. data/spec_app/spec/javascripts/up/form_spec.js.coffee +80 -18
  39. data/spec_app/spec/javascripts/up/history_spec.js.coffee +1 -5
  40. data/spec_app/spec/javascripts/up/link_spec.js.coffee +18 -17
  41. data/spec_app/spec/javascripts/up/modal_spec.js.coffee +32 -37
  42. data/spec_app/spec/javascripts/up/navigation_spec.js.coffee +7 -26
  43. data/spec_app/spec/javascripts/up/popup_spec.js.coffee +1 -7
  44. data/spec_app/spec/javascripts/up/proxy_spec.js.coffee +26 -25
  45. data/spec_app/spec/javascripts/up/util_spec.js.coffee +23 -0
  46. data/spec_app/spec/spec_helper.rb +62 -0
  47. metadata +12 -3
  48. data/lib/upjs/rails/request_ext.rb +0 -13
@@ -5,4 +5,5 @@ beforeEach ->
5
5
  afterEach ->
6
6
  if up.browser.canPushState()
7
7
  history.replaceState?({}, @previousTitle, @previousHref)
8
+ document.title = @previousTitle
8
9
 
@@ -21,66 +21,121 @@ describe 'up.flow', ->
21
21
  <div class="after">new-after</div>
22
22
  """
23
23
 
24
- @respond = ->
25
- @lastRequest().respondWith
26
- status: 200
27
- contentType: 'text/html'
28
- responseText: @responseText
24
+ @respond = -> @respondWith(@responseText)
29
25
 
30
26
  it 'replaces the given selector with the same selector from a freshly fetched page', (done) ->
31
- @request = up.replace('.middle', '/path')
27
+ promise = up.replace('.middle', '/path')
32
28
  @respond()
33
- @request.then ->
29
+ promise.then ->
34
30
  expect($('.before')).toHaveText('old-before')
35
31
  expect($('.middle')).toHaveText('new-middle')
36
32
  expect($('.after')).toHaveText('old-after')
37
33
  done()
38
34
 
39
35
  it 'should set the browser location to the given URL', (done) ->
40
- @request = up.replace('.middle', '/path')
36
+ promise = up.replace('.middle', '/path')
41
37
  @respond()
42
- @request.then ->
38
+ promise.then ->
43
39
  expect(window.location.pathname).toBe('/path')
44
40
  done()
45
-
41
+
42
+ it "detects a redirect's new URL when the server sets an X-Up-Location header", (done) ->
43
+ promise = up.replace('.middle', '/path')
44
+ @respondWith(@responseText, responseHeaders: { 'X-Up-Location': '/other-path' })
45
+ promise.then ->
46
+ expect(window.location.pathname).toBe('/other-path')
47
+ done()
48
+
49
+ it 'understands non-standard CSS selector extensions such as :has(...)', (done) ->
50
+ $first = affix('.boxx#first')
51
+ $firstChild = $('<span class="first-child">old first</span>').appendTo($first)
52
+ $second = affix('.boxx#second')
53
+ $secondChild = $('<span class="second-child">old second</span>').appendTo($second)
54
+
55
+ promise = up.replace('.boxx:has(.first-child)', '/path')
56
+ @respondWith """
57
+ <div class="boxx" id="first">
58
+ <span class="first-child">new first</span>
59
+ </div>
60
+ """
61
+
62
+ promise.then ->
63
+ expect($('#first span')).toHaveText('new first')
64
+ expect($('#second span')).toHaveText('old second')
65
+ done()
66
+
46
67
  it 'marks the element with the URL from which it was retrieved', (done) ->
47
- @request = up.replace('.middle', '/path')
68
+ promise = up.replace('.middle', '/path')
48
69
  @respond()
49
- @request.then ->
70
+ promise.then ->
50
71
  expect($('.middle').attr('up-source')).toMatch(/\/path$/)
51
72
  done()
52
73
 
53
74
  it 'replaces multiple selectors separated with a comma', (done) ->
54
- @request = up.replace('.middle, .after', '/path')
75
+ promise = up.replace('.middle, .after', '/path')
55
76
  @respond()
56
- @request.then ->
77
+ promise.then ->
57
78
  expect($('.before')).toHaveText('old-before')
58
79
  expect($('.middle')).toHaveText('new-middle')
59
80
  expect($('.after')).toHaveText('new-after')
60
81
  done()
61
82
 
83
+ it 'replaces the body if asked to replace the "html" selector'
84
+
85
+ it "sets the document title to a 'title' tag in the response", ->
86
+ affix('.container').text('old container text')
87
+ up.replace('.container', '/path')
88
+ @respondWith """
89
+ <html>
90
+ <head>
91
+ <title>Title from HTML</title>
92
+ </head>
93
+ <body>
94
+ <div class='container'>
95
+ new container text
96
+ </div>
97
+ </body>
98
+ </html>
99
+ """
100
+ expect($('.container')).toHaveText('new container text')
101
+ expect(document.title).toBe('Title from HTML')
102
+
103
+ it "sets the document title to an 'X-Up-Title' header in the response", ->
104
+ affix('.container').text('old container text')
105
+ up.replace('.container', '/path')
106
+ @respondWith
107
+ responseHeaders:
108
+ 'X-Up-Title': 'Title from header'
109
+ responseText: """
110
+ <div class='container'>
111
+ new container text
112
+ </div>
113
+ """
114
+ expect($('.container')).toHaveText('new container text')
115
+ expect(document.title).toBe('Title from header')
116
+
62
117
  it 'prepends instead of replacing when the target has a :before pseudo-selector', (done) ->
63
- @request = up.replace('.middle:before', '/path')
118
+ promise = up.replace('.middle:before', '/path')
64
119
  @respond()
65
- @request.then ->
120
+ promise.then ->
66
121
  expect($('.before')).toHaveText('old-before')
67
122
  expect($('.middle')).toHaveText('new-middleold-middle')
68
123
  expect($('.after')).toHaveText('old-after')
69
124
  done()
70
125
 
71
126
  it 'appends instead of replacing when the target has a :after pseudo-selector', (done) ->
72
- @request = up.replace('.middle:after', '/path')
127
+ promise = up.replace('.middle:after', '/path')
73
128
  @respond()
74
- @request.then ->
129
+ promise.then ->
75
130
  expect($('.before')).toHaveText('old-before')
76
131
  expect($('.middle')).toHaveText('old-middlenew-middle')
77
132
  expect($('.after')).toHaveText('old-after')
78
133
  done()
79
134
 
80
135
  it "lets the developer choose between replacing/prepending/appending for each selector", (done) ->
81
- @request = up.replace('.before:before, .middle, .after:after', '/path')
136
+ promise = up.replace('.before:before, .middle, .after:after', '/path')
82
137
  @respond()
83
- @request.then ->
138
+ promise.then ->
84
139
  expect($('.before')).toHaveText('new-beforeold-before')
85
140
  expect($('.middle')).toHaveText('new-middle')
86
141
  expect($('.after')).toHaveText('old-afternew-after')
@@ -105,10 +160,10 @@ describe 'up.flow', ->
105
160
  </div>
106
161
  """
107
162
 
108
- @request = up.replace('.middle', '/path')
163
+ promise = up.replace('.middle', '/path')
109
164
  @respond()
110
165
 
111
- @request.then ->
166
+ promise.then ->
112
167
  expect(window.scriptTagExecuted).not.toHaveBeenCalledWith('before')
113
168
  expect(window.scriptTagExecuted).toHaveBeenCalledWith('middle')
114
169
  done()
@@ -154,9 +209,9 @@ describe 'up.flow', ->
154
209
  u.resolvedDeferred()
155
210
 
156
211
  it 'reveals a new element before it is being replaced', (done) ->
157
- @request = up.replace('.middle', '/path', reveal: true)
212
+ promise = up.replace('.middle', '/path', reveal: true)
158
213
  @respond()
159
- @request.then =>
214
+ promise.then =>
160
215
  expect(@revealMock).not.toHaveBeenCalledWith(@oldMiddle)
161
216
  expect(@revealedHTML).toContain('new-middle')
162
217
  done()
@@ -164,7 +219,7 @@ describe 'up.flow', ->
164
219
  describe 'when there is an anchor #hash in the URL', ->
165
220
 
166
221
  it 'reveals a child with the ID of that #hash', (done) ->
167
- @request = up.replace('.middle', '/path#three', reveal: true)
222
+ promise = up.replace('.middle', '/path#three', reveal: true)
168
223
  @responseText =
169
224
  """
170
225
  <div class="middle">
@@ -174,12 +229,12 @@ describe 'up.flow', ->
174
229
  </div>
175
230
  """
176
231
  @respond()
177
- @request.then =>
232
+ promise.then =>
178
233
  expect(@revealedHTML).toEqual('<div id="three">three</div>')
179
234
  done()
180
235
 
181
236
  it "reveals the entire element if it has no child with the ID of that #hash", (done) ->
182
- @request = up.replace('.middle', '/path#four', reveal: true)
237
+ promise = up.replace('.middle', '/path#four', reveal: true)
183
238
  @responseText =
184
239
  """
185
240
  <div class="middle">
@@ -187,14 +242,14 @@ describe 'up.flow', ->
187
242
  </div>
188
243
  """
189
244
  @respond()
190
- @request.then =>
245
+ promise.then =>
191
246
  expect(@revealedHTML).toContain('new-middle')
192
247
  done()
193
248
 
194
249
  it 'reveals a new element that is being appended', (done) ->
195
- @request = up.replace('.middle:after', '/path', reveal: true)
250
+ promise = up.replace('.middle:after', '/path', reveal: true)
196
251
  @respond()
197
- @request.then =>
252
+ promise.then =>
198
253
  expect(@revealMock).not.toHaveBeenCalledWith(@oldMiddle)
199
254
  # Text nodes are wrapped in a .up-insertion container so we can
200
255
  # animate them and measure their position/size for scrolling.
@@ -205,9 +260,9 @@ describe 'up.flow', ->
205
260
  done()
206
261
 
207
262
  it 'reveals a new element that is being prepended', (done) ->
208
- @request = up.replace('.middle:before', '/path', reveal: true)
263
+ promise = up.replace('.middle:before', '/path', reveal: true)
209
264
  @respond()
210
- @request.then =>
265
+ promise.then =>
211
266
  expect(@revealMock).not.toHaveBeenCalledWith(@oldMiddle)
212
267
  # Text nodes are wrapped in a .up-insertion container so we can
213
268
  # animate them and measure their position/size for scrolling.
@@ -315,18 +370,13 @@ describe 'up.flow', ->
315
370
  expect($('.element')).toHaveText('new text')
316
371
  done()
317
372
 
318
- request = @lastRequest()
319
- expect(request.url).toMatch(/\/source$/)
373
+ expect(@lastRequest().url).toMatch(/\/source$/)
320
374
 
321
- request.respondWith
322
- status: 200
323
- contentType: '/text/html'
324
- responseText:
325
- """
326
- <div class="container">
327
- <div class="element">new text</div>
328
- </div>
329
- """
375
+ @respondWith """
376
+ <div class="container">
377
+ <div class="element">new text</div>
378
+ </div>
379
+ """
330
380
 
331
381
  else
332
382
 
@@ -28,19 +28,15 @@ describe 'up.form', ->
28
28
 
29
29
  it 'submits the given form and replaces the target with the response', (done) ->
30
30
 
31
- @request.respondWith
32
- status: 200
33
- contentType: 'text/html'
34
- responseText:
35
- """
36
- text-before
37
-
38
- <div class="response">
39
- new-text
40
- </div>
41
-
42
- text-after
43
- """
31
+ @respondWith """
32
+ text-before
33
+
34
+ <div class="response">
35
+ new-text
36
+ </div>
37
+
38
+ text-after
39
+ """
44
40
 
45
41
  @promise.then ->
46
42
  expect($('.response')).toHaveText('new-text')
@@ -96,17 +92,83 @@ describe 'up.form', ->
96
92
 
97
93
  up.submit($form)
98
94
  expect(form.submit).toHaveBeenCalled()
99
-
100
95
 
101
96
  describe 'unobtrusive behavior', ->
102
-
97
+
103
98
  describe 'form[up-target]', ->
104
99
 
105
100
  it 'rigs the form to use up.submit instead of a standard submit'
106
101
 
107
-
108
102
  describe 'input[up-observe]', ->
109
103
 
110
104
  it 'should have tests'
111
-
112
-
105
+
106
+ describe 'input[up-validate]', ->
107
+
108
+ describe 'when a selector is given', ->
109
+
110
+ it "submits the input's form with an 'X-Up-Validate' header and replaces the selector with the response", ->
111
+
112
+ $form = affix('form[action="/path/to"]')
113
+ $group = $("""
114
+ <div class="field-group">
115
+ <input name="user" value="judy" up-validate=".field-group:has(&)">
116
+ </div>
117
+ """).appendTo($form)
118
+ $group.find('input').trigger('change')
119
+
120
+ request = @lastRequest()
121
+ expect(request.requestHeaders['X-Up-Validate']).toEqual('user')
122
+ expect(request.requestHeaders['X-Up-Selector']).toEqual(".field-group:has([name='user'])")
123
+
124
+ @respondWith """
125
+ <div class="field-group has-error">
126
+ <div class='error'>Username has already been taken</div>
127
+ <input name="user" value="judy" up-validate=".field-group:has(&)">
128
+ </div>
129
+ """
130
+
131
+ $group = $('.field-group')
132
+ expect($group.length).toBe(1)
133
+ expect($group).toHaveClass('has-error')
134
+ expect($group).toHaveText('Username has already been taken')
135
+
136
+ describe 'when no selector is given', ->
137
+
138
+ it 'automatically finds a form group around the input field and only updates that', ->
139
+
140
+ @appendFixture """
141
+ <form action="/users" id="registration">
142
+
143
+ <label>
144
+ <input type="text" name="email" up-validate />
145
+ </label>
146
+
147
+ <label>
148
+ <input type="password" name="password" up-validate />
149
+ </label>
150
+
151
+ </form>
152
+ """
153
+
154
+ $('#registration input[name=password]').trigger('change')
155
+
156
+ @respondWith """
157
+ <form action="/users" id="registration">
158
+
159
+ <label>
160
+ Validation message
161
+ <input type="text" name="email" up-validate />
162
+ </label>
163
+
164
+ <label>
165
+ Validation message
166
+ <input type="password" name="password" up-validate />
167
+ </label>
168
+
169
+ </form>
170
+ """
171
+
172
+ $labels = $('#registration label')
173
+ expect($labels[0]).not.toHaveText('Validation message')
174
+ expect($labels[1]).toHaveText('Validation message')
@@ -44,11 +44,7 @@ describe 'up.history', ->
44
44
  </div>
45
45
  """
46
46
 
47
- respond = (html) =>
48
- @lastRequest().respondWith
49
- status: 200
50
- contentType: 'text/html'
51
- responseText: longContentHtml
47
+ respond = => @respondWith(longContentHtml)
52
48
 
53
49
  $viewport = $(longContentHtml).appendTo(document.body)
54
50
 
@@ -16,15 +16,11 @@ describe 'up.link', ->
16
16
 
17
17
  promise = up.follow($link)
18
18
 
19
- @lastRequest().respondWith
20
- status: 200
21
- contentType: 'text/html'
22
- responseText:
23
- """
24
- <div class="before">new-before</div>
25
- <div class="middle">new-middle</div>
26
- <div class="after">new-after</div>
27
- """
19
+ @respondWith """
20
+ <div class="before">new-before</div>
21
+ <div class="middle">new-middle</div>
22
+ <div class="after">new-after</div>
23
+ """
28
24
 
29
25
  promise.then ->
30
26
  expect($('.before')).toHaveText('old-before')
@@ -38,6 +34,14 @@ describe 'up.link', ->
38
34
  request = @lastRequest()
39
35
  expect(request.method).toBe('PUT')
40
36
 
37
+ it 'allows to refer to the link itself as "&" in the CSS selector', ->
38
+ $container = affix('div')
39
+ $link1 = $('<a id="first" href="/path" up-target="&">first-link</a>').appendTo($container)
40
+ $link2 = $('<a id="second" href="/path" up-target="&">second-link</a>').appendTo($container)
41
+ up.follow($link2)
42
+ @respondWith '<div id="second">second-div</div>'
43
+ expect($container.text()).toBe('first-linksecond-div')
44
+
41
45
  it 'adds history entries and allows the user to use the back- and forward-buttons', (done) ->
42
46
 
43
47
  # By default, up.history will replace the <body> tag when
@@ -108,14 +112,11 @@ describe 'up.link', ->
108
112
  up.follow($link, options)
109
113
 
110
114
  respond = (linkDestination) =>
111
- @lastRequest().respondWith
112
- status: 200
113
- contentType: 'text/html'
114
- responseText: """
115
- <div class="element" style="height: 300px">
116
- <a class="link" href="#{linkDestination}" up-target=".element">Link</a>
117
- </div>
118
- """
115
+ @respondWith """
116
+ <div class="element" style="height: 300px">
117
+ <a class="link" href="#{linkDestination}" up-target=".element">Link</a>
118
+ </div>
119
+ """
119
120
 
120
121
  up.replace('.element', '/foo')
121
122
  # Provide the content at /foo with a link to /bar in the HTML
@@ -9,17 +9,12 @@ describe 'up.modal', ->
9
9
  it "loads the given link's destination in a dialog window", (done) ->
10
10
  $link = affix('a[href="/path/to"][up-modal=".middle"]').text('link')
11
11
  promise = up.modal.follow($link)
12
- request = @lastRequest()
13
- expect(request.url).toMatch /\/path\/to$/
14
- request.respondWith
15
- status: 200
16
- contentType: 'text/html'
17
- responseText:
18
- """
19
- <div class="before">new-before</div>
20
- <div class="middle">new-middle</div>
21
- <div class="after">new-after</div>
22
- """
12
+ expect(@lastRequest().url).toMatch /\/path\/to$/
13
+ @respondWith """
14
+ <div class="before">new-before</div>
15
+ <div class="middle">new-middle</div>
16
+ <div class="after">new-after</div>
17
+ """
23
18
  promise.then ->
24
19
  expect($('.up-modal')).toExist()
25
20
  expect($('.up-modal-dialog')).toExist()
@@ -34,13 +29,7 @@ describe 'up.modal', ->
34
29
  it "brings its own scrollbar, padding the body on the right in order to prevent jumping", (done) ->
35
30
  promise = up.modal.visit('/foo', target: '.container')
36
31
 
37
- @lastRequest().respondWith
38
- status: 200
39
- contentType: 'text/html'
40
- responseText:
41
- """
42
- <div class="container">text</div>
43
- """
32
+ @respondWith('<div class="container">text</div>')
44
33
 
45
34
  promise.then ->
46
35
 
@@ -66,13 +55,7 @@ describe 'up.modal', ->
66
55
 
67
56
  promise = up.modal.visit('/foo', target: '.container')
68
57
 
69
- @lastRequest().respondWith
70
- status: 200
71
- contentType: 'text/html'
72
- responseText:
73
- """
74
- <div class="container">text</div>
75
- """
58
+ @respondWith('<div class="container">text</div>')
76
59
 
77
60
  promise.then ->
78
61
  expect(parseInt($anchoredElement.css('right'))).toBeAround(30 + assumedScrollbarWidth, 10)
@@ -88,13 +71,7 @@ describe 'up.modal', ->
88
71
  up.history.replace('/foo')
89
72
  expect(up.modal.coveredUrl()).toBeUndefined()
90
73
  up.modal.visit('/bar', target: '.container')
91
- @lastRequest().respondWith
92
- status: 200
93
- contentType: 'text/html'
94
- responseText:
95
- """
96
- <div class="container">text</div>
97
- """
74
+ @respondWith('<div class="container">text</div>')
98
75
  expect(up.modal.coveredUrl()).toEndWith('/foo')
99
76
  up.modal.close().then ->
100
77
  expect(up.modal.coveredUrl()).toBeUndefined()
@@ -103,7 +80,9 @@ describe 'up.modal', ->
103
80
 
104
81
  describe 'up.modal.close', ->
105
82
 
106
- it 'should have tests'
83
+ it 'closes a currently open modal'
84
+
85
+ it 'does nothing if no modal is open'
107
86
 
108
87
  describe 'up.modal.source', ->
109
88
 
@@ -113,15 +92,31 @@ describe 'up.modal', ->
113
92
 
114
93
  describe 'a[up-modal]', ->
115
94
 
116
- it 'should have tests'
117
-
95
+ it 'opens the clicked link in a modal', ->
96
+ followSpy = up.modal.knife.mock('follow')
97
+ $link = affix('a[href="/path"][up-modal=".foo"]')
98
+ up.hello($link)
99
+ $link.click()
100
+ expect(followSpy).toHaveBeenCalledWith($link)
101
+
118
102
  describe '[up-close]', ->
119
103
 
120
- it 'should have tests'
104
+ it 'closes the modal when clicked', ->
105
+ closeSpy = up.modal.knife.mock('close')
106
+ $link = affix('a[up-close]')
107
+ up.hello($link)
108
+ $link.click()
109
+ expect(closeSpy).toHaveBeenCalled()
121
110
 
122
111
  describe 'when following links inside a modal', ->
123
112
 
124
- it 'prefers to replace a selector within the modal'
113
+ it 'prefers to replace a selector within the modal', ->
114
+ $outside = affix('.foo').text('old outside')
115
+ up.modal.visit('/path', target: '.foo')
116
+ @respondWith("<div class='foo'>old inside</div>")
117
+ up.flow.implant('.foo', "<div class='foo'>new text</div>")
118
+ expect($outside).toHaveText('old outside')
119
+ expect($('.up-modal-content')).toHaveText('new text')
125
120
 
126
121
  it 'auto-closes the modal if a selector behind the modal gets replaced'
127
122
 
@@ -50,9 +50,7 @@ describe 'up.navigation', ->
50
50
  $link = affix('a[href="/foo"][up-target=".main"]')
51
51
  affix('.main')
52
52
  $link.click()
53
- @lastRequest().respondWith
54
- status: 200
55
- contentType: 'text/html'
53
+ @respondWith
56
54
  responseHeaders: { 'X-Up-Location': '/foo/' }
57
55
  responseText: '<div class="main">new-text</div>'
58
56
  expect($link).toHaveClass('up-current')
@@ -61,9 +59,7 @@ describe 'up.navigation', ->
61
59
  $link = affix('a[href="/foo/"][up-target=".main"]')
62
60
  affix('.main')
63
61
  $link.click()
64
- @lastRequest().respondWith
65
- status: 200
66
- contentType: 'text/html'
62
+ @respondWith
67
63
  responseHeaders: { 'X-Up-Location': '/foo' }
68
64
  responseText: '<div class="main">new-text</div>'
69
65
  expect($link).toHaveClass('up-current')
@@ -75,10 +71,7 @@ describe 'up.navigation', ->
75
71
  $unrelatedLink = affix('a[href="/baz]')
76
72
 
77
73
  $modalLink.click()
78
- @lastRequest().respondWith
79
- status: 200
80
- contentType: 'text/html'
81
- responseText: '<div class="main">new-text</div>'
74
+ @respondWith('<div class="main">new-text</div>')
82
75
  expect($backgroundLink).toHaveClass('up-current')
83
76
  expect($modalLink).toHaveClass('up-current')
84
77
  expect($unrelatedLink).not.toHaveClass('up-current')
@@ -96,10 +89,7 @@ describe 'up.navigation', ->
96
89
  $unrelatedLink = affix('a[href="/baz]')
97
90
 
98
91
  $popupLink.click()
99
- @lastRequest().respondWith
100
- status: 200
101
- contentType: 'text/html'
102
- responseText: '<div class="main">new-text</div>'
92
+ @respondWith('<div class="main">new-text</div>')
103
93
  expect($backgroundLink).toHaveClass('up-current')
104
94
  expect($popupLink).toHaveClass('up-current')
105
95
  expect($unrelatedLink).not.toHaveClass('up-current')
@@ -117,10 +107,7 @@ describe 'up.navigation', ->
117
107
  affix('.main')
118
108
  $link.click()
119
109
  expect($link).toHaveClass('up-active')
120
- @lastRequest().respondWith
121
- status: 200
122
- contentType: 'text/html'
123
- responseText: '<div class="main">new-text</div>'
110
+ @respondWith('<div class="main">new-text</div>')
124
111
  expect($link).not.toHaveClass('up-active')
125
112
  expect($link).toHaveClass('up-current')
126
113
 
@@ -129,10 +116,7 @@ describe 'up.navigation', ->
129
116
  affix('.main')
130
117
  Trigger.mousedown($link)
131
118
  expect($link).toHaveClass('up-active')
132
- @lastRequest().respondWith
133
- status: 200
134
- contentType: 'text/html'
135
- responseText: '<div class="main">new-text</div>'
119
+ @respondWith('<div class="main">new-text</div>')
136
120
  expect($link).not.toHaveClass('up-active')
137
121
  expect($link).toHaveClass('up-current')
138
122
 
@@ -143,9 +127,6 @@ describe 'up.navigation', ->
143
127
  affix('.main')
144
128
  $link.click()
145
129
  expect($area).toHaveClass('up-active')
146
- @lastRequest().respondWith
147
- status: 200
148
- contentType: 'text/html'
149
- responseText: '<div class="main">new-text</div>'
130
+ @respondWith('<div class="main">new-text</div>')
150
131
  expect($area).toHaveClass('up-current')
151
132
 
@@ -14,13 +14,7 @@ describe 'up.popup', ->
14
14
 
15
15
  $popupLink = affix('a[href="/bar"][up-popup=".container"]')
16
16
  $popupLink.click()
17
- @lastRequest().respondWith
18
- status: 200
19
- contentType: 'text/html'
20
- responseText:
21
- """
22
- <div class="container">text</div>
23
- """
17
+ @respondWith('<div class="container">text</div>')
24
18
  expect(up.popup.coveredUrl()).toEndWith('/foo')
25
19
  up.popup.close().then ->
26
20
  expect(up.popup.coveredUrl()).toBeUndefined()