unpoly-rails 0.33.0 → 0.34.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of unpoly-rails might be problematic. Click here for more details.

@@ -79,8 +79,6 @@ up.proxy = (($) ->
79
79
  An array of uppercase HTTP method names. AJAX requests with one of these methods
80
80
  will be converted into a `POST` request and carry their original method as a `_method`
81
81
  parameter. This is to [prevent unexpected redirect behavior](https://makandracards.com/makandra/38347).
82
- @param {String} [config.wrapMethodParam]
83
- The name of the POST parameter when wrapping HTTP methods in a `POST` request.
84
82
  @param {Array<String>} [config.safeMethods]
85
83
  An array of uppercase HTTP method names that are considered idempotent.
86
84
  The proxy cache will only cache idempotent requests and will clear the entire
@@ -94,7 +92,6 @@ up.proxy = (($) ->
94
92
  cacheExpiry: 1000 * 60 * 5
95
93
  maxRequests: 4
96
94
  wrapMethods: ['PATCH', 'PUT', 'DELETE']
97
- wrapMethodParam: '_method'
98
95
  safeMethods: ['GET', 'OPTIONS', 'HEAD']
99
96
 
100
97
  cacheKey = (request) ->
@@ -206,7 +203,7 @@ up.proxy = (($) ->
206
203
  @param {String} [request.timeout]
207
204
  A timeout in milliseconds for the request.
208
205
 
209
- If [`up.proxy.config.maxRequests`](/up.proxy.config#maxRequests) is set, the timeout
206
+ If [`up.proxy.config.maxRequests`](/up.proxy.config#config.maxRequests) is set, the timeout
210
207
  will not include the time spent waiting in the queue.
211
208
  @return
212
209
  A promise for the response that is API-compatible with the
@@ -410,10 +407,10 @@ up.proxy = (($) ->
410
407
  request = u.copy(request)
411
408
 
412
409
  request.headers ||= {}
413
- request.headers['X-Up-Target'] = request.target
410
+ request.headers[up.protocol.config.targetHeader] = request.target
414
411
 
415
412
  if u.contains(config.wrapMethods, request.method)
416
- request.data = u.appendRequestData(request.data, config.wrapMethodParam, request.method)
413
+ request.data = u.appendRequestData(request.data, up.protocol.config.methodParam, request.method)
417
414
  request.method = 'POST'
418
415
 
419
416
  if u.isFormData(request.data)
@@ -375,8 +375,8 @@ up.syntax = (($) ->
375
375
  ###
376
376
 
377
377
  ###*
378
- If an element annotated with [`up-data`] is inserted into the DOM,
379
- Up will parse the JSON and pass the resulting object to any matching
378
+ If an element with an `up-data` attribute enters the DOM,
379
+ Unpoly will parse the JSON and pass the resulting object to any matching
380
380
  [`up.compiler()`](/up.compiler) handlers.
381
381
 
382
382
  For instance, a container for a [Google Map](https://developers.google.com/maps/documentation/javascript/tutorial)
@@ -1172,27 +1172,6 @@ up.util = (($) ->
1172
1172
  # castsToFalse = (object) ->
1173
1173
  # String(object) == "false"
1174
1174
 
1175
- ###*
1176
- @function up.util.locationFromXhr
1177
- @internal
1178
- ###
1179
- locationFromXhr = (xhr) ->
1180
- xhr.getResponseHeader('X-Up-Location')
1181
-
1182
- ###*
1183
- @function up.util.titleFromXhr
1184
- @internal
1185
- ###
1186
- titleFromXhr = (xhr) ->
1187
- xhr.getResponseHeader('X-Up-Title')
1188
-
1189
- ###*
1190
- @function up.util.methodFromXhr
1191
- @internal
1192
- ###
1193
- methodFromXhr = (xhr) ->
1194
- xhr.getResponseHeader('X-Up-Method')
1195
-
1196
1175
  ###*
1197
1176
  Returns a copy of the given object that only contains
1198
1177
  the given properties.
@@ -2078,9 +2057,6 @@ up.util = (($) ->
2078
2057
  contains: contains
2079
2058
  toArray: toArray
2080
2059
  castedAttr: castedAttr
2081
- locationFromXhr: locationFromXhr
2082
- titleFromXhr: titleFromXhr
2083
- methodFromXhr: methodFromXhr
2084
2060
  clientSize: clientSize
2085
2061
  only: only
2086
2062
  except: except
@@ -13,7 +13,7 @@ module Unpoly
13
13
  module Rails
14
14
  module RequestMethod
15
15
 
16
- COOKIE_NAME = '_up_request_method'
16
+ COOKIE_NAME = '_up_method'
17
17
 
18
18
  def self.included(base)
19
19
  base.before_filter :set_up_request_method_cookie
@@ -22,10 +22,10 @@ module Unpoly
22
22
  private
23
23
 
24
24
  def set_up_request_method_cookie
25
- if request.get?
26
- cookies.delete(COOKIE_NAME)
27
- else
25
+ if !request.get? && !up?
28
26
  cookies[COOKIE_NAME] = request.request_method
27
+ else
28
+ cookies.delete(COOKIE_NAME)
29
29
  end
30
30
  end
31
31
 
@@ -4,6 +4,6 @@ module Unpoly
4
4
  # The current version of the unpoly-rails gem.
5
5
  # This version number is also used for releases of the Unpoly
6
6
  # frontend code.
7
- VERSION = '0.33.0'
7
+ VERSION = '0.34.0'
8
8
  end
9
9
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unpoly",
3
- "version": "0.33.0",
3
+ "version": "0.34.0",
4
4
  "description": "Unobtrusive JavaScript framework",
5
5
  "main": "dist/unpoly.js",
6
6
  "files": [
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- unpoly-rails (0.32.0)
4
+ unpoly-rails (0.33.0)
5
5
  rails (>= 3)
6
6
 
7
7
  GEM
@@ -144,4 +144,50 @@ describe BindingTestController do
144
144
 
145
145
  end
146
146
 
147
+ describe 'request method cookie' do
148
+
149
+ describe 'if the request is both non-GET and not a fragment update' do
150
+
151
+ it 'echoes the request method in an _up_method cookie ' do
152
+ put :text
153
+ expect(response.cookies['_up_method']).to eq('PUT')
154
+ end
155
+
156
+ end
157
+
158
+ describe 'if the request is not a fragment update, but GET' do
159
+
160
+ it 'does not set the cookie' do
161
+ get :text
162
+ expect(response.cookies['_up_method']).to be_nil
163
+ end
164
+
165
+ it 'deletes an existing cookie' do
166
+ request.cookies['_up_method'] = 'PUT'
167
+ get :text
168
+ expect(response.cookies['_up_method']).to be_nil
169
+ end
170
+
171
+ end
172
+
173
+ describe 'if the request is non-GET but a fragment update' do
174
+
175
+ it 'does not set the cookie' do
176
+ request.headers['X-Up-Target'] = '.target'
177
+ put :text
178
+ expect(response.cookies['_up_method']).to be_nil
179
+ end
180
+
181
+ it 'deletes an existing cookie' do
182
+ request.cookies['_up_method'] = 'PUT'
183
+ request.headers['X-Up-Target'] = '.target'
184
+ put :text
185
+ expect(response.cookies['_up_method']).to be_nil
186
+ end
187
+
188
+ end
189
+
190
+
191
+ end
192
+
147
193
  end
@@ -318,6 +318,36 @@ describe 'up.layout', ->
318
318
  # Viewing 100 to 199
319
319
  expect($viewport.scrollTop()).toBe(100)
320
320
 
321
+ describe 'revealHash', ->
322
+
323
+ it 'reveals an element with an ID matching the hash in the location', ->
324
+ revealSpy = up.layout.knife.mock('reveal')
325
+ $match = affix('div#hash')
326
+ location.hash = '#hash'
327
+ up.layout.revealHash()
328
+ expect(revealSpy).toHaveBeenCalledWith($match)
329
+
330
+ it 'reveals a named anchor matching the hash in the location', ->
331
+ revealSpy = up.layout.knife.mock('reveal')
332
+ $match = affix('a[name="hash"]')
333
+ location.hash = '#hash'
334
+ up.layout.revealHash()
335
+ expect(revealSpy).toHaveBeenCalledWith($match)
336
+
337
+ it 'does nothing and returns a rejected promise if no element or anchor matches the hash in the location', ->
338
+ revealSpy = up.layout.knife.mock('reveal')
339
+ location.hash = '#hash'
340
+ promise = up.layout.revealHash()
341
+ expect(revealSpy).not.toHaveBeenCalled()
342
+ expect(promise.state()).toEqual('rejected')
343
+
344
+ it 'does nothing and returns a resolved promise if the location has no hash', ->
345
+ revealSpy = up.layout.knife.mock('reveal')
346
+ location.hash = ''
347
+ promise = up.layout.revealHash()
348
+ expect(revealSpy).not.toHaveBeenCalled()
349
+ expect(promise.state()).toEqual('resolved')
350
+
321
351
  describe 'up.layout.viewportsWithin', ->
322
352
 
323
353
  it 'should have tests'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unpoly-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.33.0
4
+ version: 0.34.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henning Koch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-28 00:00:00.000000000 Z
11
+ date: 2017-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -109,6 +109,7 @@ files:
109
109
  - lib/assets/javascripts/unpoly/motion.coffee
110
110
  - lib/assets/javascripts/unpoly/namespace.coffee.erb
111
111
  - lib/assets/javascripts/unpoly/popup.coffee
112
+ - lib/assets/javascripts/unpoly/protocol.coffee
112
113
  - lib/assets/javascripts/unpoly/proxy.coffee
113
114
  - lib/assets/javascripts/unpoly/rails.coffee
114
115
  - lib/assets/javascripts/unpoly/syntax.coffee
@@ -119,7 +120,7 @@ files:
119
120
  - lib/assets/stylesheets/unpoly-bootstrap3/modal-ext.sass
120
121
  - lib/assets/stylesheets/unpoly.sass
121
122
  - lib/assets/stylesheets/unpoly/close.sass
122
- - lib/assets/stylesheets/unpoly/flow.sass
123
+ - lib/assets/stylesheets/unpoly/dom.sass
123
124
  - lib/assets/stylesheets/unpoly/link.sass
124
125
  - lib/assets/stylesheets/unpoly/modal.sass
125
126
  - lib/assets/stylesheets/unpoly/popup.sass