jquery-rails 4.0.0.beta1 → 4.0.0.beta2

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

Potentially problematic release.


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

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 980af19d5077a9cbd177a653fd33964f5c68df2f
4
- data.tar.gz: 2becaf966d6b6a7774a77d93254cd719b367c12e
3
+ metadata.gz: e887a893642721415c82ed5352f0bf20aeaf7b80
4
+ data.tar.gz: 78878da2589447f73ba45d807fcfdbf46277216f
5
5
  SHA512:
6
- metadata.gz: 2a43212bb1c63b6776ff6d179112bfd2220a2db779c1f276eac06ad0ff975b879febaa1e56e3088b6bdec9e1f11516e711fc23bf49f23d45f7ee40c500acbdc3
7
- data.tar.gz: 86d4029e21e50608ffd4b1c77da3168d07a7f14ae9b28a99d4edf3b707d53b278a9bf9b9ab3821d78a161689086ee15e127641b2a8ab9f5ee9923b3e30a596c1
6
+ metadata.gz: 2b7534cbe3d773035193a64966498fccf547cc4a5c7bb6d253599429f2fecd59ce669d6e93ff05ebd1a5a5120c3d6cfcdfa62eaa9fed1682677a5f618599688e
7
+ data.tar.gz: 9db1588e83c175bee49ae8e1da8a417ca6dd96808dbe3f6b81a89becabeb708c32ef16b6daf89e90974a515fe878d8e12ecdf078bd8cd23312b0bf36ff5e9f8f
@@ -1,104 +1,96 @@
1
1
  require 'rails/dom/testing/assertions/selector_assertions'
2
2
 
3
- module Jquery
4
- module Rails
5
- module SelectorAssertions
6
- # Selects content from a JQuery response. Patterned loosely on
7
- # assert_select_rjs.
8
- #
9
- # === Narrowing down
10
- #
11
- # With no arguments, asserts that one or more method calls are made.
12
- #
13
- # Use the +method+ argument to narrow down the assertion to only
14
- # statements that call that specific method.
15
- #
16
- # Use the +opt+ argument to narrow down the assertion to only statements
17
- # that pass +opt+ as the first argument.
18
- #
19
- # Use the +id+ argument to narrow down the assertion to only statements
20
- # that invoke methods on the result of using that identifier as a
21
- # selector.
22
- #
23
- # === Using blocks
24
- #
25
- # Without a block, +assert_select_jquery_ merely asserts that the
26
- # response contains one or more statements that match the conditions
27
- # specified above
28
- #
29
- # With a block +assert_select_jquery_ also asserts that the method call
30
- # passes a javascript escaped string containing HTML. All such HTML
31
- # fragments are selected and passed to the block. Nested assertions are
32
- # supported.
33
- #
34
- # === Examples
35
- #
36
- # # asserts that the #notice element is hidden
37
- # assert_select :hide, '#notice'
38
- #
39
- # # asserts that the #cart element is shown with a blind parameter
40
- # assert_select :show, :blind, '#cart'
41
- #
42
- # # asserts that #cart content contains a #current_item
43
- # assert_select :html, '#cart' do
44
- # assert_select '#current_item'
45
- # end
46
-
47
- PATTERN_HTML = "\"((\\\\\"|[^\"])*)\""
48
- PATTERN_UNICODE_ESCAPED_CHAR = /\\u([0-9a-zA-Z]{4})/
49
-
50
- def assert_select_jquery(*args, &block)
51
- jquery_method = args.first.is_a?(Symbol) ? args.shift : nil
52
- jquery_opt = args.first.is_a?(Symbol) ? args.shift : nil
53
- id = args.first.is_a?(String) ? args.shift : nil
3
+ module Rails::Dom::Testing::Assertions::SelectorAssertions
4
+ # Selects content from a JQuery response. Patterned loosely on
5
+ # assert_select_rjs.
6
+ #
7
+ # === Narrowing down
8
+ #
9
+ # With no arguments, asserts that one or more method calls are made.
10
+ #
11
+ # Use the +method+ argument to narrow down the assertion to only
12
+ # statements that call that specific method.
13
+ #
14
+ # Use the +opt+ argument to narrow down the assertion to only statements
15
+ # that pass +opt+ as the first argument.
16
+ #
17
+ # Use the +id+ argument to narrow down the assertion to only statements
18
+ # that invoke methods on the result of using that identifier as a
19
+ # selector.
20
+ #
21
+ # === Using blocks
22
+ #
23
+ # Without a block, +assert_select_jquery_ merely asserts that the
24
+ # response contains one or more statements that match the conditions
25
+ # specified above
26
+ #
27
+ # With a block +assert_select_jquery_ also asserts that the method call
28
+ # passes a javascript escaped string containing HTML. All such HTML
29
+ # fragments are selected and passed to the block. Nested assertions are
30
+ # supported.
31
+ #
32
+ # === Examples
33
+ #
34
+ # # asserts that the #notice element is hidden
35
+ # assert_select :hide, '#notice'
36
+ #
37
+ # # asserts that the #cart element is shown with a blind parameter
38
+ # assert_select :show, :blind, '#cart'
39
+ #
40
+ # # asserts that #cart content contains a #current_item
41
+ # assert_select :html, '#cart' do
42
+ # assert_select '#current_item'
43
+ # end
54
44
 
