diff options
Diffstat (limited to 'qa/qa/resource/reusable_project.rb')
-rw-r--r-- | qa/qa/resource/reusable_project.rb | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/qa/qa/resource/reusable_project.rb b/qa/qa/resource/reusable_project.rb index d2dfff8ad56..b9fca314122 100644 --- a/qa/qa/resource/reusable_project.rb +++ b/qa/qa/resource/reusable_project.rb @@ -15,36 +15,36 @@ module QA super @add_name_uuid = false - @name = "reusable_project" + @name = @path = 'reusable_project' @reuse_as = :default_project @initialize_with_readme = true end - # Confirms that the project can be reused - # - # @return [nil] returns nil unless an error is raised - def validate_reuse_preconditions - unless reused_name_unique? - raise ResourceReuseError, - "Reusable projects must have the same name. The project reused as #{reuse_as} has the name '#{name}' but it should be '#{self.class.resources[reuse_as].name}'" - end - end + private - # Checks if the project is being reused with the same name. + # Creates a new project that can be compared to a reused project, 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 project's name is different from another project with the same reuse symbol (reuse_as) - def reused_name_unique? - return true unless self.class.resources.key?(reuse_as) - - self.class.resources[reuse_as].name == name + # @return [QA::Resource] a new instance of Resource::ReusableProject that should be a copy of the original resource + def reference_resource + attributes = self.class.resources[reuse_as][:attributes] + name = "reference_resource_#{SecureRandom.hex(8)}_for_#{attributes.delete(:name)}" + + Project.fabricate_via_api! do |project| + self.class.resources[reuse_as][:attributes].each do |attribute_name, attribute_value| + project.instance_variable_set("@#{attribute_name}", attribute_value) if attribute_value + end + project.name = name + project.path = name + project.path_with_namespace = "#{project.group.full_path}/#{project.name}" + end end - # Overrides QA::Resource::Project#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 project. # - # @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 |