File tree Expand file tree Collapse file tree 3 files changed +25
-5
lines changed Expand file tree Collapse file tree 3 files changed +25
-5
lines changed Original file line number Diff line number Diff line change 1+ ## Unreleased
2+ - Fix issue with inherited hook in helper ([ #33 ] ( https://github.com/avo-hq/class_variants/pull/33 ) )
3+
14## 1.1.0 (2025-01-20)
25- Add support for merging ([ #23 ] ( https://github.com/avo-hq/class_variants/pull/23 ) )
36- Add support for subclass inheritance in helper ([ #24 ] ( https://github.com/avo-hq/class_variants/pull/24 ) )
Original file line number Diff line number Diff line change @@ -11,9 +11,12 @@ def class_variants(...)
1111 def self . included ( base )
1212 base . extend ( ClassMethods )
1313 base . singleton_class . instance_variable_set ( :@_class_variants_instance , ClassVariants ::Instance . new )
14- base . define_singleton_method ( :inherited ) do |subclass |
14+
15+ def base . inherited ( subclass )
16+ super if defined? ( super )
17+
1518 subclass . singleton_class . instance_variable_set (
16- :@_class_variants_instance , base . singleton_class . instance_variable_get ( :@_class_variants_instance ) . dup
19+ :@_class_variants_instance , singleton_class . instance_variable_get ( :@_class_variants_instance ) . dup
1720 )
1821 end
1922 end
Original file line number Diff line number Diff line change 11require "test_helper"
22
33class HelperTest < Minitest ::Test
4- class DemoClass
4+ class BaseClass
5+ end
6+
7+ class DemoClass < BaseClass
58 include ClassVariants ::Helper
69
710 class_variants base : "rounded border"
811 end
912
10- class Subclass < DemoClass
13+ class SubClass < DemoClass
1114 class_variants base : "bg-black"
1215 end
1316
17+ def test_inherited
18+ mock = Minitest ::Mock . new
19+ mock . expect ( :call , nil , [ Class ] )
20+
21+ BaseClass . stub ( :inherited , mock ) do
22+ Class . new ( DemoClass )
23+ end
24+
25+ mock . verify
26+ end
27+
1428 def test_call_from_instance
1529 assert_equal "rounded border" , DemoClass . new . class_variants
1630 end
1731
1832 def test_call_from_subclass
19- assert_equal "rounded border bg-black" , Subclass . new . class_variants
33+ assert_equal "rounded border bg-black" , SubClass . new . class_variants
2034 end
2135end
You can’t perform that action at this time.
0 commit comments