From bc3e25f9d07d5bd839972c499df79d9522acc328 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Sun, 22 Jul 2018 17:33:19 -1000 Subject: [PATCH] Added method RenderOptions has_random_dom_id --- lib/react_on_rails/react_component/render_options.rb | 8 ++++++++ .../react_on_rails/react_component/render_options_spec.rb | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/react_on_rails/react_component/render_options.rb b/lib/react_on_rails/react_component/render_options.rb index 367612df7c..fb93816f4d 100644 --- a/lib/react_on_rails/react_component/render_options.rb +++ b/lib/react_on_rails/react_component/render_options.rb @@ -36,6 +36,14 @@ def dom_id end end + def has_random_dom_id + return false if options[:id] + + return false unless random_dom_id + + true + end + def html_options options[:html_options].to_h end diff --git a/spec/react_on_rails/react_component/render_options_spec.rb b/spec/react_on_rails/react_component/render_options_spec.rb index 8992eabf9d..5a2a84d5c8 100644 --- a/spec/react_on_rails/react_component/render_options_spec.rb +++ b/spec/react_on_rails/react_component/render_options_spec.rb @@ -64,11 +64,12 @@ def the_attrs(react_component_name: "App", options: {}) context "without id option" do context "with random_dom_id set to true" do it "returns a unique identifier" do - attrs = the_attrs(react_component_name: "SomeApp") + attrs = the_attrs(react_component_name: "SomeApp", options: { random_dom_id: true }) opts = described_class.new(attrs) expect(SecureRandom).to receive(:uuid).and_return("123456789") expect(opts.dom_id).to eq "SomeApp-react-component-123456789" + expect(opts.has_random_dom_id).to eq(true) end it "is memoized" do @@ -83,6 +84,7 @@ def the_attrs(react_component_name: "App", options: {}) attrs = the_attrs(react_component_name: "SomeApp", options: { random_dom_id: false}) opts = described_class.new(attrs) expect(opts.dom_id).to eq "SomeApp-react-component" + expect(opts.has_random_dom_id).to eq(false) end end end @@ -95,6 +97,7 @@ def the_attrs(react_component_name: "App", options: {}) opts = described_class.new(attrs) expect(opts.dom_id).to eq "im-an-id" + expect(opts.has_random_dom_id).to eq(false) end end end