Write specs for GraphQL::AssociationResolver

This commit is contained in:
Alberto Miedes Garcés
2017-01-03 18:30:53 +01:00
parent cdc3b46370
commit 9cfb3eb52e
2 changed files with 77 additions and 14 deletions

View File

@@ -13,23 +13,24 @@ module GraphQL
filter_forbidden_elements(requested_elements)
end
def target_public_elements
target_model.respond_to?(:public_for_api) ? target_model.public_for_api : target_model.all
end
def filter_forbidden_elements(requested_elements)
if AssociationResolver.matching_exceptions.include?(field_name)
requested_elements
elsif requested_elements.respond_to?(:each)
requested_elements.all & allowed_elements.all
else
allowed_elements.include?(requested_elements) ? requested_elements : nil
end
end
def self.matching_exceptions
[:public_voter]
end
private
def target_public_elements
target_model.respond_to?(:public_for_api) ? target_model.public_for_api : target_model.all
end
def filter_forbidden_elements(requested_elements)
if AssociationResolver.matching_exceptions.include?(field_name)
requested_elements
elsif requested_elements.respond_to?(:each)
requested_elements.all & allowed_elements.all
else
allowed_elements.include?(requested_elements) ? requested_elements : nil
end
end
end
end