diff --git a/app/models/element/null.rb b/app/models/element/null.rb index aac67aa..fdbd9d2 100644 --- a/app/models/element/null.rb +++ b/app/models/element/null.rb @@ -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 diff --git a/test/models/element/radio_button_test.rb b/test/models/element/radio_button_test.rb new file mode 100644 index 0000000..325f7a9 --- /dev/null +++ b/test/models/element/radio_button_test.rb @@ -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 diff --git a/test/models/element_test.rb b/test/models/element_test.rb index f738add..9e27fac 100644 --- a/test/models/element_test.rb +++ b/test/models/element_test.rb @@ -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