view_component 2.59.0 → 2.61.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of view_component might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/docs/CHANGELOG.md +26 -0
- data/lib/view_component/polymorphic_slots.rb +2 -2
- data/lib/view_component/render_preview_helper.rb +11 -1
- data/lib/view_component/slotable_v2.rb +2 -2
- data/lib/view_component/test_helpers.rb +1 -22
- data/lib/view_component/version.rb +2 -2
- data/lib/view_component.rb +0 -1
- metadata +2 -3
- data/lib/view_component/capybara_simple_session.rb +0 -132
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f405812996b460c943dba2ae0802dbc7e924ce3ae45ff69eb917333c77ecb890
|
4
|
+
data.tar.gz: b50121e18674aa4c5f7b569cc4c2edb5078d4685192e8154d4654b4b21a03ef6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23b295998753b2f0d17af1ee5cbc18ec0602cafa48c1ca4ee19568073c38453c79b7aadd1ec42160eab0b522d4a5c3c10f8682a224ed771b4ff25da1e97730fa
|
7
|
+
data.tar.gz: 43e4f27eb614d7de04e6b44747e4d7f2c006367cae62b2b3dc7ad67bdc6a22ea9ea7822308895b704bd19a50879d3bb3ecf2f0209adb9f039eb149217ef479b5
|
data/docs/CHANGELOG.md
CHANGED
@@ -9,6 +9,32 @@ title: Changelog
|
|
9
9
|
|
10
10
|
## main
|
11
11
|
|
12
|
+
## 2.61.1
|
13
|
+
|
14
|
+
* Revert `Expose Capybara DSL methods directly inside tests.` This change unintentionally broke other Capybara methods and thus introduced a regression. We aren't confident that we can fail forward so we have decided to revert this change.
|
15
|
+
|
16
|
+
*Joel Hawksley*, *Blake Williams*
|
17
|
+
|
18
|
+
* Revert change making content evaluation consistent.
|
19
|
+
|
20
|
+
*Blake Williams*
|
21
|
+
|
22
|
+
* Pin `rails` `main` dependency due to incompatibility with Global Output Buffer.
|
23
|
+
|
24
|
+
*Joel Hawksley*
|
25
|
+
|
26
|
+
## 2.61.0
|
27
|
+
|
28
|
+
* Ensure side-effects in `content` are consistently evaluated before components are rendered. This change effectively means that `content` is evaluated for every component render where `render?` returns true. As a result, code that is passed to a component via a block/content will now always be evaluated, before `#call`, which can reveal bugs in existing components.
|
29
|
+
|
30
|
+
*Blake Williams*
|
31
|
+
|
32
|
+
## 2.60.0
|
33
|
+
|
34
|
+
* Add support for `render_preview` in RSpec tests.
|
35
|
+
|
36
|
+
*Thomas Hutterer*
|
37
|
+
|
12
38
|
## 2.59.0
|
13
39
|
|
14
40
|
* Expose Capybara DSL methods directly inside tests.
|
@@ -10,7 +10,7 @@ module ViewComponent
|
|
10
10
|
location = Kernel.caller_locations(1, 1)[0]
|
11
11
|
|
12
12
|
warn(
|
13
|
-
"warning: ViewComponent::PolymorphicSlots is now included in ViewComponent::Base by default "\
|
13
|
+
"warning: ViewComponent::PolymorphicSlots is now included in ViewComponent::Base by default " \
|
14
14
|
"and can be removed from #{location.path}:#{location.lineno}"
|
15
15
|
)
|
16
16
|
# :nocov:
|
@@ -58,7 +58,7 @@ module ViewComponent
|
|
58
58
|
|
59
59
|
define_method(setter_name) do |*args, &block|
|
60
60
|
ViewComponent::Deprecation.warn(
|
61
|
-
"polymorphic slot setters like `#{setter_name}` are deprecated and will be removed in"\
|
61
|
+
"polymorphic slot setters like `#{setter_name}` are deprecated and will be removed in" \
|
62
62
|
"ViewComponent v3.0.0.\n\nUse `with_#{setter_name}` instead."
|
63
63
|
)
|
64
64
|
|
@@ -15,11 +15,21 @@ module ViewComponent
|
|
15
15
|
#
|
16
16
|
# MyComponentTest -> MyComponentPreview etc.
|
17
17
|
#
|
18
|
+
# In RSpec, `Preview` is appended to `described_class`.
|
19
|
+
#
|
18
20
|
# @param preview [String] The name of the preview to be rendered.
|
19
21
|
# @return [Nokogiri::HTML]
|
20
22
|
def render_preview(name)
|
21
23
|
begin
|
22
|
-
preview_klass =
|
24
|
+
preview_klass = if respond_to?(:described_class)
|
25
|
+
if described_class.nil?
|
26
|
+
raise "`render_preview` expected a described_class, but it is nil."
|
27
|
+
end
|
28
|
+
|
29
|
+
"#{described_class}Preview"
|
30
|
+
else
|
31
|
+
self.class.name.gsub("Test", "Preview")
|
32
|
+
end
|
23
33
|
preview_klass = preview_klass.constantize
|
24
34
|
rescue NameError
|
25
35
|
raise NameError.new(
|
@@ -266,8 +266,8 @@ module ViewComponent
|
|
266
266
|
def raise_if_slot_ends_with_question_mark(slot_name)
|
267
267
|
if slot_name.to_s.ends_with?("?")
|
268
268
|
raise ArgumentError.new(
|
269
|
-
"#{self} declares a slot named #{slot_name}, which ends with a question mark.\n\n"\
|
270
|
-
"This is not allowed because the ViewComponent framework already provides predicate "\
|
269
|
+
"#{self} declares a slot named #{slot_name}, which ends with a question mark.\n\n" \
|
270
|
+
"This is not allowed because the ViewComponent framework already provides predicate " \
|
271
271
|
"methods ending in `?`.\n\n" \
|
272
272
|
"To fix this issue, choose a different name."
|
273
273
|
)
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "view_component/render_preview_helper"
|
4
|
-
require "view_component/capybara_simple_session"
|
5
4
|
|
6
5
|
module ViewComponent
|
7
6
|
module TestHelpers
|
@@ -10,28 +9,8 @@ module ViewComponent
|
|
10
9
|
|
11
10
|
include Capybara::Minitest::Assertions
|
12
11
|
|
13
|
-
CapybaraSimpleSession::DSL_METHODS.each do |method|
|
14
|
-
if RUBY_VERSION >= "2.7"
|
15
|
-
class_eval <<~METHOD, __FILE__, __LINE__ + 1
|
16
|
-
def #{method}(...)
|
17
|
-
page.method("#{method}").call(...)
|
18
|
-
end
|
19
|
-
METHOD
|
20
|
-
else
|
21
|
-
define_method method do |*args, &block|
|
22
|
-
page.send method, *args, &block
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.included(mod)
|
28
|
-
Capybara::Node::Simple.send(:define_method, :to_capybara_node) do
|
29
|
-
self
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
12
|
def page
|
34
|
-
@page ||=
|
13
|
+
@page ||= Capybara::Node::Simple.new(rendered_content)
|
35
14
|
end
|
36
15
|
|
37
16
|
def refute_component_rendered
|
data/lib/view_component.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: view_component
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.61.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitHub Open Source
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -325,7 +325,6 @@ files:
|
|
325
325
|
- lib/rails/generators/test_unit/templates/component_test.rb.tt
|
326
326
|
- lib/view_component.rb
|
327
327
|
- lib/view_component/base.rb
|
328
|
-
- lib/view_component/capybara_simple_session.rb
|
329
328
|
- lib/view_component/collection.rb
|
330
329
|
- lib/view_component/compile_cache.rb
|
331
330
|
- lib/view_component/compiler.rb
|
@@ -1,132 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ViewComponent
|
4
|
-
# This is a simpler version of {Capybara::Session}.
|
5
|
-
#
|
6
|
-
# It only includes {Capybara::Node::Finders}, {Capybara::Node::Matchers},
|
7
|
-
# {#within} and {#within_element}. It is useful in that it does not require a
|
8
|
-
# session, an application or a driver, but can still use Capybara's finders
|
9
|
-
# and matchers on any string that contains HTML.
|
10
|
-
class CapybaraSimpleSession
|
11
|
-
# Most of the code in this class is shamelessly stolen from the
|
12
|
-
# {Capybara::Session} class in the Capybara gem
|
13
|
-
# (https://github.com/teamcapybara/capybara/blob/e704d00879fb1d1e1a0cc01e04c101bcd8af4a68/lib/capybara/session.rb#L38).
|
14
|
-
|
15
|
-
NODE_METHODS = %i[
|
16
|
-
all
|
17
|
-
first
|
18
|
-
text
|
19
|
-
|
20
|
-
find
|
21
|
-
find_all
|
22
|
-
find_button
|
23
|
-
find_by_id
|
24
|
-
find_field
|
25
|
-
find_link
|
26
|
-
|
27
|
-
has_content?
|
28
|
-
has_text?
|
29
|
-
has_css?
|
30
|
-
has_no_content?
|
31
|
-
has_no_text?
|
32
|
-
has_no_css?
|
33
|
-
has_no_xpath?
|
34
|
-
has_xpath?
|
35
|
-
has_link?
|
36
|
-
has_no_link?
|
37
|
-
has_button?
|
38
|
-
has_no_button?
|
39
|
-
has_field?
|
40
|
-
has_no_field?
|
41
|
-
has_checked_field?
|
42
|
-
has_unchecked_field?
|
43
|
-
has_no_table?
|
44
|
-
has_table?
|
45
|
-
has_select?
|
46
|
-
has_no_select?
|
47
|
-
has_selector?
|
48
|
-
has_no_selector?
|
49
|
-
has_no_checked_field?
|
50
|
-
has_no_unchecked_field?
|
51
|
-
|
52
|
-
assert_selector
|
53
|
-
assert_no_selector
|
54
|
-
assert_all_of_selectors
|
55
|
-
assert_none_of_selectors
|
56
|
-
assert_any_of_selectors
|
57
|
-
assert_text
|
58
|
-
assert_no_text
|
59
|
-
].freeze
|
60
|
-
|
61
|
-
private_constant :NODE_METHODS
|
62
|
-
|
63
|
-
SESSION_METHODS = %i[within within_element within_fieldset within_table].freeze
|
64
|
-
|
65
|
-
private_constant :SESSION_METHODS
|
66
|
-
|
67
|
-
DSL_METHODS = (NODE_METHODS + SESSION_METHODS).freeze
|
68
|
-
|
69
|
-
# Stolen from: https://github.com/teamcapybara/capybara/blob/e704d00879fb1d1e1a0cc01e04c101bcd8af4a68/lib/capybara/session.rb#L767-L774.
|
70
|
-
NODE_METHODS.each do |method|
|
71
|
-
if RUBY_VERSION >= "2.7"
|
72
|
-
class_eval <<~METHOD, __FILE__, __LINE__ + 1
|
73
|
-
def #{method}(...)
|
74
|
-
current_scope.#{method}(...)
|
75
|
-
end
|
76
|
-
METHOD
|
77
|
-
else
|
78
|
-
define_method method do |*args, &block|
|
79
|
-
current_scope.send(method, *args, &block)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
# Initializes the receiver with the given string of HTML.
|
85
|
-
#
|
86
|
-
# @param html [String] the HTML to create the session out of
|
87
|
-
def initialize(html)
|
88
|
-
@document = Capybara::Node::Simple.new(html)
|
89
|
-
end
|
90
|
-
|
91
|
-
# (see Capybara::Session#within)
|
92
|
-
def within(*args, **kw_args)
|
93
|
-
new_scope = args.first.respond_to?(:to_capybara_node) ? args.first.to_capybara_node : find(*args, **kw_args)
|
94
|
-
begin
|
95
|
-
scopes.push(new_scope)
|
96
|
-
yield if block_given?
|
97
|
-
ensure
|
98
|
-
scopes.pop
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
# (see Capybara::Session#within_element)
|
103
|
-
alias_method :within_element, :within
|
104
|
-
|
105
|
-
# (see Capybara::Session#within_fieldset)
|
106
|
-
def within_fieldset(locator, &block)
|
107
|
-
within(:fieldset, locator, &block)
|
108
|
-
end
|
109
|
-
|
110
|
-
# (see Capybara::Session#within_table)
|
111
|
-
def within_table(locator, &block)
|
112
|
-
within(:table, locator, &block)
|
113
|
-
end
|
114
|
-
|
115
|
-
# (see Capybara::Node::Element#native)
|
116
|
-
def native
|
117
|
-
current_scope.native
|
118
|
-
end
|
119
|
-
|
120
|
-
private
|
121
|
-
|
122
|
-
attr_reader :document
|
123
|
-
|
124
|
-
def scopes
|
125
|
-
@scopes ||= [nil]
|
126
|
-
end
|
127
|
-
|
128
|
-
def current_scope
|
129
|
-
scopes.last.presence || document
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|