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
@@ -1,16 +1,34 @@
1
1
  ###*
2
- Custom elements
3
- ===============
4
-
2
+ Enhancing elements
3
+ ==================
4
+
5
5
  Up.js keeps a persistent Javascript environment during page transitions.
6
- To prevent memory leaks it is important to cleanly set up and tear down
7
- event handlers and custom elements.
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
- \#\#\# Incomplete documentation!
23
+ Instead you should register a [`compiler`](/up.compiler) for the `a.lightbox` selector:
10
24
 
11
- We need to work on this page:
25
+ up.compiler('a.lightbox', function($element) {
26
+ $element.lightboxify();
27
+ });
12
28
 
13
- - Better class-level introduction for this module
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 [Angular directives](https://docs.angularjs.org/guide/directive).
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 `[rel=lightbox]` attribute:
64
+ do this for all links with an `lightbox` class:
46
65
 
47
- <a href="river.png" rel="lightbox">River</a>
48
- <a href="ocean.png" rel="lightbox">Ocean</a>
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[rel=lightbox]', function($element) {
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
- Sends a notification that the given element has been inserted
272
- into the DOM. This causes Up.js to compile the fragment (apply
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 plugin code that
278
- is not aware of Up.js:
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
- // Add an element with naked jQuery, without going through Upjs:
281
- $element = $('<div>...</div>').appendTo(document.body);
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
- "X-Up-Selector": request.selector
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 = ($element) ->
198
- debug("Creating selector from element %o", $element)
199
- classes = if classString = $element.attr("class") then classString.split(" ") else []
200
- id = $element.attr("id")
201
- selector = $element.prop("tagName").toLowerCase()
202
- selector += "#" + id if id
203
- for klass in classes
204
- selector += "." + klass
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(&)')
@@ -1,6 +1,6 @@
1
1
  module Upjs
2
2
  module Rails
3
- class Engine < ::Rails::Engine
3
+ class Engine < ::Rails::Engine # :nodoc:
4
4
  end
5
5
  end
6
6
  end
@@ -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
- # See
2
- # https://github.com/rails/turbolinks/search?q=request_method&ref=cmdform
3
- # https://github.com/rails/turbolinks/blob/83d4b3d2c52a681f07900c28adb28bc8da604733/README.md#initialization
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
 
@@ -1,5 +1,9 @@
1
1
  module Upjs
2
2
  module Rails
3
- VERSION = '0.12.5'
3
+ ##
4
+ # The current version of the upjs-rails gem.
5
+ # This version number is also used for releases of the Up.js
6
+ # frontend code.
7
+ VERSION = '0.13.0'
4
8
  end
5
9
  end
data/lib/upjs-rails.rb CHANGED
@@ -1,5 +1,7 @@
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/request_ext"
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
@@ -0,0 +1,2 @@
1
+ --require spec_helper
2
+ --color
data/spec_app/Gemfile CHANGED
@@ -16,9 +16,6 @@ group :development, :test do
16
16
  gem 'byebug'
17
17
  gem 'web-console', '~> 2.0'
18
18
  gem 'jasmine-rails'
19
- # gem 'rails-assets-jasmine-jquery'
20
- # gem 'rails-assets-jasmine-fixture'
21
- # gem 'rails-assets-jasmine-ajax'
22
19
  end
23
20
 
24
21
  group :test do
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- upjs-rails (0.12.1)
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.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.0)
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.2)
118
+ json (1.8.3)
119
119
  libv8 (3.16.14.3)
120
- loofah (2.0.1)
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.4.3)
125
- mini_portile (0.6.2)
126
- minitest (5.5.1)
127
- multi_json (1.10.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.6.2)
130
- mini_portile (~> 0.6.0)
129
+ nokogiri (1.6.7.1)
130
+ mini_portile2 (~> 2.0.0.rc2)
131
131
  phantomjs (1.9.8.0)
132
- rack (1.6.0)
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.5)
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.1)
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.0.4)
162
- rspec-support (~> 3.0.0)
163
- rspec-expectations (3.0.4)
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.0.0)
166
- rspec-mocks (3.0.4)
167
- rspec-support (~> 3.0.0)
168
- rspec-rails (3.0.2)
169
- actionpack (>= 3.0)
170
- activesupport (>= 3.0)
171
- railties (>= 3.0)
172
- rspec-core (~> 3.0.0)
173
- rspec-expectations (~> 3.0.0)
174
- rspec-mocks (~> 3.0.0)
175
- rspec-support (~> 3.0.0)
176
- rspec-support (3.0.4)
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.9)
181
- sass-rails (5.0.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 (~> 1.1)
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 (2.12.3)
199
- hike (~> 1.2)
200
- multi_json (~> 1.0)
201
- rack (~> 1.0)
202
- tilt (~> 1.1, != 1.3.0)
203
- sprockets-rails (2.2.4)
204
- actionpack (>= 3.0)
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.4)
213
- tilt (1.4.1)
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)
@@ -11,7 +11,7 @@
11
11
  * file per style scope.
12
12
  *
13
13
  *= require up
14
- *= require_tree .
14
+ *= require_tree ./blocks
15
15
  *= require_self
16
16
  */
17
17
 
@@ -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
@@ -3,4 +3,6 @@ Rails.application.routes.draw do
3
3
  mount JasmineRails::Engine => '/specs' if defined?(JasmineRails)
4
4
  root to: redirect('/specs')
5
5
 
6
+ get 'test/:action', controller: 'test'
7
+
6
8
  end
@@ -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
@@ -0,0 +1,8 @@
1
+ beforeEach ->
2
+ @appendFixture = (html) ->
3
+ @$fixtureContainer ||= $('<div class="fixture-container"></div>').appendTo(document.body)
4
+ $(html).appendTo(@$fixtureContainer)
5
+
6
+ afterEach ->
7
+ $('.fixture-container').remove()
8
+ @$fixtureContainer = undefined
@@ -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