Skip to content

Commit

Permalink
Added method RenderOptions has_random_dom_id?
Browse files Browse the repository at this point in the history
  • Loading branch information
justin808 committed Jul 23, 2018
1 parent 6d38d20 commit ebef895
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/react_on_rails/react_component/render_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion spec/react_on_rails/react_component/render_options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ebef895

Please sign in to comment.