Skip to content

Commit

Permalink
Use Rails validation to check minimal configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
andysellick committed Oct 22, 2024
1 parent f8cc2ed commit 357afbd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
enableInteractivity = false if minimal
textPosition = nil
textPosition = 'none' if minimal
valid_minimal = true
valid_minimal = false if minimal && !minimal_link # minimal version must include a link
if minimal && !minimal_link
raise ArgumentError, "Minimal version must include a link"
end

chart_library_options = {
chartArea: { width: '80%', height: '60%' },
Expand Down Expand Up @@ -80,7 +81,7 @@
end
end
%>
<% if rows.length > 0 && keys.length > 0 && valid_minimal %>
<% if rows.length > 0 && keys.length > 0 %>
<%= javascript_include_tag "https://www.gstatic.com/charts/loader.js" if @external_script[:loaded] == 1 %>
<%= tag.div(**component_helper.all_attributes) do %>
<% if chart_heading && !minimal %>
Expand Down
4 changes: 3 additions & 1 deletion spec/components/chart_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ def component_name

it "does not render a minimal version if a link is not supplied" do
data[:minimal] = true
assert_empty render_component(data)
expect {
render_component(data)
}.to raise_error("Minimal version must include a link")
end

it "only calls an external script once" do
Expand Down

0 comments on commit 357afbd

Please sign in to comment.