55
- pattern = "\\s*\\.#{jquery_method || '\\w+'}\\("
56
- pattern = "#{pattern}['\"]#{jquery_opt}['\"],?\\s*" if jquery_opt
57
- pattern = "#{pattern}#{PATTERN_HTML}"
58
- pattern = "(?:jQuery|\\$)\\(['\"]#{id}['\"]\\)#{pattern}" if id
45
+ PATTERN_HTML = "\"((\\\\\"|[^\"])*)\""
46
+ PATTERN_UNICODE_ESCAPED_CHAR = /\\u([0-9a-zA-Z]{4})/
59
47
 
60
- fragments = Nokogiri::HTML::Document.new
61
- response.body.scan(Regexp.new(pattern)).each do |match|
62
- doc = Nokogiri::HTML::Document.parse(unescape_js(match.first))
63
- doc.root.children.each do |child|
64
- fragments << child if child.element?
65
- end
66
- end
48
+ def assert_select_jquery(*args, &block)
49
+ jquery_method = args.first.is_a?(Symbol) ? args.shift : nil
50
+ jquery_opt = args.first.is_a?(Symbol) ? args.shift : nil
51
+ id = args.first.is_a?(String) ? args.shift : nil
67
52
 
68
- unless fragments.children.any? { |child| child.element? }
69
- opts = [jquery_method, jquery_opt, id].compact
70
- flunk "No JQuery call matches #{opts.inspect}"
71
- end
53
+ pattern = "\\s*\\.#{jquery_method || '\\w+'}\\("
54
+ pattern = "#{pattern}['\"]#{jquery_opt}['\"],?\\s*" if jquery_opt
55
+ pattern = "#{pattern}#{PATTERN_HTML}"
56
+ pattern = "(?:jQuery|\\$)\\(['\"]#{id}['\"]\\)#{pattern}" if id
72
57
 
73
- if block
74
- begin
75
- in_scope, @selected = @selected, fragments
76
- yield
77
- ensure
78
- @selected = in_scope
79
- end
80
- end
58
+ fragments = Nokogiri::HTML::Document.new
59
+ response.body.scan(Regexp.new(pattern)).each do |match|
60
+ doc = Nokogiri::HTML::Document.parse(unescape_js(match.first))
61
+ doc.root.children.each do |child|
62
+ fragments << child if child.element?
81
63
  end
64
+ end
82
65
 
83
- private
66
+ unless fragments.children.any? { |child| child.element? }
67
+ opts = [jquery_method, jquery_opt, id].compact
68
+ flunk "No JQuery call matches #{opts.inspect}"
69
+ end
84
70
 
85
- # Unescapes a JS string.
86
- def unescape_js(js_string)
87
- # js encodes double quotes and line breaks.
88
- unescaped= js_string.gsub('\"', '"')
89
- unescaped.gsub!('\\\'', "'")
90
- unescaped.gsub!(/\\\//, '/')
91
- unescaped.gsub!('\n', "\n")
92
- unescaped.gsub!('\076', '>')
93
- unescaped.gsub!('\074', '<')
94
- # js encodes non-ascii characters.
95
- unescaped.gsub!(PATTERN_UNICODE_ESCAPED_CHAR) {|u| [$1.hex].pack('U*')}
96
- unescaped
71
+ if block
72
+ begin
73
+ in_scope, @selected = @selected, fragments
74
+ yield
75
+ ensure
76
+ @selected = in_scope
97
77
  end
98
78
  end
99
79
  end
100
- end
101
80
 
102
- module Rails::Dom::Testing::Assertions::SelectorAssertions
103
- include Jquery::Rails::SelectorAssertions
81
+ private
82
+
83
+ # Unescapes a JS string.
84
+ def unescape_js(js_string)
85
+ # js encodes double quotes and line breaks.
86
+ unescaped= js_string.gsub('\"', '"')
87
+ unescaped.gsub!('\\\'', "'")
88
+ unescaped.gsub!(/\\\//, '/')
89
+ unescaped.gsub!('\n', "\n")
90
+ unescaped.gsub!('\076', '>')
91
+ unescaped.gsub!('\074', '<')
92
+ # js encodes non-ascii characters.
93
+ unescaped.gsub!(PATTERN_UNICODE_ESCAPED_CHAR) {|u| [$1.hex].pack('U*')}
94
+ unescaped
95
+ end
104
96
  end
@@ -1,6 +1,6 @@
1
1
  module Jquery
2
2
  module Rails
3
- VERSION = "4.0.0.beta1"
3
+ VERSION = "4.0.0.beta2"
4
4
  JQUERY_VERSION = "1.11.1"
5
5
  JQUERY_2_VERSION = "2.1.1"
6
6
  JQUERY_UJS_VERSION = "1.0.1"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jquery-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.beta1
4
+ version: 4.0.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - André Arko