diff options
Diffstat (limited to 'qa/qa/resource/reusable_group.rb')
-rw-r--r-- | qa/qa/resource/reusable_group.rb | 51 |
1 files changed, 20 insertions, 31 deletions
diff --git a/qa/qa/resource/reusable_group.rb b/qa/qa/resource/reusable_group.rb index a4bd799e85c..b75cb0517bf 100644 --- a/qa/qa/resource/reusable_group.rb +++ b/qa/qa/resource/reusable_group.rb @@ -8,46 +8,35 @@ module QA def initialize super - @path = "reusable_group" + @name = @path = 'reusable_group' @description = "QA reusable group" @reuse_as = :default_group end - # Confirms that the group can be reused - # - # @return [nil] returns nil unless an error is raised - def validate_reuse_preconditions - unless reused_path_unique? - raise ResourceReuseError, - "Reusable groups must have the same name. The group reused as #{reuse_as} has the path '#{path}' but it should be '#{self.class.resources[reuse_as].path}'" - end - end + private - # Confirms that reuse of the resource did not change it in a way that breaks later reuse. This raises an error if - # the current group path doesn't match the original path. - def validate_reuse - reload! - - if api_resource[:path] != @path - raise ResourceReuseError, "The group now has the path '#{api_resource[:path]}' but it should be '#{path}'" - end - end - - # Checks if the group is being reused with the same path. + # Creates a new group that can be compared to a reused group, using the attributes of the original. Attributes that + # must be unique (path and name) are replaced with new unique values. # - # @return [Boolean] true if the group's path is different from another group with the same reuse symbol (reuse_as) - def reused_path_unique? - return true unless self.class.resources.key?(reuse_as) - - self.class.resources[reuse_as].path == path + # @return [QA::Resource] a new instance of Resource::ReusableGroup that should be a copy of the original resource + def reference_resource + attributes = self.class.resources[reuse_as][:attributes] + name = "ref#{SecureRandom.hex(8)}_#{attributes.delete(:path)}"[0...MAX_NAME_LENGTH] + + Group.fabricate_via_api! do |resource| + self.class.resources[reuse_as][:attributes].each do |attribute_name, attribute_value| + resource.instance_variable_set("@#{attribute_name}", attribute_value) if attribute_value + end + resource.path = name + resource.name = name + end end - # Overrides QA::Resource::Group#remove_via_api! to log a debug message stating that removal will happen after - # the suite completes rather than now. + # The attributes of the resource that should be the same whenever a test wants to reuse a group. # - # @return [nil] - def remove_via_api! - QA::Runtime::Logger.debug("#{self.class.name} - deferring removal until after suite") + # @return [Array<Symbol>] the attribute names. + def unique_identifiers + [:name, :path] end end end |