Skip to content

Commit

Permalink
100% test coverage 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
trinitytakei committed Nov 21, 2024
1 parent 58f3139 commit 179ebaa
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/models/element/null.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,24 @@ class Element::Null
def displayed?
false
end

def self.has_query_constraints?
false
end

def self.composite_primary_key?
nil
end

def self.primary_key
"id"
end

def _read_attribute(attr)
nil
end

def self.polymorphic_name
"Element::Null"
end
end
9 changes: 9 additions & 0 deletions test/models/element/radio_button_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Element::RadioButtonTest < ActiveSupport::TestCase
setup do
@radio_button = Element::RadioButton.new
end

test "radio button is displayed" do
assert @radio_button.displayed?
end
end
14 changes: 14 additions & 0 deletions test/models/element_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,18 @@
require "test_helper"

class ElementTest < ActiveSupport::TestCase
test "#null returns a new Element with Null variant" do
element = Element.null
assert_equal "Element::Null", element.variant_type
end

test "#variant returns Null variant when super is nil" do
element = Element.new
assert_instance_of Element::Null, element.variant
end

test "#displayed? delegates to variant" do
element = Element.new(variant: Element::RadioButton.new)
assert element.displayed?
end
end

0 comments on commit 179ebaa

Please sign in to comment.