From e5f8bf7963069c4628acad71dd200601e77e8194 Mon Sep 17 00:00:00 2001
From: Mauricio Giacomini Girardello <mauriciogiacomini4@gmail.com>
Date: Thu, 12 Nov 2015 11:53:16 -0200
Subject: [PATCH] change CollectionRepository#owner signature. Now collection
 param can be an id or a Collection object

---
 app/repositories/orient_db/collection_repository.rb | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/app/repositories/orient_db/collection_repository.rb b/app/repositories/orient_db/collection_repository.rb
index 13a5200fe..073877d36 100644
--- a/app/repositories/orient_db/collection_repository.rb
+++ b/app/repositories/orient_db/collection_repository.rb
@@ -81,9 +81,11 @@ module OrientDb
     end
 
     # return owner of collection rid
-    def owner(collection_id)
-      edge = get_edges("BelongsTo", "out", collection_id).first
+    def owner(collection)
+      collection_id = collection
+      collection_id = collection.id if collection.class == Collection
 
+      edge = get_edges("BelongsTo", "out", collection_id).first
       owner = get_by_rid(edge["in"])
 
       if owner['@class'] == "User"
@@ -99,7 +101,7 @@ module OrientDb
       return false if collection.blank? || user.blank?
 
       if collection.owner.class == Institution
-        institution_repository.associated_with(user).each do |institution|
+        user.institutions.each do |institution|
           return true if institution.id == collection.owner.id
         end
       else
@@ -111,7 +113,7 @@ module OrientDb
     end
 
     def change_privacy(collection, privacy)
-      update_property(collection, 'privacy', privacy) if accepted_privacies(privacy)
+      update_property(collection, 'privacy', privacy) if privacy_accepted?(privacy)
     end
 
     private
@@ -120,7 +122,7 @@ module OrientDb
       ['privacy']
     end
 
-    def accepted_privacies(privacy)
+    def privacy_accepted?(privacy)
       ['private', 'public'].include? privacy
     end
 
-- 
GitLab