jquery-rails 4.0.0.beta1 → 4.0.0.beta2
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.
Potentially problematic release.
This version of jquery-rails might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/jquery/assert_select.rb +82 -90
- data/lib/jquery/rails/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e887a893642721415c82ed5352f0bf20aeaf7b80
|
4
|
+
data.tar.gz: 78878da2589447f73ba45d807fcfdbf46277216f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b7534cbe3d773035193a64966498fccf547cc4a5c7bb6d253599429f2fecd59ce669d6e93ff05ebd1a5a5120c3d6cfcdfa62eaa9fed1682677a5f618599688e
|
7
|
+
data.tar.gz: 9db1588e83c175bee49ae8e1da8a417ca6dd96808dbe3f6b81a89becabeb708c32ef16b6daf89e90974a515fe878d8e12ecdf078bd8cd23312b0bf36ff5e9f8f
|
data/lib/jquery/assert_select.rb
CHANGED
@@ -1,104 +1,96 @@
|
|
1
1
|
require 'rails/dom/testing/assertions/selector_assertions'
|
2
2
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
56
|
-
|
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
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
-
|
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
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
-
|
103
|
-
|
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
|
data/lib/jquery/rails/version.rb
CHANGED