hyper-react 0.12.7 → 0.99.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +48 -34
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +5 -6
- data/README.md +47 -98
- data/Rakefile +6 -28
- data/hyper-react.gemspec +36 -43
- data/lib/hyper-react.rb +4 -73
- data/lib/react/version.rb +3 -0
- metadata +91 -249
- data/.codeclimate.yml +0 -27
- data/.rubocop.yml +0 -1159
- data/.travis.yml +0 -62
- data/Appraisals +0 -31
- data/CHANGELOG.md +0 -143
- data/LICENSE +0 -19
- data/UPGRADING.md +0 -24
- data/component-name-lookup.md +0 -145
- data/config.ru +0 -26
- data/gemfiles/opal_0.10_react_13.gemfile +0 -15
- data/gemfiles/opal_0.10_react_14.gemfile +0 -15
- data/gemfiles/opal_0.10_react_15.gemfile +0 -15
- data/gemfiles/opal_0.8_react_13.gemfile +0 -15
- data/gemfiles/opal_0.8_react_14.gemfile +0 -15
- data/gemfiles/opal_0.8_react_15.gemfile +0 -15
- data/gemfiles/opal_0.9_react_13.gemfile +0 -15
- data/gemfiles/opal_0.9_react_14.gemfile +0 -15
- data/gemfiles/opal_0.9_react_15.gemfile +0 -15
- data/gemfiles/opal_master_react_15.gemfile +0 -16
- data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/components.rb +0 -3
- data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/test_application.rb +0 -2
- data/lib/generators/reactive_ruby/test_app/templates/boot.rb.erb +0 -6
- data/lib/generators/reactive_ruby/test_app/templates/script/rails +0 -5
- data/lib/generators/reactive_ruby/test_app/templates/test_application.rb.erb +0 -13
- data/lib/generators/reactive_ruby/test_app/templates/views/components/hello_world.rb +0 -11
- data/lib/generators/reactive_ruby/test_app/templates/views/components/todo.rb +0 -14
- data/lib/generators/reactive_ruby/test_app/templates/views/layouts/test_layout.html.erb +0 -0
- data/lib/generators/reactive_ruby/test_app/test_app_generator.rb +0 -111
- data/lib/rails-helpers/top_level_rails_component.rb +0 -54
- data/lib/react-sources/react-server.js +0 -2
- data/lib/react/api.rb +0 -173
- data/lib/react/callbacks.rb +0 -41
- data/lib/react/children.rb +0 -30
- data/lib/react/component.rb +0 -168
- data/lib/react/component/api.rb +0 -50
- data/lib/react/component/base.rb +0 -13
- data/lib/react/component/class_methods.rb +0 -189
- data/lib/react/component/dsl_instance_methods.rb +0 -23
- data/lib/react/component/params.rb +0 -6
- data/lib/react/component/props_wrapper.rb +0 -78
- data/lib/react/component/should_component_update.rb +0 -94
- data/lib/react/component/tags.rb +0 -129
- data/lib/react/config.rb +0 -5
- data/lib/react/config/client.rb.erb +0 -19
- data/lib/react/config/server.rb +0 -23
- data/lib/react/element.rb +0 -169
- data/lib/react/event.rb +0 -76
- data/lib/react/ext/hash.rb +0 -9
- data/lib/react/ext/opal-jquery/element.rb +0 -26
- data/lib/react/ext/string.rb +0 -8
- data/lib/react/hash.rb +0 -13
- data/lib/react/native_library.rb +0 -87
- data/lib/react/object.rb +0 -15
- data/lib/react/react-source-browser.rb +0 -3
- data/lib/react/react-source-server.rb +0 -3
- data/lib/react/react-source.rb +0 -20
- data/lib/react/ref_callback.rb +0 -31
- data/lib/react/rendering_context.rb +0 -144
- data/lib/react/server.rb +0 -23
- data/lib/react/state_wrapper.rb +0 -23
- data/lib/react/test.rb +0 -16
- data/lib/react/test/dsl.rb +0 -17
- data/lib/react/test/matchers/render_html_matcher.rb +0 -56
- data/lib/react/test/rspec.rb +0 -15
- data/lib/react/test/session.rb +0 -37
- data/lib/react/test/utils.rb +0 -25
- data/lib/react/top_level.rb +0 -118
- data/lib/react/top_level_render.rb +0 -29
- data/lib/react/validator.rb +0 -136
- data/lib/reactive-ruby/component_loader.rb +0 -50
- data/lib/reactive-ruby/isomorphic_helpers.rb +0 -212
- data/lib/reactive-ruby/rails.rb +0 -7
- data/lib/reactive-ruby/rails/component_mount.rb +0 -46
- data/lib/reactive-ruby/rails/controller_helper.rb +0 -15
- data/lib/reactive-ruby/rails/railtie.rb +0 -33
- data/lib/reactive-ruby/serializers.rb +0 -15
- data/lib/reactive-ruby/server_rendering/contextual_renderer.rb +0 -42
- data/lib/reactive-ruby/version.rb +0 -3
- data/lib/reactrb/auto-import.rb +0 -27
- data/lib/reactrb/deep-compare.rb +0 -24
- data/lib/reactrb/new-event-name-convention.rb +0 -11
- data/logo1.png +0 -0
- data/logo2.png +0 -0
- data/logo3.png +0 -0
- data/path_release_steps.md +0 -9
- data/spec/controller_helper_spec.rb +0 -34
- data/spec/index.html.erb +0 -11
- data/spec/react/callbacks_spec.rb +0 -138
- data/spec/react/children_spec.rb +0 -76
- data/spec/react/component/base_spec.rb +0 -32
- data/spec/react/component_spec.rb +0 -884
- data/spec/react/dsl_spec.rb +0 -303
- data/spec/react/element_spec.rb +0 -136
- data/spec/react/event_spec.rb +0 -24
- data/spec/react/native_library_spec.rb +0 -322
- data/spec/react/observable_spec.rb +0 -42
- data/spec/react/opal_jquery_extensions_spec.rb +0 -68
- data/spec/react/param_declaration_spec.rb +0 -269
- data/spec/react/react_spec.rb +0 -215
- data/spec/react/refs_callback_spec.rb +0 -56
- data/spec/react/server_spec.rb +0 -25
- data/spec/react/state_spec.rb +0 -55
- data/spec/react/test/dsl_spec.rb +0 -43
- data/spec/react/test/matchers/render_html_matcher_spec.rb +0 -83
- data/spec/react/test/rspec_spec.rb +0 -62
- data/spec/react/test/session_spec.rb +0 -88
- data/spec/react/test/utils_spec.rb +0 -28
- data/spec/react/top_level_component_spec.rb +0 -101
- data/spec/react/tutorial/tutorial_spec.rb +0 -36
- data/spec/react/validator_spec.rb +0 -124
- data/spec/reactive-ruby/component_loader_spec.rb +0 -77
- data/spec/reactive-ruby/isomorphic_helpers_spec.rb +0 -160
- data/spec/reactive-ruby/rails/asset_pipeline_spec.rb +0 -10
- data/spec/reactive-ruby/rails/component_mount_spec.rb +0 -66
- data/spec/reactive-ruby/server_rendering/contextual_renderer_spec.rb +0 -35
- data/spec/spec_helper.rb +0 -149
- data/spec/support/react/spec_helpers.rb +0 -44
- data/spec/vendor/es5-shim.min.js +0 -6
- data/spec/vendor/jquery-2.2.4.min.js +0 -4
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
if opal?
|
4
|
-
RSpec.describe 'react/test/rspec', type: :component do
|
5
|
-
before do
|
6
|
-
stub_const 'Greeter', Class.new
|
7
|
-
Greeter.class_eval do
|
8
|
-
include React::Component
|
9
|
-
params do
|
10
|
-
optional :message
|
11
|
-
optional :from
|
12
|
-
end
|
13
|
-
|
14
|
-
def render
|
15
|
-
span { "Hello #{params.message}" }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'should include react/test in rspec' do
|
21
|
-
comp = mount(Greeter)
|
22
|
-
expect(component.instance).to eq(comp)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'includes rspec matchers' do
|
26
|
-
expect(Greeter).to render_static_html(
|
27
|
-
'<span>Hello world</span>'
|
28
|
-
).with_params(message: 'world')
|
29
|
-
end
|
30
|
-
|
31
|
-
describe 'resetting the session' do
|
32
|
-
it 'creates an instance of the mounted component in one example' do
|
33
|
-
mount(Greeter)
|
34
|
-
end
|
35
|
-
|
36
|
-
it '...then is not availalbe in the next' do
|
37
|
-
expect { component.instance }.to raise_error
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
RSpec.describe 'react/test/rspec', type: :other do
|
43
|
-
before do
|
44
|
-
stub_const 'Greeter', Class.new
|
45
|
-
Greeter.class_eval do
|
46
|
-
include React::Component
|
47
|
-
params do
|
48
|
-
optional :message
|
49
|
-
optional :from
|
50
|
-
end
|
51
|
-
|
52
|
-
def render
|
53
|
-
span { "Hello #{params.message}" }
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'should not include react/test in rspec' do
|
59
|
-
expect { mount(Greeter) }.to raise_error
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,88 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
if opal?
|
4
|
-
RSpec.describe React::Test::Session do
|
5
|
-
subject { described_class.new }
|
6
|
-
before do
|
7
|
-
stub_const 'Greeter', Class.new
|
8
|
-
Greeter.class_eval do
|
9
|
-
include React::Component
|
10
|
-
|
11
|
-
params do
|
12
|
-
optional :message
|
13
|
-
optional :from
|
14
|
-
end
|
15
|
-
|
16
|
-
def render
|
17
|
-
span { "Hello #{params.message}" }
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '#mount' do
|
23
|
-
it 'returns an instance of the mounted component' do
|
24
|
-
expect(subject.mount(Greeter)).to be_a(Greeter)
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'actualy mounts the component' do
|
28
|
-
expect(subject.mount(Greeter)).to be_mounted
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'optionaly passes params to the component' do
|
32
|
-
instance = subject.mount(Greeter, message: 'world')
|
33
|
-
expect(instance.params.message).to eq('world')
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe '#instance' do
|
38
|
-
it 'returns the instance of the mounted component' do
|
39
|
-
instance = subject.mount(Greeter)
|
40
|
-
expect(subject.instance).to eq(instance)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe '#html' do
|
45
|
-
it 'returns the component rendered to static html' do
|
46
|
-
subject.mount(Greeter, message: 'world')
|
47
|
-
expect(subject.html).to eq('<span>Hello world</span>')
|
48
|
-
end
|
49
|
-
|
50
|
-
async 'returns the updated static html' do
|
51
|
-
subject.mount(Greeter)
|
52
|
-
subject.update_params(message: 'moon') do
|
53
|
-
run_async {
|
54
|
-
expect(subject.html).to eq('<span>Hello moon</span>')
|
55
|
-
}
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe '#update_params' do
|
61
|
-
it 'sends new params to the component' do
|
62
|
-
instance = subject.mount(Greeter, message: 'world')
|
63
|
-
subject.update_params(message: 'moon')
|
64
|
-
expect(instance.params.message).to eq('moon')
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'leaves unspecified params in tact' do
|
68
|
-
instance = subject.mount(Greeter, message: 'world', from: 'outerspace')
|
69
|
-
subject.update_params(message: 'moon')
|
70
|
-
expect(instance.params.from).to eq('outerspace')
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'causes the component to render' do
|
74
|
-
instance = subject.mount(Greeter, message: 'world')
|
75
|
-
expect(instance).to receive(:render)
|
76
|
-
subject.update_params(message: 'moon')
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe 'instance#force_update!' do
|
81
|
-
it 'causes the component to render' do
|
82
|
-
instance = subject.mount(Greeter)
|
83
|
-
expect(instance).to receive(:render)
|
84
|
-
subject.instance.force_update!
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
if opal?
|
4
|
-
RSpec.describe React::Test::Utils do
|
5
|
-
it 'simulates' do
|
6
|
-
stub_const 'Foo', Class.new
|
7
|
-
Foo.class_eval do
|
8
|
-
include React::Component
|
9
|
-
|
10
|
-
def render
|
11
|
-
div { 'Click Me' }.on(:click) { |e| click(e) }
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
instance = React::Test::Utils.render_into_document(React.create_element(Foo))
|
16
|
-
expect(instance).to receive(:click)
|
17
|
-
described_class.simulate(:click, instance.dom_node)
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "render_into_document" do
|
21
|
-
it "works with native element" do
|
22
|
-
expect {
|
23
|
-
described_class.render_into_document(React.create_element('div'))
|
24
|
-
}.to_not raise_error
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,101 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
if opal?
|
4
|
-
module Components
|
5
|
-
module Controller
|
6
|
-
class Component1
|
7
|
-
include React::Component
|
8
|
-
def render
|
9
|
-
self.class.name.to_s
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class Component1
|
15
|
-
include React::Component
|
16
|
-
def render
|
17
|
-
self.class.name.to_s
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
class Component2
|
22
|
-
include React::Component
|
23
|
-
def render
|
24
|
-
self.class.name.to_s
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
module Controller
|
30
|
-
class SomeOtherClass # see issue #80
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class Component1
|
35
|
-
include React::Component
|
36
|
-
def render
|
37
|
-
self.class.name.to_s
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def render_top_level(controller, component_name)
|
42
|
-
params = {
|
43
|
-
controller: controller,
|
44
|
-
component_name: component_name,
|
45
|
-
render_params: {}
|
46
|
-
}
|
47
|
-
element = React.create_element(React::TopLevelRailsComponent, params)
|
48
|
-
React::Server.render_to_static_markup(element)
|
49
|
-
end
|
50
|
-
|
51
|
-
describe React::TopLevelRailsComponent do
|
52
|
-
|
53
|
-
it 'uses the controller name to lookup a component' do
|
54
|
-
expect(render_top_level("Controller", "Component1")).to eq('<span>Components::Controller::Component1</span>')
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'can find the name without matching the controller' do
|
58
|
-
expect(render_top_level("Controller", "Component2")).to eq('<span>Components::Component2</span>')
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'will find the outer most matching component' do
|
62
|
-
expect(render_top_level("OtherController", "Component1")).to eq('<span>Component1</span>')
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'can find the correct component when the name is fully qualified' do
|
66
|
-
expect(render_top_level("Controller", "::Components::Component1")).to eq('<span>Components::Component1</span>')
|
67
|
-
end
|
68
|
-
|
69
|
-
describe '.html_tag?' do
|
70
|
-
it 'is truthy for valid html tags' do
|
71
|
-
expect(React.html_tag?('a')).to be_truthy
|
72
|
-
expect(React.html_tag?('div')).to be_truthy
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'is truthy for valid svg tags' do
|
76
|
-
expect(React.html_tag?('svg')).to be_truthy
|
77
|
-
expect(React.html_tag?('circle')).to be_truthy
|
78
|
-
end
|
79
|
-
|
80
|
-
it 'is falsey for invalid tags' do
|
81
|
-
expect(React.html_tag?('tagizzle')).to be_falsey
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe '.html_attr?' do
|
86
|
-
it 'is truthy for valid html attributes' do
|
87
|
-
expect(React.html_attr?('id')).to be_truthy
|
88
|
-
expect(React.html_attr?('data')).to be_truthy
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'is truthy for valid svg attributes' do
|
92
|
-
expect(React.html_attr?('cx')).to be_truthy
|
93
|
-
expect(React.html_attr?('strokeWidth')).to be_truthy
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'is falsey for invalid attributes' do
|
97
|
-
expect(React.html_tag?('attrizzle')).to be_falsey
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
if opal?
|
4
|
-
class HelloMessage
|
5
|
-
include React::Component
|
6
|
-
def render
|
7
|
-
div { "Hello World!" }
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
describe 'An Example from the react.rb doc', type: :component do
|
12
|
-
it 'produces the correct result' do
|
13
|
-
expect(HelloMessage).to render_static_html('<div>Hello World!</div>')
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class HelloMessage2
|
18
|
-
include React::Component
|
19
|
-
define_state(:user_name) { '@catmando' }
|
20
|
-
def render
|
21
|
-
div { "Hello #{state.user_name}" }
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe 'Adding state to a component (second tutorial example)', type: :component do
|
26
|
-
it "produces the correct result" do
|
27
|
-
expect(HelloMessage2).to render_static_html('<div>Hello @catmando</div>')
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'renders to the document' do
|
31
|
-
ele = `document.createElement('div')`
|
32
|
-
React.render(React.create_element(HelloMessage2), ele)
|
33
|
-
expect(`#{ele}.innerHTML`) =~ 'Hello @catmando'
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,124 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
if opal?
|
4
|
-
describe React::Validator do
|
5
|
-
describe '#validate' do
|
6
|
-
describe "Presence validation" do
|
7
|
-
it "should check if required props provided" do
|
8
|
-
validator = React::Validator.new.build do
|
9
|
-
requires :foo
|
10
|
-
requires :bar
|
11
|
-
end
|
12
|
-
|
13
|
-
expect(validator.validate({})).to eq(["Required prop `foo` was not specified", "Required prop `bar` was not specified"])
|
14
|
-
expect(validator.validate({foo: 1, bar: 3})).to eq([])
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should check if passed non specified prop" do
|
18
|
-
validator = React::Validator.new.build do
|
19
|
-
optional :foo
|
20
|
-
end
|
21
|
-
|
22
|
-
expect(validator.validate({bar: 10})).to eq(["Provided prop `bar` not specified in spec"])
|
23
|
-
expect(validator.validate({foo: 10})).to eq([])
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "Type validation" do
|
28
|
-
it "should check if passed value with wrong type" do
|
29
|
-
validator = React::Validator.new.build do
|
30
|
-
requires :foo, type: String
|
31
|
-
end
|
32
|
-
|
33
|
-
expect(validator.validate({foo: 10})).to eq(["Provided prop `foo` could not be converted to String"])
|
34
|
-
expect(validator.validate({foo: "10"})).to eq([])
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should check if passed value with wrong custom type" do
|
38
|
-
stub_const 'Bar', Class.new
|
39
|
-
validator = React::Validator.new.build do
|
40
|
-
requires :foo, type: Bar
|
41
|
-
end
|
42
|
-
|
43
|
-
expect(validator.validate({foo: 10})).to eq(["Provided prop `foo` could not be converted to Bar"])
|
44
|
-
expect(validator.validate({foo: Bar.new})).to eq([])
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'coerces native JS prop types to opal objects' do
|
48
|
-
validator = React::Validator.new.build do
|
49
|
-
requires :foo, type: `{ x: 1 }`
|
50
|
-
end
|
51
|
-
|
52
|
-
message = "Provided prop `foo` could not be converted to [object Object]"
|
53
|
-
expect(validator.validate({foo: `{ x: 1 }`})).to eq([message])
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'coerces native JS values to opal objects' do
|
57
|
-
validator = React::Validator.new.build do
|
58
|
-
requires :foo, type: Array[Fixnum]
|
59
|
-
end
|
60
|
-
message = "Provided prop `foo`[0] could not be converted to #{Fixnum.name}"
|
61
|
-
expect(validator.validate({foo: `[ { x: 1 } ]`})).to eq([message])
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should support Array[Class] validation" do
|
65
|
-
validator = React::Validator.new.build do
|
66
|
-
requires :foo, type: Array[Hash]
|
67
|
-
end
|
68
|
-
|
69
|
-
expect(validator.validate({foo: [1,'2',3]})).to eq(
|
70
|
-
[
|
71
|
-
"Provided prop `foo`[0] could not be converted to Hash",
|
72
|
-
"Provided prop `foo`[1] could not be converted to Hash",
|
73
|
-
"Provided prop `foo`[2] could not be converted to Hash"
|
74
|
-
]
|
75
|
-
)
|
76
|
-
expect(validator.validate({foo: [{},{},{}]})).to eq([])
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe "Limited values" do
|
81
|
-
it "should check if passed value is not one of the specified values" do
|
82
|
-
validator = React::Validator.new.build do
|
83
|
-
requires :foo, values: [4,5,6]
|
84
|
-
end
|
85
|
-
|
86
|
-
expect(validator.validate({foo: 3})).to eq(["Value `3` for prop `foo` is not an allowed value"])
|
87
|
-
expect(validator.validate({foo: 4})).to eq([])
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
describe '#undefined_props' do
|
93
|
-
let(:props) { { foo: 'foo', bar: 'bar', biz: 'biz', baz: 'baz' } }
|
94
|
-
let(:validator) do
|
95
|
-
React::Validator.new.build do
|
96
|
-
requires :foo
|
97
|
-
optional :bar
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'slurps up any extra params into a hash' do
|
102
|
-
others = validator.undefined_props(props)
|
103
|
-
expect(others).to eq({ biz: 'biz', baz: 'baz' })
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'prevents validate non-specified params' do
|
107
|
-
validator.undefined_props(props)
|
108
|
-
expect(validator.validate(props)).to eq([])
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
describe "default_props" do
|
113
|
-
it "should return specified default values" do
|
114
|
-
validator = React::Validator.new.build do
|
115
|
-
requires :foo, default: 10
|
116
|
-
requires :bar
|
117
|
-
optional :lorem, default: 20
|
118
|
-
end
|
119
|
-
|
120
|
-
expect(validator.default_props).to eq({foo: 10, lorem: 20})
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
if ruby?
|
4
|
-
RSpec.describe ReactiveRuby::ComponentLoader do
|
5
|
-
GLOBAL_WRAPPER = <<-JS
|
6
|
-
#{React::ServerRendering::ExecJSRenderer::GLOBAL_WRAPPER}
|
7
|
-
var console = {
|
8
|
-
warn: function(s) { }
|
9
|
-
};
|
10
|
-
JS
|
11
|
-
|
12
|
-
let(:js) do
|
13
|
-
if ::Rails.application.assets['react-server.js'] &&
|
14
|
-
!::Rails.application.assets['react-server.js'].to_s.start_with?("// A placeholder file")
|
15
|
-
react_source = ::Rails.application.assets['react-server.js']
|
16
|
-
else
|
17
|
-
react_source = ::Rails.application.assets['react.js']
|
18
|
-
end
|
19
|
-
::Rails.application.assets['components'].to_s + react_source.to_s
|
20
|
-
end
|
21
|
-
let(:context) { ExecJS.compile(GLOBAL_WRAPPER + js) }
|
22
|
-
let(:v8_context) { ReactiveRuby::ServerRendering.context_instance_for(context) }
|
23
|
-
|
24
|
-
describe '.new' do
|
25
|
-
it 'raises a meaningful exception when initialized without a context' do
|
26
|
-
expect {
|
27
|
-
described_class.new(nil)
|
28
|
-
}.to raise_error(/Could not obtain ExecJS runtime context/)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe '#load' do
|
33
|
-
it 'loads given asset file into context' do
|
34
|
-
loader = described_class.new(v8_context)
|
35
|
-
|
36
|
-
expect {
|
37
|
-
loader.load
|
38
|
-
}.to change { !!v8_context.eval('Opal.React') }.from(false).to(true)
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'is truthy upon successful load' do
|
42
|
-
loader = described_class.new(v8_context)
|
43
|
-
expect(loader.load).to be_truthy
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'fails silently returning false' do
|
47
|
-
loader = described_class.new(v8_context)
|
48
|
-
expect(loader.load('foo')).to be_falsey
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe '#load!' do
|
53
|
-
it 'is truthy upon successful load' do
|
54
|
-
loader = described_class.new(v8_context)
|
55
|
-
expect(loader.load!).to be_truthy
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'raises an expection if loading fails' do
|
59
|
-
loader = described_class.new(v8_context)
|
60
|
-
expect { loader.load!('foo') }.to raise_error(/No react\.rb components/)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe '#loaded?' do
|
65
|
-
it 'is truthy if components file is already loaded' do
|
66
|
-
loader = described_class.new(v8_context)
|
67
|
-
loader.load
|
68
|
-
expect(loader).to be_loaded
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'is false if components file is not loaded' do
|
72
|
-
loader = described_class.new(v8_context)
|
73
|
-
expect(loader).to_not be_loaded
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|