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.
- checksums.yaml +4 -4
- data/.rdoc_options +23 -0
- data/CHANGELOG.md +20 -0
- data/design/up-validate.js.coffee +284 -0
- data/dist/up-bootstrap.js +4 -0
- data/dist/up-bootstrap.min.js +1 -1
- data/dist/up.js +547 -102
- data/dist/up.min.js +2 -2
- data/lib/assets/javascripts/up/browser.js.coffee +3 -2
- data/lib/assets/javascripts/up/flow.js.coffee +95 -17
- data/lib/assets/javascripts/up/form.js.coffee +327 -34
- data/lib/assets/javascripts/up/history.js.coffee +1 -1
- data/lib/assets/javascripts/up/layout.js.coffee +4 -4
- data/lib/assets/javascripts/up/link.js.coffee +5 -2
- data/lib/assets/javascripts/up/modal.js.coffee +1 -0
- data/lib/assets/javascripts/up/proxy.js.coffee +27 -12
- data/lib/assets/javascripts/up/syntax.js.coffee +39 -20
- data/lib/assets/javascripts/up/util.js.coffee +29 -12
- data/lib/assets/javascripts/up-bootstrap/form-ext.js.coffee +1 -0
- data/lib/upjs/rails/engine.rb +1 -1
- data/lib/upjs/rails/inspector.rb +63 -0
- data/lib/upjs/rails/inspector_accessor.rb +28 -0
- data/lib/upjs/rails/request_echo_headers.rb +7 -0
- data/lib/upjs/rails/request_method_cookie.rb +12 -4
- data/lib/upjs/rails/version.rb +5 -1
- data/lib/upjs-rails.rb +7 -5
- data/spec_app/.rspec +2 -0
- data/spec_app/Gemfile +0 -3
- data/spec_app/Gemfile.lock +43 -44
- data/spec_app/app/assets/stylesheets/application.css +1 -1
- data/spec_app/app/controllers/test_controller.rb +23 -0
- data/spec_app/config/routes.rb +2 -0
- data/spec_app/spec/controllers/test_controller_spec.rb +67 -0
- data/spec_app/spec/javascripts/helpers/append_fixture.js.coffee +8 -0
- data/spec_app/spec/javascripts/helpers/last_request.js.coffee +18 -0
- data/spec_app/spec/javascripts/helpers/reset_path.js.coffee +1 -0
- data/spec_app/spec/javascripts/up/flow_spec.js.coffee +93 -43
- data/spec_app/spec/javascripts/up/form_spec.js.coffee +80 -18
- data/spec_app/spec/javascripts/up/history_spec.js.coffee +1 -5
- data/spec_app/spec/javascripts/up/link_spec.js.coffee +18 -17
- data/spec_app/spec/javascripts/up/modal_spec.js.coffee +32 -37
- data/spec_app/spec/javascripts/up/navigation_spec.js.coffee +7 -26
- data/spec_app/spec/javascripts/up/popup_spec.js.coffee +1 -7
- data/spec_app/spec/javascripts/up/proxy_spec.js.coffee +26 -25
- data/spec_app/spec/javascripts/up/util_spec.js.coffee +23 -0
- data/spec_app/spec/spec_helper.rb +62 -0
- metadata +12 -3
- data/lib/upjs/rails/request_ext.rb +0 -13
@@ -1,16 +1,34 @@
|
|
1
1
|
###*
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
Enhancing elements
|
3
|
+
==================
|
4
|
+
|
5
5
|
Up.js keeps a persistent Javascript environment during page transitions.
|
6
|
-
|
7
|
-
|
6
|
+
If you wire Javascript to run on `ready` or `onload` events, those scripts will
|
7
|
+
only run during the initial page load. Subsequently [inserted](/up.replace)
|
8
|
+
page fragments will not be compiled.
|
9
|
+
|
10
|
+
Let's say your Javascript plugin wants you to call `lightboxify()`
|
11
|
+
on links that should open a lightbox. You decide to
|
12
|
+
do this for all links with an `lightbox` class:
|
13
|
+
|
14
|
+
<a href="river.png" class="lightbox">River</a>
|
15
|
+
<a href="ocean.png" class="lightbox">Ocean</a>
|
16
|
+
|
17
|
+
You should **avoid** doing this on page load:
|
18
|
+
|
19
|
+
$(document).on('ready', function() {
|
20
|
+
$('a.lightbox').lightboxify();
|
21
|
+
});
|
8
22
|
|
9
|
-
|
23
|
+
Instead you should register a [`compiler`](/up.compiler) for the `a.lightbox` selector:
|
10
24
|
|
11
|
-
|
25
|
+
up.compiler('a.lightbox', function($element) {
|
26
|
+
$element.lightboxify();
|
27
|
+
});
|
12
28
|
|
13
|
-
|
29
|
+
The compiler function will be called on matching elements when
|
30
|
+
the page loads, or whenever a matching fragment is [updated through Up.js](/up.replace)
|
31
|
+
later.
|
14
32
|
|
15
33
|
@class up.syntax
|
16
34
|
###
|
@@ -34,7 +52,8 @@ up.syntax = (($) ->
|
|
34
52
|
the page loads, or whenever a matching fragment is [updated through Up.js](/up.replace)
|
35
53
|
later.
|
36
54
|
|
37
|
-
If you have used Angular.js before, this resembles
|
55
|
+
If you have used Angular.js before, this resembles
|
56
|
+
[Angular directives](https://docs.angularjs.org/guide/directive).
|
38
57
|
|
39
58
|
|
40
59
|
\#\#\#\# Integrating jQuery plugins
|
@@ -42,14 +61,14 @@ up.syntax = (($) ->
|
|
42
61
|
`up.compiler` is a great way to integrate jQuery plugins.
|
43
62
|
Let's say your Javascript plugin wants you to call `lightboxify()`
|
44
63
|
on links that should open a lightbox. You decide to
|
45
|
-
do this for all links with an `
|
64
|
+
do this for all links with an `lightbox` class:
|
46
65
|
|
47
|
-
<a href="river.png"
|
48
|
-
<a href="ocean.png"
|
66
|
+
<a href="river.png" class="lightbox">River</a>
|
67
|
+
<a href="ocean.png" class="lightbox">Ocean</a>
|
49
68
|
|
50
69
|
This Javascript will do exactly that:
|
51
70
|
|
52
|
-
up.compiler('a
|
71
|
+
up.compiler('a.lightbox', function($element) {
|
53
72
|
$element.lightboxify();
|
54
73
|
});
|
55
74
|
|
@@ -268,17 +287,17 @@ up.syntax = (($) ->
|
|
268
287
|
compilers = u.copy(defaultCompilers)
|
269
288
|
|
270
289
|
###*
|
271
|
-
|
272
|
-
|
273
|
-
event listeners, etc.).
|
290
|
+
Compiles a page fragment that has been inserted into the DOM
|
291
|
+
without Up.js.
|
274
292
|
|
275
293
|
**As long as you manipulate the DOM using Up.js, you will never
|
276
294
|
need to call this method.** You only need to use `up.hello` if the
|
277
|
-
DOM is manipulated without Up.js' involvement, e.g. by
|
278
|
-
|
295
|
+
DOM is manipulated without Up.js' involvement, e.g. by setting
|
296
|
+
the `innerHTML` property or calling jQuery methods like
|
297
|
+
`html`, `insertAfter` or `appendTo`:
|
279
298
|
|
280
|
-
|
281
|
-
$element
|
299
|
+
$element = $('.element');
|
300
|
+
$element.html('<div>...</div>');
|
282
301
|
up.hello($element);
|
283
302
|
|
284
303
|
This function emits the [`up:fragment:inserted`](/up:fragment:inserted)
|
@@ -25,9 +25,8 @@ up.util = (($) ->
|
|
25
25
|
ajax = (request) ->
|
26
26
|
request = copy(request)
|
27
27
|
if request.selector
|
28
|
-
request.headers
|
29
|
-
|
30
|
-
}
|
28
|
+
request.headers ||= {}
|
29
|
+
request.headers['X-Up-Selector'] = request.selector
|
31
30
|
# Delegate to jQuery
|
32
31
|
$.ajax(request)
|
33
32
|
|
@@ -194,14 +193,25 @@ up.util = (($) ->
|
|
194
193
|
arg += " }"
|
195
194
|
arg
|
196
195
|
|
197
|
-
createSelectorFromElement = (
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
selector
|
202
|
-
|
203
|
-
|
204
|
-
selector
|
196
|
+
createSelectorFromElement = (element) ->
|
197
|
+
$element = $(element)
|
198
|
+
selector = undefined
|
199
|
+
|
200
|
+
debug("Creating selector from element %o", $element.get(0))
|
201
|
+
|
202
|
+
if upId = presence($element.attr("up-id"))
|
203
|
+
selector = "[up-id='#{upId}']"
|
204
|
+
else if id = presence($element.attr("id"))
|
205
|
+
selector = "##{id}"
|
206
|
+
else if name = presence($element.attr("name"))
|
207
|
+
selector = "[name='#{name}']"
|
208
|
+
else if classString = presence($element.attr("class"))
|
209
|
+
classes = classString.split(' ')
|
210
|
+
selector = ''
|
211
|
+
for klass in classes
|
212
|
+
selector += ".#{klass}"
|
213
|
+
else
|
214
|
+
selector = $element.prop('tagName').toLowerCase()
|
205
215
|
selector
|
206
216
|
|
207
217
|
# jQuery's implementation of $(...) cannot create elements that have
|
@@ -638,7 +648,10 @@ up.util = (($) ->
|
|
638
648
|
|
639
649
|
locationFromXhr = (xhr) ->
|
640
650
|
xhr.getResponseHeader('X-Up-Location')
|
641
|
-
|
651
|
+
|
652
|
+
titleFromXhr = (xhr) ->
|
653
|
+
xhr.getResponseHeader('X-Up-Title')
|
654
|
+
|
642
655
|
methodFromXhr = (xhr) ->
|
643
656
|
xhr.getResponseHeader('X-Up-Method')
|
644
657
|
|
@@ -758,6 +771,9 @@ up.util = (($) ->
|
|
758
771
|
will be discarded.
|
759
772
|
@param {String} [config.log]
|
760
773
|
A prefix for log entries printed by this cache object.
|
774
|
+
@param {Function<Object>} [config.key]
|
775
|
+
A function that takes an argument and returns a `String` key
|
776
|
+
for storage. If omitted, `toString()` is called on the argument.
|
761
777
|
###
|
762
778
|
cache = (config = {}) ->
|
763
779
|
|
@@ -978,6 +994,7 @@ up.util = (($) ->
|
|
978
994
|
# castsToFalse: castsToFalse
|
979
995
|
castedAttr: castedAttr
|
980
996
|
locationFromXhr: locationFromXhr
|
997
|
+
titleFromXhr: titleFromXhr
|
981
998
|
methodFromXhr: methodFromXhr
|
982
999
|
clientSize: clientSize
|
983
1000
|
only: only
|
@@ -0,0 +1 @@
|
|
1
|
+
up.form.config.validateTargets.unshift('.form-group:has(&)')
|
data/lib/upjs/rails/engine.rb
CHANGED
@@ -0,0 +1,63 @@
|
|
1
|
+
module Upjs
|
2
|
+
module Rails
|
3
|
+
##
|
4
|
+
# This object allows the server to inspect the current request
|
5
|
+
# for Up.js-related concerns such as "is this a page fragment update?".
|
6
|
+
#
|
7
|
+
# Available through the `#up` method in all controllers, helpers and views.
|
8
|
+
class Inspector
|
9
|
+
|
10
|
+
def initialize(controller)
|
11
|
+
@controller = controller
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
# Returns whether the current request is an
|
16
|
+
# [page fragment update](http://upjs.io/up.replace) triggered by an
|
17
|
+
# Up.js frontend.
|
18
|
+
def up?
|
19
|
+
selector.present?
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# If the current request is a [fragment update](http://upjs.io/up.replace),
|
24
|
+
# this returns the CSS selector of the page fragment that should be updated.
|
25
|
+
#
|
26
|
+
# The Up.js frontend will expect an HTML response containing an element
|
27
|
+
# that matches this selector. If no such element is found, an error is shown
|
28
|
+
# to the user.
|
29
|
+
#
|
30
|
+
# Server-side code is free to optimize its response by only returning HTML
|
31
|
+
# that matches this selector.
|
32
|
+
def selector
|
33
|
+
request.headers['X-Up-Selector']
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Returns whether the current form submission should be
|
38
|
+
# [validated](http://upjs.io/up-validate) (and not be saved to the database).
|
39
|
+
def validate?
|
40
|
+
validate_name.present?
|
41
|
+
end
|
42
|
+
|
43
|
+
###
|
44
|
+
# If the current form submission is a [validation](http://upjs.io/up-validate),
|
45
|
+
# this returns the name attribute of the form field that has triggered
|
46
|
+
# the validation.
|
47
|
+
def validate_name
|
48
|
+
request.headers['X-Up-Validate']
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def request
|
54
|
+
@controller.request
|
55
|
+
end
|
56
|
+
|
57
|
+
def params
|
58
|
+
@controller.params
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Upjs
|
2
|
+
module Rails
|
3
|
+
##
|
4
|
+
# This adds two methods `#up` and `#up?` to all controllers,
|
5
|
+
# helpers and views, allowing the server to inspect the current request
|
6
|
+
# for Up.js-related concerns such as "is this a page fragment update?".
|
7
|
+
module InspectorAccessor
|
8
|
+
|
9
|
+
def self.included(base) # :nodoc:
|
10
|
+
base.helper_method :up, :up?
|
11
|
+
end
|
12
|
+
|
13
|
+
def up
|
14
|
+
@up_inspector ||= Inspector.new(self)
|
15
|
+
end
|
16
|
+
|
17
|
+
##
|
18
|
+
# :method: up?
|
19
|
+
# Returns whether the current request is an
|
20
|
+
# [page fragment update](http://upjs.io/up.replace) triggered by an
|
21
|
+
# Up.js frontend.
|
22
|
+
delegate :up?, :to => :up
|
23
|
+
|
24
|
+
ActionController::Base.send(:include, self)
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,5 +1,12 @@
|
|
1
1
|
module Upjs
|
2
2
|
module Rails
|
3
|
+
##
|
4
|
+
# Installs a before_filter into all controllers which echoes the
|
5
|
+
# request's URL as a response header `X-Up-Location` and the request's
|
6
|
+
# HTTP method as `X-Up-Method`.
|
7
|
+
#
|
8
|
+
# The Up.js frontend requires these headers to detect redirects,
|
9
|
+
# which are otherwise undetectable for an AJAX client.
|
3
10
|
module RequestEchoHeaders
|
4
11
|
|
5
12
|
def self.included(base)
|
@@ -1,13 +1,21 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
#
|
1
|
+
##
|
2
|
+
# Installs a before_filter into all controllers which echoes the
|
3
|
+
# request's method as a cookie named `_up_request_method`.
|
4
|
+
#
|
5
|
+
# The Up.js requires this cookie to detect whether the initial page
|
6
|
+
# load was requested using a non-GET method. In this case the Up.js
|
7
|
+
# framework will prevent itself from booting until it was loaded
|
8
|
+
# from a GET request. For the terrible reasons behind this see:
|
9
|
+
|
10
|
+
# - <https://github.com/rails/turbolinks/search?q=request_method&ref=cmdform>
|
11
|
+
# - <https://github.com/rails/turbolinks/blob/83d4b3d2c52a681f07900c28adb28bc8da604733/README.md#initialization>
|
4
12
|
module Upjs
|
5
13
|
module Rails
|
6
14
|
module RequestMethod
|
7
15
|
|
8
16
|
COOKIE_NAME = '_up_request_method'
|
9
17
|
|
10
|
-
def self.included(base)
|
18
|
+
def self.included(base) # :nodoc:
|
11
19
|
base.before_filter :set_up_request_method_cookie
|
12
20
|
end
|
13
21
|
|
data/lib/upjs/rails/version.rb
CHANGED
data/lib/upjs-rails.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require 'upjs/rails/version'
|
2
|
+
require 'upjs/rails/engine'
|
3
|
+
require 'upjs/rails/request_echo_headers'
|
4
|
+
require 'upjs/rails/request_method_cookie'
|
5
|
+
require 'upjs/rails/inspector'
|
6
|
+
require 'upjs/rails/inspector_accessor'
|
7
|
+
|
data/spec_app/.rspec
ADDED
data/spec_app/Gemfile
CHANGED
data/spec_app/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
upjs-rails (0.
|
4
|
+
upjs-rails (0.13.0)
|
5
5
|
rails (>= 3)
|
6
6
|
|
7
7
|
GEM
|
@@ -42,7 +42,7 @@ GEM
|
|
42
42
|
minitest (~> 5.1)
|
43
43
|
thread_safe (~> 0.3, >= 0.3.4)
|
44
44
|
tzinfo (~> 1.1)
|
45
|
-
arel (6.0.
|
45
|
+
arel (6.0.3)
|
46
46
|
binding_of_caller (0.7.2)
|
47
47
|
debug_inspector (>= 0.0.1)
|
48
48
|
bower-rails (0.9.2)
|
@@ -67,6 +67,7 @@ GEM
|
|
67
67
|
execjs
|
68
68
|
coffee-script-source (1.8.0)
|
69
69
|
columnize (0.9.0)
|
70
|
+
concurrent-ruby (1.0.0)
|
70
71
|
cucumber (1.3.16)
|
71
72
|
builder (>= 2.1.2)
|
72
73
|
diff-lcs (>= 1.1.3)
|
@@ -87,7 +88,7 @@ GEM
|
|
87
88
|
ffi (1.9.5)
|
88
89
|
gherkin (2.12.2)
|
89
90
|
multi_json (~> 1.3)
|
90
|
-
globalid (0.3.
|
91
|
+
globalid (0.3.6)
|
91
92
|
activesupport (>= 4.1.0)
|
92
93
|
haml (4.1.0.beta.1)
|
93
94
|
tilt
|
@@ -97,7 +98,6 @@ GEM
|
|
97
98
|
haml (>= 3.1, < 5.0)
|
98
99
|
html2haml (>= 1.0.1)
|
99
100
|
railties (>= 4.0.1)
|
100
|
-
hike (1.2.3)
|
101
101
|
hpricot (0.8.6)
|
102
102
|
html2haml (1.0.1)
|
103
103
|
erubis (~> 2.7.0)
|
@@ -115,21 +115,21 @@ GEM
|
|
115
115
|
rails-dom-testing (~> 1.0)
|
116
116
|
railties (>= 4.2.0)
|
117
117
|
thor (>= 0.14, < 2.0)
|
118
|
-
json (1.8.
|
118
|
+
json (1.8.3)
|
119
119
|
libv8 (3.16.14.3)
|
120
|
-
loofah (2.0.
|
120
|
+
loofah (2.0.3)
|
121
121
|
nokogiri (>= 1.5.9)
|
122
122
|
mail (2.6.3)
|
123
123
|
mime-types (>= 1.16, < 3)
|
124
|
-
mime-types (2.
|
125
|
-
|
126
|
-
minitest (5.
|
127
|
-
multi_json (1.
|
124
|
+
mime-types (2.99)
|
125
|
+
mini_portile2 (2.0.0)
|
126
|
+
minitest (5.8.3)
|
127
|
+
multi_json (1.11.2)
|
128
128
|
multi_test (0.1.1)
|
129
|
-
nokogiri (1.6.
|
130
|
-
|
129
|
+
nokogiri (1.6.7.1)
|
130
|
+
mini_portile2 (~> 2.0.0.rc2)
|
131
131
|
phantomjs (1.9.8.0)
|
132
|
-
rack (1.6.
|
132
|
+
rack (1.6.4)
|
133
133
|
rack-test (0.6.3)
|
134
134
|
rack (>= 1.0)
|
135
135
|
rails (4.2.0)
|
@@ -145,11 +145,11 @@ GEM
|
|
145
145
|
sprockets-rails
|
146
146
|
rails-deprecated_sanitizer (1.0.3)
|
147
147
|
activesupport (>= 4.2.0.alpha)
|
148
|
-
rails-dom-testing (1.0.
|
148
|
+
rails-dom-testing (1.0.7)
|
149
149
|
activesupport (>= 4.2.0.beta, < 5.0)
|
150
150
|
nokogiri (~> 1.6.0)
|
151
151
|
rails-deprecated_sanitizer (>= 1.0.1)
|
152
|
-
rails-html-sanitizer (1.0.
|
152
|
+
rails-html-sanitizer (1.0.2)
|
153
153
|
loofah (~> 2.0)
|
154
154
|
railties (4.2.0)
|
155
155
|
actionpack (= 4.2.0)
|
@@ -158,32 +158,33 @@ GEM
|
|
158
158
|
thor (>= 0.18.1, < 2.0)
|
159
159
|
rake (10.4.2)
|
160
160
|
ref (1.0.5)
|
161
|
-
rspec-core (3.
|
162
|
-
rspec-support (~> 3.
|
163
|
-
rspec-expectations (3.0
|
161
|
+
rspec-core (3.4.1)
|
162
|
+
rspec-support (~> 3.4.0)
|
163
|
+
rspec-expectations (3.4.0)
|
164
164
|
diff-lcs (>= 1.2.0, < 2.0)
|
165
|
-
rspec-support (~> 3.
|
166
|
-
rspec-mocks (3.0
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
rspec-
|
174
|
-
rspec-
|
175
|
-
rspec-
|
176
|
-
|
165
|
+
rspec-support (~> 3.4.0)
|
166
|
+
rspec-mocks (3.4.0)
|
167
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
168
|
+
rspec-support (~> 3.4.0)
|
169
|
+
rspec-rails (3.4.0)
|
170
|
+
actionpack (>= 3.0, < 4.3)
|
171
|
+
activesupport (>= 3.0, < 4.3)
|
172
|
+
railties (>= 3.0, < 4.3)
|
173
|
+
rspec-core (~> 3.4.0)
|
174
|
+
rspec-expectations (~> 3.4.0)
|
175
|
+
rspec-mocks (~> 3.4.0)
|
176
|
+
rspec-support (~> 3.4.0)
|
177
|
+
rspec-support (3.4.1)
|
177
178
|
ruby_parser (3.1.3)
|
178
179
|
sexp_processor (~> 4.1)
|
179
180
|
rubyzip (1.1.6)
|
180
|
-
sass (3.4.
|
181
|
-
sass-rails (5.0.
|
181
|
+
sass (3.4.20)
|
182
|
+
sass-rails (5.0.4)
|
182
183
|
railties (>= 4.0.0, < 5.0)
|
183
184
|
sass (~> 3.1)
|
184
185
|
sprockets (>= 2.8, < 4.0)
|
185
186
|
sprockets-rails (>= 2.0, < 4.0)
|
186
|
-
tilt (
|
187
|
+
tilt (>= 1.1, < 3)
|
187
188
|
selenium-webdriver (2.42.0)
|
188
189
|
childprocess (>= 0.5.0)
|
189
190
|
multi_json (~> 1.0)
|
@@ -195,22 +196,20 @@ GEM
|
|
195
196
|
capybara
|
196
197
|
cucumber
|
197
198
|
cucumber-rails
|
198
|
-
sprockets (
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
activesupport (>= 3.0)
|
206
|
-
sprockets (>= 2.8, < 4.0)
|
199
|
+
sprockets (3.5.2)
|
200
|
+
concurrent-ruby (~> 1.0)
|
201
|
+
rack (> 1, < 3)
|
202
|
+
sprockets-rails (3.0.0)
|
203
|
+
actionpack (>= 4.0)
|
204
|
+
activesupport (>= 4.0)
|
205
|
+
sprockets (>= 3.0.0)
|
207
206
|
sqlite3 (1.3.10)
|
208
207
|
therubyracer (0.12.1)
|
209
208
|
libv8 (~> 3.16.14.0)
|
210
209
|
ref
|
211
210
|
thor (0.19.1)
|
212
|
-
thread_safe (0.3.
|
213
|
-
tilt (
|
211
|
+
thread_safe (0.3.5)
|
212
|
+
tilt (2.0.1)
|
214
213
|
tzinfo (1.2.2)
|
215
214
|
thread_safe (~> 0.1)
|
216
215
|
uglifier (2.6.0)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class TestController < ActionController::Base
|
2
|
+
|
3
|
+
def is_up
|
4
|
+
render :text => up?.to_s
|
5
|
+
end
|
6
|
+
|
7
|
+
def up_selector
|
8
|
+
render :text => up.selector
|
9
|
+
end
|
10
|
+
|
11
|
+
def is_up_validate
|
12
|
+
render :text => up.validate?.to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
def up_validate_name
|
16
|
+
render :text => up.validate_name
|
17
|
+
end
|
18
|
+
|
19
|
+
def text
|
20
|
+
render :text => 'text from controller'
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/spec_app/config/routes.rb
CHANGED
@@ -0,0 +1,67 @@
|
|
1
|
+
describe TestController do
|
2
|
+
|
3
|
+
describe '#up?' do
|
4
|
+
|
5
|
+
it 'returns true if the request has an X-Up-Selector header' do
|
6
|
+
request.headers['X-Up-Selector'] = 'body'
|
7
|
+
get :is_up
|
8
|
+
expect(response.body).to eq('true')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'returns false if the request has no X-Up-Selector header' do
|
12
|
+
get :is_up
|
13
|
+
expect(response.body).to eq('false')
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#up' do
|
19
|
+
|
20
|
+
describe '#selector' do
|
21
|
+
|
22
|
+
it 'returns the CSS selector that is requested via Up.js' do
|
23
|
+
request.headers['X-Up-Selector'] = '.foo'
|
24
|
+
get :up_selector
|
25
|
+
expect(response.body).to eq('.foo')
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#validate?' do
|
31
|
+
|
32
|
+
it 'returns true the request is an Up.js validation call' do
|
33
|
+
request.headers['X-Up-Validate'] = 'user[email]'
|
34
|
+
get :is_up_validate
|
35
|
+
expect(response.body).to eq('true')
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'returns false if the request is not an Up.js validation call' do
|
39
|
+
get :is_up_validate
|
40
|
+
expect(response.body).to eq('false')
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#validate_name' do
|
46
|
+
|
47
|
+
it 'returns the name of the field that is being validated' do
|
48
|
+
request.headers['X-Up-Validate'] = 'user[email]'
|
49
|
+
get :up_validate_name
|
50
|
+
expect(response.body).to eq('user[email]')
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
# describe '#test' do
|
59
|
+
#
|
60
|
+
# it 'does stuff' do
|
61
|
+
# get :test
|
62
|
+
# expect(response.body).to eq('foo')
|
63
|
+
# end
|
64
|
+
#
|
65
|
+
# end
|
66
|
+
|
67
|
+
end
|
@@ -1,4 +1,22 @@
|
|
1
|
+
u = up.util
|
2
|
+
|
1
3
|
beforeEach ->
|
2
4
|
@lastRequest = ->
|
3
5
|
jasmine.Ajax.requests.mostRecent() or up.util.error('There is no last request')
|
4
6
|
|
7
|
+
@respondWith = (args...) ->
|
8
|
+
firstArg = args.shift()
|
9
|
+
responseText = undefined
|
10
|
+
options = undefined
|
11
|
+
if u.isString(firstArg)
|
12
|
+
responseText = firstArg
|
13
|
+
options = args[0] || {}
|
14
|
+
else
|
15
|
+
options = firstArg
|
16
|
+
responseText = options.responseText
|
17
|
+
request = options.request || @lastRequest()
|
18
|
+
request.respondWith
|
19
|
+
status: options.status || 200
|
20
|
+
contentType: options.contentType || 'text/html'
|
21
|
+
responseHeaders: options.responseHeaders
|
22
|
+
responseText: responseText
|