Commit ffa70949 authored by Andrejs Cunskis's avatar Andrejs Cunskis

E2E: Move custom resource comparison logic to resource base

parent 80efecbd
...@@ -80,27 +80,12 @@ module QA ...@@ -80,27 +80,12 @@ module QA
parse_body(response) parse_body(response)
end 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 protected
# Return subset of fields for comparing epics # Return subset of fields for comparing epics
# #
# @return [Hash] # @return [Hash]
def comparable_epic def comparable
reload! if api_response.nil? reload! if api_response.nil?
api_resource.slice( api_resource.slice(
......
...@@ -124,27 +124,12 @@ module QA ...@@ -124,27 +124,12 @@ module QA
GQL GQL
end 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 protected
# Return subset of fields for comparing iterations # Return subset of fields for comparing iterations
# #
# @return [Hash] # @return [Hash]
def comparable_iteration def comparable
reload! unless api_response reload! unless api_response
api_response.slice( api_response.slice(
......
...@@ -179,6 +179,30 @@ module QA ...@@ -179,6 +179,30 @@ module QA
QA::Support::Waiter.wait_until(max_duration: max_duration, sleep_interval: sleep_interval, &block) QA::Support::Waiter.wait_until(max_duration: max_duration, sleep_interval: sleep_interval, &block)
end 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 private
def attribute_value(name, block) def attribute_value(name, block)
......
...@@ -39,27 +39,12 @@ module QA ...@@ -39,27 +39,12 @@ module QA
# @return [String] # @return [String]
def resource_web_url(_resource); end 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 protected
# Return subset of fields for comparing badges # Return subset of fields for comparing badges
# #
# @return [Hash] # @return [Hash]
def comparable_badge def comparable
reload! unless api_response reload! unless api_response
api_response.slice( api_response.slice(
......
...@@ -123,18 +123,12 @@ module QA ...@@ -123,18 +123,12 @@ module QA
end end
# Object comparison # Object comparison
# Override to make sure we are comparing descendands of GroupBase
# #
# @param [QA::Resource::GroupBase] other # @param [QA::Resource::GroupBase] other
# @return [Boolean] # @return [Boolean]
def ==(other) def ==(other)
other.is_a?(GroupBase) && comparable_group == other.comparable_group other.is_a?(GroupBase) && comparable == other.comparable
end
# Override inspect for a better rspec failure diff output
#
# @return [String]
def inspect
JSON.pretty_generate(comparable_group)
end end
protected protected
...@@ -142,7 +136,7 @@ module QA ...@@ -142,7 +136,7 @@ module QA
# Return subset of fields for comparing groups # Return subset of fields for comparing groups
# #
# @return [Hash] # @return [Hash]
def comparable_group def comparable
reload! if api_response.nil? reload! if api_response.nil?
api_resource.slice( api_resource.slice(
......
...@@ -56,27 +56,12 @@ module QA ...@@ -56,27 +56,12 @@ module QA
end end
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 protected
# Return subset of fields for comparing milestones # Return subset of fields for comparing milestones
# #
# @return [Hash] # @return [Hash]
def comparable_milestone def comparable
reload! unless api_response reload! unless api_response
api_response.slice( api_response.slice(
......
...@@ -95,27 +95,12 @@ module QA ...@@ -95,27 +95,12 @@ module QA
) )
end 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 protected
# Return subset of fields for comparing issues # Return subset of fields for comparing issues
# #
# @return [Hash] # @return [Hash]
def comparable_issue def comparable
reload! if api_response.nil? reload! if api_response.nil?
api_resource.slice( api_resource.slice(
......
...@@ -49,27 +49,12 @@ module QA ...@@ -49,27 +49,12 @@ module QA
} }
end 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 protected
# Return subset of fields for comparing labels # Return subset of fields for comparing labels
# #
# @return [Hash] # @return [Hash]
def comparable_label def comparable
reload! unless api_response reload! unless api_response
api_response.slice( api_response.slice(
......
...@@ -168,27 +168,12 @@ module QA ...@@ -168,27 +168,12 @@ module QA
) )
end 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 protected
# Return subset of fields for comparing merge requests # Return subset of fields for comparing merge requests
# #
# @return [Hash] # @return [Hash]
def comparable_mr def comparable
reload! if api_response.nil? reload! if api_response.nil?
api_resource.except( api_resource.except(
......
...@@ -372,27 +372,12 @@ module QA ...@@ -372,27 +372,12 @@ module QA
api_post_to(api_wikis_path, title: title, content: content) api_post_to(api_wikis_path, title: title, content: content)
end 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 protected
# Return subset of fields for comparing projects # Return subset of fields for comparing projects
# #
# @return [Hash] # @return [Hash]
def comparable_project def comparable
reload! if api_response.nil? reload! if api_response.nil?
api_resource.slice( api_resource.slice(
......
...@@ -181,6 +181,15 @@ module QA ...@@ -181,6 +181,15 @@ module QA
) )
end end
protected
# Compare users by username and password
#
# @return [Array]
def comparable
[username, password]
end
private private
def ldap_post_body 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