Skip to content

Commit

Permalink
Fixed broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
justin808 committed Feb 8, 2016
1 parent 42e1536 commit 6008e72
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 23 deletions.
6 changes: 3 additions & 3 deletions .rubocop.yml
Expand Up @@ -44,13 +44,13 @@ Lint/HandleExceptions:
- 'spec/dummy/bin/rake'

Metrics/AbcSize:
Max: 25
Max: 26

Metrics/CyclomaticComplexity:
Max: 7

Metrics/PerceivedComplexity:
Max: 9
Max: 10

Metrics/ClassLength:
Max: 114
Expand All @@ -63,7 +63,7 @@ Metrics/MethodLength:
Max: 41

Metrics/ModuleLength:
Max: 160
Max: 180

Style/GlobalVars:
Exclude:
Expand Down
18 changes: 13 additions & 5 deletions app/helpers/react_on_rails_helper.rb
Expand Up @@ -54,6 +54,8 @@ def react_component(component_name, options = {}, other_options = nil)
# The reason is that React is smart about not doing extra work if the server rendering did its job.
turbolinks_loaded = Object.const_defined?(:Turbolinks)

props = {} if props.nil?

data = {
component_name: react_component_name,
props: props,
Expand Down Expand Up @@ -237,18 +239,21 @@ def replay_console(options)
end

def parse_options_props(component_name, options, other_options)
if options.is_a?(Hash) && options.key?(:props) # new syntax
other_options ||= {}
if options.is_a?(Hash) && options.key?(:props)
props = options[:props]
final_options = options.except(:props)
final_options.merge!(other_options) if other_options.present?
else
deprecated_syntax = false
# either no props specified or deprecated
if other_options.present? || options.is_a?(String)
deprecated_syntax = true
else
options_has_no_reserved_keys =
%i(prerender trace replay_console raise_on_prerender_error).none? do |key|
options.key?(key)
end
deprecated_syntax = true if options_has_no_reserved_keys
deprecated_syntax = options_has_no_reserved_keys
end

if deprecated_syntax
Expand All @@ -257,9 +262,12 @@ def parse_options_props(component_name, options, other_options)
"component_name: #{component_name}, controller: #{controller_name}, "\
"action: #{action_name}."
props = options
options = other_options
final_options = other_options
else
options ||= {}
final_options = options.merge(other_options)
end
end
[options, props]
[final_options, props]
end
end
@@ -1,13 +1,13 @@
<%= render "header" %>
<%= redux_store("SharedReduxStore", @app_props_server_render) %>
<%= react_component("ReduxSharedStoreApp", props: {}, prerender: false, trace: true) %>
<%= react_component("ReduxSharedStoreApp", prerender: false, trace: true) %>
<hr/>
<h3>Second Hello World</h3>
<%= react_component("ReduxSharedStoreApp", props: {}, prerender: false, trace: true) %>
<h1>Second Hello World</h1>
<%= react_component("ReduxSharedStoreApp", prerender: false, trace: true) %>
<hr/>

<h1>React Rails Client Side Only Rendering</h1>
<h1>React Rails Client Side Only Rendering, 2 components, same Redux store </h1>
<p>
This example demonstrates using 2 components attached to the same store.<br/><br/>
</p>
Expand All @@ -16,22 +16,24 @@
<h2>Setup</h2>
<ol>
<li>
Create component source: spec/dummy/client/app/components/HelloWorld.jsx
Create component source: spec/dummy/client/app/startup/ReduxSharedStoreApp.jsx
</li>
<li>
Expose the HelloWorld Component: spec/dummy/client/app/startup/clientRegistration.jsx
<br/>
<pre>
import HelloWorld from '../components/HelloWorld';
import ReactOnRails from 'react-on-rails';
ReactOnRails.register({ HelloWorld });
</pre>
Create store source: spec/dummy/client/app/stores/SharedReduxStore.jsx
</li>
<li>
Place the component on the view: spec/dummy/app/views/pages/client_side_hello_world.html.erb
Register the components: spec/dummy/client/app/startup/clientRegistration.jsx
</li>
<li>
Place the components and store on the view: spec/dummy/app/views/pages/client_side_hello_world_shared_store.html.erb
<br/>
<pre>
<%%= react_component("HelloWorld", props: @app_props_server_render, prerender: false, trace: true) %>
<%%= redux_store("SharedReduxStore", @app_props_server_render) %>

<%%= react_component("ReduxSharedStoreApp", prerender: false, trace: true) %>

Second Hello World
<%%= react_component("ReduxSharedStoreApp", prerender: false, trace: true) %>
</pre>
</li>
</ol>
9 changes: 8 additions & 1 deletion spec/dummy/spec/helpers/react_on_rails_helper_spec.rb
Expand Up @@ -36,7 +36,7 @@
end

describe "#react_component" do
subject { react_component("App", props) }
subject { react_component("App", props: props) }

let(:props) do
{ name: "My Test Name" }
Expand All @@ -58,6 +58,13 @@
data-dom-id="#{id}"></div>).squish
end

describe "deprecated API" do
subject { react_component("App", props) }
it { is_expected.to be_an_instance_of ActiveSupport::SafeBuffer }
it { is_expected.to include react_component_div }
it { is_expected.to include react_definition_div }
end

it { expect(self).to respond_to :react_component }

it { is_expected.to be_an_instance_of ActiveSupport::SafeBuffer }
Expand Down

0 comments on commit 6008e72

Please sign in to comment.