From dcee32ae7a7ec2be9abe6baa670c3c43f3c5e69f Mon Sep 17 00:00:00 2001
From: Alexandre Arias <apa13@inf.ufpr.br>
Date: Fri, 16 Oct 2015 09:46:15 -0300
Subject: [PATCH] fix rid passing from object and double complaint

Signed-off-by: Alexandre Arias <apa13@inf.ufpr.br>
---
 app/controllers/complaints_controller.rb           |  4 ++--
 app/repositories/orient_db/complaint_repository.rb | 13 ++++++-------
 app/views/complaints/_form.html.erb                |  2 +-
 3 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/app/controllers/complaints_controller.rb b/app/controllers/complaints_controller.rb
index 26f48b71b..bb1bc86bd 100644
--- a/app/controllers/complaints_controller.rb
+++ b/app/controllers/complaints_controller.rb
@@ -6,8 +6,8 @@ class ComplaintsController < ApplicationController
   def create
     @complaint = Complaint.new(complaint_params)
     @complaint.user = current_user
-    @complaint.object = params[:object]
-    
+    @complaint.object = params[:complaint][:object_rid]
+
     respond_to do |format|
       if complaint_repository.report @complaint
         format.html { redirect_to @complaint, notice: 'complaint was successfully created.' }
diff --git a/app/repositories/orient_db/complaint_repository.rb b/app/repositories/orient_db/complaint_repository.rb
index 58dd7de10..416b6462d 100644
--- a/app/repositories/orient_db/complaint_repository.rb
+++ b/app/repositories/orient_db/complaint_repository.rb
@@ -4,19 +4,18 @@ module OrientDb
     include RepositoriesProxy
 
       def report(complaint)
-        if edge_exists?(odb_class, complaint.user.id, complaint.object.id)
-          raise "The user has already been reported"
+        if edge_exists?(odb_class, complaint.user.rid, complaint.object)
+          raise "The object has already been reported by you."
         end
-
-        connection.command "CREATE EDGE Complaint FROM #{complaint.user.id} TO #{complaint.object.id} SET message = #{complaint.message}, description = #{complaint.description}"
+        connection.command "CREATE EDGE Complaint FROM #{complaint.user.rid} TO #{complaint.object} SET message = #{complaint.message}, description = #{complaint.description}"
       end
 
       def destroy(object)
-        if !edge_exists?(odb_class, complaint.user.id, complaint.object.id)
-          raise "The user has not already been reported"
+        if !edge_exists?(odb_class, complaint.user.rid, complaint.object)
+          raise "The object has not been reported by you yet."
         end
 
-        connection.command "DELETE EDGE Complaint FROM #{complaint.user.id} TO #{complaint.object.id}"
+        connection.command "DELETE EDGE Complaint FROM #{complaint.user.rid} TO #{complaint.object}"
       end
 
       def build_object(args={})
diff --git a/app/views/complaints/_form.html.erb b/app/views/complaints/_form.html.erb
index 6abcde32d..aef72f5ba 100644
--- a/app/views/complaints/_form.html.erb
+++ b/app/views/complaints/_form.html.erb
@@ -21,7 +21,7 @@
 
   </div>
 
-  <%= f.hidden_field :object, value: @learning_object %>
+  <%= f.hidden_field :object_rid, value: @learning_object.id %>
   </fieldset>
 
   <div align="center" class="ls-btn-primary">
-- 
GitLab