turbo-rails 1.3.2 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +48 -3
- data/Rakefile +15 -2
- data/app/assets/javascripts/turbo.js +280 -127
- data/app/assets/javascripts/turbo.min.js +5 -5
- data/app/assets/javascripts/turbo.min.js.map +1 -1
- data/app/controllers/turbo/frames/frame_request.rb +17 -7
- data/app/controllers/turbo/native/navigation.rb +19 -9
- data/app/helpers/turbo/frames_helper.rb +1 -1
- data/app/helpers/turbo/streams/action_helper.rb +17 -5
- data/app/javascript/turbo/cable_stream_source_element.js +17 -2
- data/app/javascript/turbo/fetch_requests.js +43 -3
- data/app/models/concerns/turbo/broadcastable.rb +42 -10
- data/app/models/turbo/streams/tag_builder.rb +2 -0
- data/app/views/layouts/turbo_rails/frame.html.erb +8 -0
- data/config/routes.rb +1 -1
- data/lib/install/turbo_with_bun.rb +9 -0
- data/lib/tasks/turbo_tasks.rake +35 -18
- data/lib/turbo/broadcastable/test_helper.rb +172 -0
- data/lib/turbo/engine.rb +15 -1
- data/lib/turbo/test_assertions/integration_test_assertions.rb +76 -0
- data/lib/turbo/test_assertions.rb +61 -5
- data/lib/turbo/version.rb +1 -1
- data/lib/turbo-rails.rb +2 -0
- metadata +7 -3
@@ -0,0 +1,76 @@
|
|
1
|
+
module Turbo
|
2
|
+
module TestAssertions
|
3
|
+
module IntegrationTestAssertions
|
4
|
+
# Assert that the Turbo Stream request's response body's HTML contains a
|
5
|
+
# `<turbo-stream>` element.
|
6
|
+
#
|
7
|
+
# === Options
|
8
|
+
#
|
9
|
+
# * <tt>:status</tt> [Integer, Symbol] the HTTP response status
|
10
|
+
# * <tt>:action</tt> [String] matches the element's <tt>[action]</tt>
|
11
|
+
# attribute
|
12
|
+
# * <tt>:target</tt> [String, #to_key] matches the element's
|
13
|
+
# <tt>[target]</tt> attribute. If the value responds to <tt>#to_key</tt>,
|
14
|
+
# the value will be transformed by calling <tt>dom_id</tt>
|
15
|
+
# * <tt>:targets</tt> [String] matches the element's <tt>[targets]</tt>
|
16
|
+
# attribute
|
17
|
+
#
|
18
|
+
# Given the following HTML response body:
|
19
|
+
#
|
20
|
+
# <turbo-stream action="remove" target="message_1"></turbo-stream>
|
21
|
+
#
|
22
|
+
# The following assertion would pass:
|
23
|
+
#
|
24
|
+
# assert_turbo_stream action: "remove", target: "message_1"
|
25
|
+
#
|
26
|
+
# You can also pass a block make assertions about the contents of the
|
27
|
+
# element. Given the following HTML response body:
|
28
|
+
#
|
29
|
+
# <turbo-stream action="replace" target="message_1">
|
30
|
+
# <template>
|
31
|
+
# <p>Hello!</p>
|
32
|
+
# <template>
|
33
|
+
# </turbo-stream>
|
34
|
+
#
|
35
|
+
# The following assertion would pass:
|
36
|
+
#
|
37
|
+
# assert_turbo_stream action: "replace", target: "message_1" do
|
38
|
+
# assert_select "template p", text: "Hello!"
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
def assert_turbo_stream(status: :ok, **attributes, &block)
|
42
|
+
assert_response status
|
43
|
+
assert_equal Mime[:turbo_stream], response.media_type
|
44
|
+
super(**attributes, &block)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Assert that the Turbo Stream request's response body's HTML does not
|
48
|
+
# contain a `<turbo-stream>` element.
|
49
|
+
#
|
50
|
+
# === Options
|
51
|
+
#
|
52
|
+
# * <tt>:status</tt> [Integer, Symbol] the HTTP response status
|
53
|
+
# * <tt>:action</tt> [String] matches the element's <tt>[action]</tt>
|
54
|
+
# attribute
|
55
|
+
# * <tt>:target</tt> [String, #to_key] matches the element's
|
56
|
+
# <tt>[target]</tt> attribute. If the value responds to <tt>#to_key</tt>,
|
57
|
+
# the value will be transformed by calling <tt>dom_id</tt>
|
58
|
+
# * <tt>:targets</tt> [String] matches the element's <tt>[targets]</tt>
|
59
|
+
# attribute
|
60
|
+
#
|
61
|
+
# Given the following HTML response body:
|
62
|
+
#
|
63
|
+
# <turbo-stream action="remove" target="message_1"></turbo-stream>
|
64
|
+
#
|
65
|
+
# The following assertion would fail:
|
66
|
+
#
|
67
|
+
# assert_no_turbo_stream action: "remove", target: "message_1"
|
68
|
+
#
|
69
|
+
def assert_no_turbo_stream(status: :ok, **attributes)
|
70
|
+
assert_response status
|
71
|
+
assert_equal Mime[:turbo_stream], response.media_type
|
72
|
+
super(**attributes)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -7,17 +7,73 @@ module Turbo
|
|
7
7
|
delegate :dom_id, :dom_class, to: ActionView::RecordIdentifier
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
# Assert that the rendered fragment of HTML contains a `<turbo-stream>`
|
11
|
+
# element.
|
12
|
+
#
|
13
|
+
# === Options
|
14
|
+
#
|
15
|
+
# * <tt>:action</tt> [String] matches the element's <tt>[action]</tt>
|
16
|
+
# attribute
|
17
|
+
# * <tt>:target</tt> [String, #to_key] matches the element's
|
18
|
+
# <tt>[target]</tt> attribute. If the value responds to <tt>#to_key</tt>,
|
19
|
+
# the value will be transformed by calling <tt>dom_id</tt>
|
20
|
+
# * <tt>:targets</tt> [String] matches the element's <tt>[targets]</tt>
|
21
|
+
# attribute
|
22
|
+
# * <tt>:count</tt> [Integer] indicates how many turbo streams are expected.
|
23
|
+
# Defaults to <tt>1</tt>.
|
24
|
+
#
|
25
|
+
# Given the following HTML fragment:
|
26
|
+
#
|
27
|
+
# <turbo-stream action="remove" target="message_1"></turbo-stream>
|
28
|
+
#
|
29
|
+
# The following assertion would pass:
|
30
|
+
#
|
31
|
+
# assert_turbo_stream action: "remove", target: "message_1"
|
32
|
+
#
|
33
|
+
# You can also pass a block make assertions about the contents of the
|
34
|
+
# element. Given the following HTML fragment:
|
35
|
+
#
|
36
|
+
# <turbo-stream action="replace" target="message_1">
|
37
|
+
# <template>
|
38
|
+
# <p>Hello!</p>
|
39
|
+
# <template>
|
40
|
+
# </turbo-stream>
|
41
|
+
#
|
42
|
+
# The following assertion would pass:
|
43
|
+
#
|
44
|
+
# assert_turbo_stream action: "replace", target: "message_1" do
|
45
|
+
# assert_select "template p", text: "Hello!"
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
def assert_turbo_stream(action:, target: nil, targets: nil, count: 1, &block)
|
13
49
|
selector = %(turbo-stream[action="#{action}"])
|
14
50
|
selector << %([target="#{target.respond_to?(:to_key) ? dom_id(target) : target}"]) if target
|
15
51
|
selector << %([targets="#{targets}"]) if targets
|
16
|
-
assert_select selector, count:
|
52
|
+
assert_select selector, count: count, &block
|
17
53
|
end
|
18
54
|
|
55
|
+
# Assert that the rendered fragment of HTML does not contain a `<turbo-stream>`
|
56
|
+
# element.
|
57
|
+
#
|
58
|
+
# === Options
|
59
|
+
#
|
60
|
+
# * <tt>:action</tt> [String] matches the element's <tt>[action]</tt>
|
61
|
+
# attribute
|
62
|
+
# * <tt>:target</tt> [String, #to_key] matches the element's
|
63
|
+
# <tt>[target]</tt> attribute. If the value responds to <tt>#to_key</tt>,
|
64
|
+
# the value will be transformed by calling <tt>dom_id</tt>
|
65
|
+
# * <tt>:targets</tt> [String] matches the element's <tt>[targets]</tt>
|
66
|
+
# attribute
|
67
|
+
#
|
68
|
+
# Given the following HTML fragment:
|
69
|
+
#
|
70
|
+
# <turbo-stream action="remove" target="message_1"></turbo-stream>
|
71
|
+
#
|
72
|
+
# The following assertion would fail:
|
73
|
+
#
|
74
|
+
# assert_no_turbo_stream action: "remove", target: "message_1"
|
75
|
+
#
|
19
76
|
def assert_no_turbo_stream(action:, target: nil, targets: nil)
|
20
|
-
assert_equal Mime[:turbo_stream], response.media_type
|
21
77
|
selector = %(turbo-stream[action="#{action}"])
|
22
78
|
selector << %([target="#{target.respond_to?(:to_key) ? dom_id(target) : target}"]) if target
|
23
79
|
selector << %([targets="#{targets}"]) if targets
|
data/lib/turbo/version.rb
CHANGED
data/lib/turbo-rails.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: turbo-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Stephenson
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2023-10-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activejob
|
@@ -87,14 +87,18 @@ files:
|
|
87
87
|
- app/jobs/turbo/streams/broadcast_job.rb
|
88
88
|
- app/models/concerns/turbo/broadcastable.rb
|
89
89
|
- app/models/turbo/streams/tag_builder.rb
|
90
|
+
- app/views/layouts/turbo_rails/frame.html.erb
|
90
91
|
- config/routes.rb
|
91
92
|
- lib/install/turbo_needs_redis.rb
|
93
|
+
- lib/install/turbo_with_bun.rb
|
92
94
|
- lib/install/turbo_with_importmap.rb
|
93
95
|
- lib/install/turbo_with_node.rb
|
94
96
|
- lib/tasks/turbo_tasks.rake
|
95
97
|
- lib/turbo-rails.rb
|
98
|
+
- lib/turbo/broadcastable/test_helper.rb
|
96
99
|
- lib/turbo/engine.rb
|
97
100
|
- lib/turbo/test_assertions.rb
|
101
|
+
- lib/turbo/test_assertions/integration_test_assertions.rb
|
98
102
|
- lib/turbo/version.rb
|
99
103
|
homepage: https://github.com/hotwired/turbo-rails
|
100
104
|
licenses:
|
@@ -115,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
119
|
- !ruby/object:Gem::Version
|
116
120
|
version: '0'
|
117
121
|
requirements: []
|
118
|
-
rubygems_version: 3.
|
122
|
+
rubygems_version: 3.4.15
|
119
123
|
signing_key:
|
120
124
|
specification_version: 4
|
121
125
|
summary: The speed of a single-page web application without having to write any JavaScript.
|