From 0a234a381b85fb5fe02c3ff4b2437d452848ca63 Mon Sep 17 00:00:00 2001 From: Mauricio Giacomini Girardello <mauriciogiacomini4@gmail.com> Date: Wed, 4 Nov 2015 10:14:37 -0200 Subject: [PATCH] change collection repository save method signature for save_learning_objects --- app/controllers/collections_controller.rb | 2 +- .../learning_objects_controller.rb | 2 +- .../orient_db/collection_repository.rb | 2 +- .../orient_db/collection_repository_test.rb | 21 +++++++++---------- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb index 1eac1a77..6c9587dc 100644 --- a/app/controllers/collections_controller.rb +++ b/app/controllers/collections_controller.rb @@ -64,7 +64,7 @@ class CollectionsController < ApplicationController def add_learning_object learning_object = learning_object_repository.find params[:learning_object_id] @collection.add learning_object - collection_repository.save @collection + collection_repository.save_learning_objects @collection if request.xhr? render json: {collections: @collection.learning_objects.as_json} diff --git a/app/controllers/learning_objects_controller.rb b/app/controllers/learning_objects_controller.rb index ac12721c..7d813085 100644 --- a/app/controllers/learning_objects_controller.rb +++ b/app/controllers/learning_objects_controller.rb @@ -81,7 +81,7 @@ class LearningObjectsController < ApplicationController def bookmarks bookmarks = current_user.bookmarks bookmarks.add @learning_object - collection_repository.save bookmarks + collection_repository.save_learning_objects bookmarks if request.xhr? render json: {id: params[:id]} diff --git a/app/repositories/orient_db/collection_repository.rb b/app/repositories/orient_db/collection_repository.rb index c64c4a70..ea63a1bd 100644 --- a/app/repositories/orient_db/collection_repository.rb +++ b/app/repositories/orient_db/collection_repository.rb @@ -7,7 +7,7 @@ module OrientDb CollectionBuilder.build_from_orientdb args end - def save(collection = Collection.new) + def save_learning_objects(collection = Collection.new) if collection.id.to_s.empty? raise NotPersistedRecordError, 'Before save learning objects to collection, you must persist using CollectionRepository::create method' end diff --git a/test/repositories/orient_db/collection_repository_test.rb b/test/repositories/orient_db/collection_repository_test.rb index 60862d4c..5e3745c5 100644 --- a/test/repositories/orient_db/collection_repository_test.rb +++ b/test/repositories/orient_db/collection_repository_test.rb @@ -7,23 +7,22 @@ class OrientDb::CollectionRepositoryTest < ActiveSupport::TestCase collection_repository = OrientDb::CollectionRepository.new odb_client assert_raise NotPersistedRecordError do - collection_repository.save Collection.new + collection_repository.save_learning_objects Collection.new end end test 'save learning objects to persisted collection' do + lo = LearningObject.new(id: '#14:14') + collection = Collection.new(id: '#12:12', learning_objects: [lo]) + + # setup orient4r mock + expected_mock_arg = sprintf("update %s add learning_objects = %s", collection.id, lo.id) odb_client = mock - odb_client.expect :command, nil + odb_client.expect :command, nil, [expected_mock_arg] + collection_repository = OrientDb::CollectionRepository.new odb_client - collection_repository.save Collection.new(id: '#12:12') - assert !mock.verify + collection_repository.save_learning_objects collection + assert mock.verify end - #def save(collection = Collection.new) - #collection.learning_objects.each do |learning_object| - # query = sprintf("update %s add learning_objects = %s", collection.id, learning_object.id) - # connection.command query - #end - #end - end \ No newline at end of file -- GitLab