Skip to content
Snippets Groups Projects
Commit 0a234a38 authored by Mauricio Giacomini Girardello's avatar Mauricio Giacomini Girardello
Browse files

change collection repository save method signature for save_learning_objects

parent 6b4e6938
No related branches found
No related tags found
No related merge requests found
......@@ -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}
......
......@@ -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]}
......
......@@ -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
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment