Skip to content

Commit 01162ab

Browse files
committed
Fix changelog entry; conditionally define #format for collections; fix allocations (again)
1 parent 31b1744 commit 01162ab

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

docs/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ nav_order: 6
1414

1515
*Hans Lemuet*
1616

17-
* Re-introduce Base#format and Collection#format to fix Rails 7.1 tests.
17+
* Conditionally add the `ViewComponent::Base#format` method back for Rails 7.1 only.
18+
* Compute and check lockfiles into source control.
19+
* Constrain Rails versions in gemfiles to only allow the patch version to vary, eg. `~> 7.1.0` instead of `~> 7.1`.
1820

1921
*Cameron Dutro*
2022

lib/view_component/collection.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ def each(&block)
1919
components.each(&block)
2020
end
2121

22-
# Rails expects us to define `format` on all renderables,
23-
# but we do not know the `format` of a ViewComponent until runtime.
24-
def format
25-
nil
22+
if Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR == 1
23+
# Rails expects us to define `format` on all renderables,
24+
# but we do not know the `format` of a ViewComponent until runtime.
25+
def format
26+
nil
27+
end
2628
end
2729

2830
private

test/sandbox/test/rendering_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_render_collection_inline_allocations
3434
ViewComponent::CompileCache.cache.delete(ProductComponent)
3535
ProductComponent.__vc_ensure_compiled
3636

37-
allocations = {"3.5" => 76, "3.4" => 82, "3.3" => 86, "3.2" => 90}
37+
allocations = {"3.5" => 76, "3.4" => 82, "3.3" => 86, "3.2" => 89}
3838

3939
products = [Product.new(name: "Radio clock"), Product.new(name: "Mints")]
4040
notice = "On sale"

0 commit comments

Comments
 (0)