Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit a2ae4be

Browse files
catmandozetachang
authored andcommitted
closes #151
# Conflicts: # CHANGELOG.md
1 parent 780e61e commit a2ae4be

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

lib/react/component/tags.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,20 @@ def find_name_and_parent(component)
9494
private
9595

9696
def find_component(name)
97-
scopes = "#{self.class.name}".split('::').inject([Module]) do |nesting, next_const|
97+
component = lookup_const(name)
98+
if component && !component.method_defined?(:render)
99+
raise "#{name} does not appear to be a react component."
100+
end
101+
component
102+
end
103+
104+
def lookup_const(name)
105+
return nil unless name =~ /^[A-Z]/
106+
scopes = self.class.name.to_s.split('::').inject([Module]) do |nesting, next_const|
98107
nesting + [nesting.last.const_get(next_const)]
99108
end.reverse
100-
scope = scopes.detect { |s| s.const_defined?(name) } || return
101-
component = scope.const_get(name)
102-
return component if component.method_defined?(:render)
103-
raise "#{name} does not appear to be a react component."
109+
scope = scopes.detect { |s| s.const_defined?(name) }
110+
scope.const_get(name) if scope
104111
end
105112
end
106113
end

spec/react/dsl_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,18 @@ def render
148148
.to raise_error('Comp does not appear to be a react component.')
149149
end
150150

151+
it 'raises a method missing error' do
152+
stub_const 'Foo', Class.new(React::Component::Base)
153+
Foo.class_eval do
154+
backtrace :none
155+
render do
156+
_undefined_method
157+
end
158+
end
159+
expect { React.render_to_static_markup(React.create_element(Foo)) }
160+
.to raise_error(NoMethodError)
161+
end
162+
151163
it "will treat the component class name as a first class component name" do
152164
stub_const 'Mod::Bar', Class.new
153165
Mod::Bar.class_eval do

0 commit comments

Comments
 (0)