Skip to content

Commit bc3e25f

Browse files
committed
Added method RenderOptions has_random_dom_id
1 parent 6d38d20 commit bc3e25f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/react_on_rails/react_component/render_options.rb

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ def dom_id
3636
end
3737
end
3838

39+
def has_random_dom_id
40+
return false if options[:id]
41+
42+
return false unless random_dom_id
43+
44+
true
45+
end
46+
3947
def html_options
4048
options[:html_options].to_h
4149
end

spec/react_on_rails/react_component/render_options_spec.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,12 @@ def the_attrs(react_component_name: "App", options: {})
6464
context "without id option" do
6565
context "with random_dom_id set to true" do
6666
it "returns a unique identifier" do
67-
attrs = the_attrs(react_component_name: "SomeApp")
67+
attrs = the_attrs(react_component_name: "SomeApp", options: { random_dom_id: true })
6868
opts = described_class.new(attrs)
6969

7070
expect(SecureRandom).to receive(:uuid).and_return("123456789")
7171
expect(opts.dom_id).to eq "SomeApp-react-component-123456789"
72+
expect(opts.has_random_dom_id).to eq(true)
7273
end
7374

7475
it "is memoized" do
@@ -83,6 +84,7 @@ def the_attrs(react_component_name: "App", options: {})
8384
attrs = the_attrs(react_component_name: "SomeApp", options: { random_dom_id: false})
8485
opts = described_class.new(attrs)
8586
expect(opts.dom_id).to eq "SomeApp-react-component"
87+
expect(opts.has_random_dom_id).to eq(false)
8688
end
8789
end
8890
end
@@ -95,6 +97,7 @@ def the_attrs(react_component_name: "App", options: {})
9597
opts = described_class.new(attrs)
9698

9799
expect(opts.dom_id).to eq "im-an-id"
100+
expect(opts.has_random_dom_id).to eq(false)
98101
end
99102
end
100103
end

0 commit comments

Comments
 (0)