This repository was archived by the owner on Oct 19, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +54
-1
lines changed Expand file tree Collapse file tree 2 files changed +54
-1
lines changed Original file line number Diff line number Diff line change @@ -69,15 +69,27 @@ def component_will_unmount
69
69
self . run_callback ( :before_unmount )
70
70
end
71
71
72
+ def p ( *args , &block )
73
+ if block || args . count == 0 || ( args . count == 1 && args . first . is_a? ( Hash ) )
74
+ _p_tag ( *args , &block )
75
+ else
76
+ Kernel . p ( *args )
77
+ end
78
+ end
79
+
72
80
def method_missing ( name , *args , &block )
73
- unless ( React ::HTML_TAGS . include? ( name ) || name == 'present' )
81
+ unless ( React ::HTML_TAGS . include? ( name ) || name == 'present' || name == '_p_tag' )
74
82
return super
75
83
end
76
84
77
85
if name == "present"
78
86
name = args . shift
79
87
end
80
88
89
+ if name == "_p_tag"
90
+ name = "p"
91
+ end
92
+
81
93
@buffer = [ ] unless @buffer
82
94
if block
83
95
current = @buffer
Original file line number Diff line number Diff line change @@ -536,6 +536,47 @@ def render
536
536
element = React . create_element ( Foo )
537
537
expect ( React . render_to_static_markup ( element ) ) . to eq ( "<div></div>" )
538
538
end
539
+
540
+ it "should redefine `p` to make method missing work" do
541
+ stub_const 'Foo' , Class . new
542
+ Foo . class_eval do
543
+ include React ::Component
544
+
545
+ def render
546
+ p ( class_name : "foo" ) do
547
+ p
548
+ div { "lorem ipsum" }
549
+ p ( id : "10" )
550
+ end
551
+ end
552
+ end
553
+
554
+ element = React . create_element ( Foo )
555
+ expect ( React . render_to_static_markup ( element ) ) . to eq ( "<p class=\" foo\" ><p></p><div>lorem ipsum</div><p id=\" 10\" ></p></p>" )
556
+ end
557
+
558
+ it "should only override `p` in render context" do
559
+ stub_const 'Foo' , Class . new
560
+ Foo . class_eval do
561
+ include React ::Component
562
+
563
+ before_mount do
564
+ p "first"
565
+ end
566
+
567
+ after_mount do
568
+ p "second"
569
+ end
570
+
571
+ def render
572
+ div
573
+ end
574
+ end
575
+
576
+ expect ( Kernel ) . to receive ( :p ) . with ( "first" )
577
+ expect ( Kernel ) . to receive ( :p ) . with ( "second" )
578
+ renderToDocument ( Foo )
579
+ end
539
580
end
540
581
541
582
describe "isMounted()" do
You can’t perform that action at this time.
0 commit comments