Commit c55c7142 authored by Andrejs Cunskis's avatar Andrejs Cunskis

Merge branch 'acunskis-refactor-comparable' into 'master'

E2E: Move custom resource comparison logic to resource base

See merge request gitlab-org/gitlab!76854
parents 908b3890 ffa70949
......@@ -80,27 +80,12 @@ module QA
parse_body(response)
end
# Object comparison
#
# @param [QA::EE::Resource::Epic] other
# @return [Boolean]
def ==(other)
other.is_a?(Epic) && comparable_epic == other.comparable_epic
end
# Override inspect for a better rspec failure diff output
#
# @return [String]
def inspect
JSON.pretty_generate(comparable_epic)
end
protected
# Return subset of fields for comparing epics
#
# @return [Hash]
def comparable_epic
def comparable
reload! if api_response.nil?
api_resource.slice(
......
......@@ -124,27 +124,12 @@ module QA
GQL
end
# Object comparison
#
# @param [QA::EE::Resource::GroupIteration] other
# @return [Boolean]
def ==(other)
other.is_a?(GroupIteration) && comparable_iteration == other.comparable_iteration
end
# Override inspect for a better rspec failure diff output
#
# @return [String]
def inspect
JSON.pretty_generate(comparable_iteration)
end
protected
# Return subset of fields for comparing iterations
#
# @return [Hash]
def comparable_iteration
def comparable
reload! unless api_response
api_response.slice(
......
......@@ -179,6 +179,30 @@ module QA
QA::Support::Waiter.wait_until(max_duration: max_duration, sleep_interval: sleep_interval, &block)
end
# Object comparison
#
# @param [QA::Resource::Base] other
# @return [Boolean]
def ==(other)
other.is_a?(self.class) && comparable == other.comparable
end
# Override inspect for a better rspec failure diff output
#
# @return [String]
def inspect
JSON.pretty_generate(comparable)
end
protected
# Custom resource comparison logic using resource attributes from api_resource
#
# @return [Hash]
def comparable
raise("comparable method needs to be implemented in order to compare resources via '=='")
end
private
def attribute_value(name, block)
......
......@@ -39,27 +39,12 @@ module QA
# @return [String]
def resource_web_url(_resource); end
# Object comparison
#
# @param [QA::Resource::GroupBadge] other
# @return [Boolean]
def ==(other)
other.is_a?(GroupBadge) && comparable_badge == other.comparable_badge
end
# Override inspect for a better rspec failure diff output
#
# @return [String]
def inspect
JSON.pretty_generate(comparable_badge)
end
protected
# Return subset of fields for comparing badges
#
# @return [Hash]
def comparable_badge
def comparable
reload! unless api_response
api_response.slice(
......
......@@ -123,18 +123,12 @@ module QA
end
# Object comparison
# Override to make sure we are comparing descendands of GroupBase
#
# @param [QA::Resource::GroupBase] other
# @return [Boolean]
def ==(other)
other.is_a?(GroupBase) && comparable_group == other.comparable_group
end
# Override inspect for a better rspec failure diff output
#
# @return [String]
def inspect
JSON.pretty_generate(comparable_group)
other.is_a?(GroupBase) && comparable == other.comparable
end
protected
......@@ -142,7 +136,7 @@ module QA
# Return subset of fields for comparing groups
#
# @return [Hash]
def comparable_group
def comparable
reload! if api_response.nil?
api_resource.slice(
......
......@@ -56,27 +56,12 @@ module QA
end
end
# Object comparison
#
# @param [QA::Resource::GroupMilestone] other
# @return [Boolean]
def ==(other)
other.is_a?(GroupMilestone) && comparable_milestone == other.comparable_milestone
end
# Override inspect for a better rspec failure diff output
#
# @return [String]
def inspect
JSON.pretty_generate(comparable_milestone)
end
protected
# Return subset of fields for comparing milestones
#
# @return [Hash]
def comparable_milestone
def comparable
reload! unless api_response
api_response.slice(
......
......@@ -95,27 +95,12 @@ module QA
)
end
# Object comparison
#
# @param [QA::Resource::Issue] other
# @return [Boolean]
def ==(other)
other.is_a?(Issue) && comparable_issue == other.comparable_issue
end
# Override inspect for a better rspec failure diff output
#
# @return [String]
def inspect
JSON.pretty_generate(comparable_issue)
end
protected
# Return subset of fields for comparing issues
#
# @return [Hash]
def comparable_issue
def comparable
reload! if api_response.nil?
api_resource.slice(
......
......@@ -49,27 +49,12 @@ module QA
}
end
# Object comparison
#
# @param [QA::Resource::GroupBase] other
# @return [Boolean]
def ==(other)
other.is_a?(LabelBase) && comparable_label == other.comparable_label
end
# Override inspect for a better rspec failure diff output
#
# @return [String]
def inspect
JSON.pretty_generate(comparable_label)
end
protected
# Return subset of fields for comparing labels
#
# @return [Hash]
def comparable_label
def comparable
reload! unless api_response
api_response.slice(
......
......@@ -168,27 +168,12 @@ module QA
)
end
# Object comparison
#
# @param [QA::Resource::MergeRequest] other
# @return [Boolean]
def ==(other)
other.is_a?(MergeRequest) && comparable_mr == other.comparable_mr
end
# Override inspect for a better rspec failure diff output
#
# @return [String]
def inspect
JSON.pretty_generate(comparable_mr)
end
protected
# Return subset of fields for comparing merge requests
#
# @return [Hash]
def comparable_mr
def comparable
reload! if api_response.nil?
api_resource.except(
......
......@@ -372,27 +372,12 @@ module QA
api_post_to(api_wikis_path, title: title, content: content)
end
# Object comparison
#
# @param [QA::Resource::Project] other
# @return [Boolean]
def ==(other)
other.is_a?(Project) && comparable_project == other.comparable_project
end
# Override inspect for a better rspec failure diff output
#
# @return [String]
def inspect
JSON.pretty_generate(comparable_project)
end
protected
# Return subset of fields for comparing projects
#
# @return [Hash]
def comparable_project
def comparable
reload! if api_response.nil?
api_resource.slice(
......
......@@ -181,6 +181,15 @@ module QA
)
end
protected
# Compare users by username and password
#
# @return [Array]
def comparable
[username, password]
end
private
def ldap_post_body
......
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