Commit 22ecca36 authored by Andrejs Cunskis's avatar Andrejs Cunskis Committed by Mark Lapierre

E2E: Allow nil and boolean values for resource attributes

parent 25f1cc5d
...@@ -100,7 +100,9 @@ module QA ...@@ -100,7 +100,9 @@ module QA
attr_writer(name) attr_writer(name)
define_method(name) do define_method(name) do
instance_variable_get("@#{name}") || instance_variable_set("@#{name}", populate_attribute(name, block)) return instance_variable_get("@#{name}") if instance_variable_defined?("@#{name}")
instance_variable_set("@#{name}", attribute_value(name, block))
end end
end end
...@@ -121,9 +123,7 @@ module QA ...@@ -121,9 +123,7 @@ module QA
return self unless api_resource return self unless api_resource
all_attributes.each do |attribute_name| all_attributes.each do |attribute_name|
api_value = api_resource[attribute_name] instance_variable_set("@#{attribute_name}", api_resource[attribute_name]) if api_resource.key?(attribute_name)
instance_variable_set("@#{attribute_name}", api_value) if api_value
end end
self self
...@@ -160,20 +160,17 @@ module QA ...@@ -160,20 +160,17 @@ module QA
private private
def populate_attribute(name, block)
value = attribute_value(name, block)
raise NoValueError, "No value was computed for #{name} of #{self.class.name}." unless value
value
end
def attribute_value(name, block) def attribute_value(name, block)
api_value = api_resource&.dig(name) no_api_value = !api_resource&.key?(name)
raise NoValueError, "No value was computed for #{name} of #{self.class.name}." if no_api_value && !block
log_having_both_api_result_and_block(name, api_value) if api_value && block unless no_api_value
api_value = api_resource[name]
log_having_both_api_result_and_block(name, api_value) if block
return api_value
end
api_value || (block && instance_exec(&block)) instance_exec(&block)
end end
# Get all defined attributes across all parents # Get all defined attributes across all parents
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment