From 79ed06f85c30da0470cf4dc2eba3114408f50a6c Mon Sep 17 00:00:00 2001 From: Tanner Mares Date: Mon, 17 Apr 2017 18:00:04 -0700 Subject: [PATCH] fixed variable typo in findDOMNodes, added spec --- lib/assets/javascripts/react_ujs.js | 4 ++-- react_ujs/dist/react_ujs.js | 4 ++-- react_ujs/index.js | 2 +- test/dummy/app/views/pages/show.html.erb | 9 ++++++--- test/react/rails/controller_lifecycle_test.rb | 2 +- test/react/rails/react_rails_ujs_test.rb | 15 +++++++++++++++ 6 files changed, 27 insertions(+), 9 deletions(-) diff --git a/lib/assets/javascripts/react_ujs.js b/lib/assets/javascripts/react_ujs.js index 78a3c4e72..f99db649e 100644 --- a/lib/assets/javascripts/react_ujs.js +++ b/lib/assets/javascripts/react_ujs.js @@ -238,7 +238,7 @@ var ReactRailsUJS = { // helper method for the mount and unmount methods to find the // `data-react-class` DOM elements - findDOMNodes: function(selector) { + findDOMNodes: function(searchSelector) { var classNameAttr = ReactRailsUJS.CLASS_NAME_ATTR // we will use fully qualified paths as we do not bind the callbacks var selector, parent; @@ -502,4 +502,4 @@ module.exports = function(reqctx) { /***/ }) /******/ ]); -}); \ No newline at end of file +}); diff --git a/react_ujs/dist/react_ujs.js b/react_ujs/dist/react_ujs.js index 78a3c4e72..f99db649e 100644 --- a/react_ujs/dist/react_ujs.js +++ b/react_ujs/dist/react_ujs.js @@ -238,7 +238,7 @@ var ReactRailsUJS = { // helper method for the mount and unmount methods to find the // `data-react-class` DOM elements - findDOMNodes: function(selector) { + findDOMNodes: function(searchSelector) { var classNameAttr = ReactRailsUJS.CLASS_NAME_ATTR // we will use fully qualified paths as we do not bind the callbacks var selector, parent; @@ -502,4 +502,4 @@ module.exports = function(reqctx) { /***/ }) /******/ ]); -}); \ No newline at end of file +}); diff --git a/react_ujs/index.js b/react_ujs/index.js index 81163dc32..29e79dad9 100644 --- a/react_ujs/index.js +++ b/react_ujs/index.js @@ -20,7 +20,7 @@ var ReactRailsUJS = { // helper method for the mount and unmount methods to find the // `data-react-class` DOM elements - findDOMNodes: function(selector) { + findDOMNodes: function(searchSelector) { var classNameAttr = ReactRailsUJS.CLASS_NAME_ATTR // we will use fully qualified paths as we do not bind the callbacks var selector, parent; diff --git a/test/dummy/app/views/pages/show.html.erb b/test/dummy/app/views/pages/show.html.erb index f88cbb549..04644a308 100644 --- a/test/dummy/app/views/pages/show.html.erb +++ b/test/dummy/app/views/pages/show.html.erb @@ -1,10 +1,13 @@
- <%= react_component 'GreetingMessage', { :name => @name }, { :id => 'component', prerender: @prerender } %> + <%= react_component 'GreetingMessage', { name: @name }, { id: 'component', prerender: @prerender } %> +
diff --git a/test/react/rails/controller_lifecycle_test.rb b/test/react/rails/controller_lifecycle_test.rb index dca5a7ae6..eb1d61a34 100644 --- a/test/react/rails/controller_lifecycle_test.rb +++ b/test/react/rails/controller_lifecycle_test.rb @@ -46,7 +46,7 @@ def teardown test "it calls setup and teardown methods" do get '/pages/1?param_test=123' helper_obj = controller.__react_component_helper - lifecycle_steps = ["123", :react_component, :teardown] + lifecycle_steps = ["123", :react_component, :react_component, :teardown] assert_equal(lifecycle_steps, helper_obj.events) end diff --git a/test/react/rails/react_rails_ujs_test.rb b/test/react/rails/react_rails_ujs_test.rb index a74b707ac..a55e1567a 100644 --- a/test/react/rails/react_rails_ujs_test.rb +++ b/test/react/rails/react_rails_ujs_test.rb @@ -124,6 +124,21 @@ def refute_greeting(page, greeting) assert_greeting(page, 'Hello Bob') end + test 'react_ujs does not unmount components that do not match a selector reference for the component' do + visit '/pages/1' + assert_greeting page, 'Hello Bob' + assert page.has_content?('Another Component'), page.body + + page.click_button "Unmount by own selector" + refute_greeting(page, 'Hello Bob') + assert page.has_content?('Another Component'), page.body + + page.click_button "Mount by own selector" + assert_greeting(page, 'Hello Bob') + assert page.has_content?('Another Component'), page.body + end + + test 'react_ujs can unmount/mount using a dom node context' do visit '/pages/1' assert_greeting(page, 'Hello Bob')