diff --git a/spec/acceptance/learning_objects_spec.rb b/spec/acceptance/learning_objects_spec.rb index 13a8a4f2019d4e938d9b0ef9621b6bd70185530c..fc2de13f7fd61021f80192fece9be8d7289a57c8 100644 --- a/spec/acceptance/learning_objects_spec.rb +++ b/spec/acceptance/learning_objects_spec.rb @@ -41,7 +41,7 @@ resource 'Learning Objects' do end post '/v1/learning_objects' do - include_context "authenticate_user" + include_context "authenticate_user_submitter" parameter :author, 'The author of a educational content', scope: :learning_object parameter :name, 'The name of the learning object', scope: :learning_object @@ -79,7 +79,7 @@ resource 'Learning Objects' do end put '/v1/learning_objects/:id' do - include_context "authenticate_user" + include_context "authenticate_user_submitter" parameter :author, 'The author of a educational content' parameter :name, 'The name of the learning object' @@ -159,12 +159,12 @@ resource 'Learning Objects' do end post '/v1/learning_objects/:id/publish' do - include_context "authenticate_user" + include_context "authenticate_user_moderator" let(:id) { @learning_object.id } before do - @learning_object = create(:learning_object, publisher: @user, state: LearningObject.states[:draft]) + @learning_object = create(:learning_object, publisher: @user, state: LearningObject.states[:submitted]) end example 'Publishing a learning object' do diff --git a/spec/shared/contexts.rb b/spec/shared/contexts.rb index 6fe0df567a93d0dadba7f94dd581d5e1677cf40d..672320ff84da667a48ca06ca92a2c5a46c4058a2 100644 --- a/spec/shared/contexts.rb +++ b/spec/shared/contexts.rb @@ -28,3 +28,68 @@ RSpec.shared_context "authenticate_user_admin", shared_context: :metadata do end end + +RSpec.shared_context "authenticate_user_submitter", shared_context: :metadata do + let(:auth_client) { @auth_headers['client'] } + let(:uid) { @auth_headers['uid'] } + let(:access_token) { @auth_headers['access-token'] } + let(:role) { Role.all } + + before do + @user = create(:user, roles: [role.find_by(name: 'submitter')]) + @auth_headers = @user.create_new_auth_token + end + +end + +RSpec.shared_context "authenticate_user_curator", shared_context: :metadata do + let(:auth_client) { @auth_headers['client'] } + let(:uid) { @auth_headers['uid'] } + let(:access_token) { @auth_headers['access-token'] } + let(:role) { Role.all } + + before do + @user = create(:user, roles: [role.find_by(name: 'curator')]) + @auth_headers = @user.create_new_auth_token + end + +end + +RSpec.shared_context "authenticate_user_moderator", shared_context: :metadata do + let(:auth_client) { @auth_headers['client'] } + let(:uid) { @auth_headers['uid'] } + let(:access_token) { @auth_headers['access-token'] } + let(:role) { Role.all } + + before do + @user = create(:user, roles: [role.find_by(name: 'moderator')]) + @auth_headers = @user.create_new_auth_token + end + +end + +RSpec.shared_context "authenticate_user_editor", shared_context: :metadata do + let(:auth_client) { @auth_headers['client'] } + let(:uid) { @auth_headers['uid'] } + let(:access_token) { @auth_headers['access-token'] } + let(:role) { Role.all } + + before do + @user = create(:user, roles: [role.find_by(name: 'editor')]) + @auth_headers = @user.create_new_auth_token + end + +end + +RSpec.shared_context "authenticate_user_supervisor", shared_context: :metadata do + let(:auth_client) { @auth_headers['client'] } + let(:uid) { @auth_headers['uid'] } + let(:access_token) { @auth_headers['access-token'] } + let(:role) { Role.all } + + before do + @user = create(:user, roles: [role.find_by(name: 'supervisor')]) + @auth_headers = @user.create_new_auth_token + end + +end