diff --git a/app/controllers/v1/learning_objects_controller.rb b/app/controllers/v1/learning_objects_controller.rb index 81da21258866d5d74d2f41b1ad6b89eed6b39bce..2b274844ece406954e64eaf05ddf56eb59d880ad 100644 --- a/app/controllers/v1/learning_objects_controller.rb +++ b/app/controllers/v1/learning_objects_controller.rb @@ -39,7 +39,7 @@ class V1::LearningObjectsController < ApplicationController publisher = LearningObjectPublisher.new(DspaceService.create_client) if publisher.create_draft(learning_object, current_user) - learning_object_associations(learning_object) + learning_object_associations(learning_object, false) render json: learning_object, status: :created else render json: learning_object.errors, status: :unprocessable_entity @@ -49,7 +49,7 @@ class V1::LearningObjectsController < ApplicationController # PATCH/PUT /learning_objects/1 # PATCH/PUT /learning_objects/1.json def update - if !learning_object_params[:object_type_id].blank? && learning_object_params[:object_type_id] != @learning_object.object_type_id && learning_object_params[:link].blank? + if !learning_object_params[:object_type_id].blank? && learning_object_params[:object_type_id] != @learning_object.object_type_id && learning_object_params[:link].blank? change_object_type_id = true end if @learning_object.update(learning_object_params) @@ -119,8 +119,7 @@ class V1::LearningObjectsController < ApplicationController end learning_object.add_subjects(ids: extra_params[:subjects]) unless extra_params[:subjects].nil? learning_object.add_educational_stages(ids: extra_params[:educational_stages]) unless extra_params[:educational_stages].nil? - - if change_object_type_id + if change_object_type_id learning_object.link = nil end end diff --git a/spec/acceptance/downloads_spec.rb b/spec/acceptance/downloads_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..63526173338a8362af4875c793b3b78982287b9e --- /dev/null +++ b/spec/acceptance/downloads_spec.rb @@ -0,0 +1,28 @@ +require 'acceptance_helpers' +require 'shared/contexts' + +resource 'Downloads' do + + explanation "An user can download the content of a learning object or collection." + + get '/v1/:type/:id/download' do + include_context "authenticate_user" + + parameter :type, "Represents the type of object [‘learning_objects’,'collections']", scope: :download + parameter :id, "The id of object", scope: :download + + let(:type) { 'learning_objects' } + let(:id) { @learning_object.id } + + + before do + @learning_object = create(:learning_object, publisher: @user) + create(:attachment, learning_object: @learning_object) + end + + example_request 'Download an object' do + expect(status).to eq(302) + end + end + +end diff --git a/spec/factories/attachments.rb b/spec/factories/attachments.rb new file mode 100644 index 0000000000000000000000000000000000000000..4141d1e6493599412a40b9555cfbcdad6bef0d49 --- /dev/null +++ b/spec/factories/attachments.rb @@ -0,0 +1,10 @@ +FactoryGirl.define do + + factory :attachment, class: LearningObject::Attachment do |f| + f.name { Faker::Name.name } + f.retrieve_link { Faker::File.file_name } + f.mime_type { Faker::File.mime_type } + end + +end +